summaryrefslogtreecommitdiffstats
path: root/tests/auto/qimage
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@nokia.com>2010-08-04 07:14:30 (GMT)
committerGunnar Sletta <gunnar.sletta@nokia.com>2010-08-04 08:43:34 (GMT)
commit5683a6f6f30e65c272c1194f31395161bde229e4 (patch)
treea4432011ade11e353a4da732dd2ea3e83f58c05e /tests/auto/qimage
parent0d6a0f1371d899c4105bc4383550ca1cb6b132b2 (diff)
downloadQt-5683a6f6f30e65c272c1194f31395161bde229e4.zip
Qt-5683a6f6f30e65c272c1194f31395161bde229e4.tar.gz
Qt-5683a6f6f30e65c272c1194f31395161bde229e4.tar.bz2
QImage::fill() overloads that take QColor and Qt::GlobalColor
This will break source compatibility in some cases, but only when the user has a bug in the first place, so this is preferable Reviewed-by: Eskil
Diffstat (limited to 'tests/auto/qimage')
-rw-r--r--tests/auto/qimage/tst_qimage.cpp113
1 files changed, 113 insertions, 0 deletions
diff --git a/tests/auto/qimage/tst_qimage.cpp b/tests/auto/qimage/tst_qimage.cpp
index 517c1816..63320b2 100644
--- a/tests/auto/qimage/tst_qimage.cpp
+++ b/tests/auto/qimage/tst_qimage.cpp
@@ -59,6 +59,7 @@
#endif
Q_DECLARE_METATYPE(QImage::Format)
+Q_DECLARE_METATYPE(Qt::GlobalColor)
class tst_QImage : public QObject
{
@@ -139,6 +140,11 @@ private slots:
void premultipliedAlphaConsistency();
void compareIndexed();
+
+ void fillColor_data();
+ void fillColor();
+
+ void fillColorWithAlpha();
};
tst_QImage::tst_QImage()
@@ -1820,5 +1826,112 @@ void tst_QImage::compareIndexed()
QCOMPARE(img, imgInverted);
}
+void tst_QImage::fillColor_data()
+{
+ QTest::addColumn<QImage::Format>("format");
+ QTest::addColumn<Qt::GlobalColor>("color");
+ QTest::addColumn<uint>("pixelValue");
+
+ QTest::newRow("Mono, color0") << QImage::Format_Mono << Qt::color0 << 0u;
+ QTest::newRow("Mono, color1") << QImage::Format_Mono << Qt::color1 << 1u;
+
+ QTest::newRow("MonoLSB, color0") << QImage::Format_MonoLSB << Qt::color0 << 0u;
+ QTest::newRow("MonoLSB, color1") << QImage::Format_MonoLSB << Qt::color1 << 1u;
+
+ const char *names[] = {
+ "Indexed8",
+ "RGB32",
+ "ARGB32",
+ "ARGB32pm",
+ "RGB16",
+ "ARGB8565pm",
+ "RGB666",
+ "ARGB6666pm",
+ "RGB555",
+ "ARGB8555pm",
+ "RGB888",
+ "RGB444",
+ "ARGB4444pm",
+ 0
+ };
+
+ QImage::Format formats[] = {
+ QImage::Format_Indexed8,
+ QImage::Format_RGB32,
+ QImage::Format_ARGB32,
+ QImage::Format_ARGB32_Premultiplied,
+ QImage::Format_RGB16,
+ QImage::Format_ARGB8565_Premultiplied,
+ QImage::Format_RGB666,
+ QImage::Format_ARGB6666_Premultiplied,
+ QImage::Format_RGB555,
+ QImage::Format_ARGB8555_Premultiplied,
+ QImage::Format_RGB888,
+ QImage::Format_RGB444,
+ QImage::Format_ARGB4444_Premultiplied
+ };
+
+ for (int i=0; names[i] != 0; ++i) {
+ QByteArray name;
+ name.append(names[i]).append(", ");
+
+ QTest::newRow(QByteArray(name).append("black").constData()) << formats[i] << Qt::black << 0xff000000;
+ QTest::newRow(QByteArray(name).append("white").constData()) << formats[i] << Qt::white << 0xffffffff;
+ QTest::newRow(QByteArray(name).append("red").constData()) << formats[i] << Qt::red << 0xffff0000;
+ QTest::newRow(QByteArray(name).append("green").constData()) << formats[i] << Qt::green << 0xff00ff00;
+ QTest::newRow(QByteArray(name).append("blue").constData()) << formats[i] << Qt::blue << 0xff0000ff;
+ }
+
+ QTest::newRow("RGB16, transparent") << QImage::Format_RGB16 << Qt::transparent << 0xff000000;
+ QTest::newRow("RGB32, transparent") << QImage::Format_RGB32 << Qt::transparent << 0xff000000;
+ QTest::newRow("ARGB32, transparent") << QImage::Format_ARGB32 << Qt::transparent << 0x00000000u;
+ QTest::newRow("ARGB32pm, transparent") << QImage::Format_ARGB32_Premultiplied << Qt::transparent << 0x00000000u;
+}
+
+void tst_QImage::fillColor()
+{
+ QFETCH(QImage::Format, format);
+ QFETCH(Qt::GlobalColor, color);
+ QFETCH(uint, pixelValue);
+
+ QImage image(1, 1, format);
+
+ if (image.depth() == 8) {
+ QVector<QRgb> table;
+ table << 0xff000000;
+ table << 0xffffffff;
+ table << 0xffff0000;
+ table << 0xff00ff00;
+ table << 0xff0000ff;
+ image.setColorTable(table);
+ }
+
+ image.fill(color);
+ if (image.depth() == 1) {
+ QCOMPARE(image.pixelIndex(0, 0), (int) pixelValue);
+ } else {
+ QCOMPARE(image.pixel(0, 0), pixelValue);
+ }
+
+ image.fill(QColor(color));
+ if (image.depth() == 1) {
+ QCOMPARE(image.pixelIndex(0, 0), (int) pixelValue);
+ } else {
+ QCOMPARE(image.pixel(0, 0), pixelValue);
+ }
+}
+
+void tst_QImage::fillColorWithAlpha()
+{
+ QImage argb32(1, 1, QImage::Format_ARGB32);
+ argb32.fill(QColor(255, 0, 0, 127));
+ QCOMPARE(argb32.pixel(0, 0), qRgba(255, 0, 0, 127));
+
+ QImage argb32pm(1, 1, QImage::Format_ARGB32_Premultiplied);
+ argb32pm.fill(QColor(255, 0, 0, 127));
+ QCOMPARE(argb32pm.pixel(0, 0), 0x7f7f0000u);
+}
+
+
QTEST_MAIN(tst_QImage)
#include "tst_qimage.moc"