summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/image/qimage/tst_qimage.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-05-06 14:23:57 +0200
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-06-03 12:01:26 +0000
commit8f760808e0fe0fe6dd89d561f118b19ed8085e7a (patch)
tree8cc259b6098d83b91b6ec8ac22745546947860c7 /tests/auto/gui/image/qimage/tst_qimage.cpp
parent754efa57d89c62d1796e01b407e9222e67450f52 (diff)
Fix premul conversion from ARGB32 to A2RGB30 formats.
When a premultiplied alpha changes value because it is rounded to fewer bits the premultiplied colors may need to be recalculated with the new value. Otherwise the color will both be wrong and potentially invalid. Change-Id: I9ec74a22aac73cd7ffab04e180cf2bf35bb4c315 Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'tests/auto/gui/image/qimage/tst_qimage.cpp')
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index da29a57f98..f7c71f05bd 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -190,6 +190,8 @@ private slots:
void devicePixelRatio();
void rgb30Unpremul();
+ void rgb30Repremul_data();
+ void rgb30Repremul();
void metadataPassthrough();
@@ -2946,6 +2948,31 @@ void tst_QImage::rgb30Unpremul()
QCOMPARE(bbits[2], (3U << 30) | (201 << 20) | (393 << 10) | 777);
}
+void tst_QImage::rgb30Repremul_data()
+{
+ QTest::addColumn<uint>("color");
+ for (int i = 255; i > 0; i -= 15) {
+ QTest::newRow(qPrintable(QStringLiteral("100% red=") + QString::number(i))) << qRgba(i, 0, 0, 0xff);
+ QTest::newRow(qPrintable(QStringLiteral("75% red=") + QString::number(i))) << qRgba(i, 0, 0, 0xc0);
+ QTest::newRow(qPrintable(QStringLiteral("50% red=") + QString::number(i))) << qRgba(i, 0, 0, 0x80);
+ QTest::newRow(qPrintable(QStringLiteral("37.5% red=") + QString::number(i))) << qRgba(i, 0, 0, 0x60);
+ }
+}
+
+void tst_QImage::rgb30Repremul()
+{
+ QFETCH(uint, color);
+
+ QImage a(1, 1, QImage::Format_ARGB32);
+ a.setPixel(0, 0, color);
+
+ QImage b = a.convertToFormat(QImage::Format_A2BGR30_Premultiplied);
+ b = b.convertToFormat(QImage::Format_ARGB32);
+ uint expectedColor = qUnpremultiply(qPremultiply(color));
+ uint newColor = b.pixel(0, 0);
+ QVERIFY(qAbs(qRed(newColor) - qRed(expectedColor)) <= 1);
+}
+
void tst_QImage::metadataPassthrough()
{
QImage a(64, 64, QImage::Format_ARGB32);