summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-04-27 10:37:27 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-05-23 08:31:07 +0000
commitdfa434a9799618eba48a84cbad279262679aa108 (patch)
tree5d0e5bb32305c10e6487086683fb476c6c1e15e1 /tests/auto/gui/painting/qcolor/tst_qcolor.cpp
parent5e67c653db2aecb332f9f3d93da7c4fdd8a4ad35 (diff)
Optimize unpremultiply using SSE rcp
Change-Id: I255031d354b0fde7abe8366ea2c86a35f9f24afd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/gui/painting/qcolor/tst_qcolor.cpp')
-rw-r--r--tests/auto/gui/painting/qcolor/tst_qcolor.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
index 67d30d7c9a..ece7a30830 100644
--- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
+++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
@@ -1492,10 +1492,28 @@ void tst_QColor::unpremultiply_sse4()
// Tests that qUnpremultiply_sse4 returns the same as qUnpremultiply.
#if QT_COMPILER_SUPPORTS_HERE(SSE4_1)
if (qCpuHasFeature(SSE4_1)) {
+ int minorDifferences = 0;
+ for (uint a = 0; a < 256; a++) {
+ for (uint c = 0; c <= a; c++) {
+ const QRgb p = qRgba(c, a-c, c/2, a);
+ const uint u = qUnpremultiply(p);
+ const uint usse4 = qUnpremultiply_sse4(p);
+ if (u != usse4) {
+ QCOMPARE(qAlpha(u), qAlpha(usse4));
+ QVERIFY(qAbs(qRed(u) - qRed(usse4)) <= 1);
+ QVERIFY(qAbs(qGreen(u) - qGreen(usse4)) <= 1);
+ QVERIFY(qAbs(qBlue(u) - qBlue(usse4)) <= 1);
+ ++minorDifferences;
+ }
+ }
+ }
+ // Allow a few rounding differences as long as it still obeys
+ // the qPremultiply(qUnpremultiply(x)) == x invariant
+ QVERIFY(minorDifferences <= 16 * 255);
for (uint a = 0; a < 256; a++) {
for (uint c = 0; c <= a; c++) {
QRgb p = qRgba(c, a-c, c, a);
- QCOMPARE(qUnpremultiply(p), qUnpremultiply_sse4(p));
+ QCOMPARE(p, qPremultiply(qUnpremultiply_sse4(p)));
}
}
return;