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

Fix HSV mode

Turns out there was an 'undefined' value...

Ref T2438
parent 5282f861
......@@ -88,11 +88,11 @@ void KisVisualColorSelector::slotsetColorSpace(const KoColorSpace *cs)
} else if (m_d->currentCS->colorChannelCount() == 3) {
KisVisualRectangleSelectorShape *bar = new KisVisualRectangleSelectorShape(this,
KisVisualRectangleSelectorShape::onedimensional,
KisVisualColorSelectorShape::HSL,
KisVisualColorSelectorShape::HSV,
cs, 0, 0,
m_d->displayRenderer);
KisVisualRectangleSelectorShape *block = new KisVisualRectangleSelectorShape(this, KisVisualRectangleSelectorShape::twodimensional,
KisVisualColorSelectorShape::HSL,
KisVisualColorSelectorShape::HSV,
cs, 1, 2,
m_d->displayRenderer);
bar->setMaximumWidth(width()*0.1);
......@@ -346,14 +346,23 @@ KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coo
if (m_d->model != ColorModel::Channel && c.colorSpace()->colorModelId().id() == "RGBA") {
if (c.colorSpace()->colorModelId().id() == "RGBA") {
if (m_d->model == ColorModel::HSV){
/*
* RGBToHSV has a undefined hue possibility. This means that hue will be -1.
* This can be annoying for dealing with a selector, but I understand it is being
* used for the KoColorSelector... For now implement a qMax here.
*/
QVector <float> inbetween(3);
RGBToHSV(channelValues[2],channelValues[1], channelValues[0], &inbetween[0], &inbetween[1], &inbetween[2]);
inbetween[m_d->channel1] = coordinates.x()*huedivider;
if (m_d->dimension == Dimensions::twodimensional) {
inbetween[m_d->channel2] = coordinates.y()*huedivider2;
}
HSVToRGB(inbetween[0], inbetween[1], inbetween[2], &channelValues[2], &channelValues[1], &channelValues[0]);
HSVToRGB(qMax(inbetween[0],(float)0.0), inbetween[1], inbetween[2], &channelValues[2], &channelValues[1], &channelValues[0]);
} else if (m_d->model == ColorModel::HSL) {
/*
* HSLToRGB can give negative values on the grey. I fixed the fromNormalisedChannel function to clamp,
* but you might want to manually clamp for floating point values.
*/
QVector <float> inbetween(3);
RGBToHSL(channelValues[2],channelValues[1], channelValues[0], &inbetween[0], &inbetween[1], &inbetween[2]);
inbetween[m_d->channel1] = coordinates.x()*huedivider;
......@@ -362,6 +371,9 @@ KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coo
}
HSLToRGB(inbetween[0], inbetween[1], inbetween[2],&channelValues[2],&channelValues[1], &channelValues[0]);
} else if (m_d->model == ColorModel::HSI) {
/*
* HSI is a modified HSY function.
*/
QVector <qreal> chan2 = convertvectorfloatToqreal(channelValues);
QVector <qreal> inbetween(3);
RGBToHSI(chan2[2],chan2[1], chan2[0], &inbetween[0], &inbetween[1], &inbetween[2]);
......@@ -372,6 +384,11 @@ KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coo
HSIToRGB(inbetween[0], inbetween[1], inbetween[2],&chan2[2],&chan2[1], &chan2[0]);
channelValues = convertvectorqrealTofloat(chan2);
} else /*if (m_d->model == ColorModel::HSY)*/ {
/*
* HSY is pretty slow to render due being a pretty over-the-top function.
* Might be worth investigating whether HCY can be used instead, but I have had
* some weird results with that.
*/
QVector <qreal> luma= m_d->cs->lumaCoefficients();
QVector <qreal> chan2 = convertvectorfloatToqreal(channelValues);
QVector <qreal> inbetween(3);
......
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