summaryrefslogtreecommitdiff
path: root/tests/auto/gui/image
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2014-07-24 15:54:58 +0200
committerAllan Sandfeld Jensen <allan.jensen@digia.com>2014-07-31 20:16:09 +0200
commitd8dc664b945d8832eab97c5df0e1ea47ebf895fd (patch)
treebe9fe35ad391540c7fc8e328d22cc01b5e4592da /tests/auto/gui/image
parent1852ece715b6eefadd8c9bf048d5f8d147f08b5b (diff)
downloadqtbase-d8dc664b945d8832eab97c5df0e1ea47ebf895fd.tar.gz
Ensure valid data after QImage::invertPixels
QImage::invertPixels may produce invalid data after inversions of images with premultiplied alpha, because the inverted colors will be larger than the alpha. This patch converts any image with a premultiplied alpha channel to ARGB32 before inverting the pixels, and then back to the original format after the inversion. Support is added for correct inversion of RGBA8888 and RGB30 formats. Task-number: QTBUG-39901 Change-Id: Ief24c55f495e67ef2ad6429b5b418d02963a64dd Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Diffstat (limited to 'tests/auto/gui/image')
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index d885ab6dd4..f922deb815 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -178,6 +178,9 @@ private slots:
void convertToImageFormat_data();
void convertToImageFormat();
+ void invertPixelsRGB_data();
+ void invertPixelsRGB();
+
void cleanupFunctions();
private:
@@ -2585,6 +2588,7 @@ void tst_QImage::convertToImageFormat_data()
QTest::newRow("Convert Format_RGBA8888") << QImage::Format_RGBA8888;
QTest::newRow("Convert Format_RGBA8888_Premultiplied") << QImage::Format_RGBA8888_Premultiplied;
}
+
void tst_QImage::convertToImageFormat()
{
QFETCH(QImage::Format, image_format);
@@ -2594,6 +2598,40 @@ void tst_QImage::convertToImageFormat()
QCOMPARE(format, image_format);
}
+void tst_QImage::invertPixelsRGB_data()
+{
+ QTest::addColumn<QImage::Format>("image_format");
+
+ QTest::newRow("invertPixels RGB16") << QImage::Format_RGB16;
+ QTest::newRow("invertPixels RGB32") << QImage::Format_RGB32;
+ QTest::newRow("invertPixels BGR30") << QImage::Format_BGR30;
+ QTest::newRow("invertPixels RGB444") << QImage::Format_RGB444;
+ QTest::newRow("invertPixels RGB555") << QImage::Format_RGB555;
+ QTest::newRow("invertPixels RGB888") << QImage::Format_RGB888;
+
+ QTest::newRow("invertPixels ARGB32") << QImage::Format_ARGB32;
+ QTest::newRow("invertPixels ARGB32pm") << QImage::Format_ARGB32_Premultiplied;
+ QTest::newRow("invertPixels RGBA8888") << QImage::Format_RGBA8888;
+ QTest::newRow("invertPixels RGBA8888pm") << QImage::Format_RGBA8888_Premultiplied;
+ QTest::newRow("invertPixels RGBA4444pm") << QImage::Format_ARGB4444_Premultiplied;
+}
+
+void tst_QImage::invertPixelsRGB()
+{
+ QFETCH(QImage::Format, image_format);
+
+ QImage image(1, 1, image_format);
+ image.fill(QColor::fromRgb(32, 64, 96));
+ image.invertPixels();
+
+ QCOMPARE(image.format(), image_format);
+
+ uint pixel = image.pixel(0, 0);
+ QCOMPARE(qRed(pixel) >> 4, (255 - 32) >> 4);
+ QCOMPARE(qGreen(pixel) >> 4, (255 - 64) >> 4);
+ QCOMPARE(qBlue(pixel) >> 4, (255 - 96) >> 4);
+}
+
static void cleanupFunction(void* info)
{
bool *called = static_cast<bool*>(info);