summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Kling <andreas.kling@nokia.com>2010-08-03 09:18:18 (GMT)
committerAndreas Kling <andreas.kling@nokia.com>2010-08-03 13:47:54 (GMT)
commit544d31b68c05ab70538bd34fd747b64d8b19f5de (patch)
treee42f7a007c1081d19b4d921ba7948c354b21bd4e /tests
parent307601da8d3b64de7b7d83a6de0b5dac290b0eb6 (diff)
downloadQt-544d31b68c05ab70538bd34fd747b64d8b19f5de.zip
Qt-544d31b68c05ab70538bd34fd747b64d8b19f5de.tar.gz
Qt-544d31b68c05ab70538bd34fd747b64d8b19f5de.tar.bz2
Unbreak QImage::rgbSwapped() for many image formats.
These formats had broken rgbSwapped() implementations: argb8565, argb6666, rgb555, argb8555, rgb444, argb4444 Reviewed-by: Benjamin Poulain
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qimage/tst_qimage.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/qimage/tst_qimage.cpp b/tests/auto/qimage/tst_qimage.cpp
index 1330d96..49514dc 100644
--- a/tests/auto/qimage/tst_qimage.cpp
+++ b/tests/auto/qimage/tst_qimage.cpp
@@ -139,6 +139,9 @@ private slots:
void premultipliedAlphaConsistency();
void compareIndexed();
+
+ void rgbSwapped_data();
+ void rgbSwapped();
};
tst_QImage::tst_QImage()
@@ -1820,5 +1823,68 @@ void tst_QImage::compareIndexed()
QCOMPARE(img, imgInverted);
}
+void tst_QImage::rgbSwapped_data()
+{
+ QTest::addColumn<QImage::Format>("format");
+
+ QTest::newRow("Format_Indexed8") << QImage::Format_Indexed8;
+ QTest::newRow("Format_RGB32") << QImage::Format_RGB32;
+ QTest::newRow("Format_ARGB32") << QImage::Format_ARGB32;
+ QTest::newRow("Format_ARGB32_Premultiplied") << QImage::Format_ARGB32_Premultiplied;
+ QTest::newRow("Format_RGB16") << QImage::Format_RGB16;
+ QTest::newRow("Format_ARGB8565_Premultiplied") << QImage::Format_ARGB8565_Premultiplied;
+ QTest::newRow("Format_ARGB6666_Premultiplied") << QImage::Format_ARGB6666_Premultiplied;
+ QTest::newRow("Format_ARGB4444_Premultiplied") << QImage::Format_ARGB4444_Premultiplied;
+ QTest::newRow("Format_RGB666") << QImage::Format_RGB666;
+ QTest::newRow("Format_RGB555") << QImage::Format_RGB555;
+ QTest::newRow("Format_ARGB8555_Premultiplied") << QImage::Format_ARGB8555_Premultiplied;
+ QTest::newRow("Format_RGB888") << QImage::Format_RGB888;
+ QTest::newRow("Format_RGB444") << QImage::Format_RGB444;
+}
+
+void tst_QImage::rgbSwapped()
+{
+ QFETCH(QImage::Format, format);
+
+ QImage image(100, 1, format);
+ image.fill(0);
+
+ QVector<QColor> testColor(image.width());
+
+ for (int i = 0; i < image.width(); ++i)
+ testColor[i] = QColor(i, 10 + i, 20 + i * 2, 30 + i);
+
+ if (format != QImage::Format_Indexed8) {
+ QPainter p(&image);
+ p.setCompositionMode(QPainter::CompositionMode_Source);
+ for (int i = 0; i < image.width(); ++i)
+ p.fillRect(QRect(i, 0, 1, 1), testColor[i].rgb());
+ } else {
+ image.setColorCount(image.width());
+ for (int i = 0; i < image.width(); ++i) {
+ image.setColor(0, testColor[i].rgba());
+ image.setPixel(i, 0, i);
+ }
+ }
+
+ QImage imageSwapped = image.rgbSwapped();
+
+ for (int i = 0; i < image.width(); ++i) {
+ QColor referenceColor = QColor(image.pixel(i, 0));
+ QColor swappedColor = QColor(imageSwapped.pixel(i, 0));
+
+ QCOMPARE(swappedColor.alpha(), referenceColor.alpha());
+ QCOMPARE(swappedColor.red(), referenceColor.blue());
+ QCOMPARE(swappedColor.green(), referenceColor.green());
+ QCOMPARE(swappedColor.blue(), referenceColor.red());
+ }
+
+ QImage imageSwappedTwice = imageSwapped.rgbSwapped();
+
+ QCOMPARE(image, imageSwappedTwice);
+
+ QCOMPARE(memcmp(image.constBits(), imageSwappedTwice.constBits(), image.numBytes()), 0);
+}
+
QTEST_MAIN(tst_QImage)
#include "tst_qimage.moc"