From f657ecdc5ddef611a503ce460dc81fe2f0bbc2d6 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 20 Apr 2015 16:53:25 +0200 Subject: Fix inplace double mirroring on odd sized images The QImage inplace mirroring method, failed to handle the middle line when mirroring both ways (rotate 180). In both other mirroring cases the middle can be left untouched, but in this case it needs to be mirrored half way. To make the logic simpler, double mirroring will now mirror half the lines instead of half of every line. Change-Id: Iaa1f1e1c3f7dedfb78891fc93207f6d0c64bcafe Reviewed-by: Konstantin Ritt Reviewed-by: Gunnar Sletta --- tests/auto/gui/image/qimage/tst_qimage.cpp | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 525d5b33a0..5691a654d7 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -155,6 +155,9 @@ private slots: void inplaceMirrored_data(); void inplaceMirrored(); + void inplaceMirroredOdd_data(); + void inplaceMirroredOdd(); + void inplaceRgbMirrored(); void inplaceConversion_data(); @@ -2471,6 +2474,54 @@ void tst_QImage::inplaceMirrored() #endif } +void tst_QImage::inplaceMirroredOdd_data() +{ + QTest::addColumn("format"); + QTest::addColumn("swap_vertical"); + QTest::addColumn("swap_horizontal"); + + QTest::newRow("Format_ARGB32, vertical") << QImage::Format_ARGB32 << true << false; + QTest::newRow("Format_RGB888, vertical") << QImage::Format_RGB888 << true << false; + QTest::newRow("Format_RGB16, vertical") << QImage::Format_RGB16 << true << false; + + QTest::newRow("Format_ARGB32, horizontal") << QImage::Format_ARGB32 << false << true; + QTest::newRow("Format_RGB888, horizontal") << QImage::Format_RGB888 << false << true; + QTest::newRow("Format_RGB16, horizontal") << QImage::Format_RGB16 << false << true; + + QTest::newRow("Format_ARGB32, horizontal+vertical") << QImage::Format_ARGB32 << true << true; + QTest::newRow("Format_RGB888, horizontal+vertical") << QImage::Format_RGB888 << true << true; + QTest::newRow("Format_RGB16, horizontal+vertical") << QImage::Format_RGB16 << true << true; +} + +void tst_QImage::inplaceMirroredOdd() +{ +#if defined(Q_COMPILER_REF_QUALIFIERS) + QFETCH(QImage::Format, format); + QFETCH(bool, swap_vertical); + QFETCH(bool, swap_horizontal); + + QImage image(15, 15, format); + + for (int i = 0; i < image.height(); ++i) + for (int j = 0; j < image.width(); ++j) + image.setPixel(j, i, qRgb(j*16, i*16, 0)); + + const uchar* originalPtr = image.constScanLine(0); + + QImage imageMirrored = std::move(image).mirrored(swap_horizontal, swap_vertical); + for (int i = 0; i < imageMirrored.height(); ++i) { + int mirroredI = swap_vertical ? (imageMirrored.height() - i - 1) : i; + for (int j = 0; j < imageMirrored.width(); ++j) { + int mirroredJ = swap_horizontal ? (imageMirrored.width() - j - 1) : j; + QRgb mirroredColor = imageMirrored.pixel(mirroredJ, mirroredI); + QCOMPARE(qRed(mirroredColor) & 0xF8, j * 16); + QCOMPARE(qGreen(mirroredColor) & 0xF8, i * 16); + } + } + QCOMPARE(imageMirrored.constScanLine(0), originalPtr); +#endif +} + void tst_QImage::inplaceRgbMirrored() { #if defined(Q_COMPILER_REF_QUALIFIERS) -- cgit v1.2.3