summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/painting/qcolor
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2016-11-21 15:10:39 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-11-24 09:40:14 +0000
commitffd316ebe3963b7ff8d94a3484ac85de793b8299 (patch)
tree6b933591f176af9451c746ee2c340ae7bd8c72fb /tests/auto/gui/painting/qcolor
parent38a446b69e95423d8d42d33b30b3154caa475e09 (diff)
Replace QDrawHelperGammaTables with QColorProfile
Turns the two set of tables in QDrawHelperGammaTables into two QColorProfile classes that use similar structures and can be reused for other gamma correction. At the same time clean-up and improve the comma-correct blending code to use the new profiles and QRgba64 precision. Change-Id: I302bd87a5c836e1010fff6d633eeb56fd4ae2ff0 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/gui/painting/qcolor')
-rw-r--r--tests/auto/gui/painting/qcolor/tst_qcolor.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
index 9dd9ab05e8..1ce7e797fc 100644
--- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
+++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
@@ -33,6 +33,7 @@
#include <qcolor.h>
#include <qdebug.h>
+#include <private/qcolorprofile_p.h>
#include <private/qdrawingprimitive_sse2_p.h>
#include <qrgba64.h>
@@ -107,6 +108,9 @@ private slots:
void qrgba64Premultiply();
void qrgba64Equivalence();
+ void qcolorprofile_data();
+ void qcolorprofile();
+
#if 0 // Used to be included in Qt4 for Q_WS_X11
void setallowX11ColorNames();
#endif
@@ -1587,5 +1591,36 @@ void tst_QColor::qrgba64Equivalence()
}
}
+void tst_QColor::qcolorprofile_data()
+{
+ QTest::addColumn<qreal>("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("SRgb") << qreal(0.0) << 7;
+}
+
+void tst_QColor::qcolorprofile()
+{
+ QFETCH(qreal, gammaC);
+ QFETCH(int, tolerance);
+ QColorProfile *cp = (gammaC == 0) ? QColorProfile::fromSRgb(): QColorProfile::fromGamma(gammaC);
+
+ // Test we are accurate for most values after converting through gamma-correction.
+ int error = 0;
+ for (uint i = 0; i < 256; i++) {
+ QRgb cin = qRgb(i, i, i);
+ QRgba64 tmp = cp->toLinear64(cin);
+ QRgb cout = cp->fromLinear64(tmp);
+ error += qAbs(qRed(cin) - qRed(cout));
+ }
+ QVERIFY(error <= tolerance);
+ delete cp;
+}
+
QTEST_MAIN(tst_QColor)
#include "tst_qcolor.moc"