diff options
author | John Brooks <special@dereferenced.net> | 2010-07-29 09:06:03 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-07-29 09:10:21 (GMT) |
commit | 121c5143f1002734ff7aa62785ff14e0e6612aae (patch) | |
tree | 6ac18a879f6ab5997d1f070f86f70c7d5910ddf5 /tests | |
parent | 5d68ac574e7edbfd91c53e96c80045effa17a1e9 (diff) | |
download | Qt-121c5143f1002734ff7aa62785ff14e0e6612aae.zip Qt-121c5143f1002734ff7aa62785ff14e0e6612aae.tar.gz Qt-121c5143f1002734ff7aa62785ff14e0e6612aae.tar.bz2 |
Fix the byte order in QImage::fill for 24bpp formats
QImage::fill() was using BGR ordering for 24-bit formats, which is
always incorrect as QImage does not support BGR. qrgb888 is the
correct 24-bit helper class that does use the proper order.
Merge-request: 2440
Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qimage/tst_qimage.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/auto/qimage/tst_qimage.cpp b/tests/auto/qimage/tst_qimage.cpp index 1330d96..62deb5ae 100644 --- a/tests/auto/qimage/tst_qimage.cpp +++ b/tests/auto/qimage/tst_qimage.cpp @@ -103,6 +103,9 @@ private slots: void copy(); + void fill_data(); + void fill(); + void setPixel_data(); void setPixel(); @@ -1015,6 +1018,67 @@ void tst_QImage::copy() } } +void tst_QImage::fill_data() +{ + QTest::addColumn<int>("format"); + QTest::addColumn<uint>("input"); + QTest::addColumn<uint>("expectedResult"); + + QTest::newRow("ARGB32") << int(QImage::Format_ARGB32) << 0x33557799u << 0x33557799u; + QTest::newRow("RGB888") << int(QImage::Format_RGB888) << 0x335577u << 0x335577u; + QTest::newRow("RGB16") << int(QImage::Format_RGB16) << 0x3355u << 0x3355u; + QTest::newRow("Indexed8") << int(QImage::Format_Indexed8) << 0x55u << 0x55u; + QTest::newRow("Mono") << int(QImage::Format_Mono) << 1u << 1u; + QTest::newRow("Mono_LSB") << int(QImage::Format_MonoLSB) << 0u << 0u; +} + +void tst_QImage::fill() +{ + QFETCH(int, format); + QFETCH(uint, input); + QFETCH(uint, expectedResult); + + QImage img(13, 15, (QImage::Format)format); + img.fill(input); + + const int bpp = img.depth(); + for (int y = 0; y < img.height(); ++y) { + uchar *line = img.scanLine(y); + for (int x = 0; x < img.width(); ++x) { + uint value; + switch (bpp) { + case 32: + value = *((uint*)line); + line += 4; + break; + case 24: + value = ((uint)line[0] << 16) | ((uint)line[1] << 8) | line[2]; + line += 3; + break; + case 16: + value = *((quint16*)line); + line += 2; + break; + case 8: + value = *line; + line++; + break; + case 1: + if (format == QImage::Format_Mono) + value = (*line >> (7- (x & 7))) & 1; + else if (format == QImage::Format_MonoLSB) + value = (*line >> (x & 7)) & 1; + + if (x && !(x & 7)) + ++line; + break; + } + + QCOMPARE(value, expectedResult); + } + } +} + void tst_QImage::setPixel_data() { QTest::addColumn<int>("format"); |