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

Fix errors in HSL formula.

Also fix hsx cursor wiggling position _again_...
parent ba6dd494
...@@ -382,9 +382,7 @@ void RGBToHSL(float r, float g, float b, float *h, float *s, float *l) ...@@ -382,9 +382,7 @@ void RGBToHSL(float r, float g, float b, float *h, float *s, float *l)
*h = (r == m ? 3.0 + g2 : 5.0 - r2); *h = (r == m ? 3.0 + g2 : 5.0 - r2);
*h *= 60; *h *= 60;
if (*h == 360.) { *h = fmod(*h, 360.0);
*h = 0;
}
} }
void HSLToRGB(float h, float sl, float l, float *r, float *g, float *b) void HSLToRGB(float h, float sl, float l, float *r, float *g, float *b)
...@@ -403,6 +401,7 @@ void HSLToRGB(float h, float sl, float l, float *r, float *g, float *b) ...@@ -403,6 +401,7 @@ void HSLToRGB(float h, float sl, float l, float *r, float *g, float *b)
m = l + l - v; m = l + l - v;
sv = (v - m) / v; sv = (v - m) / v;
h = fmod(h, 360.0);
h /= 60.0; h /= 60.0;
sextant = static_cast<int>(h); sextant = static_cast<int>(h);
fract = h - sextant; fract = h - sextant;
......
...@@ -149,12 +149,12 @@ void KisVisualColorSelector::slotRebuildSelectors() ...@@ -149,12 +149,12 @@ void KisVisualColorSelector::slotRebuildSelectors()
channel3 = 1; channel3 = 1;
break; break;
case hsiSH: case hsiSH:
modelS = KisVisualColorSelectorShape::HSL; modelS = KisVisualColorSelectorShape::HSI;
channel2 = 0; channel2 = 0;
channel3 = 1; channel3 = 1;
break; break;
case hslSH: case hslSH:
modelS = KisVisualColorSelectorShape::HSI; modelS = KisVisualColorSelectorShape::HSL;
channel2 = 0; channel2 = 0;
channel3 = 1; channel3 = 1;
break; break;
...@@ -365,8 +365,8 @@ void KisVisualColorSelector::HSXwrangler() ...@@ -365,8 +365,8 @@ void KisVisualColorSelector::HSXwrangler()
m_d->currentCoordinates[ch[1]] = w2[ch[1]]; m_d->currentCoordinates[ch[1]] = w2[ch[1]];
m_d->currentCoordinates[ch[2]] = w2[ch[2]]; m_d->currentCoordinates[ch[2]] = w2[ch[2]];
m_d->widgetlist.at(0)->setHSX(m_d->currentCoordinates); m_d->widgetlist.at(0)->setHSX(m_d->currentCoordinates, true);
m_d->widgetlist.at(1)->setHSX(m_d->currentCoordinates); m_d->widgetlist.at(1)->setHSX(m_d->currentCoordinates, true);
} }
/*------------Selector shape------------*/ /*------------Selector shape------------*/
...@@ -388,6 +388,7 @@ struct KisVisualColorSelectorShape::Private ...@@ -388,6 +388,7 @@ struct KisVisualColorSelectorShape::Private
const KoColorDisplayRendererInterface *displayRenderer = 0; const KoColorDisplayRendererInterface *displayRenderer = 0;
qreal hue = 0.0; qreal hue = 0.0;
qreal sat = 0.0; qreal sat = 0.0;
qreal tone = 0.0;
}; };
...@@ -440,7 +441,7 @@ void KisVisualColorSelectorShape::setColor(KoColor c) ...@@ -440,7 +441,7 @@ void KisVisualColorSelectorShape::setColor(KoColor c)
} }
m_d->currentColor = c; m_d->currentColor = c;
updateCursor(); updateCursor();
convertShapeCoordinateToKoColor(getCursorPosition()); convertShapeCoordinateToKoColor(getCursorPosition(), true);
m_d->imagesNeedUpdate = true; m_d->imagesNeedUpdate = true;
update(); update();
} }
...@@ -586,14 +587,14 @@ KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coo ...@@ -586,14 +587,14 @@ KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coo
* but you might want to manually clamp for floating point values. * but you might want to manually clamp for floating point values.
*/ */
QVector <float> inbetween(3); QVector <float> inbetween(3);
RGBToHSL(channelValuesDisplay[1],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2]); RGBToHSL(channelValuesDisplay[0],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2]);
inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween))); inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween)));
inbetween[m_d->channel1] = coordinates.x()*huedivider; inbetween[m_d->channel1] = fmod(coordinates.x()*huedivider, 360.0);
if (m_d->dimension == Dimensions::twodimensional) { if (m_d->dimension == Dimensions::twodimensional) {
inbetween[m_d->channel2] = coordinates.y()*huedivider2; inbetween[m_d->channel2] = coordinates.y()*huedivider2;
} }
if (cursor==true){setHSX(convertvectorfloatToqreal(inbetween));Q_EMIT sigHSXchange();} if (cursor==true){setHSX(convertvectorfloatToqreal(inbetween));Q_EMIT sigHSXchange();}
HSLToRGB(inbetween[0], inbetween[1], inbetween[2],&channelValuesDisplay[0],&channelValuesDisplay[1], &channelValuesDisplay[2]); HSLToRGB(qMax(inbetween[0],(float)0.0), inbetween[1], inbetween[2],&channelValuesDisplay[0],&channelValuesDisplay[1], &channelValuesDisplay[2]);
} else if (m_d->model == ColorModel::HSI) { } else if (m_d->model == ColorModel::HSI) {
/* /*
* HSI is a modified HSY function. * HSI is a modified HSY function.
...@@ -813,6 +814,7 @@ QVector <qreal> KisVisualColorSelectorShape::getHSX(QVector<qreal> hsx, bool wra ...@@ -813,6 +814,7 @@ QVector <qreal> KisVisualColorSelectorShape::getHSX(QVector<qreal> hsx, bool wra
{ {
QVector <qreal> ihsx = hsx; QVector <qreal> ihsx = hsx;
if (!wrangler){ if (!wrangler){
ihsx[2] = m_d->tone;
if (m_d->model==HSV){ if (m_d->model==HSV){
if (hsx[2]<=0.0) { if (hsx[2]<=0.0) {
ihsx[1] = m_d->sat; ihsx[1] = m_d->sat;
...@@ -822,20 +824,38 @@ QVector <qreal> KisVisualColorSelectorShape::getHSX(QVector<qreal> hsx, bool wra ...@@ -822,20 +824,38 @@ QVector <qreal> KisVisualColorSelectorShape::getHSX(QVector<qreal> hsx, bool wra
ihsx[1] = m_d->sat; ihsx[1] = m_d->sat;
} }
} }
if ((hsx[1]<0.0 || hsx[0]<0.0)){ if ((hsx[1]<=0.0 || hsx[0]<0.0)){
ihsx[0]=m_d->hue; ihsx[0]=m_d->hue;
} }
} else { } else {
ihsx[0]=m_d->hue; ihsx[0]=m_d->hue;
ihsx[1]=m_d->sat; ihsx[1]=m_d->sat;
ihsx[2]=m_d->tone;
} }
return ihsx; return ihsx;
} }
void KisVisualColorSelectorShape::setHSX(QVector<qreal> hsx) void KisVisualColorSelectorShape::setHSX(QVector<qreal> hsx, bool wrangler)
{ {
m_d->sat = hsx[1]; if (wrangler){
m_d->hue = hsx[0]; m_d->tone = hsx[2];
m_d->sat = hsx[1];
m_d->hue = hsx[0];
} else {
m_d->tone = hsx[2];
if (m_d->model==HSV){
if (hsx[2]>0.0) {
m_d->sat = hsx[1];
}
} else {
if ((hsx[2]>0.0 || hsx[2]<1.0)) {
m_d->sat = hsx[1];
}
}
if ((hsx[1]>0.0 && hsx[0]>=0.0)){
m_d->hue = hsx[0];
}
}
} }
QVector <int> KisVisualColorSelectorShape::getChannels() QVector <int> KisVisualColorSelectorShape::getChannels()
......
...@@ -236,7 +236,7 @@ public: ...@@ -236,7 +236,7 @@ public:
* black, white, and desaturated values. Will not change the non-native values. * black, white, and desaturated values. Will not change the non-native values.
* @param hsx the hsx value. * @param hsx the hsx value.
*/ */
void setHSX(QVector <qreal> hsx); void setHSX(QVector <qreal> hsx, bool wrangler=false);
/** /**
* @brief getHSX sets the sat and hue so they won't * @brief getHSX sets the sat and hue so they won't
* switch around much. * switch around much.
......
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