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 733afddd authored by Mathias Wein's avatar Mathias Wein

Fix tone reproduction curve estimation

The ITUR_2100_PQ_FULL.ICC has no colorants and revealed the bugs.
Iteration order was inverted so normalization didn't work.
Also only the first colorant was ever written, and
consequently the luma coefficients were also incomplete.

Additionally, RGB vs. BGR channel ordering was not respected,
and the sum of luma coefficients needs to be 1.0 for HSY
color space calculations.

And while at it, calculate a few more points so the graph in
the color space browser looks at least somewhat like a curve.

(cherry picked from commit fe47c0619d97e0d727afc9a48c95bf18c4475ddd)
parent 4bca019b
......@@ -204,34 +204,33 @@ QPolygonF KoColorSpace::estimatedTRCXYY() const
// This is fixed to 5 since the maximum number of channels are 5 for CMYKA
QVector <float> channelValuesF(5);//for getting the coordinates.
d->colorants.resize(3*colorChannelCount());
const int segments = 10;
for (quint32 i=0; i<colorChannelCount(); i++) {
qreal colorantY=1.0;
if (colorModelId().id()!="CMYKA") {
for (int j=4; j>=0; j--){
for (int j = 0; j <= segments; j++) {
channelValuesF.fill(0.0);
channelValuesF[i] = ((max/4)*(4-j));
channelValuesF[channels()[i]->displayPosition()] = ((max/segments)*(segments-j));
if (colorModelId().id()!="XYZA") { //no need for conversion when using xyz.
fromNormalisedChannelsValue(data, channelValuesF);
convertPixelsTo(data, data2, xyzColorSpace, 1, KoColorConversionTransformation::IntentAbsoluteColorimetric, KoColorConversionTransformation::adjustmentConversionFlags());
xyzColorSpace->normalisedChannelsValue(data2,channelValuesF);
}
if (j==0) {
colorantY = channelValuesF[1];
if (d->colorants.size()<2){
d->colorants.resize(3*colorChannelCount());
d->colorants[i] = channelValuesF[0]/(channelValuesF[0]+channelValuesF[1]+channelValuesF[2]);
d->colorants[i+1]= channelValuesF[1]/(channelValuesF[0]+channelValuesF[1]+channelValuesF[2]);
d->colorants[i+2]= channelValuesF[1];
}
d->colorants[3*i] = channelValuesF[0]/(channelValuesF[0]+channelValuesF[1]+channelValuesF[2]);
d->colorants[3*i+1] = channelValuesF[1]/(channelValuesF[0]+channelValuesF[1]+channelValuesF[2]);
d->colorants[3*i+2] = channelValuesF[1];
}
d->TRCXYY << QPointF(channelValuesF[1]/colorantY, ((1.0/4)*(4-j)));
d->TRCXYY << QPointF(channelValuesF[1]/colorantY, ((1.0/segments)*(segments-j)));
}
} else {
for (int j=0; j<5; j++){
for (int j = 0; j <= segments; j++) {
channelValuesF.fill(0.0);
channelValuesF[i] = ((max/4)*(j));
channelValuesF[i] = ((max/segments)*(j));
fromNormalisedChannelsValue(data, channelValuesF);
......@@ -241,14 +240,11 @@ QPolygonF KoColorSpace::estimatedTRCXYY() const
if (j==0) {
colorantY = channelValuesF[1];
if (d->colorants.size()<2){
d->colorants.resize(3*colorChannelCount());
d->colorants[i] = channelValuesF[0]/(channelValuesF[0]+channelValuesF[1]+channelValuesF[2]);
d->colorants[i+1]= channelValuesF[1]/(channelValuesF[0]+channelValuesF[1]+channelValuesF[2]);
d->colorants[i+2]= channelValuesF[1];
}
d->colorants[3*i] = channelValuesF[0]/(channelValuesF[0]+channelValuesF[1]+channelValuesF[2]);
d->colorants[3*i+1] = channelValuesF[1]/(channelValuesF[0]+channelValuesF[1]+channelValuesF[2]);
d->colorants[3*i+2] = channelValuesF[1];
}
d->TRCXYY << QPointF(channelValuesF[1]/colorantY, ((1.0/4)*(j)));
d->TRCXYY << QPointF(channelValuesF[1]/colorantY, ((1.0/segments)*(j)));
}
}
}
......@@ -285,9 +281,11 @@ QVector <qreal> KoColorSpace::lumaCoefficients() const
d->lumaCoefficients[1]=0.7152;
d->lumaCoefficients[2]=0.0722;
} else {
d->lumaCoefficients[0]=d->colorants[2];
d->lumaCoefficients[1]=d->colorants[5];
d->lumaCoefficients[2]=d->colorants[8];
// luma coefficients need to add up to 1.0
qreal sum = d->colorants[2] + d->colorants[5] + d->colorants[8];
d->lumaCoefficients[0] = d->colorants[2] / sum;
d->lumaCoefficients[1] = d->colorants[5] / sum;
d->lumaCoefficients[2] = d->colorants[8] / sum;
}
}
return d->lumaCoefficients;
......
......@@ -222,9 +222,12 @@ void KisAdvancedColorSpaceSelector::fillDescription()
d->colorSpaceSelector->TRCwidget->setRGBCurve(redcurve, greencurve, bluecurve);
} else {
QPolygonF curve = currentColorSpace()->estimatedTRCXYY();
redcurve << curve.at(0) << curve.at(1) << curve.at(2) << curve.at(3) << curve.at(4);
greencurve << curve.at(5) << curve.at(6) << curve.at(7) << curve.at(8) << curve.at(9);
bluecurve << curve.at(10) << curve.at(11) << curve.at(12) << curve.at(13) << curve.at(14);
int numPoints = curve.size() / 3;
for (int i = 0; i < numPoints; i++) {
redcurve << curve.at(i);
greencurve << curve.at(i + numPoints);
bluecurve << curve.at(i + 2*numPoints);
}
d->colorSpaceSelector->TRCwidget->setRGBCurve(redcurve, greencurve, bluecurve);
}
......@@ -281,10 +284,13 @@ void KisAdvancedColorSpaceSelector::fillDescription()
d->colorSpaceSelector->TRCwidget->setGreyscaleCurve(tonecurve);
} else {
QPolygonF curve = currentColorSpace()->estimatedTRCXYY();
cyancurve << curve.at(0) << curve.at(1) << curve.at(2) << curve.at(3) << curve.at(4);
magentacurve << curve.at(5) << curve.at(6) << curve.at(7) << curve.at(8) << curve.at(9);
yellowcurve << curve.at(10) << curve.at(11) << curve.at(12) << curve.at(13) << curve.at(14);
tonecurve << curve.at(15) << curve.at(16) << curve.at(17) << curve.at(18) << curve.at(19);
int numPoints = curve.size() / 4;
for (int i = 0; i < numPoints; i++) {
cyancurve << curve.at(i);
magentacurve << curve.at(i + numPoints);
yellowcurve << curve.at(i + 2*numPoints);
tonecurve << curve.at(i + 3*numPoints);
}
d->colorSpaceSelector->TRCwidget->setCMYKCurve(cyancurve, magentacurve, yellowcurve, tonecurve);
}
d->colorSpaceSelector->TRCwidget->setToolTip(i18nc("@info:tooltip","Estimated Gamma cannot be retrieved for CMYK."));
......
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