summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-05-26 12:33:24 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-09-11 20:41:15 +0200
commit5bb4baae0379d5903f547f0399be9620f5ab06a0 (patch)
tree3a36b2009dfbbdead4e603412886facf6f88b15e
parent25a01538021c526a86adf47f30c9e5607da51cd4 (diff)
Replace qreal with float in QColor
There is no reason to use double precision for colors. We at most have 16 significant bits anyway. Change-Id: I8b402cd978675b8ba7248176976d934363212ff1 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
-rw-r--r--src/gui/painting/qcolor.cpp382
-rw-r--r--src/gui/painting/qcolor.h66
-rw-r--r--tests/auto/gui/painting/qcolor/tst_qcolor.cpp150
-rw-r--r--tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp8
4 files changed, 303 insertions, 303 deletions
diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp
index 89a75d8b2b..54a0fcf011 100644
--- a/src/gui/painting/qcolor.cpp
+++ b/src/gui/painting/qcolor.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
@@ -472,7 +472,7 @@ static QStringList get_colornames()
The alpha channel of a color can be retrieved and set using the
alpha() and setAlpha() functions if its value is an integer, and
- alphaF() and setAlphaF() if its value is qreal (double). By
+ alphaF() and setAlphaF() if its value is float. By
default, the alpha-channel is set to 255 (opaque). To retrieve and
set \e all the RGB color components (including the alpha-channel)
in one go, use the rgba() and setRgba() functions.
@@ -613,9 +613,9 @@ static QStringList get_colornames()
#define QCOLOR_REAL_RANGE_CHECK(fn, var) \
do { \
- if (var < qreal(0.0) || var > qreal(1.0)) { \
+ if (var < 0.0f || var > 1.0f) { \
qWarning(#fn": invalid value %g", var); \
- var = qMax(qreal(0.0), qMin(var, qreal(1.0))); \
+ var = qMax(0.0f, qMin(var, 1.0f)); \
} \
} while (0)
@@ -1020,7 +1020,7 @@ QStringList QColor::colorNames()
\sa setHsv(), {QColor#The HSV Color Model}{The HSV Color Model}
*/
-void QColor::getHsvF(qreal *h, qreal *s, qreal *v, qreal *a) const
+void QColor::getHsvF(float *h, float *s, float *v, float *a) const
{
if (!h || !s || !v)
return;
@@ -1030,12 +1030,12 @@ void QColor::getHsvF(qreal *h, qreal *s, qreal *v, qreal *a) const
return;
}
- *h = ct.ahsv.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsv.hue / qreal(36000.0);
- *s = ct.ahsv.saturation / qreal(USHRT_MAX);
- *v = ct.ahsv.value / qreal(USHRT_MAX);
+ *h = ct.ahsv.hue == USHRT_MAX ? -1.0f : ct.ahsv.hue / 36000.0f;
+ *s = ct.ahsv.saturation / float(USHRT_MAX);
+ *v = ct.ahsv.value / float(USHRT_MAX);
if (a)
- *a = ct.ahsv.alpha / qreal(USHRT_MAX);
+ *a = ct.ahsv.alpha / float(USHRT_MAX);
}
/*!
@@ -1074,12 +1074,12 @@ void QColor::getHsv(int *h, int *s, int *v, int *a) const
\sa getHsvF(), setHsv(), {QColor#The HSV Color Model}{The HSV Color Model}
*/
-void QColor::setHsvF(qreal h, qreal s, qreal v, qreal a)
+void QColor::setHsvF(float h, float s, float v, float a)
{
- if (((h < qreal(0.0) || h > qreal(1.0)) && h != qreal(-1.0))
- || (s < qreal(0.0) || s > qreal(1.0))
- || (v < qreal(0.0) || v > qreal(1.0))
- || (a < qreal(0.0) || a > qreal(1.0))) {
+ if (((h < 0.0f || h > 1.0f) && h != -1.0f)
+ || (s < 0.0f || s > 1.0f)
+ || (v < 0.0f || v > 1.0f)
+ || (a < 0.0f || a > 1.0f)) {
qWarning("QColor::setHsvF: HSV parameters out of range");
invalidate();
return;
@@ -1087,7 +1087,7 @@ void QColor::setHsvF(qreal h, qreal s, qreal v, qreal a)
cspec = Hsv;
ct.ahsv.alpha = qRound(a * USHRT_MAX);
- ct.ahsv.hue = h == qreal(-1.0) ? USHRT_MAX : qRound(h * 36000);
+ ct.ahsv.hue = h == -1.0f ? USHRT_MAX : qRound(h * 36000.0f);
ct.ahsv.saturation = qRound(s * USHRT_MAX);
ct.ahsv.value = qRound(v * USHRT_MAX);
ct.ahsv.pad = 0;
@@ -1130,7 +1130,7 @@ void QColor::setHsv(int h, int s, int v, int a)
\sa getHsl(), setHslF(), {QColor#The HSL Color Model}{The HSL Color Model}
*/
-void QColor::getHslF(qreal *h, qreal *s, qreal *l, qreal *a) const
+void QColor::getHslF(float *h, float *s, float *l, float *a) const
{
if (!h || !s || !l)
return;
@@ -1140,12 +1140,12 @@ void QColor::getHslF(qreal *h, qreal *s, qreal *l, qreal *a) const
return;
}
- *h = ct.ahsl.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsl.hue / qreal(36000.0);
- *s = ct.ahsl.saturation / qreal(USHRT_MAX);
- *l = ct.ahsl.lightness / qreal(USHRT_MAX);
+ *h = ct.ahsl.hue == USHRT_MAX ? -1.0f : ct.ahsl.hue / 36000.0f;
+ *s = ct.ahsl.saturation / float(USHRT_MAX);
+ *l = ct.ahsl.lightness / float(USHRT_MAX);
if (a)
- *a = ct.ahsl.alpha / qreal(USHRT_MAX);
+ *a = ct.ahsl.alpha / float(USHRT_MAX);
}
/*!
@@ -1188,12 +1188,12 @@ void QColor::getHsl(int *h, int *s, int *l, int *a) const
\sa getHslF(), setHsl()
*/
-void QColor::setHslF(qreal h, qreal s, qreal l, qreal a)
+void QColor::setHslF(float h, float s, float l, float a)
{
- if (((h < qreal(0.0) || h > qreal(1.0)) && h != qreal(-1.0))
- || (s < qreal(0.0) || s > qreal(1.0))
- || (l < qreal(0.0) || l > qreal(1.0))
- || (a < qreal(0.0) || a > qreal(1.0))) {
+ if (((h < 0.0f || h > 1.0f) && h != -1.0f)
+ || (s < 0.0f || s > 1.0f)
+ || (l < 0.0f || l > 1.0f)
+ || (a < 0.0f || a > 1.0f)) {
qWarning("QColor::setHslF: HSL parameters out of range");
invalidate();
return;
@@ -1201,7 +1201,7 @@ void QColor::setHslF(qreal h, qreal s, qreal l, qreal a)
cspec = Hsl;
ct.ahsl.alpha = qRound(a * USHRT_MAX);
- ct.ahsl.hue = h == qreal(-1.0) ? USHRT_MAX : qRound(h * 36000);
+ ct.ahsl.hue = h == -1.0f ? USHRT_MAX : qRound(h * 36000.0f);
ct.ahsl.saturation = qRound(s * USHRT_MAX);
ct.ahsl.lightness = qRound(l * USHRT_MAX);
ct.ahsl.pad = 0;
@@ -1255,7 +1255,7 @@ static inline const qfloat16 &castF16(const quint16 &v)
\sa rgb(), setRgb()
*/
-void QColor::getRgbF(qreal *r, qreal *g, qreal *b, qreal *a) const
+void QColor::getRgbF(float *r, float *g, float *b, float *a) const
{
if (!r || !g || !b)
return;
@@ -1269,11 +1269,11 @@ void QColor::getRgbF(qreal *r, qreal *g, qreal *b, qreal *a) const
}
if (cspec == Rgb) {
- *r = ct.argb.red / qreal(USHRT_MAX);
- *g = ct.argb.green / qreal(USHRT_MAX);
- *b = ct.argb.blue / qreal(USHRT_MAX);
+ *r = ct.argb.red / float(USHRT_MAX);
+ *g = ct.argb.green / float(USHRT_MAX);
+ *b = ct.argb.blue / float(USHRT_MAX);
if (a)
- *a = ct.argb.alpha / qreal(USHRT_MAX);
+ *a = ct.argb.alpha / float(USHRT_MAX);
} else {
*r = castF16(ct.argbExtended.redF16);
*g = castF16(ct.argbExtended.greenF16);
@@ -1312,7 +1312,7 @@ void QColor::getRgb(int *r, int *g, int *b, int *a) const
}
/*!
- \fn void QColor::setRgbF(qreal r, qreal g, qreal b, qreal a)
+ \fn void QColor::setRgbF(float r, float g, float b, float a)
Sets the color channels of this color to \a r (red), \a g (green),
\a b (blue) and \a a (alpha, transparency).
@@ -1323,16 +1323,16 @@ void QColor::getRgb(int *r, int *g, int *b, int *a) const
\sa rgb(), getRgbF(), setRgb()
*/
-void QColor::setRgbF(qreal r, qreal g, qreal b, qreal a)
+void QColor::setRgbF(float r, float g, float b, float a)
{
- if (a < qreal(0.0) || a > qreal(1.0)) {
+ if (a < 0.0f || a > 1.0f) {
qWarning("QColor::setRgbF: Alpha parameter is out of range");
invalidate();
return;
}
- if (r < qreal(0.0) || r > qreal(1.0) ||
- g < qreal(0.0) || g > qreal(1.0) ||
- b < qreal(0.0) || b > qreal(1.0) || cspec == ExtendedRgb) {
+ if (r < 0.0f || r > 1.0f ||
+ g < 0.0f || g > 1.0f ||
+ b < 0.0f || b > 1.0f || cspec == ExtendedRgb) {
cspec = ExtendedRgb;
castF16(ct.argbExtended.redF16) = qfloat16(r);
castF16(ct.argbExtended.greenF16) = qfloat16(g);
@@ -1475,7 +1475,7 @@ void QColor::setRgb(QRgb rgb) noexcept
int QColor::alpha() const noexcept
{
if (cspec == ExtendedRgb)
- return qRound(qreal(castF16(ct.argbExtended.alphaF16)) * 255);
+ return qRound(float(castF16(ct.argbExtended.alphaF16)) * 255);
return qt_div_257(ct.argb.alpha);
}
@@ -1491,7 +1491,7 @@ void QColor::setAlpha(int alpha)
{
QCOLOR_INT_RANGE_CHECK("QColor::setAlpha", alpha);
if (cspec == ExtendedRgb) {
- constexpr qreal f = qreal(1.0) / 255;
+ constexpr float f = 1.0f / 255;
castF16(ct.argbExtended.alphaF16) = alpha * f;
return;
}
@@ -1503,28 +1503,28 @@ void QColor::setAlpha(int alpha)
\sa setAlphaF(), alpha(), {QColor#Alpha-Blended Drawing}{Alpha-Blended Drawing}
*/
-qreal QColor::alphaF() const noexcept
+float QColor::alphaF() const noexcept
{
if (cspec == ExtendedRgb)
return castF16(ct.argbExtended.alphaF16);
- return ct.argb.alpha / qreal(USHRT_MAX);
+ return ct.argb.alpha / float(USHRT_MAX);
}
/*!
- Sets the alpha of this color to \a alpha. qreal alpha is specified in the
+ Sets the alpha of this color to \a alpha. float alpha is specified in the
range 0.0-1.0.
\sa alphaF(), alpha(), {QColor#Alpha-Blended Drawing}{Alpha-Blended Drawing}
*/
-void QColor::setAlphaF(qreal alpha)
+void QColor::setAlphaF(float alpha)
{
QCOLOR_REAL_RANGE_CHECK("QColor::setAlphaF", alpha);
if (cspec == ExtendedRgb) {
castF16(ct.argbExtended.alphaF16) = alpha;
return;
}
- qreal tmp = alpha * USHRT_MAX;
+ float tmp = alpha * USHRT_MAX;
ct.argb.alpha = qRound(tmp);
}
@@ -1617,10 +1617,10 @@ void QColor::setBlue(int blue)
\sa setRedF(), red(), getRgbF()
*/
-qreal QColor::redF() const noexcept
+float QColor::redF() const noexcept
{
if (cspec == Rgb || cspec == Invalid)
- return ct.argb.red / qreal(USHRT_MAX);
+ return ct.argb.red / float(USHRT_MAX);
if (cspec == ExtendedRgb)
return castF16(ct.argbExtended.redF16);
@@ -1634,9 +1634,9 @@ qreal QColor::redF() const noexcept
\sa redF(), red(), setRgbF()
*/
-void QColor::setRedF(qreal red)
+void QColor::setRedF(float red)
{
- if (cspec == Rgb && red >= qreal(0.0) && red <= qreal(1.0))
+ if (cspec == Rgb && red >= 0.0f && red <= 1.0f)
ct.argb.red = qRound(red * USHRT_MAX);
else if (cspec == ExtendedRgb)
castF16(ct.argbExtended.redF16) = red;
@@ -1649,10 +1649,10 @@ void QColor::setRedF(qreal red)
\sa setGreenF(), green(), getRgbF()
*/
-qreal QColor::greenF() const noexcept
+float QColor::greenF() const noexcept
{
if (cspec == Rgb || cspec == Invalid)
- return ct.argb.green / qreal(USHRT_MAX);
+ return ct.argb.green / float(USHRT_MAX);
if (cspec == ExtendedRgb)
return castF16(ct.argbExtended.greenF16);
@@ -1666,9 +1666,9 @@ qreal QColor::greenF() const noexcept
\sa greenF(), green(), setRgbF()
*/
-void QColor::setGreenF(qreal green)
+void QColor::setGreenF(float green)
{
- if (cspec == Rgb && green >= qreal(0.0) && green <= qreal(1.0))
+ if (cspec == Rgb && green >= 0.0f && green <= 1.0f)
ct.argb.green = qRound(green * USHRT_MAX);
else if (cspec == ExtendedRgb)
castF16(ct.argbExtended.greenF16) = green;
@@ -1681,10 +1681,10 @@ void QColor::setGreenF(qreal green)
\sa setBlueF(), blue(), getRgbF()
*/
-qreal QColor::blueF() const noexcept
+float QColor::blueF() const noexcept
{
if (cspec == Rgb || cspec == Invalid)
- return ct.argb.blue / qreal(USHRT_MAX);
+ return ct.argb.blue / float(USHRT_MAX);
if (cspec == ExtendedRgb)
return castF16(ct.argbExtended.blueF16);
@@ -1696,9 +1696,9 @@ qreal QColor::blueF() const noexcept
the 0.0-1.0 range, the color model will be changed to \c ExtendedRgb.
\sa blueF(), blue(), setRgbF()
*/
-void QColor::setBlueF(qreal blue)
+void QColor::setBlueF(float blue)
{
- if (cspec == Rgb && blue >= qreal(0.0) && blue <= qreal(1.0))
+ if (cspec == Rgb && blue >= 0.0f && blue <= 1.0f)
ct.argb.blue = qRound(blue * USHRT_MAX);
else if (cspec == ExtendedRgb)
castF16(ct.argbExtended.blueF16) = blue;
@@ -1776,7 +1776,7 @@ int QColor::value() const noexcept
\sa hsvHueF(), hslHueF(), hue(), getHsvF(), {QColor#The HSV Color Model}{The HSV Color Model}
*/
-qreal QColor::hueF() const noexcept
+float QColor::hueF() const noexcept
{
return hsvHueF();
}
@@ -1787,11 +1787,11 @@ qreal QColor::hueF() const noexcept
\sa hue(), hslHueF(), getHsvF(), {QColor#The HSV Color Model}{The HSV Color
Model}
*/
-qreal QColor::hsvHueF() const noexcept
+float QColor::hsvHueF() const noexcept
{
if (cspec != Invalid && cspec != Hsv)
return toHsv().hueF();
- return ct.ahsv.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsv.hue / qreal(36000.0);
+ return ct.ahsv.hue == USHRT_MAX ? -1.0f : ct.ahsv.hue / 36000.0f;
}
/*!
@@ -1802,7 +1802,7 @@ qreal QColor::hsvHueF() const noexcept
\sa hsvSaturationF(), hslSaturationF(), saturation(), getHsvF(), {QColor#The HSV Color Model}{The HSV Color
Model}
*/
-qreal QColor::saturationF() const noexcept
+float QColor::saturationF() const noexcept
{
return hsvSaturationF();
}
@@ -1812,11 +1812,11 @@ qreal QColor::saturationF() const noexcept
\sa saturation(), hslSaturationF(), getHsvF(), {QColor#The HSV Color Model}{The HSV Color Model}
*/
-qreal QColor::hsvSaturationF() const noexcept
+float QColor::hsvSaturationF() const noexcept
{
if (cspec != Invalid && cspec != Hsv)
return toHsv().saturationF();
- return ct.ahsv.saturation / qreal(USHRT_MAX);
+ return ct.ahsv.saturation / float(USHRT_MAX);
}
/*!
@@ -1824,11 +1824,11 @@ qreal QColor::hsvSaturationF() const noexcept
\sa value(), getHsvF(), {QColor#The HSV Color Model}{The HSV Color Model}
*/
-qreal QColor::valueF() const noexcept
+float QColor::valueF() const noexcept
{
if (cspec != Invalid && cspec != Hsv)
return toHsv().valueF();
- return ct.ahsv.value / qreal(USHRT_MAX);
+ return ct.ahsv.value / float(USHRT_MAX);
}
/*!
@@ -1880,11 +1880,11 @@ int QColor::lightness() const noexcept
\sa hslHue(), hsvHueF(), getHslF()
*/
-qreal QColor::hslHueF() const noexcept
+float QColor::hslHueF() const noexcept
{
if (cspec != Invalid && cspec != Hsl)
return toHsl().hslHueF();
- return ct.ahsl.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsl.hue / qreal(36000.0);
+ return ct.ahsl.hue == USHRT_MAX ? -1.0f : ct.ahsl.hue / 36000.0f;
}
/*!
@@ -1894,11 +1894,11 @@ qreal QColor::hslHueF() const noexcept
\sa hslSaturation(), hsvSaturationF(), getHslF(), {QColor#The HSL Color Model}{The HSL Color Model}
*/
-qreal QColor::hslSaturationF() const noexcept
+float QColor::hslSaturationF() const noexcept
{
if (cspec != Invalid && cspec != Hsl)
return toHsl().hslSaturationF();
- return ct.ahsl.saturation / qreal(USHRT_MAX);
+ return ct.ahsl.saturation / float(USHRT_MAX);
}
/*!
@@ -1908,11 +1908,11 @@ qreal QColor::hslSaturationF() const noexcept
\sa value(), getHslF()
*/
-qreal QColor::lightnessF() const noexcept
+float QColor::lightnessF() const noexcept
{
if (cspec != Invalid && cspec != Hsl)
return toHsl().lightnessF();
- return ct.ahsl.lightness / qreal(USHRT_MAX);
+ return ct.ahsl.lightness / float(USHRT_MAX);
}
/*!
@@ -1969,11 +1969,11 @@ int QColor::black() const noexcept
\sa cyan(), getCmykF(), {QColor#The CMYK Color Model}{The CMYK Color Model}
*/
-qreal QColor::cyanF() const noexcept
+float QColor::cyanF() const noexcept
{
if (cspec != Invalid && cspec != Cmyk)
return toCmyk().cyanF();
- return ct.acmyk.cyan / qreal(USHRT_MAX);
+ return ct.acmyk.cyan / float(USHRT_MAX);
}
/*!
@@ -1981,11 +1981,11 @@ qreal QColor::cyanF() const noexcept
\sa magenta(), getCmykF(), {QColor#The CMYK Color Model}{The CMYK Color Model}
*/
-qreal QColor::magentaF() const noexcept
+float QColor::magentaF() const noexcept
{
if (cspec != Invalid && cspec != Cmyk)
return toCmyk().magentaF();
- return ct.acmyk.magenta / qreal(USHRT_MAX);
+ return ct.acmyk.magenta / float(USHRT_MAX);
}
/*!
@@ -1993,11 +1993,11 @@ qreal QColor::magentaF() const noexcept
\sa yellow(), getCmykF(), {QColor#The CMYK Color Model}{The CMYK Color Model}
*/
-qreal QColor::yellowF() const noexcept
+float QColor::yellowF() const noexcept
{
if (cspec != Invalid && cspec != Cmyk)
return toCmyk().yellowF();
- return ct.acmyk.yellow / qreal(USHRT_MAX);
+ return ct.acmyk.yellow / float(USHRT_MAX);
}
/*!
@@ -2005,11 +2005,11 @@ qreal QColor::yellowF() const noexcept
\sa black(), getCmykF(), {QColor#The CMYK Color Model}{The CMYK Color Model}
*/
-qreal QColor::blackF() const noexcept
+float QColor::blackF() const noexcept
{
if (cspec != Invalid && cspec != Cmyk)
return toCmyk().blackF();
- return ct.acmyk.black / qreal(USHRT_MAX);
+ return ct.acmyk.black / float(USHRT_MAX);
}
/*!
@@ -2025,7 +2025,7 @@ QColor QColor::toExtendedRgb() const noexcept
if (cspec != Rgb)
return toRgb().toExtendedRgb();
- constexpr qreal f = qreal(1.0) / USHRT_MAX;
+ constexpr float f = 1.0f / USHRT_MAX;
QColor color;
color.cspec = ExtendedRgb;
castF16(color.ct.argbExtended.alphaF16) = qfloat16(ct.argb.alpha * f);
@@ -2062,15 +2062,15 @@ QColor QColor::toRgb() const noexcept
}
// chromatic case
- const qreal h = ct.ahsv.hue == 36000 ? 0 : ct.ahsv.hue / 6000.;
- const qreal s = ct.ahsv.saturation / qreal(USHRT_MAX);
- const qreal v = ct.ahsv.value / qreal(USHRT_MAX);
+ const float h = ct.ahsv.hue == 36000 ? 0.0f : ct.ahsv.hue / 6000.0f;
+ const float s = ct.ahsv.saturation / float(USHRT_MAX);
+ const float v = ct.ahsv.value / float(USHRT_MAX);
const int i = int(h);
- const qreal f = h - i;
- const qreal p = v * (qreal(1.0) - s);
+ const float f = h - i;
+ const float p = v * (1.0f - s);
if (i & 1) {
- const qreal q = v * (qreal(1.0) - (s * f));
+ const float q = v * (1.0f - (s * f));
switch (i) {
case 1:
@@ -2090,7 +2090,7 @@ QColor QColor::toRgb() const noexcept
break;
}
} else {
- const qreal t = v * (qreal(1.0) - (s * (qreal(1.0) - f)));
+ const float t = v * (1.0f - (s * (1.0f - f)));
switch (i) {
case 0:
@@ -2122,34 +2122,34 @@ QColor QColor::toRgb() const noexcept
color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = 0;
} else {
// chromatic case
- const qreal h = ct.ahsl.hue == 36000 ? 0 : ct.ahsl.hue / 36000.;
- const qreal s = ct.ahsl.saturation / qreal(USHRT_MAX);
- const qreal l = ct.ahsl.lightness / qreal(USHRT_MAX);
+ const float h = ct.ahsl.hue == 36000 ? 0.0f : ct.ahsl.hue / 36000.0f;
+ const float s = ct.ahsl.saturation / float(USHRT_MAX);
+ const float l = ct.ahsl.lightness / float(USHRT_MAX);
- qreal temp2;
- if (l < qreal(0.5))
- temp2 = l * (qreal(1.0) + s);
+ float temp2;
+ if (l < 0.5f)
+ temp2 = l * (1.0f + s);
else
temp2 = l + s - (l * s);
- const qreal temp1 = (qreal(2.0) * l) - temp2;
- qreal temp3[3] = { h + (qreal(1.0) / qreal(3.0)),
+ const float temp1 = (2.0f * l) - temp2;
+ float temp3[3] = { h + (1.0f / 3.0f),
h,
- h - (qreal(1.0) / qreal(3.0)) };
+ h - (1.0f / 3.0f) };
for (int i = 0; i != 3; ++i) {
- if (temp3[i] < qreal(0.0))
- temp3[i] += qreal(1.0);
- else if (temp3[i] > qreal(1.0))
- temp3[i] -= qreal(1.0);
+ if (temp3[i] < 0.0f)
+ temp3[i] += 1.0f;
+ else if (temp3[i] > 1.0f)
+ temp3[i] -= 1.0f;
- const qreal sixtemp3 = temp3[i] * qreal(6.0);
- if (sixtemp3 < qreal(1.0))
+ const float sixtemp3 = temp3[i] * 6.0f;
+ if (sixtemp3 < 1.0f)
color.ct.array[i+1] = qRound((temp1 + (temp2 - temp1) * sixtemp3) * USHRT_MAX);
- else if ((temp3[i] * qreal(2.0)) < qreal(1.0))
+ else if ((temp3[i] * 2.0f) < 1.0f)
color.ct.array[i+1] = qRound(temp2 * USHRT_MAX);
- else if ((temp3[i] * qreal(3.0)) < qreal(2.0))
- color.ct.array[i+1] = qRound((temp1 + (temp2 -temp1) * (qreal(2.0) /qreal(3.0) - temp3[i]) * qreal(6.0)) * USHRT_MAX);
+ else if ((temp3[i] * 3.0f) < 2.0f)
+ color.ct.array[i+1] = qRound((temp1 + (temp2 -temp1) * (2.0f /3.0f - temp3[i]) * 6.0f) * USHRT_MAX);
else
color.ct.array[i+1] = qRound(temp1 * USHRT_MAX);
}
@@ -2161,21 +2161,21 @@ QColor QColor::toRgb() const noexcept
}
case Cmyk:
{
- const qreal c = ct.acmyk.cyan / qreal(USHRT_MAX);
- const qreal m = ct.acmyk.magenta / qreal(USHRT_MAX);
- const qreal y = ct.acmyk.yellow / qreal(USHRT_MAX);
- const qreal k = ct.acmyk.black / qreal(USHRT_MAX);
-
- color.ct.argb.red = qRound((qreal(1.0) - (c * (qreal(1.0) - k) + k)) * USHRT_MAX);
- color.ct.argb.green = qRound((qreal(1.0) - (m * (qreal(1.0) - k) + k)) * USHRT_MAX);
- color.ct.argb.blue = qRound((qreal(1.0) - (y * (qreal(1.0) - k) + k)) * USHRT_MAX);
+ const float c = ct.acmyk.cyan / float(USHRT_MAX);
+ const float m = ct.acmyk.magenta / float(USHRT_MAX);
+ const float y = ct.acmyk.yellow / float(USHRT_MAX);
+ const float k = ct.acmyk.black / float(USHRT_MAX);
+
+ color.ct.argb.red = qRound((1.0f - (c * (1.0f - k) + k)) * USHRT_MAX);
+ color.ct.argb.green = qRound((1.0f - (m * (1.0f - k) + k)) * USHRT_MAX);
+ color.ct.argb.blue = qRound((1.0f - (y * (1.0f - k) + k)) * USHRT_MAX);
break;
}
case ExtendedRgb:
- color.ct.argb.alpha = qRound(USHRT_MAX * qreal(castF16(ct.argbExtended.alphaF16)));
- color.ct.argb.red = qRound(USHRT_MAX * qBound(qreal(0.0), qreal(castF16(ct.argbExtended.redF16)), qreal(1.0)));
- color.ct.argb.green = qRound(USHRT_MAX * qBound(qreal(0.0), qreal(castF16(ct.argbExtended.greenF16)), qreal(1.0)));
- color.ct.argb.blue = qRound(USHRT_MAX * qBound(qreal(0.0), qreal(castF16(ct.argbExtended.blueF16)), qreal(1.0)));
+ color.ct.argb.alpha = qRound(USHRT_MAX * float(castF16(ct.argbExtended.alphaF16)));
+ color.ct.argb.red = qRound(USHRT_MAX * qBound(0.0f, float(castF16(ct.argbExtended.redF16)), 1.0f));
+ color.ct.argb.green = qRound(USHRT_MAX * qBound(0.0f, float(castF16(ct.argbExtended.greenF16)), 1.0f));
+ color.ct.argb.blue = qRound(USHRT_MAX * qBound(0.0f, float(castF16(ct.argbExtended.blueF16)), 1.0f));
break;
default:
break;
@@ -2207,12 +2207,12 @@ QColor QColor::toHsv() const noexcept
color.ct.ahsv.alpha = ct.argb.alpha;
color.ct.ahsv.pad = 0;
- const qreal r = ct.argb.red / qreal(USHRT_MAX);
- const qreal g = ct.argb.green / qreal(USHRT_MAX);
- const qreal b = ct.argb.blue / qreal(USHRT_MAX);
- const qreal max = Q_MAX_3(r, g, b);
- const qreal min = Q_MIN_3(r, g, b);
- const qreal delta = max - min;
+ const float r = ct.argb.red / float(USHRT_MAX);
+ const float g = ct.argb.green / float(USHRT_MAX);
+ const float b = ct.argb.blue / float(USHRT_MAX);
+ const float max = Q_MAX_3(r, g, b);
+ const float min = Q_MIN_3(r, g, b);
+ const float delta = max - min;
color.ct.ahsv.value = qRound(max * USHRT_MAX);
if (qFuzzyIsNull(delta)) {
// achromatic case, hue is undefined
@@ -2220,21 +2220,21 @@ QColor QColor::toHsv() const noexcept
color.ct.ahsv.saturation = 0;
} else {
// chromatic case
- qreal hue = 0;
+ float hue = 0;
color.ct.ahsv.saturation = qRound((delta / max) * USHRT_MAX);
if (qFuzzyCompare(r, max)) {
hue = ((g - b) /delta);
} else if (qFuzzyCompare(g, max)) {
- hue = (qreal(2.0) + (b - r) / delta);
+ hue = (2.0f + (b - r) / delta);
} else if (qFuzzyCompare(b, max)) {
- hue = (qreal(4.0) + (r - g) / delta);
+ hue = (4.0f + (r - g) / delta);
} else {
Q_ASSERT_X(false, "QColor::toHsv", "internal error");
}
- hue *= qreal(60.0);
- if (hue < qreal(0.0))
- hue += qreal(360.0);
- color.ct.ahsv.hue = qRound(hue * 100);
+ hue *= 60.0f;
+ if (hue < 0.0f)
+ hue += 360.0f;
+ color.ct.ahsv.hue = qRound(hue * 100.0f);
}
return color;
@@ -2258,14 +2258,14 @@ QColor QColor::toHsl() const noexcept
color.ct.ahsl.alpha = ct.argb.alpha;
color.ct.ahsl.pad = 0;
- const qreal r = ct.argb.red / qreal(USHRT_MAX);
- const qreal g = ct.argb.green / qreal(USHRT_MAX);
- const qreal b = ct.argb.blue / qreal(USHRT_MAX);
- const qreal max = Q_MAX_3(r, g, b);
- const qreal min = Q_MIN_3(r, g, b);
- const qreal delta = max - min;
- const qreal delta2 = max + min;
- const qreal lightness = qreal(0.5) * delta2;
+ const float r = ct.argb.red / float(USHRT_MAX);
+ const float g = ct.argb.green / float(USHRT_MAX);
+ const float b = ct.argb.blue / float(USHRT_MAX);
+ const float max = Q_MAX_3(r, g, b);
+ const float min = Q_MIN_3(r, g, b);
+ const float delta = max - min;
+ const float delta2 = max + min;
+ const float lightness = 0.5f * delta2;
color.ct.ahsl.lightness = qRound(lightness * USHRT_MAX);
if (qFuzzyIsNull(delta)) {
// achromatic case, hue is undefined
@@ -2273,24 +2273,24 @@ QColor QColor::toHsl() const noexcept
color.ct.ahsl.saturation = 0;
} else {
// chromatic case
- qreal hue = 0;
- if (lightness < qreal(0.5))
+ float hue = 0;
+ if (lightness < 0.5f)
color.ct.ahsl.saturation = qRound((delta / delta2) * USHRT_MAX);
else
- color.ct.ahsl.saturation = qRound((delta / (qreal(2.0) - delta2)) * USHRT_MAX);
+ color.ct.ahsl.saturation = qRound((delta / (2.0f - delta2)) * USHRT_MAX);
if (qFuzzyCompare(r, max)) {
hue = ((g - b) /delta);
} else if (qFuzzyCompare(g, max)) {
- hue = (qreal(2.0) + (b - r) / delta);
+ hue = (2.0f + (b - r) / delta);
} else if (qFuzzyCompare(b, max)) {
- hue = (qreal(4.0) + (r - g) / delta);
+ hue = (4.0f + (r - g) / delta);
} else {
Q_ASSERT_X(false, "QColor::toHsv", "internal error");
}
- hue *= qreal(60.0);
- if (hue < qreal(0.0))
- hue += qreal(360.0);
- color.ct.ahsl.hue = qRound(hue * 100);
+ hue *= 60.0f;
+ if (hue < 0.0f)
+ hue += 360.0f;
+ color.ct.ahsl.hue = qRound(hue * 100.0f);
}
return color;
@@ -2320,18 +2320,18 @@ QColor QColor::toCmyk() const noexcept
color.ct.acmyk.black = USHRT_MAX;
} else {
// rgb -> cmy
- const qreal r = ct.argb.red / qreal(USHRT_MAX);
- const qreal g = ct.argb.green / qreal(USHRT_MAX);
- const qreal b = ct.argb.blue / qreal(USHRT_MAX);
- qreal c = qreal(1.0) - r;
- qreal m = qreal(1.0) - g;
- qreal y = qreal(1.0) - b;
+ const float r = ct.argb.red / float(USHRT_MAX);
+ const float g = ct.argb.green / float(USHRT_MAX);
+ const float b = ct.argb.blue / float(USHRT_MAX);
+ float c = 1.0f - r;
+ float m = 1.0f - g;
+ float y = 1.0f - b;
// cmy -> cmyk
- const qreal k = qMin(c, qMin(m, y));
- c = (c - k) / (qreal(1.0) - k);
- m = (m - k) / (qreal(1.0) - k);
- y = (y - k) / (qreal(1.0) - k);
+ const float k = qMin(c, qMin(m, y));
+ c = (c - k) / (1.0f - k);
+ m = (m - k) / (1.0f - k);
+ y = (y - k) / (1.0f - k);
color.ct.acmyk.cyan = qRound(c * USHRT_MAX);
color.ct.acmyk.magenta = qRound(m * USHRT_MAX);
@@ -2433,16 +2433,16 @@ QColor QColor::fromRgb(int r, int g, int b, int a)
\sa fromRgb(), fromRgba64(), toRgb(), isValid()
*/
-QColor QColor::fromRgbF(qreal r, qreal g, qreal b, qreal a)
+QColor QColor::fromRgbF(float r, float g, float b, float a)
{
- if (a < qreal(0.0) || a > qreal(1.0)) {
+ if (a < 0.0f || a > 1.0f) {
qWarning("QColor::fromRgbF: Alpha parameter out of range");
return QColor();
}
- if (r < qreal(0.0) || r > qreal(1.0)
- || g < qreal(0.0) || g > qreal(1.0)
- || b < qreal(0.0) || b > qreal(1.0)) {
+ if (r < 0.0f || r > 1.0f
+ || g < 0.0f || g > 1.0f
+ || b < 0.0f || b > 1.0f) {
QColor color;
color.cspec = ExtendedRgb;
castF16(color.ct.argbExtended.alphaF16) = qfloat16(a);
@@ -2536,12 +2536,12 @@ QColor QColor::fromHsv(int h, int s, int v, int a)
\sa toHsv(), fromHsv(), isValid(), {QColor#The HSV Color Model}{The HSV Color Model}
*/
-QColor QColor::fromHsvF(qreal h, qreal s, qreal v, qreal a)
+QColor QColor::fromHsvF(float h, float s, float v, float a)
{
- if (((h < qreal(0.0) || h > qreal(1.0)) && h != qreal(-1.0))
- || (s < qreal(0.0) || s > qreal(1.0))
- || (v < qreal(0.0) || v > qreal(1.0))
- || (a < qreal(0.0) || a > qreal(1.0))) {
+ if (((h < 0.0f || h > 1.0f) && h != -1.0f)
+ || (s < 0.0f || s > 1.0f)
+ || (v < 0.0f || v > 1.0f)
+ || (a < 0.0f || a > 1.0f)) {
qWarning("QColor::fromHsvF: HSV parameters out of range");
return QColor();
}
@@ -2549,7 +2549,7 @@ QColor QColor::fromHsvF(qreal h, qreal s, qreal v, qreal a)
QColor color;
color.cspec = Hsv;
color.ct.ahsv.alpha = qRound(a * USHRT_MAX);
- color.ct.ahsv.hue = h == qreal(-1.0) ? USHRT_MAX : qRound(h * 36000);
+ color.ct.ahsv.hue = h == -1.0f ? USHRT_MAX : qRound(h * 36000.0f);
color.ct.ahsv.saturation = qRound(s * USHRT_MAX);
color.ct.ahsv.value = qRound(v * USHRT_MAX);
color.ct.ahsv.pad = 0;
@@ -2600,12 +2600,12 @@ QColor QColor::fromHsl(int h, int s, int l, int a)
\sa toHsl(), fromHsl(), isValid(), {QColor#The HSL Color Model}{The HSL Color Model}
*/
-QColor QColor::fromHslF(qreal h, qreal s, qreal l, qreal a)
+QColor QColor::fromHslF(float h, float s, float l, float a)
{
- if (((h < qreal(0.0) || h > qreal(1.0)) && h != qreal(-1.0))
- || (s < qreal(0.0) || s > qreal(1.0))
- || (l < qreal(0.0) || l > qreal(1.0))
- || (a < qreal(0.0) || a > qreal(1.0))) {
+ if (((h < 0.0f || h > 1.0f) && h != -1.0f)
+ || (s < 0.0f || s > 1.0f)
+ || (l < 0.0f || l > 1.0f)
+ || (a < 0.0f || a > 1.0f)) {
qWarning("QColor::fromHslF: HSL parameters out of range");
return QColor();
}
@@ -2613,7 +2613,7 @@ QColor QColor::fromHslF(qreal h, qreal s, qreal l, qreal a)
QColor color;
color.cspec = Hsl;
color.ct.ahsl.alpha = qRound(a * USHRT_MAX);
- color.ct.ahsl.hue = (h == qreal(-1.0)) ? USHRT_MAX : qRound(h * 36000);
+ color.ct.ahsl.hue = (h == -1.0f) ? USHRT_MAX : qRound(h * 36000.0f);
if (color.ct.ahsl.hue == 36000)
color.ct.ahsl.hue = 0;
color.ct.ahsl.saturation = qRound(s * USHRT_MAX);
@@ -2661,7 +2661,7 @@ void QColor::getCmyk(int *c, int *m, int *y, int *k, int *a) const
\sa setCmykF(), {QColor#The CMYK Color Model}{The CMYK Color Model}
*/
-void QColor::getCmykF(qreal *c, qreal *m, qreal *y, qreal *k, qreal *a) const
+void QColor::getCmykF(float *c, float *m, float *y, float *k, float *a) const
{
if (!c || !m || !y || !k)
return;
@@ -2671,13 +2671,13 @@ void QColor::getCmykF(qreal *c, qreal *m, qreal *y, qreal *k, qreal *a) const
return;
}
- *c = ct.acmyk.cyan / qreal(USHRT_MAX);
- *m = ct.acmyk.magenta / qreal(USHRT_MAX);
- *y = ct.acmyk.yellow / qreal(USHRT_MAX);
- *k = ct.acmyk.black / qreal(USHRT_MAX);
+ *c = ct.acmyk.cyan / float(USHRT_MAX);
+ *m = ct.acmyk.magenta / float(USHRT_MAX);
+ *y = ct.acmyk.yellow / float(USHRT_MAX);
+ *k = ct.acmyk.black / float(USHRT_MAX);
if (a)
- *a = ct.acmyk.alpha / qreal(USHRT_MAX);
+ *a = ct.acmyk.alpha / float(USHRT_MAX);
}
/*!
@@ -2718,13 +2718,13 @@ void QColor::setCmyk(int c, int m, int y, int k, int a)
\sa getCmykF(), setCmyk(), {QColor#The CMYK Color Model}{The CMYK Color Model}
*/
-void QColor::setCmykF(qreal c, qreal m, qreal y, qreal k, qreal a)
+void QColor::setCmykF(float c, float m, float y, float k, float a)
{
- if (c < qreal(0.0) || c > qreal(1.0)
- || m < qreal(0.0) || m > qreal(1.0)
- || y < qreal(0.0) || y > qreal(1.0)
- || k < qreal(0.0) || k > qreal(1.0)
- || a < qreal(0.0) || a > qreal(1.0)) {
+ if (c < 0.0f || c > 1.0f
+ || m < 0.0f || m > 1.0f
+ || y < 0.0f || y > 1.0f
+ || k < 0.0f || k > 1.0f
+ || a < 0.0f || a > 1.0f) {
qWarning("QColor::setCmykF: CMYK parameters out of range");
invalidate();
return;
@@ -2779,13 +2779,13 @@ QColor QColor::fromCmyk(int c, int m, int y, int k, int a)
\sa toCmyk(), fromCmyk(), isValid(), {QColor#The CMYK Color Model}{The CMYK Color Model}
*/
-QColor QColor::fromCmykF(qreal c, qreal m, qreal y, qreal k, qreal a)
+QColor QColor::fromCmykF(float c, float m, float y, float k, float a)
{
- if (c < qreal(0.0) || c > qreal(1.0)
- || m < qreal(0.0) || m > qreal(1.0)
- || y < qreal(0.0) || y > qreal(1.0)
- || k < qreal(0.0) || k > qreal(1.0)
- || a < qreal(0.0) || a > qreal(1.0)) {
+ if (c < 0.0f || c > 1.0f
+ || m < 0.0f || m > 1.0f
+ || y < 0.0f || y > 1.0f
+ || k < 0.0f || k > 1.0f
+ || a < 0.0f || a > 1.0f) {
qWarning("QColor::fromCmykF: CMYK parameters out of range");
return QColor();
}
diff --git a/src/gui/painting/qcolor.h b/src/gui/painting/qcolor.h
index 0bac2b5d7a..d8269974be 100644
--- a/src/gui/painting/qcolor.h
+++ b/src/gui/painting/qcolor.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
@@ -109,8 +109,8 @@ public:
int alpha() const noexcept;
void setAlpha(int alpha);
- qreal alphaF() const noexcept;
- void setAlphaF(qreal alpha);
+ float alphaF() const noexcept;
+ void setAlphaF(float alpha);
int red() const noexcept;
int green() const noexcept;
@@ -119,18 +119,18 @@ public:
void setGreen(int green);
void setBlue(int blue);
- qreal redF() const noexcept;
- qreal greenF() const noexcept;
- qreal blueF() const noexcept;
- void setRedF(qreal red);
- void setGreenF(qreal green);
- void setBlueF(qreal blue);
+ float redF() const noexcept;
+ float greenF() const noexcept;
+ float blueF() const noexcept;
+ void setRedF(float red);
+ void setGreenF(float green);
+ void setBlueF(float blue);
void getRgb(int *r, int *g, int *b, int *a = nullptr) const;
void setRgb(int r, int g, int b, int a = 255);
- void getRgbF(qreal *r, qreal *g, qreal *b, qreal *a = nullptr) const;
- void setRgbF(qreal r, qreal g, qreal b, qreal a = 1.0);
+ void getRgbF(float *r, float *g, float *b, float *a = nullptr) const;
+ void setRgbF(float r, float g, float b, float a = 1.0);
QRgba64 rgba64() const noexcept;
void setRgba64(QRgba64 rgba) noexcept;
@@ -147,47 +147,47 @@ public:
int hsvSaturation() const noexcept;
int value() const noexcept;
- qreal hueF() const noexcept; // 0.0 <= hueF < 360.0
- qreal saturationF() const noexcept;
- qreal hsvHueF() const noexcept; // 0.0 <= hueF < 360.0
- qreal hsvSaturationF() const noexcept;
- qreal valueF() const noexcept;
+ float hueF() const noexcept; // 0.0 <= hueF < 360.0
+ float saturationF() const noexcept;
+ float hsvHueF() const noexcept; // 0.0 <= hueF < 360.0
+ float hsvSaturationF() const noexcept;
+ float valueF() const noexcept;
void getHsv(int *h, int *s, int *v, int *a = nullptr) const;
void setHsv(int h, int s, int v, int a = 255);
- void getHsvF(qreal *h, qreal *s, qreal *v, qreal *a = nullptr) const;
- void setHsvF(qreal h, qreal s, qreal v, qreal a = 1.0);
+ void getHsvF(float *h, float *s, float *v, float *a = nullptr) const;
+ void setHsvF(float h, float s, float v, float a = 1.0);
int cyan() const noexcept;
int magenta() const noexcept;
int yellow() const noexcept;
int black() const noexcept;
- qreal cyanF() const noexcept;
- qreal magentaF() const noexcept;
- qreal yellowF() const noexcept;
- qreal blackF() const noexcept;
+ float cyanF() const noexcept;
+ float magentaF() const noexcept;
+ float yellowF() const noexcept;
+ float blackF() const noexcept;
void getCmyk(int *c, int *m, int *y, int *k, int *a = nullptr) const;
void setCmyk(int c, int m, int y, int k, int a = 255);
- void getCmykF(qreal *c, qreal *m, qreal *y, qreal *k, qreal *a = nullptr) const;
- void setCmykF(qreal c, qreal m, qreal y, qreal k, qreal a = 1.0);
+ void getCmykF(float *c, float *m, float *y, float *k, float *a = nullptr) const;
+ void setCmykF(float c, float m, float y, float k, float a = 1.0);
int hslHue() const noexcept; // 0 <= hue < 360
int hslSaturation() const noexcept;
int lightness() const noexcept;
- qreal hslHueF() const noexcept; // 0.0 <= hueF < 360.0
- qreal hslSaturationF() const noexcept;
- qreal lightnessF() const noexcept;
+ float hslHueF() const noexcept; // 0.0 <= hueF < 360.0
+ float hslSaturationF() const noexcept;
+ float lightnessF() const noexcept;
void getHsl(int *h, int *s, int *l, int *a = nullptr) const;
void setHsl(int h, int s, int l, int a = 255);
- void getHslF(qreal *h, qreal *s, qreal *l, qreal *a = nullptr) const;
- void setHslF(qreal h, qreal s, qreal l, qreal a = 1.0);
+ void getHslF(float *h, float *s, float *l, float *a = nullptr) const;
+ void setHslF(float h, float s, float l, float a = 1.0);
QColor toRgb() const noexcept;
QColor toHsv() const noexcept;
@@ -201,19 +201,19 @@ public:
static QColor fromRgba(QRgb rgba) noexcept;
static QColor fromRgb(int r, int g, int b, int a = 255);
- static QColor fromRgbF(qreal r, qreal g, qreal b, qreal a = 1.0);
+ static QColor fromRgbF(float r, float g, float b, float a = 1.0);
static QColor fromRgba64(ushort r, ushort g, ushort b, ushort a = USHRT_MAX) noexcept;
static QColor fromRgba64(QRgba64 rgba) noexcept;
static QColor fromHsv(int h, int s, int v, int a = 255);
- static QColor fromHsvF(qreal h, qreal s, qreal v, qreal a = 1.0);
+ static QColor fromHsvF(float h, float s, float v, float a = 1.0);
static QColor fromCmyk(int c, int m, int y, int k, int a = 255);
- static QColor fromCmykF(qreal c, qreal m, qreal y, qreal k, qreal a = 1.0);
+ static QColor fromCmykF(float c, float m, float y, float k, float a = 1.0);
static QColor fromHsl(int h, int s, int l, int a = 255);
- static QColor fromHslF(qreal h, qreal s, qreal l, qreal a = 1.0);
+ static QColor fromHslF(float h, float s, float l, float a = 1.0);
Q_REQUIRED_RESULT QColor lighter(int f = 150) const noexcept;
Q_REQUIRED_RESULT QColor darker(int f = 200) const noexcept;
diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
index 5c558ea1b3..b9ae7a258b 100644
--- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
+++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -136,16 +136,16 @@ void tst_QColor::getSetCheck()
obj1.setAlpha(INT_MAX);
QCOMPARE(obj1.alpha(), 255); // range<0, 255>
- // qreal QColor::alphaF()
- // void QColor::setAlphaF(qreal)
+ // float QColor::alphaF()
+ // void QColor::setAlphaF(float)
obj1.setAlphaF(0.0);
- QCOMPARE(obj1.alphaF(), qreal(0.0)); // range<0.0, 1.0>
+ QCOMPARE(obj1.alphaF(), 0.0f); // range<0.0, 1.0>
obj1.setAlphaF(-0.2);
- QCOMPARE(obj1.alphaF(), qreal(0.0)); // range<0.0, 1.0>
+ QCOMPARE(obj1.alphaF(), 0.0f); // range<0.0, 1.0>
obj1.setAlphaF(1.0);
- QCOMPARE(obj1.alphaF(), qreal(1.0)); // range<0.0, 1.0>
+ QCOMPARE(obj1.alphaF(), 1.0f); // range<0.0, 1.0>
obj1.setAlphaF(1.1);
- QCOMPARE(obj1.alphaF(), qreal(1.0)); // range<0.0, 1.0>
+ QCOMPARE(obj1.alphaF(), 1.0f); // range<0.0, 1.0>
// int QColor::red()
// void QColor::setRed(int)
@@ -186,32 +186,32 @@ void tst_QColor::getSetCheck()
obj1.setBlue(INT_MAX);
QCOMPARE(obj1.blue(), 255); // range<0, 255>
- // qreal QColor::redF()
- // void QColor::setRedF(qreal)
+ // float QColor::redF()
+ // void QColor::setRedF(float)
obj1.setRedF(0.0);
- QCOMPARE(obj1.redF(), qreal(0.0));
+ QCOMPARE(obj1.redF(), 0.0f);
obj1.setRedF(-0.25);
- QCOMPARE(obj1.redF(), qreal(-0.25));
+ QCOMPARE(obj1.redF(), -0.25f);
obj1.setRedF(1.25);
- QCOMPARE(obj1.redF(), qreal(1.25));
+ QCOMPARE(obj1.redF(), 1.25f);
- // qreal QColor::greenF()
- // void QColor::setGreenF(qreal)
+ // float QColor::greenF()
+ // void QColor::setGreenF(float)
obj1.setGreenF(0.0);
- QCOMPARE(obj1.greenF(), qreal(0.0));
+ QCOMPARE(obj1.greenF(), 0.0f);
obj1.setGreenF(-0.25);
- QCOMPARE(obj1.greenF(), qreal(-0.25));
+ QCOMPARE(obj1.greenF(), -0.25f);
obj1.setGreenF(1.5);
- QCOMPARE(obj1.greenF(), qreal(1.5));
+ QCOMPARE(obj1.greenF(), 1.5f);
- // qreal QColor::blueF()
- // void QColor::setBlueF(qreal)
+ // float QColor::blueF()
+ // void QColor::setBlueF(float)
obj1.setBlueF(0.0);
- QCOMPARE(obj1.blueF(), qreal(0.0));
+ QCOMPARE(obj1.blueF(), 0.0f);
obj1.setBlueF(-0.5);
- QCOMPARE(obj1.blueF(), qreal(-0.5));
+ QCOMPARE(obj1.blueF(), -0.5f);
obj1.setBlueF(2.0);
- QCOMPARE(obj1.blueF(), qreal(2.0));
+ QCOMPARE(obj1.blueF(), 2.0f);
// QRgb QColor::rgba()
// void QColor::setRgba(QRgb)
@@ -829,8 +829,8 @@ void tst_QColor::setRed()
c = QColor(Qt::blue).toHsv();
c.setRedF(0.5);
QVERIFY(veryFuzzyCompare(c.redF(), 0.5));
- QCOMPARE(c.greenF(), qreal(0.0));
- QCOMPARE(c.blueF(), qreal(1.0));
+ QCOMPARE(c.greenF(), 0.0f);
+ QCOMPARE(c.blueF(), 1.0f);
}
void tst_QColor::setGreen()
@@ -843,9 +843,9 @@ void tst_QColor::setGreen()
c = QColor(Qt::blue).toHsv();
c.setGreenF(0.5);
- QCOMPARE(c.redF(), qreal(0.0));
+ QCOMPARE(c.redF(), 0.0f);
QVERIFY(veryFuzzyCompare(c.greenF(), 0.5));
- QCOMPARE(c.blueF(), qreal(1.0));
+ QCOMPARE(c.blueF(), 1.0f);
}
void tst_QColor::setBlue()
@@ -858,8 +858,8 @@ void tst_QColor::setBlue()
c = QColor(Qt::red).toHsv();
c.setBlueF(0.5);
- QCOMPARE(c.redF(), qreal(1.0));
- QCOMPARE(c.greenF(), qreal(0.0));
+ QCOMPARE(c.redF(), 1.0f);
+ QCOMPARE(c.greenF(), 0.0f);
QVERIFY(veryFuzzyCompare(c.blueF(), 0.5));
}
@@ -945,11 +945,11 @@ void tst_QColor::setRgbF()
for (int A = 0; A <= USHRT_MAX; ++A) {
{
// 0.0-1.0
- qreal a = A / qreal(USHRT_MAX);
+ float a = A / float(USHRT_MAX);
color.setRgbF(0.0, 0.0, 0.0, a);
QCOMPARE(color.alphaF(), a);
- qreal r, g, b, a2;
+ float r, g, b, a2;
color.getRgbF(&r, &g, &b, &a2);
QCOMPARE(a2, a);
@@ -963,11 +963,11 @@ void tst_QColor::setRgbF()
for (int R = 0; R <= USHRT_MAX; ++R) {
{
// 0.0-1.0
- qreal r = R / qreal(USHRT_MAX);
+ float r = R / float(USHRT_MAX);
color.setRgbF(r, 0.0, 0.0);
QCOMPARE(color.redF(), r);
- qreal r2, g, b, a;
+ float r2, g, b, a;
color.getRgbF(&r2, &g, &b, &a);
QCOMPARE(r2, r);
}
@@ -976,11 +976,11 @@ void tst_QColor::setRgbF()
for (int G = 0; G <= USHRT_MAX; ++G) {
{
// 0.0-1.0
- qreal g = G / qreal(USHRT_MAX);
+ float g = G / float(USHRT_MAX);
color.setRgbF(0.0, g, 0.0);
QCOMPARE(color.greenF(), g);
- qreal r, g2, b, a;
+ float r, g2, b, a;
color.getRgbF(&r, &g2, &b, &a);
QCOMPARE(g2, g);
}
@@ -989,11 +989,11 @@ void tst_QColor::setRgbF()
for (int B = 0; B <= USHRT_MAX; ++B) {
{
// 0.0-1.0
- qreal b = B / qreal(USHRT_MAX);
+ float b = B / float(USHRT_MAX);
color.setRgbF(0.0, 0.0, b);
QCOMPARE(color.blueF(), b);
- qreal r, g, b2, a;
+ float r, g, b2, a;
color.getRgbF(&r, &g, &b2, &a);
QCOMPARE(b2, b);
}
@@ -1002,11 +1002,11 @@ void tst_QColor::setRgbF()
for (int R = -128; R <= 512; ++R) {
{
// extended RGB
- qreal r = R / qreal(256);
+ float r = R / 256.0f;
color.setRgbF(r, 0.0, 0.0);
QCOMPARE(qfloat16(color.redF()), qfloat16(r));
- qreal r2, g, b, a;
+ float r2, g, b, a;
color.getRgbF(&r2, &g, &b, &a);
QCOMPARE(qfloat16(r2), qfloat16(r));
}
@@ -1015,11 +1015,11 @@ void tst_QColor::setRgbF()
for (int G = -128; G <= 512; ++G) {
{
// extended RGB
- qreal g = G / qreal(256);
+ float g = G / 256.0f;
color.setRgbF(0.0, g, 0.0);
QCOMPARE(qfloat16(color.greenF()), qfloat16(g));
- qreal r, g2, b, a;
+ float r, g2, b, a;
color.getRgbF(&r, &g2, &b, &a);
QCOMPARE(qfloat16(g2), qfloat16(g));
}
@@ -1028,11 +1028,11 @@ void tst_QColor::setRgbF()
for (int B = -128; B <= 512; ++B) {
{
// extended RGB
- qreal b = B / qreal(256);
+ float b = B / 256.0f;
color.setRgbF(0.0, 0.0, b);
QCOMPARE(qfloat16(color.blueF()), qfloat16(b));
- qreal r, g, b2, a;
+ float r, g, b2, a;
color.getRgbF(&r, &g, &b2, &a);
QCOMPARE(qfloat16(b2), qfloat16(b));
}
@@ -1079,10 +1079,10 @@ void tst_QColor::setHsv()
{
// 0.0-1.0
- qreal a = A / qreal(USHRT_MAX);
+ float a = A / float(USHRT_MAX);
color.setHsvF(0.0, 0.0, 0.0, a); QCOMPARE(color.alphaF(), a);
- qreal h, s, v, a2;
+ float h, s, v, a2;
color.getHsvF(&h, &s, &v, &a2);
QCOMPARE(a2, a);
}
@@ -1103,11 +1103,11 @@ void tst_QColor::setHsv()
{
// 0.0-1.0
- qreal h = H / 36000.0;
+ float h = H / 36000.0;
color.setHsvF(h, 0.0, 0.0, 0.0);
QCOMPARE(color.hueF(), h);
- qreal h2, s, v, a;
+ float h2, s, v, a;
color.getHsvF(&h2, &s, &v, &a);
QCOMPARE(h2, h);
}
@@ -1127,11 +1127,11 @@ void tst_QColor::setHsv()
{
// 0.0-1.0
- qreal s = S / qreal(USHRT_MAX);
+ float s = S / float(USHRT_MAX);
color.setHsvF(0.0, s, 0.0, 0.0);
QCOMPARE(color.saturationF(), s);
- qreal h, s2, v, a;
+ float h, s2, v, a;
color.getHsvF(&h, &s2, &v, &a);
QCOMPARE(s2, s);
}
@@ -1151,11 +1151,11 @@ void tst_QColor::setHsv()
{
// 0.0-1.0
- qreal v = V / qreal(USHRT_MAX);
+ float v = V / float(USHRT_MAX);
color.setHsvF(0.0, 0.0, v, 0.0);
QCOMPARE(color.valueF(), v);
- qreal h, s, v2, a;
+ float h, s, v2, a;
color.getHsvF(&h, &s, &v2, &a);
QCOMPARE(v2, v);
}
@@ -1190,11 +1190,11 @@ void tst_QColor::setCmyk()
{
// 0.0-1.0
- qreal a = A / qreal(USHRT_MAX);
+ float a = A / float(USHRT_MAX);
color.setCmykF(0.0, 0.0, 0.0, 0.0, a);
QCOMPARE(color.alphaF(), a);
- qreal c, m, y, k, a2;
+ float c, m, y, k, a2;
color.getCmykF(&c, &m, &y, &k, &a2);
QCOMPARE(a2, a);
}
@@ -1214,11 +1214,11 @@ void tst_QColor::setCmyk()
{
// 0.0-1.0
- qreal c = C / qreal(USHRT_MAX);
+ float c = C / float(USHRT_MAX);
color.setCmykF(c, 0.0, 0.0, 0.0, 0.0);
QCOMPARE(color.cyanF(), c);
- qreal c2, m, y, k, a;
+ float c2, m, y, k, a;
color.getCmykF(&c2, &m, &y, &k, &a);
QCOMPARE(c2, c);
}
@@ -1238,11 +1238,11 @@ void tst_QColor::setCmyk()
{
// 0.0-1.0
- qreal m = M / qreal(USHRT_MAX);
+ float m = M / float(USHRT_MAX);
color.setCmykF(0.0, m, 0.0, 0.0, 0.0);
QCOMPARE(color.magentaF(), m);
- qreal c, m2, y, k, a;
+ float c, m2, y, k, a;
color.getCmykF(&c, &m2, &y, &k, &a);
QCOMPARE(m2, m);
}
@@ -1262,11 +1262,11 @@ void tst_QColor::setCmyk()
{
// 0.0-1.0
- qreal y = Y / qreal(USHRT_MAX);
+ float y = Y / float(USHRT_MAX);
color.setCmykF(0.0, 0.0, y, 0.0, 0.0);
QCOMPARE(color.yellowF(), y);
- qreal c, m, y2, k, a;
+ float c, m, y2, k, a;
color.getCmykF(&c, &m, &y2, &k, &a);
QCOMPARE(y2, y);
}
@@ -1286,11 +1286,11 @@ void tst_QColor::setCmyk()
{
// 0.0-1.0
- qreal k = K / qreal(USHRT_MAX);
+ float k = K / float(USHRT_MAX);
color.setCmykF(0.0, 0.0, 0.0, k, 0.0);
QCOMPARE(color.blackF(), k);
- qreal c, m, y, k2, a;
+ float c, m, y, k2, a;
color.getCmykF(&c, &m, &y, &k2, &a);
QCOMPARE(k2, k);
}
@@ -1324,10 +1324,10 @@ void tst_QColor::setHsl()
{
// 0.0-1.0
- qreal a = A / qreal(USHRT_MAX);
+ float a = A / float(USHRT_MAX);
color.setHslF(0.0, 0.0, 0.0, a); QCOMPARE(color.alphaF(), a);
- qreal h, s, l, a2;
+ float h, s, l, a2;
color.getHslF(&h, &s, &l, &a2);
QCOMPARE(a2, a);
}
@@ -1348,11 +1348,11 @@ void tst_QColor::setHsl()
{
// 0.0-1.0
- qreal h = H / 36000.0;
+ float h = H / 36000.0;
color.setHslF(h, 0.0, 0.0, 0.0);
QCOMPARE(color.hslHueF(), h);
- qreal h2, s, l, a;
+ float h2, s, l, a;
color.getHslF(&h2, &s, &l, &a);
QCOMPARE(h2, h);
}
@@ -1372,11 +1372,11 @@ void tst_QColor::setHsl()
{
// 0.0-1.0
- qreal s = S / qreal(USHRT_MAX);
+ float s = S / float(USHRT_MAX);
color.setHslF(0.0, s, 0.0, 0.0);
QCOMPARE(color.hslSaturationF(), s);
- qreal h, s2, l, a;
+ float h, s2, l, a;
color.getHslF(&h, &s2, &l, &a);
QCOMPARE(s2, s);
}
@@ -1396,11 +1396,11 @@ void tst_QColor::setHsl()
{
// 0.0-1.0
- qreal l = L / qreal(USHRT_MAX);
+ float l = L / float(USHRT_MAX);
color.setHslF(0.0, 0.0, l, 0.0);
QCOMPARE(color.lightnessF(), l);
- qreal h, s, l2, a;
+ float h, s, l2, a;
color.getHslF(&h, &s, &l2, &a);
QCOMPARE(l2, l);
}
@@ -1850,19 +1850,19 @@ void tst_QColor::qrgba64Equivalence()
void tst_QColor::qcolorprofile_data()
{
- QTest::addColumn<qreal>("gammaC");
+ QTest::addColumn<float>("gammaC");
QTest::addColumn<int>("tolerance");
- QTest::newRow("gamma=1.0") << qreal(1.0) << 0;
- QTest::newRow("gamma=1.5") << qreal(1.5) << 1;
- QTest::newRow("gamma=1.7") << qreal(1.7) << 2;
- QTest::newRow("gamma=2.0") << qreal(2.0) << 8;
- QTest::newRow("gamma=2.31") << qreal(2.31) << 33;
+ QTest::newRow("gamma=1.0") << 1.0f << 0;
+ QTest::newRow("gamma=1.5") << 1.5f << 1;
+ QTest::newRow("gamma=1.7") << 1.7f << 2;
+ QTest::newRow("gamma=2.0") << 2.0f << 8;
+ QTest::newRow("gamma=2.31") << 2.31f << 33;
}
void tst_QColor::qcolorprofile()
{
- QFETCH(qreal, gammaC);
+ QFETCH(float, gammaC);
QFETCH(int, tolerance);
QColorTrcLut *cp = QColorTrcLut::fromGamma(gammaC);
diff --git a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
index 99fb3d3e72..3564700fe5 100644
--- a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
+++ b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
@@ -304,10 +304,10 @@ void tst_QColorSpace::loadImage()
QVERIFY(defaultProPhotoRgb.iccProfile() != image.colorSpace().iccProfile());
QColorTransform transform = image.colorSpace().transformationToColorSpace(QColorSpace::SRgb);
- qreal maxRed = 0;
- qreal maxBlue = 0;
- qreal maxRed2 = 0;
- qreal maxBlue2 = 0;
+ float maxRed = 0;
+ float maxBlue = 0;
+ float maxRed2 = 0;
+ float maxBlue2 = 0;
for (int y = 0; y < image.height(); ++y) {
for (int x = 0; x < image.width(); ++x) {
QColor p = image.pixelColor(x, y);