From 6227a0d2e2e924cf717fa2a3d7c3e1223c4aed5f Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 19 Dec 2019 15:00:15 +0100 Subject: Add test for invertPixels on indexed formats It wasn't tested and behaves in a very particular way. Change-Id: I60a31681e5b221cf9a86df77e410a76ee4c10864 Reviewed-by: Eirik Aavitsland --- tests/auto/gui/image/qimage/tst_qimage.cpp | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests/auto/gui/image/qimage/tst_qimage.cpp') diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index e9aa9aad30..bc964e0d5c 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -191,6 +191,8 @@ private slots: void invertPixelsRGB_data(); void invertPixelsRGB(); + void invertPixelsIndexed(); + void exifOrientation_data(); void exifOrientation(); @@ -3086,6 +3088,36 @@ void tst_QImage::invertPixelsRGB() QCOMPARE(qBlue(pixel) >> 4, (255 - 96) >> 4); } +void tst_QImage::invertPixelsIndexed() +{ + { + QImage image(1, 1, QImage::Format_Mono); + image.fill(Qt::color1); + image.invertPixels(); + QCOMPARE(image.pixelIndex(0, 0), 0); + } + { + QImage image(1, 1, QImage::Format_MonoLSB); + image.fill(Qt::color0); + image.invertPixels(); + QCOMPARE(image.pixelIndex(0, 0), 1); + } + { + QImage image(1, 1, QImage::Format_Indexed8); + image.setColorTable({0xff000000, 0xffffffff}); + image.fill(Qt::black); + image.invertPixels(); + QCOMPARE(image.pixelIndex(0, 0), 255); + } + { + QImage image(1, 1, QImage::Format_Indexed8); + image.setColorTable({0xff000000, 0xffffffff, 0x80000000, 0x80ffffff, 0x00000000}); + image.fill(Qt::white); + image.invertPixels(); + QCOMPARE(image.pixelIndex(0, 0), 254); + } +} + void tst_QImage::exifOrientation_data() { QTest::addColumn("fileName"); -- cgit v1.2.3