diff options
author | Gunnar Sletta <gunnar@trolltech.com> | 2010-08-17 05:30:30 (GMT) |
---|---|---|
committer | Gunnar Sletta <gunnar@trolltech.com> | 2010-08-17 05:30:30 (GMT) |
commit | ae1fde5d436a047c124f8382fdcd71bb1af306e3 (patch) | |
tree | a937de1c678aaeda2f12fac891f49930d244e954 /tests/auto/qimage/tst_qimage.cpp | |
parent | 50a53d2f7a7e12cd597dc72a08ad62b79fee4554 (diff) | |
parent | 8afc6773067bb878020c29b3bebfe8662e3fbfdd (diff) | |
download | Qt-ae1fde5d436a047c124f8382fdcd71bb1af306e3.zip Qt-ae1fde5d436a047c124f8382fdcd71bb1af306e3.tar.gz Qt-ae1fde5d436a047c124f8382fdcd71bb1af306e3.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-2
Diffstat (limited to 'tests/auto/qimage/tst_qimage.cpp')
-rw-r--r-- | tests/auto/qimage/tst_qimage.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/auto/qimage/tst_qimage.cpp b/tests/auto/qimage/tst_qimage.cpp index 63320b2..46bc6e7 100644 --- a/tests/auto/qimage/tst_qimage.cpp +++ b/tests/auto/qimage/tst_qimage.cpp @@ -145,6 +145,9 @@ private slots: void fillColor(); void fillColorWithAlpha(); + + void rgbSwapped_data(); + void rgbSwapped(); }; tst_QImage::tst_QImage() @@ -1932,6 +1935,68 @@ void tst_QImage::fillColorWithAlpha() QCOMPARE(argb32pm.pixel(0, 0), 0x7f7f0000u); } +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" |