Review Request: KColorSpace::KHCY::KHCY(const & QColor) constructor floating point precision error
Johannes Sixt
j.sixt at viscovery.net
Fri Jun 26 07:37:03 BST 2009
Matthew Woehlke schrieb:
> Benoit Jacob wrote:
>> we seem to be talking of 2 different things. I
>> was talking about the specific function in that specific file, where
>> the color is read off the RGB components of a QColor. Let's paste the
>> code:
>>
>> KHCY::KHCY(const QColor& color)
>> {
>> qreal r = gamma(color.redF());
>> qreal g = gamma(color.greenF());
>> qreal b = gamma(color.blueF());
>> a = color.alphaF();
>>
>> // luma component
>> y = lumag(r, g, b);
>>
>> // hue component
>> qreal p = qMax(qMax(r, g), b);
>> qreal n = qMin(qMin(r, g), b);
>> qreal d = 6.0 * (p - n);
>> if (n == p)
>> h = 0.0;
>> else if (r == p)
>> h = ((g - b) / d);
>> else if (g == p)
>> h = ((b - r) / d) + (1.0 / 3.0);
>> else
>> h = ((r - g) / d) + (2.0 / 3.0);
gamma() is a strictly monotonic function. Therefore, you can look at the
integer RGB values of QColor in order to decide which branch to take. You
don't have to look at the gamma-corrected floating-point RGB values.
>>
>> // chroma component
>> if (r == g && g == b)
>> c = 0.0;
>> else
>> c = qMax( (y - n) / y, (p - y) / (1 - y) );
>> }
Same here.
-- Hannes
More information about the kde-core-devel
mailing list