12#include <klocalizedstring.h>
31enum class SLIDER_TYPE {
45enum class SLIDER_SET {
46 HSV, HSL, HSI, HSY, YUV,
49struct SliderSettings {
50 SliderSettings(SLIDER_TYPE type,
KisHsvColorSlider::MIX_MODE mixMode,
const KLocalizedString &title,
int min,
int max,
int minRelative,
int maxRelative,
int resetValue)
56 , m_minRelative(minRelative)
57 , m_maxRelative(maxRelative)
58 , m_resetValue(resetValue)
62 void apply(QLabel *label,
KisHsvColorSlider *slider, QSpinBox *spinBox,
bool prevColorize,
bool colorize)
const {
63 int value = slider->value();
65 const int min = colorize ? m_min : m_minRelative;
66 const int max = colorize ? m_max : m_maxRelative;
68 label->setText(m_title.toString());
69 slider->setMinimum(min);
70 slider->setMaximum(max);
71 spinBox->setMinimum(min);
72 spinBox->setMaximum(max);
74 if (prevColorize != colorize) {
80 spinBox->setValue(
value);
81 slider->setValue(
value);
84 void recolor(
KisHsvColorSlider *slider, SLIDER_SET set,
bool colorize, qreal nHue, qreal nSaturation, qreal nValue) {
86 SLIDER_TYPE type = m_type;
90 case SLIDER_TYPE::HUE:
92 nHue = fmod(nHue + 0.5, 1);
94 case SLIDER_TYPE::GREEN_RED:
95 case SLIDER_TYPE::YELLOW_BLUE:
107 if (m_type == SLIDER_TYPE::LUMA_YUV) {
108 type = SLIDER_TYPE::LUMA;
114 case SLIDER_TYPE::HUE: {
119 slider->
setColors(nHue, 1, 1, nHue, 1, 1);
124 case SLIDER_TYPE::SATURATION: {
127 case SLIDER_SET::HSY:
131 case SLIDER_SET::HSI:
135 case SLIDER_SET::HSL:
140 case SLIDER_SET::HSV:
145 slider->
setColors(nHue, 0, nValue, nHue, 1, nValue);
149 case SLIDER_TYPE::VALUE:
150 case SLIDER_TYPE::LIGHTNESS:
151 case SLIDER_TYPE::LUMA:
152 case SLIDER_TYPE::INTENSITY: {
153 slider->
setColors(nHue, nSaturation, 0, nHue, nSaturation, 1);
157 case SLIDER_TYPE::GREEN_RED:
158 case SLIDER_TYPE::YELLOW_BLUE:
159 case SLIDER_TYPE::LUMA_YUV: {
162 qreal minR, minG, minB;
163 qreal maxR, maxG, maxB;
165 if (m_type == SLIDER_TYPE::GREEN_RED) {
166 YUVToRGB(nValue, nHue, 0, &minR, &minG, &minB);
167 YUVToRGB(nValue, nHue, 1, &maxR, &maxG, &maxB);
168 }
else if (m_type == SLIDER_TYPE::YELLOW_BLUE) {
169 YUVToRGB(nValue, 0, nSaturation, &minR, &minG, &minB);
170 YUVToRGB(nValue, 1, nSaturation, &maxR, &maxG, &maxB);
172 YUVToRGB(0, nHue, nSaturation, &minR, &minG, &minB);
173 YUVToRGB(1, nHue, nSaturation, &maxR, &maxG, &maxB);
177 minR = qBound(0.0, minR, 1.0);
178 minG = qBound(0.0, minG, 1.0);
179 minB = qBound(0.0, minB, 1.0);
181 maxR = qBound(0.0, maxR, 1.0);
182 maxG = qBound(0.0, maxG, 1.0);
183 maxB = qBound(0.0, maxB, 1.0);
186 minC.setRgbF(minR, minG, minB);
187 maxC.setRgbF(maxR, maxG, maxB);
199 slider->setValue(m_resetValue);
202 double scale(
bool colorize,
double value)
const {
204 return value / m_max;
206 return value / m_maxRelative;
211 return (
value - m_min) / (m_max - m_min);
213 return (
value - m_minRelative) / (m_maxRelative - m_minRelative);
218 KLocalizedString m_title;
220 int m_minRelative, m_maxRelative;
225const SliderSettings SLIDER_TABLE[9] = {
239const std::array<SLIDER_TYPE, 3> SLIDER_SETS[5] = {
240 { SLIDER_TYPE::HUE, SLIDER_TYPE::SATURATION, SLIDER_TYPE::VALUE },
241 { SLIDER_TYPE::HUE, SLIDER_TYPE::SATURATION, SLIDER_TYPE::LIGHTNESS },
242 { SLIDER_TYPE::HUE, SLIDER_TYPE::SATURATION, SLIDER_TYPE::INTENSITY },
243 { SLIDER_TYPE::HUE, SLIDER_TYPE::SATURATION, SLIDER_TYPE::LUMA },
244 { SLIDER_TYPE::YELLOW_BLUE, SLIDER_TYPE::GREEN_RED, SLIDER_TYPE::LUMA_YUV },
247SliderSettings sliderSetting(SLIDER_TYPE type) {
248 return SLIDER_TABLE[
static_cast<int>(type)];
268 QHash<QString, QVariant> params;
270 int type = config->getInt(
"type", 1);
271 bool colorize = config->getBool(
"colorize",
false);
272 bool compatibilityMode = config->getBool(
"compatibilityMode",
true);
274 const std::array<SLIDER_TYPE, 3> sliderSet = SLIDER_SETS[
static_cast<int>(type)];
276 params[
"h"] = sliderSetting(sliderSet[0]).scale(colorize, config->getInt(
"h", 0));
277 params[
"s"] = sliderSetting(sliderSet[1]).scale(colorize, config->getInt(
"s", 0));
278 params[
"v"] = sliderSetting(sliderSet[2]).scale(colorize, config->getInt(
"v", 0));
280 params[
"type"] = type;
281 params[
"colorize"] = colorize;
285 params[
"compatibilityMode"] = compatibilityMode;
293 config->setProperty(
"h", 0);
294 config->setProperty(
"s", 0);
295 config->setProperty(
"v", 0);
296 config->setProperty(
"type", 1);
297 config->setProperty(
"colorize",
false);
298 config->setProperty(
"compatibilityMode",
false);
304 , m_prevColorize(false)
306 m_page =
new Ui_WdgHSVAdjustment();
319 connect(
m_page->hSpinBox, SIGNAL(valueChanged(
int)),
m_page->hSlider, SLOT(setValue(
int)));
320 connect(
m_page->sSpinBox, SIGNAL(valueChanged(
int)),
m_page->sSlider, SLOT(setValue(
int)));
321 connect(
m_page->vSpinBox, SIGNAL(valueChanged(
int)),
m_page->vSlider, SLOT(setValue(
int)));
323 connect(
m_page->hSlider, SIGNAL(valueChanged(
int)),
m_page->hSpinBox, SLOT(setValue(
int)));
324 connect(
m_page->sSlider, SIGNAL(valueChanged(
int)),
m_page->sSpinBox, SLOT(setValue(
int)));
325 connect(
m_page->vSlider, SIGNAL(valueChanged(
int)),
m_page->vSpinBox, SLOT(setValue(
int)));
340 c->setProperty(
"h",
m_page->hSlider->value());
341 c->setProperty(
"s",
m_page->sSlider->value());
342 c->setProperty(
"v",
m_page->vSlider->value());
343 c->setProperty(
"type",
m_page->cmbType->currentIndex());
344 c->setProperty(
"colorize",
m_page->chkColorize->isChecked());
345 c->setProperty(
"compatibilityMode",
m_page->chkCompatibilityMode->isChecked());
351 const int type = config->getInt(
"type", 1);
352 m_page->cmbType->setCurrentIndex(type);
353 m_page->chkColorize->setChecked(config->getBool(
"colorize",
false));
354 m_page->hSlider->setValue(config->getInt(
"h", 0));
355 m_page->sSlider->setValue(config->getInt(
"s", 0));
356 m_page->vSlider->setValue(config->getInt(
"v", 0));
357 m_page->chkCompatibilityMode->setChecked(config->getInt(
"compatibilityMode",
true));
366 const std::array<SLIDER_TYPE, 3> sliderSet = SLIDER_SETS[
m_page->cmbType->currentIndex()];
367 const bool colorize =
m_page->chkColorize->isChecked();
379 const bool compat = !
m_page->chkColorize->isChecked() &&
m_page->cmbType->currentIndex() <= 3;
381 m_page->chkCompatibilityMode->setEnabled(compat);
389 const SLIDER_SET set =
static_cast<SLIDER_SET
>(
m_page->cmbType->currentIndex());
390 const std::array<SLIDER_TYPE, 3> sliderSet = SLIDER_SETS[
m_page->cmbType->currentIndex()];
391 const bool colorize =
m_page->chkColorize->isChecked();
393 const double nh = sliderSetting(sliderSet[0]).normalize(colorize,
m_page->hSlider->value());
394 const double ns = sliderSetting(sliderSet[1]).normalize(colorize,
m_page->sSlider->value());
395 const double nv = sliderSetting(sliderSet[2]).normalize(colorize,
m_page->vSlider->value());
397 sliderSetting(sliderSet[0]).recolor(
m_page->hSlider, set, colorize, nh, ns, nv);
398 sliderSetting(sliderSet[1]).recolor(
m_page->sSlider, set, colorize, nh, ns, nv);
399 sliderSetting(sliderSet[2]).recolor(
m_page->vSlider, set, colorize, nh, ns, nv);
404 const std::array<SLIDER_TYPE, 3> sliderSet = SLIDER_SETS[
m_page->cmbType->currentIndex()];
406 sliderSetting(sliderSet[0]).reset(
m_page->hSlider);
407 sliderSetting(sliderSet[1]).reset(
m_page->sSlider);
408 sliderSetting(sliderSet[2]).reset(
m_page->vSlider);
float value(const T *src, size_t ch)
void YUVToRGB(const qreal y, const qreal u, const qreal v, qreal *r, qreal *g, qreal *b, qreal R, qreal G, qreal B)
const KoID YCbCrAColorModelID("YCbCrA", ki18n("YCbCr/Alpha"))
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static KisResourcesInterfaceSP instance()
KisFilterConfigurationSP defaultConfiguration(KisResourcesInterfaceSP resourcesInterface) const override
KoColorTransformation * createTransformation(const KoColorSpace *cs, const KisFilterConfigurationSP config) const override
KisConfigWidget * createConfigurationWidget(QWidget *parent, const KisPaintDeviceSP dev, bool useForMasks) const override
QVector< qreal > lumaCoefficients
KoColorTransformation * createColorTransformation(const QString &id, const QHash< QString, QVariant > ¶meters) const
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
const KoID FiltersCategoryAdjustId("adjust_filters", ki18nc("The category of color adjustment filters, like levels. Verb.", "Adjust"))
Point normalize(const Point &a)
constexpr std::enable_if< sizeof...(values)==0, size_t >::type max()
void setShortcut(const QKeySequence &shortcut)
void setSupportsPainting(bool v)
void setColors(const KoColor minColor, const KoColor maxColor)
void setCircularHue(bool)
void setMixMode(MIX_MODE mode)
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()