summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2022-05-31 14:43:07 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2022-05-31 22:23:40 +0200
commit5ea6da55e0d29a0dc526d4fa78a0590e0e4df8f6 (patch)
tree7e42982bb1ee44d57491da1c93878a9135268a04 /tests/auto/gui
parentfb8a88b05cd3f7663efaa9c5c5cf8143a1f2b66f (diff)
Test prepared qcolortransform
Add test of explicitly prepared qcolortransform, this is a state a transform can get into if used for an image transform. Also cleans up the test code. Change-Id: I9445ed114bed0edc790e14024aaae6a42989220b Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/painting/qcolortransform/CMakeLists.txt1
-rw-r--r--tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp106
2 files changed, 90 insertions, 17 deletions
diff --git a/tests/auto/gui/painting/qcolortransform/CMakeLists.txt b/tests/auto/gui/painting/qcolortransform/CMakeLists.txt
index 008ac92905..64901eef9f 100644
--- a/tests/auto/gui/painting/qcolortransform/CMakeLists.txt
+++ b/tests/auto/gui/painting/qcolortransform/CMakeLists.txt
@@ -7,4 +7,5 @@ qt_internal_add_test(tst_qcolortransform
tst_qcolortransform.cpp
PUBLIC_LIBRARIES
Qt::Gui
+ Qt::GuiPrivate
)
diff --git a/tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp b/tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp
index c2205a02d1..17f115c308 100644
--- a/tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp
+++ b/tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp
@@ -31,6 +31,7 @@
#include <qcolorspace.h>
#include <qcolortransform.h>
+#include <QtGui/private/qcolortransform_p.h>
class tst_QColorTransform : public QObject
{
@@ -46,6 +47,8 @@ private slots:
void mapRGB64();
void mapQColor_data();
void mapQColor();
+ void mapRGB32Prepared_data();
+ void mapRGB32Prepared();
void transformIsIdentity();
};
@@ -59,23 +62,22 @@ void tst_QColorTransform::mapRGB32_data()
QTest::addColumn<QColorTransform>("transform");
QTest::addColumn<bool>("sharesRed");
- QTest::newRow("default") << QColorTransform() << true;
- QTest::newRow("sRGB to Linear") << QColorSpace(QColorSpace::SRgb).transformationToColorSpace(QColorSpace::SRgbLinear) << true;
- QTest::newRow("AdobeRGB to sRGB") << QColorSpace(QColorSpace::AdobeRgb).transformationToColorSpace(QColorSpace::SRgb) << true;
- QTest::newRow("Linear AdobeRGB to Linear sRGB")
- << QColorSpace(QColorSpace::AdobeRgb).withTransferFunction(QColorSpace::TransferFunction::Linear).transformationToColorSpace(
- QColorSpace::SRgb)
- << true;
- QTest::newRow("sRgb to AdobeRGB") << QColorSpace(QColorSpace::SRgb).transformationToColorSpace(QColorSpace::AdobeRgb) << true;
- QTest::newRow("DP3 to sRGB") << QColorSpace(QColorSpace::DisplayP3).transformationToColorSpace(QColorSpace::SRgb) << false;
- QTest::newRow("DP3 to Linear DP3")
- << QColorSpace(QColorSpace::DisplayP3).transformationToColorSpace(
- QColorSpace(QColorSpace::DisplayP3).withTransferFunction(QColorSpace::TransferFunction::Linear))
- << false;
- QTest::newRow("Linear DP3 to Linear sRGB")
- << QColorSpace(QColorSpace::DisplayP3).withTransferFunction(QColorSpace::TransferFunction::Linear).transformationToColorSpace(
- QColorSpace::SRgb)
- << false;
+ QColorSpace srgb(QColorSpace::SRgb);
+ QColorSpace srgbLinear(QColorSpace::SRgbLinear);
+ QColorSpace adobeRgb(QColorSpace::AdobeRgb);
+ QColorSpace adobeRgbLinear = adobeRgb.withTransferFunction(QColorSpace::TransferFunction::Linear);
+ QColorSpace dp3(QColorSpace::DisplayP3);
+ QColorSpace dp3Linear = dp3.withTransferFunction(QColorSpace::TransferFunction::Linear);
+
+ QTest::newRow("default") << QColorTransform() << true;
+ QTest::newRow("sRGB to Linear sRGB") << srgb.transformationToColorSpace(srgbLinear) << true;
+ QTest::newRow("AdobeRGB to sRGB") << adobeRgb.transformationToColorSpace(srgb) << true;
+ QTest::newRow("Linear AdobeRGB to AdobeRGB") << adobeRgbLinear.transformationToColorSpace(adobeRgb) << true;
+ QTest::newRow("Linear AdobeRGB to Linear sRGB") << adobeRgbLinear.transformationToColorSpace(srgbLinear) << true;
+ QTest::newRow("sRgb to AdobeRGB") << srgb.transformationToColorSpace(adobeRgb) << true;
+ QTest::newRow("DP3 to sRGB") << dp3.transformationToColorSpace(srgb) << false;
+ QTest::newRow("DP3 to Linear DP3") << dp3.transformationToColorSpace(dp3Linear) << false;
+ QTest::newRow("Linear DP3 to Linear sRGB") << dp3Linear.transformationToColorSpace(srgbLinear) << false;
}
void tst_QColorTransform::mapRGB32()
@@ -220,6 +222,76 @@ void tst_QColorTransform::mapQColor()
QVERIFY(result.blueF() >= 1.0f);
}
+void tst_QColorTransform::mapRGB32Prepared_data()
+{
+ mapRGB32_data();
+}
+
+void tst_QColorTransform::mapRGB32Prepared()
+{
+ QFETCH(QColorTransform, transform);
+ QFETCH(bool, sharesRed);
+
+ // The same tests as mapRGB32 but prepared, to use the LUT code-paths
+ if (!transform.isIdentity())
+ QColorTransformPrivate::get(transform)->prepare();
+
+ QRgb testColor = qRgb(32, 64, 128);
+ QRgb result = transform.map(testColor);
+ QVERIFY(qRed(result) < qGreen(result));
+ QVERIFY(qGreen(result) < qBlue(result));
+ QCOMPARE(qAlpha(result), 255);
+ if (transform.isIdentity())
+ QVERIFY(result == testColor);
+ else
+ QVERIFY(result != testColor);
+
+ testColor = qRgb(128, 64, 32);
+ result = transform.map(testColor);
+ QVERIFY(qRed(result) > qGreen(result));
+ QVERIFY(qGreen(result) > qBlue(result));
+ QCOMPARE(qAlpha(result), 255);
+ if (transform.isIdentity())
+ QVERIFY(result == testColor);
+ else
+ QVERIFY(result != testColor);
+
+ testColor = qRgba(15, 31, 63, 128);
+ result = transform.map(testColor);
+ QVERIFY(qRed(result) < qGreen(result));
+ QVERIFY(qGreen(result) < qBlue(result));
+ QCOMPARE(qAlpha(result), 128);
+ if (transform.isIdentity())
+ QVERIFY(result == testColor);
+ else
+ QVERIFY(result != testColor);
+
+ testColor = qRgb(0, 0, 0);
+ result = transform.map(testColor);
+ QCOMPARE(qRed(result), 0);
+ QCOMPARE(qGreen(result), 0);
+ QCOMPARE(qBlue(result), 0);
+ QCOMPARE(qAlpha(result), 255);
+
+ testColor = qRgb(255, 255, 255);
+ result = transform.map(testColor);
+ QCOMPARE(qRed(result), 255);
+ QCOMPARE(qGreen(result), 255);
+ QCOMPARE(qBlue(result), 255);
+ QCOMPARE(qAlpha(result), 255);
+
+ testColor = qRgb(255, 255, 0);
+ result = transform.map(testColor);
+ QCOMPARE(qAlpha(result), 255);
+ if (sharesRed)
+ QCOMPARE(qRed(result), 255);
+
+ testColor = qRgb(0, 255, 255);
+ result = transform.map(testColor);
+ QCOMPARE(qBlue(result), 255);
+ QCOMPARE(qAlpha(result), 255);
+}
+
void tst_QColorTransform::transformIsIdentity()
{
QColorTransform ct;