Commit ca0a0333 authored by Wolthera van Hövell's avatar Wolthera van Hövell 🐛

Add HSI and HSY support to the visual color selector.

This was mostly an experiment, which was succesful in proving to me that
the HSL and HSV functions have issues with non-chromatic values. HSY and HSI are more notably slow, so kept HSL as the RGB default.

Ref T2337
parent b7a45b00
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>418</width>
<height>300</height> <height>483</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>400</width> <width>250</width>
<height>400</height> <height>250</height>
</size> </size>
</property> </property>
</widget> </widget>
......
...@@ -327,21 +327,45 @@ KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coo ...@@ -327,21 +327,45 @@ KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coo
} }
if (m_d->model != ColorModel::Channel && c.colorSpace()->colorModelId().id() == "RGBA") { if (m_d->model != ColorModel::Channel && c.colorSpace()->colorModelId().id() == "RGBA") {
if (c.colorSpace()->colorModelId().id() == "RGBA") { if (c.colorSpace()->colorModelId().id() == "RGBA") {
QVector <float> inbetween(3);
if (m_d->model == ColorModel::HSV){ if (m_d->model == ColorModel::HSV){
QVector <float> inbetween(3);
RGBToHSV(channelValues[2],channelValues[1], channelValues[0], &inbetween[0], &inbetween[1], &inbetween[2]); RGBToHSV(channelValues[2],channelValues[1], channelValues[0], &inbetween[0], &inbetween[1], &inbetween[2]);
inbetween[m_d->channel1] = coordinates.x()*huedivider; inbetween[m_d->channel1] = coordinates.x()*huedivider;
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;
} }
HSVToRGB(inbetween[0], inbetween[1], inbetween[2], &channelValues[2], &channelValues[1], &channelValues[0]); HSVToRGB(inbetween[0], inbetween[1], inbetween[2], &channelValues[2], &channelValues[1], &channelValues[0]);
} else /*(m_d->model == KisVisualColorSelectorShape::ColorModel::HSL)*/{ } else if (m_d->model == ColorModel::HSL) {
QVector <float> inbetween(3);
RGBToHSL(channelValues[2],channelValues[1], channelValues[0], &inbetween[0], &inbetween[1], &inbetween[2]); RGBToHSL(channelValues[2],channelValues[1], channelValues[0], &inbetween[0], &inbetween[1], &inbetween[2]);
inbetween[m_d->channel1] = coordinates.x()*huedivider; inbetween[m_d->channel1] = coordinates.x()*huedivider;
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;
} }
HSLToRGB(inbetween[0], inbetween[1], inbetween[2],&channelValues[2],&channelValues[1], &channelValues[0]); HSLToRGB(inbetween[0], inbetween[1], inbetween[2],&channelValues[2],&channelValues[1], &channelValues[0]);
} else if (m_d->model == ColorModel::HSI) {
QVector <qreal> chan2 = convertvectorfloatToqreal(channelValues);
QVector <qreal> inbetween(3);
RGBToHSI(chan2[2],chan2[1], chan2[0], &inbetween[0], &inbetween[1], &inbetween[2]);
inbetween[m_d->channel1] = coordinates.x();
if (m_d->dimension == Dimensions::twodimensional) {
inbetween[m_d->channel2] = coordinates.y();
}
HSIToRGB(inbetween[0], inbetween[1], inbetween[2],&chan2[2],&chan2[1], &chan2[0]);
channelValues = convertvectorqrealTofloat(chan2);
} else /*if (m_d->model == ColorModel::HSY)*/ {
QVector <qreal> luma= m_d->cs->lumaCoefficients();
QVector <qreal> chan2 = convertvectorfloatToqreal(channelValues);
QVector <qreal> inbetween(3);
RGBToHSY(chan2[2],chan2[1], chan2[0], &inbetween[0], &inbetween[1], &inbetween[2],
luma[0], luma[1], luma[2]);
inbetween[m_d->channel1] = coordinates.x();
if (m_d->dimension == Dimensions::twodimensional) {
inbetween[m_d->channel2] = coordinates.y();
}
HSYToRGB(inbetween[0], inbetween[1], inbetween[2],&chan2[2],&chan2[1], &chan2[0],
luma[0], luma[1], luma[2]);
channelValues = convertvectorqrealTofloat(chan2);
} }
} }
} else { } else {
...@@ -373,19 +397,37 @@ QPointF KisVisualColorSelectorShape::convertKoColorToShapeCoordinate(KoColor c) ...@@ -373,19 +397,37 @@ QPointF KisVisualColorSelectorShape::convertKoColorToShapeCoordinate(KoColor c)
} }
if (m_d->model != ColorModel::Channel && c.colorSpace()->colorModelId().id() == "RGBA") { if (m_d->model != ColorModel::Channel && c.colorSpace()->colorModelId().id() == "RGBA") {
if (c.colorSpace()->colorModelId().id() == "RGBA") { if (c.colorSpace()->colorModelId().id() == "RGBA") {
QVector <float> inbetween(3);
if (m_d->model == ColorModel::HSV){ if (m_d->model == ColorModel::HSV){
QVector <float> inbetween(3);
RGBToHSV(channelValues[2],channelValues[1], channelValues[0], &inbetween[0], &inbetween[1], &inbetween[2]); RGBToHSV(channelValues[2],channelValues[1], channelValues[0], &inbetween[0], &inbetween[1], &inbetween[2]);
coordinates.setX(inbetween[m_d->channel1]/huedivider); coordinates.setX(inbetween[m_d->channel1]/huedivider);
if (m_d->dimension == Dimensions::twodimensional) { if (m_d->dimension == Dimensions::twodimensional) {
coordinates.setY(inbetween[m_d->channel2]/huedivider2); coordinates.setY(inbetween[m_d->channel2]/huedivider2);
} }
} else { } else if (m_d->model == ColorModel::HSL) {
QVector <float> inbetween(3);
RGBToHSL(channelValues[2],channelValues[1], channelValues[0], &inbetween[0], &inbetween[1], &inbetween[2]); RGBToHSL(channelValues[2],channelValues[1], channelValues[0], &inbetween[0], &inbetween[1], &inbetween[2]);
coordinates.setX(inbetween[m_d->channel1]/huedivider); coordinates.setX(inbetween[m_d->channel1]/huedivider);
if (m_d->dimension == Dimensions::twodimensional) { if (m_d->dimension == Dimensions::twodimensional) {
coordinates.setY(inbetween[m_d->channel2]/huedivider2); coordinates.setY(inbetween[m_d->channel2]/huedivider2);
} }
} else if (m_d->model == ColorModel::HSI) {
QVector <qreal> chan2 = convertvectorfloatToqreal(channelValues);
QVector <qreal> inbetween(3);
RGBToHSI(chan2[2],chan2[1], chan2[0], &inbetween[0], &inbetween[1], &inbetween[2]);
coordinates.setX(inbetween[m_d->channel1]);
if (m_d->dimension == Dimensions::twodimensional) {
coordinates.setY(inbetween[m_d->channel2]);
}
} else /*if (m_d->model == ColorModel::HSY)*/ {
QVector <qreal> luma = m_d->cs->lumaCoefficients();
QVector <qreal> chan2 = convertvectorfloatToqreal(channelValues);
QVector <qreal> inbetween(3);
RGBToHSY(chan2[2],chan2[1], chan2[0], &inbetween[0], &inbetween[1], &inbetween[2], luma[0], luma[1], luma[2]);
coordinates.setX(inbetween[m_d->channel1]);
if (m_d->dimension == Dimensions::twodimensional) {
coordinates.setY(inbetween[m_d->channel2]);
}
} }
} }
} else { } else {
...@@ -397,6 +439,24 @@ QPointF KisVisualColorSelectorShape::convertKoColorToShapeCoordinate(KoColor c) ...@@ -397,6 +439,24 @@ QPointF KisVisualColorSelectorShape::convertKoColorToShapeCoordinate(KoColor c)
return coordinates; return coordinates;
} }
QVector<float> KisVisualColorSelectorShape::convertvectorqrealTofloat(QVector<qreal> real)
{
QVector <float> vloat(real.size());
for (int i=0; i<real.size(); i++) {
vloat[i] = real[i];
}
return vloat;
}
QVector<qreal> KisVisualColorSelectorShape::convertvectorfloatToqreal(QVector <float> vloat)
{
QVector <qreal> real(vloat.size());
for (int i=0; i<vloat.size(); i++) {
real[i] = vloat[i];
}
return real;
}
void KisVisualColorSelectorShape::mousePressEvent(QMouseEvent *e) void KisVisualColorSelectorShape::mousePressEvent(QMouseEvent *e)
{ {
m_d->mousePressActive = true; m_d->mousePressActive = true;
......
...@@ -139,6 +139,9 @@ private: ...@@ -139,6 +139,9 @@ private:
*/ */
virtual QRegion getMaskMap() = 0; virtual QRegion getMaskMap() = 0;
virtual void drawCursor() = 0; virtual void drawCursor() = 0;
QVector <float> convertvectorqrealTofloat(QVector<qreal> real);
QVector <qreal> convertvectorfloatToqreal(QVector <float> vloat);
}; };
class KisVisualRectangleSelectorShape : public KisVisualColorSelectorShape class KisVisualRectangleSelectorShape : public KisVisualColorSelectorShape
......
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