Do a proper convert from [0-65535] to [0-255] on QColor integer reads

We need to divide by 257 and round to undo our setter.

Pick-to: 5.15
Fixes: QTBUG-84168
Change-Id: I55d2a8d1d05125d9560309cd77459cc94a92030f
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2020-05-13 08:53:37 +02:00
parent ee92ee7a3c
commit dfc5a10356

View File

@ -39,6 +39,7 @@
#include "qcolor.h"
#include "qcolor_p.h"
#include "qdrawhelper_p.h"
#include "qfloat16.h"
#include "qnamespace.h"
#include "qdatastream.h"
@ -1052,11 +1053,11 @@ void QColor::getHsv(int *h, int *s, int *v, int *a) const
}
*h = ct.ahsv.hue == USHRT_MAX ? -1 : ct.ahsv.hue / 100;
*s = ct.ahsv.saturation >> 8;
*v = ct.ahsv.value >> 8;
*s = qt_div_257(ct.ahsv.saturation);
*v = qt_div_257(ct.ahsv.value);
if (a)
*a = ct.ahsv.alpha >> 8;
*a = qt_div_257(ct.ahsv.alpha);
}
/*!
@ -1164,11 +1165,11 @@ void QColor::getHsl(int *h, int *s, int *l, int *a) const
}
*h = ct.ahsl.hue == USHRT_MAX ? -1 : ct.ahsl.hue / 100;
*s = ct.ahsl.saturation >> 8;
*l = ct.ahsl.lightness >> 8;
*s = qt_div_257(ct.ahsl.saturation);
*l = qt_div_257(ct.ahsl.lightness);
if (a)
*a = ct.ahsl.alpha >> 8;
*a = qt_div_257(ct.ahsl.alpha);
}
/*!
@ -1296,12 +1297,12 @@ void QColor::getRgb(int *r, int *g, int *b, int *a) const
return;
}
*r = ct.argb.red >> 8;
*g = ct.argb.green >> 8;
*b = ct.argb.blue >> 8;
*r = qt_div_257(ct.argb.red);
*g = qt_div_257(ct.argb.green);
*b = qt_div_257(ct.argb.blue);
if (a)
*a = ct.argb.alpha >> 8;
*a = qt_div_257(ct.argb.alpha);
}
/*!
@ -1379,7 +1380,7 @@ QRgb QColor::rgba() const noexcept
{
if (cspec != Invalid && cspec != Rgb)
return toRgb().rgba();
return qRgba(ct.argb.red >> 8, ct.argb.green >> 8, ct.argb.blue >> 8, ct.argb.alpha >> 8);
return qRgba(qt_div_257(ct.argb.red), qt_div_257(ct.argb.green), qt_div_257(ct.argb.blue), qt_div_257(ct.argb.alpha));
}
/*!
@ -1442,7 +1443,7 @@ QRgb QColor::rgb() const noexcept
{
if (cspec != Invalid && cspec != Rgb)
return toRgb().rgb();
return qRgb(ct.argb.red >> 8, ct.argb.green >> 8, ct.argb.blue >> 8);
return qRgb(qt_div_257(ct.argb.red), qt_div_257(ct.argb.green), qt_div_257(ct.argb.blue));
}
/*!
@ -1469,7 +1470,7 @@ int QColor::alpha() const noexcept
{
if (cspec == ExtendedRgb)
return qRound(qreal(castF16(ct.argbExtended.alphaF16)) * 255);
return ct.argb.alpha >> 8;
return qt_div_257(ct.argb.alpha);
}
@ -1531,7 +1532,7 @@ int QColor::red() const noexcept
{
if (cspec != Invalid && cspec != Rgb)
return toRgb().red();
return ct.argb.red >> 8;
return qt_div_257(ct.argb.red);
}
/*!
@ -1558,7 +1559,7 @@ int QColor::green() const noexcept
{
if (cspec != Invalid && cspec != Rgb)
return toRgb().green();
return ct.argb.green >> 8;
return qt_div_257(ct.argb.green);
}
/*!
@ -1586,7 +1587,7 @@ int QColor::blue() const noexcept
{
if (cspec != Invalid && cspec != Rgb)
return toRgb().blue();
return ct.argb.blue >> 8;
return qt_div_257(ct.argb.blue);
}
@ -1747,7 +1748,7 @@ int QColor::hsvSaturation() const noexcept
{
if (cspec != Invalid && cspec != Hsv)
return toHsv().saturation();
return ct.ahsv.saturation >> 8;
return qt_div_257(ct.ahsv.saturation);
}
/*!
@ -1759,7 +1760,7 @@ int QColor::value() const noexcept
{
if (cspec != Invalid && cspec != Hsv)
return toHsv().value();
return ct.ahsv.value >> 8;
return qt_div_257(ct.ahsv.value);
}
/*!
@ -1849,7 +1850,7 @@ int QColor::hslSaturation() const noexcept
{
if (cspec != Invalid && cspec != Hsl)
return toHsl().hslSaturation();
return ct.ahsl.saturation >> 8;
return qt_div_257(ct.ahsl.saturation);
}
/*!
@ -1863,7 +1864,7 @@ int QColor::lightness() const noexcept
{
if (cspec != Invalid && cspec != Hsl)
return toHsl().lightness();
return ct.ahsl.lightness >> 8;
return qt_div_257(ct.ahsl.lightness);
}
/*!
@ -1917,7 +1918,7 @@ int QColor::cyan() const noexcept
{
if (cspec != Invalid && cspec != Cmyk)
return toCmyk().cyan();
return ct.acmyk.cyan >> 8;
return qt_div_257(ct.acmyk.cyan);
}
/*!
@ -1929,7 +1930,7 @@ int QColor::magenta() const noexcept
{
if (cspec != Invalid && cspec != Cmyk)
return toCmyk().magenta();
return ct.acmyk.magenta >> 8;
return qt_div_257(ct.acmyk.magenta);
}
/*!
@ -1941,7 +1942,7 @@ int QColor::yellow() const noexcept
{
if (cspec != Invalid && cspec != Cmyk)
return toCmyk().yellow();
return ct.acmyk.yellow >> 8;
return qt_div_257(ct.acmyk.yellow);
}
/*!
@ -1954,7 +1955,7 @@ int QColor::black() const noexcept
{
if (cspec != Invalid && cspec != Cmyk)
return toCmyk().black();
return ct.acmyk.black >> 8;
return qt_div_257(ct.acmyk.black);
}
/*!
@ -2635,13 +2636,13 @@ void QColor::getCmyk(int *c, int *m, int *y, int *k, int *a) const
return;
}
*c = ct.acmyk.cyan >> 8;
*m = ct.acmyk.magenta >> 8;
*y = ct.acmyk.yellow >> 8;
*k = ct.acmyk.black >> 8;
*c = qt_div_257(ct.acmyk.cyan);
*m = qt_div_257(ct.acmyk.magenta);
*y = qt_div_257(ct.acmyk.yellow);
*k = qt_div_257(ct.acmyk.black);
if (a)
*a = ct.acmyk.alpha >> 8;
*a = qt_div_257(ct.acmyk.alpha);
}
/*!