Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 0f5a2de4 authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

Adds HSI and HSY' to the advanced colour selector.

So, I want to add Intensity and Luma(The latter would be like mypaint)
to the advanced colour selector options in Krita.
But for that I first need conversion functions.

HSI, intensity, uses a system where a color is mapped to a tone scale
depending on the sum of it's components. So basically, Intensity=
(r+b+g)/3.
HSY, Luma, is similar, but it weights the components instead. So
Luminosity=(r*R'+g*G'+b*B').
Both are a little more intuitive to use for artists.

Krita's Advanced c-pick currently uses QColor hsv and hsl functions
through the display converter. This patch tries to add eight functions
to KoColorConversions:
*HSIToRGB, RGBToHSI, HCIToRGB, RGBToHCI.
These functions are for converting from and to HSI, these functions use
qreals in the range of 0.0-1.0.

*HSYToRGB, RGBToHSY, HCYToRGB, RGBToHCY.
These functions are for converting from and to HSY, these functions also
use qreals in the range of 0.0-1.0. On top of that, they have extra
parameters for setting the weights, which default to rec
601(http://en.wikipedia.org/wiki/CCIR_601) when not specified.

The difference between the HSI, HSY and HCI, HCY functions is that HSI
and HSY maps to a cyllindrical space using a weighted HSL algorithm.
This is useful for colour selectors because the output is more intuitive
and has no unexpected shifts in either direction. The HCI and HCY
functions on the other hand are the basic formulas and I put them in for
compatibility.

Implementation:
The code is implemented in the advanced colour selector through
kis_display_converter, where it creates or converts a qcolor for the
proper values.

In the advanced color selector itself we can now select shapes that use
HSI and HSY, and we can request the MyPaint shade selector to use HSL,
HSI and HSY. These options have been added to the settings window, with
tooltips and all.
parent fb7ac335
......@@ -123,10 +123,10 @@ void KisColorSelector::setConfiguration(Configuration conf)
Q_ASSERT(false);
}
connect(m_mainComponent, SIGNAL(paramChanged(qreal,qreal,qreal,qreal,qreal)),
m_subComponent, SLOT(setParam(qreal,qreal,qreal,qreal,qreal)), Qt::UniqueConnection);
connect(m_subComponent, SIGNAL(paramChanged(qreal,qreal,qreal,qreal,qreal)),
m_mainComponent, SLOT(setParam(qreal,qreal,qreal,qreal, qreal)), Qt::UniqueConnection);
connect(m_mainComponent, SIGNAL(paramChanged(qreal,qreal,qreal,qreal,qreal,qreal,qreal,qreal,qreal)),
m_subComponent, SLOT(setParam(qreal,qreal,qreal,qreal,qreal,qreal,qreal,qreal,qreal)), Qt::UniqueConnection);
connect(m_subComponent, SIGNAL(paramChanged(qreal,qreal,qreal,qreal,qreal,qreal,qreal,qreal,qreal)),
m_mainComponent, SLOT(setParam(qreal,qreal,qreal,qreal, qreal, qreal, qreal, qreal, qreal)), Qt::UniqueConnection);
connect(m_mainComponent, SIGNAL(update()), m_signalCompressor, SLOT(start()), Qt::UniqueConnection);
connect(m_subComponent, SIGNAL(update()), m_signalCompressor, SLOT(start()), Qt::UniqueConnection);
......
......@@ -33,7 +33,7 @@ class KisColorSelector : public KisColorSelectorBase
Q_OBJECT
public:
enum Type {Ring, Square, Wheel, Triangle, Slider};
enum Parameters {H, hsvS, V, hslS, L, SL, SV, SV2, hsvSH, hslSH, VH, LH};
enum Parameters {H, hsvS, V, hslS, L, SL, SV, SV2, hsvSH, hslSH, VH, LH, SI, SY, hsiSH, hsySH, I, Y, IH, YH, hsiS, hsyS};
struct Configuration {
Type mainType;
Type subType;
......@@ -67,7 +67,7 @@ public:
int imtp=strili.at(2).toInt();
int istp=strili.at(3).toInt();
if(imt>Slider || ist>Slider || imtp>LH || istp>LH)
if(imt>Slider || ist>Slider || imtp>hsyS || istp>hsyS)//this was LH before
return;
mainType = Type(imt);
......@@ -85,8 +85,8 @@ public:
// enum MainType {Ring, Square, Wheel};
// enum SubType {Triangle, Square, Slider};
// enum MainTypeParameter {SL, SV, SH, VH, LH, VSV/*experimental*/};
// enum SubTypeParameter {H, S, V, L};
// enum MainTypeParameter {SL, SV, SH, VH, LH, VSV/*experimental*/, SI, SY, YH, IH};
// enum SubTypeParameter {H, S, V, L, I, Y, hsiS, hsyS};
KisColorSelector(Configuration conf, QWidget* parent = 0);
KisColorSelector(QWidget* parent=0);
......
......@@ -43,15 +43,21 @@ public:
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Ring, KisColorSelector::SL , KisColorSelector::H), this), 0,1);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Ring, KisColorSelector::SV , KisColorSelector::H), this), 0,2);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Ring, KisColorSelector::SV2, KisColorSelector::H), this), 0,3);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Ring, KisColorSelector::SI , KisColorSelector::H), this), 0,4);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Ring, KisColorSelector::SY , KisColorSelector::H), this), 0,5);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::SV, KisColorSelector::H), this), 1,0);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::SL, KisColorSelector::H), this), 1,1);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::SV2, KisColorSelector::H), this), 1,2);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::SI, KisColorSelector::H), this), 1,3);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::SY, KisColorSelector::H), this), 1,4);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::VH, KisColorSelector::hsvS), this), 2,0);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::LH, KisColorSelector::hslS), this), 2,1);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::hsvSH, KisColorSelector::V), this), 2,2);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::hslSH, KisColorSelector::L), this), 2,3);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::IH, KisColorSelector::hsiS), this), 2,4);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::YH, KisColorSelector::hsyS), this), 2,5);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::VH, KisColorSelector::hsvS), this), 3,0);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::LH, KisColorSelector::hslS), this), 3,1);
......@@ -59,6 +65,13 @@ public:
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::hslSH, KisColorSelector::L), this), 3,3);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::IH, KisColorSelector::hsiS), this), 4,0);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::YH, KisColorSelector::hsyS), this), 4,1);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::hsiSH, KisColorSelector::I), this), 4,2);
layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::hsySH, KisColorSelector::Y), this), 4,3);
for(int i=0; i<this->layout()->count(); i++) {
KisColorSelector* item = dynamic_cast<KisColorSelector*>(this->layout()->itemAt(i)->widget());
Q_ASSERT(item);
......
......@@ -31,6 +31,10 @@ KisColorSelectorComponent::KisColorSelectorComponent(KisColorSelector* parent) :
m_value(1),
m_hslSaturation(1),
m_lightness(0.5),
m_hsiSaturation(1),
m_intensity(0.333),
m_hsySaturation(1),
m_luma(0.299),
m_parent(parent),
m_width(0),
m_height(0),
......@@ -104,13 +108,17 @@ KoColor KisColorSelectorComponent::currentColor()
return selectColor(m_lastX, m_lastY);
}
void KisColorSelectorComponent::setParam(qreal hue, qreal hsvSaturation, qreal value, qreal hslSaturation, qreal lightness)
void KisColorSelectorComponent::setParam(qreal hue, qreal hsvSaturation, qreal value, qreal hslSaturation, qreal lightness, qreal hsiSaturation, qreal intensity, qreal hsySaturation, qreal luma)
{
if(qFuzzyCompare(m_hue, hue) &&
qFuzzyCompare(m_hsvSaturation, hsvSaturation) &&
qFuzzyCompare(m_value, value) &&
qFuzzyCompare(m_hslSaturation, hslSaturation) &&
qFuzzyCompare(m_lightness, lightness))
qFuzzyCompare(m_lightness, lightness) &&
qFuzzyCompare(m_hsiSaturation, hsiSaturation) &&
qFuzzyCompare(m_intensity, intensity) &&
qFuzzyCompare(m_hsySaturation, hsySaturation) &&
qFuzzyCompare(m_luma, luma))
return;
if(hue>=0. && hue<=1.)
......@@ -119,22 +127,58 @@ void KisColorSelectorComponent::setParam(qreal hue, qreal hsvSaturation, qreal v
if(hsvSaturation>=0. && hsvSaturation<=1.) {
m_hsvSaturation=hsvSaturation;
m_hslSaturation=-1;
m_hsiSaturation=-1;
m_hsySaturation=-1;
}
if(value>=0. && value<=1.) {
m_value=value;
m_lightness=-1;
m_intensity=-1;
m_luma=-1;
m_lightness=-1;
}
if(hslSaturation>=0. && hslSaturation<=1.) {
m_hslSaturation=hslSaturation;
m_hsvSaturation=-1;
m_hsiSaturation=-1;
m_hsySaturation=-1;
}
if(lightness>=0. && lightness<=1.) {
m_lightness=lightness;
m_value=-1;
m_luma=-1;
m_intensity=-1;
}
if(hsiSaturation>=0. && hsiSaturation<=1.) {
m_hsiSaturation=hsiSaturation;
m_hsvSaturation=-1;
m_hslSaturation=-1;
m_hsySaturation=-1;
}
if(intensity>=0. && intensity<=1.) {
m_intensity=intensity;
m_value=-1;
m_luma=-1;
m_lightness=-1;
}
if(hsySaturation>=0. && hsySaturation<=1.) {
m_hsySaturation=hsySaturation;
m_hsvSaturation=-1;
m_hsiSaturation=-1;
m_hslSaturation=-1;
}
if(luma>=0. && luma<=1.) {
m_intensity=-1;
m_value=-1;
m_luma=luma;
m_lightness=-1;
}
m_dirty=true;
emit update();
......
......@@ -64,12 +64,12 @@ public:
public slots:
/// set hue, saturation, value or/and lightness
/// unused parameters should be set to -1
void setParam(qreal hue, qreal hsvSaturation, qreal value, qreal hslSaturation, qreal lightness);
void setParam(qreal hue, qreal hsvSaturation, qreal value, qreal hslSaturation, qreal lightness, qreal hsiSaturation, qreal intensity, qreal hsySaturation, qreal luma);
signals:
/// request for repaint, for instance, if the hue changes.
void update();
/// -1, if unaffected
void paramChanged(qreal hue, qreal hsvSaturation, qreal value, qreal hslSaturation, qreal lightness);
void paramChanged(qreal hue, qreal hsvSaturation, qreal value, qreal hslSaturation, qreal lightness, qreal hsiSaturation, qreal intensity, qreal hsySaturation, qreal luma);
protected:
const KoColorSpace* colorSpace() const;
/// returns true, if ether the colour space, the size or the parameters have changed since the last paint event
......@@ -95,6 +95,10 @@ protected:
qreal m_value;
qreal m_hslSaturation;
qreal m_lightness;
qreal m_hsiSaturation;
qreal m_intensity;
qreal m_hsySaturation;
qreal m_luma;
Parameter m_parameter;
Type m_type;
KisColorSelector* m_parent;
......
......@@ -141,6 +141,8 @@ void KisColorSelectorContainer::updateSettings()
else
newShadeSelector = 0;
if(m_shadeSelector!=newShadeSelector && m_shadeSelector!=0) {
m_shadeSelector->hide();
}
......
......@@ -114,7 +114,7 @@ KoColor KisColorSelectorRing::selectColor(int x, int y)
QPoint ringCoord = QPoint(x, y)-ringMiddle;
qreal hue = std::atan2(qreal(ringCoord.y()), qreal(ringCoord.x()))+(M_PI);
hue/=2.*M_PI;
emit paramChanged(hue, -1, -1, -1, -1);
emit paramChanged(hue, -1, -1, -1, -1, -1, -1, -1, -1);
m_lastHue=hue;
emit update();
......@@ -126,7 +126,7 @@ void KisColorSelectorRing::setColor(const KoColor &color)
qreal h, s, v;
m_parent->converter()->getHsvF(color, &h, &s, &v);
emit paramChanged(h, -1, -1, -1, -1);
emit paramChanged(h, -1, -1, -1, -1, -1, -1, -1, -1);
// selector keeps the position on the ring if hue is undefined (when saturation is 0)
if (!qFuzzyCompare(s, 0.0)) {
......
......@@ -151,6 +151,17 @@ void KisColorSelectorSettings::savePreferences() const
cfg.writeEntry("shadeSelectorUpdateOnLeftClick", ui->shadeSelectorUpdateOnLeftClick->isChecked());
cfg.writeEntry("shadeSelectorUpdateOnBackground", ui->shadeSelectorUpdateOnBackground->isChecked());
//mypaint model
QString shadeMyPaintType("HSV");
if(ui->MyPaint_HSL->isChecked())
shadeMyPaintType="HSL";
if(ui->MyPaint_HSI->isChecked())
shadeMyPaintType="HSI";
if(ui->MyPaint_HSY->isChecked())
shadeMyPaintType="HSY";
cfg.writeEntry("shadeMyPaintType", shadeMyPaintType);
cfg.writeEntry("minimalShadeSelectorAsGradient", ui->minimalShadeSelectorAsGradient->isChecked());
cfg.writeEntry("minimalShadeSelectorPatchCount", ui->minimalShadeSelectorPatchesPerLine->value());
cfg.writeEntry("minimalShadeSelectorLineConfig", ui->minimalShadeSelectorLineSettings->toString());
......@@ -253,6 +264,12 @@ void KisColorSelectorSettings::loadPreferences()
ui->shadeSelectorUpdateOnForeground->setChecked(cfg.readEntry("shadeSelectorUpdateOnForeground", true));
ui->shadeSelectorUpdateOnBackground->setChecked(cfg.readEntry("shadeSelectorUpdateOnBackground", true));
QString shadeMyPaintType=cfg.readEntry("shadeMyPaintType", "HSV");
ui->MyPaint_HSV->setChecked(shadeMyPaintType=="HSV");
ui->MyPaint_HSL->setChecked(shadeMyPaintType=="HSL");
ui->MyPaint_HSI->setChecked(shadeMyPaintType=="HSI");
ui->MyPaint_HSY->setChecked(shadeMyPaintType=="HSY");
bool asGradient = cfg.readEntry("minimalShadeSelectorAsGradient", true);
if(asGradient) ui->minimalShadeSelectorAsGradient->setChecked(true);
else ui->minimalShadeSelectorAsColorPatches->setChecked(true);
......@@ -313,6 +330,11 @@ void KisColorSelectorSettings::loadDefaultPreferences()
ui->shadeSelectorTypeMinimal->setChecked(false);
ui->shadeSelectorTypeHidden->setChecked(false);
ui->MyPaint_HSV->setChecked(true);
ui->MyPaint_HSL->setChecked(false);
ui->MyPaint_HSI->setChecked(false);
ui->MyPaint_HSY->setChecked(false);
ui->shadeSelectorUpdateOnRightClick->setChecked(false);
ui->shadeSelectorUpdateOnLeftClick->setChecked(false);
ui->shadeSelectorUpdateOnForeground->setChecked(true);
......
......@@ -130,7 +130,7 @@ void KisColorSelectorTriangle::setColor(const KoColor &color)
// Workaround for Bug 287001
setLastMousePosition(tmp.x(), tmp.y());
emit paramChanged(-1, s, v, -1, -1);
emit paramChanged(-1, s, v, -1, -1, -1, -1, -1, -1);
emit update();
}
......
......@@ -49,16 +49,28 @@ KoColor KisColorSelectorWheel::selectColor(int x, int y)
switch (m_parameter) {
case KisColorSelector::hsvSH:
emit paramChanged(angle, radius, -1, -1, -1);
emit paramChanged(angle, radius, -1, -1, -1, -1, -1, -1, -1);
break;
case KisColorSelector::hslSH:
emit paramChanged(angle, -1, -1, radius, -1);
emit paramChanged(angle, -1, -1, radius, -1, -1, -1, -1, -1);
break;
case KisColorSelector::hsiSH:
emit paramChanged(angle, -1, -1, -1, -1, radius, -1, -1, -1);
break;
case KisColorSelector::hsySH:
emit paramChanged(angle, -1, -1, -1, -1, -1, -1, radius, -1);
break;
case KisColorSelector::VH:
emit paramChanged(angle, -1, radius, -1, -1);
emit paramChanged(angle, -1, radius, -1, -1, -1, -1, -1, -1);
break;
case KisColorSelector::LH:
emit paramChanged(angle, -1, -1, -1, radius);
emit paramChanged(angle, -1, -1, -1, radius, -1, -1, -1, -1);
break;
case KisColorSelector::IH:
emit paramChanged(angle, -1, -1, -1, -1, -1, radius, -1, -1);
break;
case KisColorSelector::YH:
emit paramChanged(angle, -1, -1, -1, -1, -1, -1, -1, radius);
break;
default:
Q_ASSERT(false);
......@@ -80,9 +92,16 @@ void KisColorSelectorWheel::setColor(const KoColor &color)
{
qreal hsvH, hsvS, hsvV;
qreal hslH, hslS, hslL;
qreal hsiH, hsiS, hsiI;
qreal hsyH, hsyS, hsyY;
m_parent->converter()->getHsvF(color, &hsvH, &hsvS, &hsvV);
m_parent->converter()->getHslF(color, &hslH, &hslS, &hslL);
m_parent->converter()->getHsiF(color, &hsiH, &hsiS, &hsiI);
m_parent->converter()->getHsyF(color, &hsyH, &hsyS, &hsyY);
//workaround, for some reason the HSI and HSY algorithms are fine, but they don't seem to update the selectors properly.
hsiH=hslH;
hsyH=hslH;
qreal angle = 0.0, radius = 0.0;
angle = hsvH;
......@@ -90,21 +109,37 @@ void KisColorSelectorWheel::setColor(const KoColor &color)
angle -= M_PI;
switch (m_parameter) {
case KisColorSelector::LH:
emit paramChanged(hslH, -1, -1, -1, hslL);
emit paramChanged(hslH, -1, -1, -1, hslL, -1, -1, -1, -1);
radius = hslL;
break;
case KisColorSelector::VH:
emit paramChanged(hsvH, -1, hsvV, -1, -1);
emit paramChanged(hsvH, -1, hsvV, -1, -1, -1, -1, -1, -1);
radius = hsvV;
break;
case KisColorSelector::IH:
emit paramChanged(hslH, -1, -1, -1, -1, -1, hsiI, -1, -1);
radius = hsiI;
break;
case KisColorSelector::YH:
emit paramChanged(hsvH, -1, -1, -1, -1, -1, -1, -1, hsyY);
radius = hsyY;
break;
case KisColorSelector::hsvSH:
emit paramChanged(hsvH, hsvS, -1, -1, -1);
emit paramChanged(hsvH, hsvS, -1, -1, -1, -1, -1, -1, -1);
radius = hsvS;
break;
case KisColorSelector::hslSH:
emit paramChanged(hslH, -1, -1, hslS, -1);
emit paramChanged(hslH, -1, -1, hslS, -1, -1, -1, -1, -1);
radius = hslS;
break;
case KisColorSelector::hsiSH:
emit paramChanged(hsiH, -1, -1, -1, -1, hsiS, -1, -1, -1);
radius = hsiS;
break;
case KisColorSelector::hsySH:
emit paramChanged(hsyH, -1, -1, -1, -1, -1, -1, hsyS, -1);
radius = hsyS;
break;
default:
Q_ASSERT(false);
break;
......@@ -198,12 +233,24 @@ KoColor KisColorSelectorWheel::colorAt(int x, int y, bool forceValid)
case KisColorSelector::hslSH:
color = m_parent->converter()->fromHslF(angle, radius, m_lightness);
break;
case KisColorSelector::hsiSH:
color = m_parent->converter()->fromHsiF(angle, radius, m_intensity);
break;
case KisColorSelector::hsySH:
color = m_parent->converter()->fromHsyF(angle, radius, m_luma);
break;
case KisColorSelector::VH:
color = m_parent->converter()->fromHsvF(angle, m_hsvSaturation, radius);
break;
case KisColorSelector::LH:
color = m_parent->converter()->fromHslF(angle, m_hslSaturation, radius);
break;
case KisColorSelector::IH:
color = m_parent->converter()->fromHsiF(angle, m_hsiSaturation, radius);
break;
case KisColorSelector::YH:
color = m_parent->converter()->fromHsyF(angle, m_hsySaturation, radius);
break;
default:
Q_ASSERT(false);
......
......@@ -78,6 +78,9 @@ void KisMyPaintShadeSelector::paintEvent(QPaintEvent *) {
m_realPixelCache = new KisPaintDevice(this->colorSpace());
KisPaintDeviceSP realCircleBorder = new KisPaintDevice(this->colorSpace());
KConfigGroup cfg = KGlobal::config()->group("advancedColorSelector");
QString shadeMyPaintType=cfg.readEntry("shadeMyPaintType", "HSV");
int size = qMin(width(), height());
int s_radius = size/2.6;
......@@ -147,9 +150,16 @@ void KisMyPaintShadeSelector::paintEvent(QPaintEvent *) {
fh -= floor(fh);
fs = qBound(qreal(0.0), fs, qreal(1.0));
fv = qBound(qreal(0.1), fv, qreal(1.0));
KoColor color = converter()->fromHsvF(fh, fs, fv);
fv = qBound(qreal(0.01), fv, qreal(1.0));
KoColor color;
//KoColor color = converter()->fromHsvF(fh, fs, fv);
if(shadeMyPaintType=="HSV"){color = converter()->fromHsvF(fh, fs, fv);}
else if(shadeMyPaintType=="HSL"){color = converter()->fromHslF(fh, fs, fv);}
else if(shadeMyPaintType=="HSI"){color = converter()->fromHsiF(fh, fs, fv);}
else if(shadeMyPaintType=="HSY"){color = converter()->fromHsyF(fh, fs, fv);}
else{qDebug()<<"MyPaint Color selector don't work right.";
color = converter()->fromHsvF(fh, fs, fv);}
//qDebug()<<color->toQcolor();
color.setOpacity(aaFactor);
Acs::setColor(realCircleBorder, QPoint(x, y), color);
......@@ -169,9 +179,16 @@ void KisMyPaintShadeSelector::paintEvent(QPaintEvent *) {
fh -= floor(fh);
fs = qBound(qreal(0.0), fs, qreal(1.0));
fv = qBound(qreal(0.1), fv, qreal(1.0));
fv = qBound(qreal(0.01), fv, qreal(1.0));
KoColor color;
//KoColor color = converter()->fromHsvF(fh, fs, fv);
if(shadeMyPaintType=="HSV"){color = converter()->fromHsvF(fh, fs, fv);}
else if(shadeMyPaintType=="HSL"){color = converter()->fromHslF(fh, fs, fv);}
else if(shadeMyPaintType=="HSI"){color = converter()->fromHsiF(fh, fs, fv);}
else if(shadeMyPaintType=="HSY"){color = converter()->fromHsyF(fh, fs, fv);}
else{qDebug()<<"MyPaint Color selector don't work right.";
color = converter()->fromHsvF(fh, fs, fv);}
KoColor color = converter()->fromHsvF(fh, fs, fv);
Acs::setColor(m_realPixelCache, QPoint(x, y), color);
}
}
......@@ -233,7 +250,13 @@ KisColorSelectorBase* KisMyPaintShadeSelector::createPopup() const
}
void KisMyPaintShadeSelector::setColor(const KoColor &color) {
this->converter()->getHsvF(color, &m_colorH, &m_colorS, &m_colorV);
KConfigGroup cfg = KGlobal::config()->group("advancedColorSelector");
QString shadeMyPaintType=cfg.readEntry("shadeMyPaintType", "HSV");
if(shadeMyPaintType=="HSV"){this->converter()->getHsvF(color, &m_colorH, &m_colorS, &m_colorV);}
if(shadeMyPaintType=="HSL"){this->converter()->getHslF(color, &m_colorH, &m_colorS, &m_colorV);}
if(shadeMyPaintType=="HSI"){this->converter()->getHsiF(color, &m_colorH, &m_colorS, &m_colorV);}
if(shadeMyPaintType=="HSY"){this->converter()->getHsyF(color, &m_colorH, &m_colorS, &m_colorV);}
m_lastRealColor = color;
m_updateTimer->start();
......
......@@ -6,15 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>582</width>
<height>385</height>
<width>650</width>
<height>469</height>
</rect>
</property>
<property name="windowTitle">
<string>Color Selector Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="KTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
......@@ -300,6 +300,65 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_8">
<property name="title">
<string>MyPaint Shade Selector</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Color-model type:</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="MyPaint_HSV">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Use the Hue Saturation Value model.(Default)&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;This model sets all the most saturated colours at the same level as white. Think value as a measure of pixel-brightness.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>HSV</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="MyPaint_HSL">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Use the Hue, Saturation, Lightness model.&lt;/p&gt;&lt;p&gt;This model sets all the most saturated colors at lightness 0.5&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>HSL</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="MyPaint_HSI">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Use the Hue, Saturation, Intensity model for the MyPaint Shade Selector&lt;/p&gt;&lt;p&gt;Intensity marks itself by measuring the sum of the r, g, b components. As such, yellow(1,1,0) is brighter than blue(0,0,1).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>HSI</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="MyPaint_HSY">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Use the Hue, Saturation, Luma model for the MyPaint Shade Selector&lt;/p&gt;&lt;p&gt;Luma is similar to Intensity, except it weighs the red green and blue components before adding them together. As such, Yellow is brighter than Cyan. This model is exactly the same as MyPaint HCY'.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>HSY'</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
......@@ -418,8 +477,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>321</width>
<height>151</height>
<width>364</width>
<height>156</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
......
......@@ -23,6 +23,7 @@
#include <KoColorSpaceMaths.h>
#include <KoColorSpaceRegistry.h>
#include <KoColorModelStandardIds.h>
#include <KoColorConversions.h>
#include <KoCanvasResourceManager.h>
#include "kis_config_notifier.h"
......@@ -562,4 +563,50 @@ void KisDisplayColorConverter::getHslF(const KoColor &srcColor, qreal *h, qreal
color.getHslF(h, s, l, a);
}
KoColor KisDisplayColorConverter::fromHsiF(qreal h, qreal s, qreal i)
{
// generate HSI from sRGB!
qreal r=0.0;
qreal g=0.0;
qreal b=0.0;
qreal a=1.0;
HSIToRGB(h, s, i, &r, &g, &b);
QColor qcolor;
qcolor.setRgbF(r, g, b, a);
return m_d->approximateFromQColor(qcolor);
}
void KisDisplayColorConverter::getHsiF(const KoColor &srcColor, qreal *h, qreal *s, qreal *i)
{
// we are going through sRGB here!
QColor color = m_d->approximateToQColor(srcColor);
qreal r=color.redF();
qreal g=color.greenF();
qreal b=color.blueF();
RGBToHSI(r, g, b, h, s, i);
}
KoColor KisDisplayColorConverter::fromHsyF(qreal h, qreal s, qreal y)
{
// generate HSL from sRGB!
qreal r=0.0;