Commit ab38362c authored by Boudewijn Rempt's avatar Boudewijn Rempt

Merge branch 'master' into vector_compositioning_kazakov

parents ccd6514d 746e3ae9
...@@ -97,36 +97,59 @@ public: ...@@ -97,36 +97,59 @@ public:
float h, s, v, r, g, b; float h, s, v, r, g, b;
while (nPixels > 0) { while (nPixels > 0) {
if (m_type == 0) { if (m_colorize) {
RGBToHSV(SCALE_TO_FLOAT(src->red), SCALE_TO_FLOAT(src->green), SCALE_TO_FLOAT(src->blue), &h, &s, &v); h = m_adj_h;
h += m_adj_h; s = m_adj_s;
if (h > 360) h -= 360;
if (h < 0) h += 360; r = SCALE_TO_FLOAT(src->red);
s += m_adj_s; g = SCALE_TO_FLOAT(src->green);
v += m_adj_v; b = SCALE_TO_FLOAT(src->blue);
HSVToRGB(h, s, v, &r, &g, &b);
float luminance = r * 0.2126 + g * 0.7152 + b * 0.0722;
if (m_adj_v > 0) {
luminance *= (1.0 - m_adj_v);
luminance += 1.0 - (1.0 - m_adj_v);
}
else if (m_adj_v < 0 ){
luminance *= (m_adj_v + 1.0);
}
v = luminance;
HSLToRGB(h, s, v, &r, &g, &b);
} }
else { else {
RGBToHSL(SCALE_TO_FLOAT(src->red), SCALE_TO_FLOAT(src->green), SCALE_TO_FLOAT(src->blue), &h, &s, &v); if (m_type == 0) {
RGBToHSV(SCALE_TO_FLOAT(src->red), SCALE_TO_FLOAT(src->green), SCALE_TO_FLOAT(src->blue), &h, &s, &v);
h += m_adj_h;
if (h > 360) h -= 360;
if (h < 0) h += 360;
s += m_adj_s;
v += m_adj_v;
HSVToRGB(h, s, v, &r, &g, &b);
}
else {
h += m_adj_h; RGBToHSL(SCALE_TO_FLOAT(src->red), SCALE_TO_FLOAT(src->green), SCALE_TO_FLOAT(src->blue), &h, &s, &v);
if (h < 0)
h += 1.0;
else if (h > 1.0)
h -= 1.0;
s *= (m_adj_s + 1.0); h += m_adj_h;
if (s < 0.0) s = 0.0; if (h > 360) h -= 360;
if (s > 1.0) s = 1.0; if (h < 0) h += 360;
if (m_adj_v < 0) s *= (m_adj_s + 1.0);
v *= (m_adj_v + 1.0); if (s < 0.0) s = 0.0;
else if (s > 1.0) s = 1.0;
v += (m_adj_v * (1.0 - v));
if (m_adj_v < 0)
v *= (m_adj_v + 1.0);
else
v += (m_adj_v * (1.0 - v));
HSLToRGB(h, s, v, &r, &g, &b);
}
HSLToRGB(h, s, v, &r, &g, &b);
} }
clamp< _channel_type_ >(&r, &g, &b); clamp< _channel_type_ >(&r, &g, &b);
...@@ -144,7 +167,7 @@ public: ...@@ -144,7 +167,7 @@ public:
virtual QList<QString> parameters() const virtual QList<QString> parameters() const
{ {
QList<QString> list; QList<QString> list;
list << "h" << "s" << "v" << "type"; list << "h" << "s" << "v" << "type" << "colorize";
return list; return list;
} }
...@@ -158,6 +181,8 @@ public: ...@@ -158,6 +181,8 @@ public:
return 2; return 2;
} else if (name == "type") { } else if (name == "type") {
return 3; return 3;
} else if (name == "colorize") {
return 4;
} }
return -1; return -1;
} }
...@@ -184,8 +209,11 @@ public: ...@@ -184,8 +209,11 @@ public:
case 3: case 3:
m_type = parameter.toDouble(); m_type = parameter.toDouble();
break; break;
case 4:
m_colorize = parameter.toBool();
break;
default: default:
qFatal("Unknown parameter id %i", id); ;
} }
} }
...@@ -193,11 +221,12 @@ private: ...@@ -193,11 +221,12 @@ private:
double m_adj_h, m_adj_s, m_adj_v; double m_adj_h, m_adj_s, m_adj_v;
int m_type; int m_type;
bool m_colorize;
}; };
KisHSVAdjustmentFactory::KisHSVAdjustmentFactory() KisHSVAdjustmentFactory::KisHSVAdjustmentFactory()
: KoColorTransformationFactory("hsv_adjustment", i18n("HSV Adjustment")) : KoColorTransformationFactory("hsv_adjustment", i18n("HSV/HSL Adjustment"))
{ {
} }
......
...@@ -45,10 +45,18 @@ KoColorTransformation* KisHSVAdjustmentFilter::createTransformation(const KoColo ...@@ -45,10 +45,18 @@ KoColorTransformation* KisHSVAdjustmentFilter::createTransformation(const KoColo
{ {
QHash<QString, QVariant> params; QHash<QString, QVariant> params;
if (config) { if (config) {
params["h"] = config->getInt("h", 0) / 180.0; if (config->getBool("colorize")) {
params["h"] = config->getInt("h", 0.5) / 360.0;
}
else {
params["h"] = config->getInt("h", 0) / 180.0;
}
params["s"] = config->getInt("s", 0) * 0.01; params["s"] = config->getInt("s", 0) * 0.01;
params["v"] = config->getInt("v", 0) * 0.01; params["v"] = config->getInt("v", 0) * 0.01;
params["type"] = config->getInt("type", 1); params["type"] = config->getInt("type", 1);
params["colorize"] = config->getBool("colorize", false);
} }
return cs->createColorTransformation("hsv_adjustment", params); return cs->createColorTransformation("hsv_adjustment", params);
} }
...@@ -60,6 +68,7 @@ KisFilterConfiguration* KisHSVAdjustmentFilter::factoryConfiguration(const KisPa ...@@ -60,6 +68,7 @@ KisFilterConfiguration* KisHSVAdjustmentFilter::factoryConfiguration(const KisPa
config->setProperty("s", 0); config->setProperty("s", 0);
config->setProperty("v", 0); config->setProperty("v", 0);
config->setProperty("type", 1); config->setProperty("type", 1);
config->setProperty("colorize", false);
return config; return config;
} }
...@@ -72,6 +81,7 @@ KisHSVConfigWidget::KisHSVConfigWidget(QWidget * parent, Qt::WFlags f) : KisConf ...@@ -72,6 +81,7 @@ KisHSVConfigWidget::KisHSVConfigWidget(QWidget * parent, Qt::WFlags f) : KisConf
connect(m_page->hue, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged())); connect(m_page->hue, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged()));
connect(m_page->value, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged())); connect(m_page->value, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged()));
connect(m_page->saturation, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged())); connect(m_page->saturation, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged()));
connect(m_page->chkColorize, SIGNAL(toggled(bool)), SLOT(switchColorize(bool)));
} }
KisHSVConfigWidget::~KisHSVConfigWidget() KisHSVConfigWidget::~KisHSVConfigWidget()
...@@ -86,6 +96,7 @@ KisPropertiesConfiguration * KisHSVConfigWidget::configuration() const ...@@ -86,6 +96,7 @@ KisPropertiesConfiguration * KisHSVConfigWidget::configuration() const
c->setProperty("s", m_page->saturation->value()); c->setProperty("s", m_page->saturation->value());
c->setProperty("v", m_page->value->value()); c->setProperty("v", m_page->value->value());
c->setProperty("type", m_page->cmbType->currentIndex()); c->setProperty("type", m_page->cmbType->currentIndex());
c->setProperty("colorize", m_page->chkColorize->isChecked());
return c; return c;
} }
...@@ -95,6 +106,7 @@ void KisHSVConfigWidget::setConfiguration(const KisPropertiesConfiguration * con ...@@ -95,6 +106,7 @@ void KisHSVConfigWidget::setConfiguration(const KisPropertiesConfiguration * con
m_page->hue->setValue(config->getInt("h", 0)); m_page->hue->setValue(config->getInt("h", 0));
m_page->saturation->setValue(config->getInt("s", 0)); m_page->saturation->setValue(config->getInt("s", 0));
m_page->value->setValue(config->getInt("v", 0)); m_page->value->setValue(config->getInt("v", 0));
m_page->chkColorize->setChecked(config->getBool("colorize", false));
switchType(m_page->cmbType->currentIndex()); switchType(m_page->cmbType->currentIndex());
} }
...@@ -112,3 +124,22 @@ void KisHSVConfigWidget::switchType(int index) ...@@ -112,3 +124,22 @@ void KisHSVConfigWidget::switchType(int index)
} }
} }
void KisHSVConfigWidget::switchColorize(bool toggle)
{
if (toggle) {
m_page->hue->setMinimum(0);
m_page->hue->setMaximum(360);
m_page->saturation->setMinimum(0);
m_page->saturation->setMaximum(100);
switchType(1);
}
else {
m_page->hue->setMinimum(-180);
m_page->hue->setMaximum(180);
m_page->saturation->setMinimum(-100);
m_page->saturation->setMaximum(100);
}
emit sigConfigurationItemChanged();
}
...@@ -74,6 +74,7 @@ public: ...@@ -74,6 +74,7 @@ public:
private slots: private slots:
void switchType(int index); void switchType(int index);
void switchColorize(bool toggle);
}; };
#endif #endif
...@@ -20,15 +20,31 @@ ...@@ -20,15 +20,31 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Hue:</string> <string>&amp;Hue:</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
<property name="buddy">
<cstring>hue</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="5" column="0" colspan="2">
<widget class="KIntNumInput" name="hue"> <spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="KIntNumInput" name="saturation">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
...@@ -36,10 +52,29 @@ ...@@ -36,10 +52,29 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimum"> <property name="minimum">
<number>-180</number> <number>-100</number>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>180</number> <number>100</number>
</property>
<property name="sliderEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="KIntNumInput" name="value">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<number>-100</number>
</property>
<property name="maximum">
<number>100</number>
</property> </property>
<property name="sliderEnabled"> <property name="sliderEnabled">
<bool>true</bool> <bool>true</bool>
...@@ -55,7 +90,7 @@ ...@@ -55,7 +90,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Saturation:</string> <string>&amp;Saturation:</string>
</property> </property>
<property name="scaledContents"> <property name="scaledContents">
<bool>false</bool> <bool>false</bool>
...@@ -63,29 +98,23 @@ ...@@ -63,29 +98,23 @@
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
<property name="buddy">
<cstring>saturation</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="0" column="0">
<widget class="KIntNumInput" name="saturation"> <widget class="QLabel" name="lblType">
<property name="sizePolicy"> <property name="text">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <string>Type:</string>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<number>-100</number>
</property>
<property name="maximum">
<number>100</number>
</property> </property>
<property name="sliderEnabled"> <property name="buddy">
<bool>true</bool> <cstring>cmbType</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="1" column="1">
<widget class="KIntNumInput" name="value"> <widget class="KIntNumInput" name="hue">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
...@@ -93,29 +122,16 @@ ...@@ -93,29 +122,16 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimum"> <property name="minimum">
<number>-100</number> <number>-180</number>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>100</number> <number>180</number>
</property> </property>
<property name="sliderEnabled"> <property name="sliderEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0" colspan="2">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
...@@ -124,6 +140,9 @@ ...@@ -124,6 +140,9 @@
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
<property name="buddy">
<cstring>value</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
...@@ -143,13 +162,10 @@ ...@@ -143,13 +162,10 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="4" column="1">
<widget class="QLabel" name="lblType"> <widget class="QCheckBox" name="chkColorize">
<property name="text"> <property name="text">
<string>Type:</string> <string>&amp;Colorize</string>
</property>
<property name="buddy">
<cstring>cmbType</cstring>
</property> </property>
</widget> </widget>
</item> </item>
......
...@@ -38,9 +38,9 @@ int KoColorTransformation::parameterId(const QString& name) const ...@@ -38,9 +38,9 @@ int KoColorTransformation::parameterId(const QString& name) const
void KoColorTransformation::setParameter(int id, const QVariant& parameter) void KoColorTransformation::setParameter(int id, const QVariant& parameter)
{ {
Q_UNUSED(id); Q_UNUSED(id);
Q_UNUSED(parameter); Q_UNUSED(parameter);
qFatal("No parameter for this transformation"); qFatal("No parameter for this transformation");
} }
void KoColorTransformation::setParameters(const QHash<QString, QVariant> & parameters) void KoColorTransformation::setParameters(const QHash<QString, QVariant> & parameters)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment