diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-02-10 16:26:25 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-02-12 20:46:11 +0000 |
commit | 1803f904bd4e48f9ca1430bb62cc430141380df1 (patch) | |
tree | cd6cfd783766886d67b7b9fd8aa9b726f690634f /tests/auto/gui | |
parent | f94fbaf80a8e6dbcd3dc16271f3ce852b9a1f6da (diff) |
Fix QImage::fill with semi-transparent QColor
A few formats were not treating the input QColor correctly. Fixed and
added more exhaustive test.
Change-Id: I872aeeb45e518f9a34b4ac35642264821f9927f2
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
(cherry picked from commit 95712c5e5438e4eb5cd205ab4659febf3192137a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/image/qimage/tst_qimage.cpp | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 2c9f3a3746..6e7fce0b75 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -148,6 +148,7 @@ private slots: void fillColor_data(); void fillColor(); + void fillColorWithAlpha_data(); void fillColorWithAlpha(); void fillRGB888(); @@ -2348,15 +2349,38 @@ void tst_QImage::fillColor() } } -void tst_QImage::fillColorWithAlpha() +void tst_QImage::fillColorWithAlpha_data() { - QImage argb32(1, 1, QImage::Format_ARGB32); - argb32.fill(QColor(255, 0, 0, 127)); - QCOMPARE(argb32.pixel(0, 0), qRgba(255, 0, 0, 127)); + QTest::addColumn<QImage::Format>("format"); - QImage argb32pm(1, 1, QImage::Format_ARGB32_Premultiplied); - argb32pm.fill(QColor(255, 0, 0, 127)); - QCOMPARE(argb32pm.pixel(0, 0), 0x7f7f0000u); + for (int c = QImage::Format_RGB32; c < QImage::NImageFormats; ++c) { + if (c == QImage::Format_Grayscale8) + continue; + if (c == QImage::Format_Grayscale16) + continue; + if (c == QImage::Format_Alpha8) + continue; + QTest::newRow(qPrintable(formatToString(QImage::Format(c)))) << QImage::Format(c); + } +} + +void tst_QImage::fillColorWithAlpha() +{ + QFETCH(QImage::Format, format); + QImage image(1, 1, format); + image.fill(QColor(255, 170, 85, 170)); + QRgb referenceColor = qRgba(255, 170, 85, 170); + + if (!image.hasAlphaChannel()) + referenceColor = 0xff000000 | referenceColor; + else if (image.pixelFormat().premultiplied() == QPixelFormat::Premultiplied) + referenceColor = qPremultiply(referenceColor); + + QRgb color = image.pixel(0, 0); + QCOMPARE(qRed(color) & 0xf0, qRed(referenceColor) & 0xf0); + QCOMPARE(qGreen(color) & 0xf0, qGreen(referenceColor) & 0xf0); + QCOMPARE(qBlue(color) & 0xf0, qBlue(referenceColor) & 0xf0); + QCOMPARE(qAlpha(color) & 0xf0, qAlpha(referenceColor) & 0xf0); } void tst_QImage::fillRGB888() |