diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2023-12-11 10:39:18 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2023-12-14 23:35:14 +0100 |
commit | 15051e205facddd8bc3f290c65ad854ec1b25091 (patch) | |
tree | b3ebebeb3db659fa9f583ef98dbc965cc1bfe33d | |
parent | 04a327f00a84b0c13cb4a4a6715b2ce86ea9f61a (diff) |
Copy color table in QImage::transform paint path
A copy without pixel ratio was made, but color table not set.
Pick-to: 6.7 6.6 6.5 6.2
Fixes: QTBUG-119902
Change-Id: I328f3faa70d7a1263061cbe51921999393e30801
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
-rw-r--r-- | src/gui/image/qimage.cpp | 9 | ||||
-rw-r--r-- | tests/auto/gui/image/qimage/tst_qimage.cpp | 11 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 2770a04bce..463a1e4a6d 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -4921,7 +4921,14 @@ QImage Q_TRACE_INSTRUMENT(qtgui) QImage::transformed(const QTransform &matrix, Q if (target_format >= QImage::Format_RGB32) { // Prevent QPainter from applying devicePixelRatio corrections - const QImage sImage = (devicePixelRatio() != 1) ? QImage(constBits(), width(), height(), format()) : *this; + QImage sImage = (devicePixelRatio() != 1) ? QImage(constBits(), width(), height(), format()) : *this; + if (sImage.d != d + && (d->format == QImage::Format_MonoLSB + || d->format == QImage::Format_Mono + || d->format == QImage::Format_Indexed8)) { + sImage.d->colortable = d->colortable; + sImage.d->has_alpha_clut = d->has_alpha_clut; + } Q_ASSERT(sImage.devicePixelRatio() == 1); Q_ASSERT(sImage.devicePixelRatio() == dImage.devicePixelRatio()); diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index c9a42af42a..cda6f8b1bd 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -231,6 +231,7 @@ private slots: void largeRasterScale(); void metadataChangeWithReadOnlyPixels(); + void scaleIndexed(); #if defined(Q_OS_WIN) void toWinHBITMAP_data(); @@ -4102,6 +4103,16 @@ void tst_QImage::metadataChangeWithReadOnlyPixels() QCOMPARE(image.constBits(), (const uchar *)data); } +void tst_QImage::scaleIndexed() +{ + QImage image(10, 10, QImage::Format_Indexed8); + image.setColor(0, qRgb(0,0,0)); + image.setColor(1, qRgb(1,1,1)); + image.fill(1); + image.setDevicePixelRatio(2); + QImage image2 = image.scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation); // do not crash +} + #if defined(Q_OS_WIN) static inline QColor COLORREFToQColor(COLORREF cr) |