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:
float h, s, v, r, g, b;
while (nPixels > 0) {
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);
if (m_colorize) {
h = m_adj_h;
s = m_adj_s;
r = SCALE_TO_FLOAT(src->red);
g = SCALE_TO_FLOAT(src->green);
b = SCALE_TO_FLOAT(src->blue);
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 {
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;
if (h < 0)
h += 1.0;
else if (h > 1.0)
h -= 1.0;
RGBToHSL(SCALE_TO_FLOAT(src->red), SCALE_TO_FLOAT(src->green), SCALE_TO_FLOAT(src->blue), &h, &s, &v);
s *= (m_adj_s + 1.0);
if (s < 0.0) s = 0.0;
if (s > 1.0) s = 1.0;
h += m_adj_h;
if (h > 360) h -= 360;
if (h < 0) h += 360;
if (m_adj_v < 0)
v *= (m_adj_v + 1.0);
else
v += (m_adj_v * (1.0 - v));
s *= (m_adj_s + 1.0);
if (s < 0.0) s = 0.0;
if (s > 1.0) s = 1.0;
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);
......@@ -144,7 +167,7 @@ public:
virtual QList<QString> parameters() const
{
QList<QString> list;
list << "h" << "s" << "v" << "type";
list << "h" << "s" << "v" << "type" << "colorize";
return list;
}
......@@ -158,6 +181,8 @@ public:
return 2;
} else if (name == "type") {
return 3;
} else if (name == "colorize") {
return 4;
}
return -1;
}
......@@ -184,8 +209,11 @@ public:
case 3:
m_type = parameter.toDouble();
break;
case 4:
m_colorize = parameter.toBool();
break;
default:
qFatal("Unknown parameter id %i", id);
;
}
}
......@@ -193,11 +221,12 @@ private:
double m_adj_h, m_adj_s, m_adj_v;
int m_type;
bool m_colorize;
};
KisHSVAdjustmentFactory::KisHSVAdjustmentFactory()
: KoColorTransformationFactory("hsv_adjustment", i18n("HSV Adjustment"))
: KoColorTransformationFactory("hsv_adjustment", i18n("HSV/HSL Adjustment"))
{
}
......
......@@ -45,10 +45,18 @@ KoColorTransformation* KisHSVAdjustmentFilter::createTransformation(const KoColo
{
QHash<QString, QVariant> params;
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["v"] = config->getInt("v", 0) * 0.01;
params["type"] = config->getInt("type", 1);
params["colorize"] = config->getBool("colorize", false);
}
return cs->createColorTransformation("hsv_adjustment", params);
}
......@@ -60,6 +68,7 @@ KisFilterConfiguration* KisHSVAdjustmentFilter::factoryConfiguration(const KisPa
config->setProperty("s", 0);
config->setProperty("v", 0);
config->setProperty("type", 1);
config->setProperty("colorize", false);
return config;
}
......@@ -72,6 +81,7 @@ KisHSVConfigWidget::KisHSVConfigWidget(QWidget * parent, Qt::WFlags f) : KisConf
connect(m_page->hue, 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->chkColorize, SIGNAL(toggled(bool)), SLOT(switchColorize(bool)));
}
KisHSVConfigWidget::~KisHSVConfigWidget()
......@@ -86,6 +96,7 @@ KisPropertiesConfiguration * KisHSVConfigWidget::configuration() const
c->setProperty("s", m_page->saturation->value());
c->setProperty("v", m_page->value->value());
c->setProperty("type", m_page->cmbType->currentIndex());
c->setProperty("colorize", m_page->chkColorize->isChecked());
return c;
}
......@@ -95,6 +106,7 @@ void KisHSVConfigWidget::setConfiguration(const KisPropertiesConfiguration * con
m_page->hue->setValue(config->getInt("h", 0));
m_page->saturation->setValue(config->getInt("s", 0));
m_page->value->setValue(config->getInt("v", 0));
m_page->chkColorize->setChecked(config->getBool("colorize", false));
switchType(m_page->cmbType->currentIndex());
}
......@@ -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:
private slots:
void switchType(int index);
void switchColorize(bool toggle);
};
#endif
......@@ -20,15 +20,31 @@
</sizepolicy>
</property>
<property name="text">
<string>Hue:</string>
<string>&amp;Hue:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>hue</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KIntNumInput" name="hue">
<item row="5" 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="2" column="1">
<widget class="KIntNumInput" name="saturation">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -36,10 +52,29 @@
</sizepolicy>
</property>
<property name="minimum">
<number>-180</number>
<number>-100</number>
</property>
<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 name="sliderEnabled">
<bool>true</bool>
......@@ -55,7 +90,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Saturation:</string>
<string>&amp;Saturation:</string>
</property>
<property name="scaledContents">
<bool>false</bool>
......@@ -63,29 +98,23 @@
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>saturation</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="KIntNumInput" name="saturation">
<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>
<item row="0" column="0">
<widget class="QLabel" name="lblType">
<property name="text">
<string>Type:</string>
</property>
<property name="sliderEnabled">
<bool>true</bool>
<property name="buddy">
<cstring>cmbType</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="KIntNumInput" name="value">
<item row="1" column="1">
<widget class="KIntNumInput" name="hue">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -93,29 +122,16 @@
</sizepolicy>
</property>
<property name="minimum">
<number>-100</number>
<number>-180</number>
</property>
<property name="maximum">
<number>100</number>
<number>180</number>
</property>
<property name="sliderEnabled">
<bool>true</bool>
</property>
</widget>
</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">
<widget class="QLabel" name="label_3">
<property name="text">
......@@ -124,6 +140,9 @@
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>value</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
......@@ -143,13 +162,10 @@
</item>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblType">
<item row="4" column="1">
<widget class="QCheckBox" name="chkColorize">
<property name="text">
<string>Type:</string>
</property>
<property name="buddy">
<cstring>cmbType</cstring>
<string>&amp;Colorize</string>
</property>
</widget>
</item>
......
......@@ -38,9 +38,9 @@ int KoColorTransformation::parameterId(const QString& name) const
void KoColorTransformation::setParameter(int id, const QVariant& parameter)
{
Q_UNUSED(id);
Q_UNUSED(parameter);
qFatal("No parameter for this transformation");
Q_UNUSED(id);
Q_UNUSED(parameter);
qFatal("No parameter for this transformation");
}
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