Support applying Hue/Saturation filter in selected palette entries

This commit is contained in:
David Capello 2017-06-21 22:31:18 -03:00
parent 6f1f7e41bf
commit 4834ff3320
4 changed files with 32 additions and 3 deletions

View File

@ -20,7 +20,9 @@
#include "app/modules/editors.h"
#include "app/modules/palettes.h"
#include "app/transaction.h"
#include "app/ui/color_bar.h"
#include "app/ui/editor/editor.h"
#include "app/ui/palette_view.h"
#include "doc/algorithm/shrink_bounds.h"
#include "doc/cel.h"
#include "doc/image.h"
@ -360,6 +362,17 @@ Palette* FilterManagerImpl::getNewPalette()
return m_site.sprite()->palette(m_site.frame());
}
doc::PalettePicks FilterManagerImpl::getPalettePicks()
{
doc::PalettePicks picks;
ColorBar::instance()
->getPaletteView()
->getSelectedEntries(picks);
if (picks.picks() == 0)
picks.all();
return picks;
}
void FilterManagerImpl::init(Cel* cel)
{
ASSERT(cel);

View File

@ -109,6 +109,7 @@ namespace app {
const doc::Palette* getPalette() const override;
const doc::RgbMap* getRgbMap() const override;
doc::Palette* getNewPalette() override;
doc::PalettePicks getPalettePicks() override;
private:
void init(doc::Cel* cel);

View File

@ -10,6 +10,7 @@
namespace doc {
class Palette;
class PalettePicks;
class RgbMap;
}
@ -26,6 +27,10 @@ namespace filters {
// If a filter ask for a new palette, it means that the filter
// will modify the palette instead of pixels.
virtual doc::Palette* getNewPalette() = 0;
// Get the selected palettes to be modified by a palette filter
// (e.g. HueSaturationFilter).
virtual doc::PalettePicks getPalettePicks() = 0;
};
} // namespace filters

View File

@ -12,6 +12,7 @@
#include "doc/image.h"
#include "doc/palette.h"
#include "doc/palette_picks.h"
#include "doc/rgbmap.h"
#include "filters/filter_indexed_data.h"
#include "filters/filter_manager.h"
@ -154,11 +155,19 @@ void HueSaturationFilter::applyToIndexed(FilterManager* filterMgr)
if (!filterMgr->isFirstRow())
return;
const Palette* pal = filterMgr->getIndexedData()->getPalette();
FilterIndexedData* fid = filterMgr->getIndexedData();
const Target target = filterMgr->getTarget();
Palette* newPal = filterMgr->getIndexedData()->getNewPalette();
const Palette* pal = fid->getPalette();
PalettePicks picks = fid->getPalettePicks();
Palette* newPal = fid->getNewPalette();
int i = 0;
for (bool state : picks) {
if (!state) {
++i;
continue;
}
for (int i=0; i<newPal->size(); ++i) {
color_t c = pal->getEntry(i);
int r = rgba_getr(c);
int g = rgba_getg(c);
@ -197,6 +206,7 @@ void HueSaturationFilter::applyToIndexed(FilterManager* filterMgr)
}
newPal->setEntry(i, c);
++i;
}
}