diff options
Diffstat (limited to 'tests/auto/gui/image/qimage/tst_qimage.cpp')
-rw-r--r-- | tests/auto/gui/image/qimage/tst_qimage.cpp | 169 |
1 files changed, 161 insertions, 8 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index e9aa9aad30..fe998c7d92 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -32,7 +32,7 @@ #include <qimage.h> #include <qimagereader.h> #include <qlist.h> -#include <qmatrix.h> +#include <qtransform.h> #include <qrandom.h> #include <stdio.h> @@ -177,6 +177,12 @@ private slots: void inplaceRgbConversion_data(); void inplaceRgbConversion(); + void largeGenericRgbConversion_data(); + void largeGenericRgbConversion(); + + void largeInplaceRgbConversion_data(); + void largeInplaceRgbConversion(); + void deepCopyWhenPaintingActive(); void scaled_QTBUG19157(); @@ -191,6 +197,8 @@ private slots: void invertPixelsRGB_data(); void invertPixelsRGB(); + void invertPixelsIndexed(); + void exifOrientation_data(); void exifOrientation(); @@ -1202,7 +1210,7 @@ void tst_QImage::rotate() // original.save("rotated90_original.png", "png"); // Initialize the matrix manually (do not use rotate) to avoid rounding errors - QMatrix matRotate90; + QTransform matRotate90; matRotate90.rotate(degrees); QImage dest = original; // And rotate it 4 times, then the image should be identical to the original @@ -1216,7 +1224,7 @@ void tst_QImage::rotate() // dest.save("rotated90_result.png","png"); QCOMPARE(original, dest); - // Test with QMatrix::rotate 90 also, since we trust that now + // Test with QTransform::rotate 90 also, since we trust that now matRotate90.rotate(degrees); dest = original; // And rotate it 4 times, then the image should be identical to the original @@ -2894,16 +2902,15 @@ void tst_QImage::inplaceRgbConversion_data() } if (i == j) continue; - QTest::addRow("%s -> %s", formatToString(QImage::Format(i)).data(), formatToString(QImage::Format(j)).data()) - << QImage::Format(i) << QImage::Format(j); + if (qt_depthForFormat(QImage::Format(i)) >= qt_depthForFormat(QImage::Format(j))) + QTest::addRow("%s -> %s", formatToString(QImage::Format(i)).data(), formatToString(QImage::Format(j)).data()) + << QImage::Format(i) << QImage::Format(j); } } } void tst_QImage::inplaceRgbConversion() { - // Test that conversions between RGB formats of the same bitwidth can be done inplace. -#if defined(Q_COMPILER_REF_QUALIFIERS) QFETCH(QImage::Format, format); QFETCH(QImage::Format, dest_format); @@ -2952,7 +2959,123 @@ void tst_QImage::inplaceRgbConversion() QVERIFY(rwInplaceConverted.constBits() != (const uchar *)readWriteData); QCOMPARE(normalConverted, rwInplaceConverted); } -#endif +} + +void tst_QImage::largeGenericRgbConversion_data() +{ + QTest::addColumn<QImage::Format>("format"); + QTest::addColumn<QImage::Format>("dest_format"); + + QImage::Format formats[] = { + QImage::Format_RGB32, + QImage::Format_ARGB32, + QImage::Format_ARGB32_Premultiplied, + QImage::Format_RGB16, + QImage::Format_RGB888, + QImage::Format_RGBA8888, + QImage::Format_BGR30, + QImage::Format_A2RGB30_Premultiplied, + QImage::Format_RGBA64_Premultiplied, + }; + + for (QImage::Format src_format : formats) { + for (QImage::Format dst_format : formats) { + if (src_format == dst_format) + continue; + + QTest::addRow("%s -> %s", formatToString(src_format).data(), formatToString(dst_format).data()) + << src_format << dst_format; + } + } +} + +void tst_QImage::largeGenericRgbConversion() +{ + // Also test a larger conversion for a few formats (here the tested precision is also higher) + QFETCH(QImage::Format, format); + QFETCH(QImage::Format, dest_format); + + // Must have more than 64k pixels to trigger threaded codepath: + QImage image(512, 216, format); + + for (int i = 0; i < image.height(); ++i) + for (int j = 0; j < image.width(); ++j) + image.setPixel(j, i, qRgb(j % 256, i, 0)); + + const bool precision_8bit = (format != QImage::Format_RGB16) && (dest_format != QImage::Format_RGB16); + + QImage imageConverted = image.convertToFormat(dest_format); + QCOMPARE(imageConverted.format(), dest_format); + for (int i = 0; i < imageConverted.height(); ++i) { + for (int j = 0; j < imageConverted.width(); ++j) { + if (precision_8bit) { + QCOMPARE(imageConverted.pixel(j, i), image.pixel(j, i)); + } else { + QRgb convertedColor = imageConverted.pixel(j,i); + QCOMPARE(qRed(convertedColor) & 0xF8, (j % 256) & 0xF8); + QCOMPARE(qGreen(convertedColor) & 0xFC, i & 0xFC); + } + } + } +} + +void tst_QImage::largeInplaceRgbConversion_data() +{ + QTest::addColumn<QImage::Format>("format"); + QTest::addColumn<QImage::Format>("dest_format"); + + QImage::Format formats[] = { + QImage::Format_RGB32, + QImage::Format_ARGB32, + QImage::Format_ARGB32_Premultiplied, + QImage::Format_RGB16, + QImage::Format_RGB888, + QImage::Format_RGBA8888, + QImage::Format_BGR30, + QImage::Format_A2RGB30_Premultiplied, + QImage::Format_RGBA64_Premultiplied, + }; + + for (QImage::Format src_format : formats) { + for (QImage::Format dst_format : formats) { + if (src_format == dst_format) + continue; + if (qt_depthForFormat(src_format) < qt_depthForFormat(dst_format)) + continue; + QTest::addRow("%s -> %s", formatToString(src_format).data(), formatToString(dst_format).data()) + << src_format << dst_format; + } + } +} + +void tst_QImage::largeInplaceRgbConversion() +{ + // Also test a larger conversion for a few formats + QFETCH(QImage::Format, format); + QFETCH(QImage::Format, dest_format); + + // Must have more than 64k pixels to trigger threaded codepath: + QImage image(512, 216, format); + + for (int i = 0; i < image.height(); ++i) + for (int j = 0; j < image.width(); ++j) + image.setPixel(j, i, qRgb(j % 256, i, 0)); + + const bool precision_8bit = (format != QImage::Format_RGB16) && (dest_format != QImage::Format_RGB16); + + image.convertTo(dest_format); + QCOMPARE(image.format(), dest_format); + for (int i = 0; i < image.height(); ++i) { + for (int j = 0; j < image.width(); ++j) { + if (precision_8bit) { + QCOMPARE(image.pixel(j,i), qRgb(j % 256, i, 0)); + } else { + QRgb convertedColor = image.pixel(j,i); + QCOMPARE(qRed(convertedColor) & 0xF8, (j % 256) & 0xF8); + QCOMPARE(qGreen(convertedColor) & 0xFC, i & 0xFC); + } + } + } } void tst_QImage::deepCopyWhenPaintingActive() @@ -3086,6 +3209,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<QString>("fileName"); |