diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-10-11 16:37:15 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-09-26 18:49:10 +0200 |
commit | b0b4fcd05cd5ae891da868829c1645acf7589acb (patch) | |
tree | 897909b238b2cc0dc9c23d515158291771973461 /tests/auto/gui | |
parent | 45896797c6dea7c3020c0db5ebeb41dc7a2ef4b7 (diff) |
Preserve formats in QImage::scaled()
Do not always use the smoothScaled routine, the normal routines are
also optimized, and do not convert to alpha formats when not necessary.
Task-number: QTBUG-49719
Change-Id: I6ee9b620cc259472c419e7363357f41ce29b594a
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/image/qimage/tst_qimage.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index db5e474711..98de3dc5df 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -123,6 +123,8 @@ private slots: void smoothScaleBig(); void smoothScaleAlpha(); + void smoothScaleFormats_data(); + void smoothScaleFormats(); void transformed_data(); void transformed(); @@ -1922,6 +1924,34 @@ void tst_QImage::smoothScaleAlpha() QCOMPARE(dst, expected); } +void tst_QImage::smoothScaleFormats_data() +{ + QTest::addColumn<QImage::Format>("format"); + for (int i = QImage::Format_RGB32; i < QImage::NImageFormats; ++i) { + QTest::addRow("%s", formatToString(QImage::Format(i)).data()) << QImage::Format(i); + } +} + +void tst_QImage::smoothScaleFormats() +{ + QFETCH(QImage::Format, format); + QImage src(32, 32, format); + src.fill(0x0); + + // Upscale using painter scaling + QImage scaled = src.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + QCOMPARE(scaled.format(), src.format()); + + // > 2x down-scaling using QImage::smoothScaled() + scaled = src.scaled(8, 8, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + QCOMPARE(scaled.format(), src.format()); + + QTransform transform; + transform.rotate(45); + QImage rotated = src.transformed(transform); + QVERIFY(rotated.hasAlphaChannel()); +} + static int count(const QImage &img, int x, int y, int dx, int dy, QRgb pixel) { int i = 0; |