From ffd316ebe3963b7ff8d94a3484ac85de793b8299 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 21 Nov 2016 15:10:39 +0100 Subject: 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) --- tests/auto/gui/painting/qcolor/tst_qcolor.cpp | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/auto/gui/painting/qcolor') 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 #include +#include #include #include @@ -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("gammaC"); + QTest::addColumn("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" -- cgit v1.2.3