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

Fix KoColorProfile::linearize/delinearize result vector resize

Sometimes it is convenient to pass the result vector with more than a 3
elements, e.g. when passing QVector(4) with RGBA values. In this case
old implementation resized vector to 3 values.

This patch fixes assertion failure in KoColorSpace::decreaseLuminosity:
out-of-bounds access to channelValues vector

It occurs because we store the number of channels before
linearize/delinearize and then iterate over the channelValues assuming
that its size was not changed.

With this patch, Alpha channel is ignored during linearization and
vector size does not change.

Patch by Andrew Savonichev <andrew.savonichev@gmail.com>(asavonic) Thanks!
parent 1168cfb8
......@@ -157,13 +157,14 @@ public:
*/
virtual bool hasTRC() const = 0;
/**
* Linearizes a QVector of 3 doubles long, if it's possible to Linearize
* if not, returns the same QVector
* Linearizes first 3 values of QVector, leaving other values unchanged.
* Returns the same QVector if it is not possible to linearize.
*/
virtual void linearizeFloatValue(QVector <qreal> & Value) const = 0;
/**
* Delinearizes a QVector of 3 doubles long, if it's possible to delinearize
* if not, returns the same QVector. Effectively undoes LinearizeFloatValue.
* Delinearizes first 3 values of QVector, leaving other values unchanged.
* Returns the same QVector if it is not possible to delinearize.
* Effectively undoes LinearizeFloatValue.
*/
virtual void delinearizeFloatValue(QVector <qreal> & Value) const = 0;
/**
......
......@@ -580,7 +580,7 @@ void KoColorSpace::decreaseLuminosity(quint8 * pixel, qreal step) const {
}
luma = pow(luma, 2.2);
channelValues = fromHSY(&hue, &sat, &luma);
profile()->delinearizeFloatValue(channelValues);
profile()->delinearizeFloatValue(channelValues);
} else {
qreal hue, sat, luma = 0.0;
toHSY(channelValues, &hue, &sat, &luma);
......
......@@ -451,7 +451,10 @@ void LcmsColorProfileContainer::LinearizeFloatValue(QVector <double> & Value) co
TRCtriplet.fill(cmsEvalToneCurveFloat(d->grayTRC, Value[0]));
}
}
Value = TRCtriplet;
Value[0] = TRCtriplet[0];
Value[1] = TRCtriplet[1];
Value[2] = TRCtriplet[2];
}
void LcmsColorProfileContainer::DelinearizeFloatValue(QVector <double> & Value) const
......@@ -483,7 +486,9 @@ void LcmsColorProfileContainer::DelinearizeFloatValue(QVector <double> & Value)
}
}
Value = TRCtriplet;
Value[0] = TRCtriplet[0];
Value[1] = TRCtriplet[1];
Value[2] = TRCtriplet[2];
}
void LcmsColorProfileContainer::LinearizeFloatValueFast(QVector <double> & Value) const
......
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