diff --git a/data/pref.xml b/data/pref.xml
index 14141a8b0..b91a6039e 100644
--- a/data/pref.xml
+++ b/data/pref.xml
@@ -101,10 +101,6 @@
-
-
-
-
@@ -352,7 +348,7 @@
diff --git a/src/app/commands/filters/cmd_hue_saturation.cpp b/src/app/commands/filters/cmd_hue_saturation.cpp
index bf21a72af..b4f1fb7f0 100644
--- a/src/app/commands/filters/cmd_hue_saturation.cpp
+++ b/src/app/commands/filters/cmd_hue_saturation.cpp
@@ -1,5 +1,5 @@
// Aseprite
-// Copyright (C) 2019 Igara Studio S.A.
+// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2017-2018 David Capello
//
// This program is distributed under the terms of
@@ -35,10 +35,12 @@
namespace app {
+using Mode = filters::HueSaturationFilter::Mode;
+
struct HueSaturationParams : public NewParams {
Param ui { this, true, "ui" };
Param channels { this, 0, "channels" };
- Param mode { this, filters::HueSaturationFilter::Mode::HSL, "mode" };
+ Param mode { this, Mode::HSL_MUL, "mode" };
Param hue { this, 0.0, "hue" };
Param saturation { this, 0.0, "saturation" };
Param lightness { this, 0.0, { "lightness", "value" } };
@@ -62,13 +64,17 @@ public:
getContainer()->addChild(&m_colorType);
getContainer()->addChild(&m_sliders);
+ static_assert(int(Mode::HSV_MUL) == 0 &&
+ int(Mode::HSL_MUL) == 1 &&
+ int(Mode::HSV_ADD) == 2 &&
+ int(Mode::HSL_ADD) == 3,
+ "Adjust widget showing filters::HueSaturationFilter::Mode enum");
auto mode = Preferences::instance().hueSaturation.mode();
m_colorType.addItem("HSV")->setFocusStop(false);
m_colorType.addItem("HSL")->setFocusStop(false);
- if (mode == gen::HueSaturationMode::HSV)
- m_colorType.setSelectedItem(0);
- else
- m_colorType.setSelectedItem(1);
+ m_colorType.addItem("HSV+")->setFocusStop(false);
+ m_colorType.addItem("HSL+")->setFocusStop(false);
+ m_colorType.setSelectedItem(int(mode));
m_colorType.ItemChange.connect(base::Bind(&HueSaturationWindow::onChangeMode, this));
m_sliders.setColorType(app::Color::HslType);
@@ -78,24 +84,21 @@ public:
onChangeMode();
}
+ Mode mode() const {
+ return Mode(m_colorType.selectedItem());
+ }
+
private:
bool isHsl() const {
- return (m_colorType.selectedItem() == 1);
+ return (mode() == Mode::HSL_MUL ||
+ mode() == Mode::HSL_ADD);
}
void onChangeMode() {
- const int isHsl = this->isHsl();
-
- Preferences::instance().hueSaturation.mode
- (isHsl ? gen::HueSaturationMode::HSL:
- gen::HueSaturationMode::HSV);
-
- m_filter.setMode(isHsl ?
- HueSaturationFilter::Mode::HSL:
- HueSaturationFilter::Mode::HSV);
-
- m_sliders.setColorType(isHsl ?
+ Preferences::instance().hueSaturation.mode(mode());
+ m_filter.setMode(mode());
+ m_sliders.setColorType(isHsl() ?
app::Color::HslType:
app::Color::HsvType);
@@ -139,8 +142,8 @@ public:
HueSaturationCommand();
protected:
- bool onEnabled(Context* context) override;
- void onExecute(Context* context) override;
+ bool onEnabled(Context* ctx) override;
+ void onExecute(Context* ctx) override;
};
HueSaturationCommand::HueSaturationCommand()
@@ -148,20 +151,20 @@ HueSaturationCommand::HueSaturationCommand()
{
}
-bool HueSaturationCommand::onEnabled(Context* context)
+bool HueSaturationCommand::onEnabled(Context* ctx)
{
- return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
- ContextFlags::HasActiveSprite);
+ return ctx->checkFlags(ContextFlags::ActiveDocumentIsWritable |
+ ContextFlags::HasActiveSprite);
}
-void HueSaturationCommand::onExecute(Context* context)
+void HueSaturationCommand::onExecute(Context* ctx)
{
#ifdef ENABLE_UI
- const bool ui = (params().ui() && context->isUIAvailable());
+ const bool ui = (params().ui() && ctx->isUIAvailable());
#endif
HueSaturationFilter filter;
- FilterManagerImpl filterMgr(context, &filter);
+ FilterManagerImpl filterMgr(ctx, &filter);
if (params().mode.isSet()) filter.setMode(params().mode());
if (params().hue.isSet()) filter.setHue(params().hue());
if (params().saturation.isSet()) filter.setSaturation(params().saturation() / 100.0);
diff --git a/src/app/commands/new_params.cpp b/src/app/commands/new_params.cpp
index be83c5dd0..db3abd8c4 100644
--- a/src/app/commands/new_params.cpp
+++ b/src/app/commands/new_params.cpp
@@ -158,10 +158,15 @@ void Param::fromString(const std::string& value)
template<>
void Param::fromString(const std::string& value)
{
- if (base::utf8_icmp(value, "hsv") == 0)
- setValue(filters::HueSaturationFilter::Mode::HSV);
+ if (base::utf8_icmp(value, "hsv") == 0 ||
+ base::utf8_icmp(value, "hsv_mul") == 0)
+ setValue(filters::HueSaturationFilter::Mode::HSV_MUL);
+ else if (base::utf8_icmp(value, "hsv_add") == 0)
+ setValue(filters::HueSaturationFilter::Mode::HSV_ADD);
+ else if (base::utf8_icmp(value, "hsl_add") == 0)
+ setValue(filters::HueSaturationFilter::Mode::HSL_ADD);
else
- setValue(filters::HueSaturationFilter::Mode::HSL);
+ setValue(filters::HueSaturationFilter::Mode::HSL_MUL);
}
template<>
diff --git a/src/app/pref/preferences.h b/src/app/pref/preferences.h
index b12577102..ee426c16a 100644
--- a/src/app/pref/preferences.h
+++ b/src/app/pref/preferences.h
@@ -26,6 +26,7 @@
#include "doc/frame.h"
#include "doc/layer_list.h"
#include "doc/sprite.h"
+#include "filters/hue_saturation_filter.h"
#include "filters/tiled_mode.h"
#include "gfx/rect.h"
#include "render/onionskin_position.h"
diff --git a/src/app/script/values.cpp b/src/app/script/values.cpp
index 3811acfea..4db3f81dc 100644
--- a/src/app/script/values.cpp
+++ b/src/app/script/values.cpp
@@ -151,7 +151,6 @@ FOR_ENUM(app::gen::ColorProfileBehavior)
FOR_ENUM(app::gen::EyedropperChannel)
FOR_ENUM(app::gen::EyedropperSample)
FOR_ENUM(app::gen::FillReferTo)
-FOR_ENUM(app::gen::HueSaturationMode)
FOR_ENUM(app::gen::OnionskinType)
FOR_ENUM(app::gen::PaintingCursorType)
FOR_ENUM(app::gen::PivotPosition)
@@ -169,6 +168,7 @@ FOR_ENUM(app::tools::RotationAlgorithm)
FOR_ENUM(doc::AniDir)
FOR_ENUM(doc::BrushPattern)
FOR_ENUM(doc::ColorMode)
+FOR_ENUM(filters::HueSaturationFilter::Mode)
FOR_ENUM(filters::TiledMode)
FOR_ENUM(render::OnionskinPosition)
diff --git a/src/filters/hue_saturation_filter.cpp b/src/filters/hue_saturation_filter.cpp
index 1ede7b0cc..f3cd8ee0f 100644
--- a/src/filters/hue_saturation_filter.cpp
+++ b/src/filters/hue_saturation_filter.cpp
@@ -34,7 +34,7 @@ const char* HueSaturationFilter::getName()
}
HueSaturationFilter::HueSaturationFilter()
- : m_mode(Mode::HSL)
+ : m_mode(Mode::HSL_MUL)
, m_h(0.0)
, m_s(0.0)
, m_l(0.0)
@@ -200,7 +200,9 @@ void HueSaturationFilter::onApplyToPalette(FilterManager* filterMgr,
template
-void HueSaturationFilter::applyFilterToRgbT(const Target target, doc::color_t& c)
+void HueSaturationFilter::applyFilterToRgbT(const Target target,
+ doc::color_t& c,
+ bool multiply)
{
int r = rgba_getr(c);
int g = rgba_getg(c);
@@ -213,10 +215,12 @@ void HueSaturationFilter::applyFilterToRgbT(const Target target, doc::color_t& c
while (h < 0.0) h += 360.0;
h = std::fmod(h, 360.0);
- double s = hsl.saturation()*(1.0+m_s);
+ double s = (multiply ? hsl.saturation()*(1.0+m_s):
+ hsl.saturation() + m_s);
s = base::clamp(s, 0.0, 1.0);
- double l = (hsl.*get_lightness)()*(1.0+m_l);
+ double l = (multiply ? (hsl.*get_lightness)()*(1.0+m_l):
+ (hsl.*get_lightness)() + m_l);
l = base::clamp(l, 0.0, 1.0);
hsl.hue(h);
@@ -238,15 +242,25 @@ void HueSaturationFilter::applyFilterToRgbT(const Target target, doc::color_t& c
void HueSaturationFilter::applyFilterToRgb(const Target target, doc::color_t& color)
{
switch (m_mode) {
- case Mode::HSL:
- applyFilterToRgbT(target, color);
- break;
- case Mode::HSV:
+ case Mode::HSV_MUL:
applyFilterToRgbT(target, color);
+ &gfx::Hsv::value>(target, color, true);
+ break;
+ case Mode::HSL_MUL:
+ applyFilterToRgbT(target, color, true);
+ break;
+ case Mode::HSV_ADD:
+ applyFilterToRgbT(target, color, false);
+ break;
+ case Mode::HSL_ADD:
+ applyFilterToRgbT(target, color, false);
break;
}
}
diff --git a/src/filters/hue_saturation_filter.h b/src/filters/hue_saturation_filter.h
index 09f91d5fc..329666d91 100644
--- a/src/filters/hue_saturation_filter.h
+++ b/src/filters/hue_saturation_filter.h
@@ -17,7 +17,10 @@ namespace filters {
class HueSaturationFilter : public FilterWithPalette {
public:
- enum class Mode { HSL, HSV };
+ enum class Mode {
+ HSV_MUL, HSL_MUL,
+ HSV_ADD, HSL_ADD,
+ };
HueSaturationFilter();
@@ -40,7 +43,7 @@ namespace filters {
template
- void applyFilterToRgbT(const Target target, doc::color_t& color);
+ void applyFilterToRgbT(const Target target, doc::color_t& color, bool multiply);
void applyFilterToRgb(const Target target, doc::color_t& color);
Mode m_mode;