From 993db3ee9a1759a858c1968f831339f8a6130d88 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 11 Dec 2023 10:39:18 +0100 Subject: [PATCH] Copy color table in QImage::transform paint path A copy without pixel ratio was made, but color table not set. Pick-to: 6.6 6.5 6.2 Fixes: QTBUG-119902 Change-Id: I328f3faa70d7a1263061cbe51921999393e30801 Reviewed-by: Eirik Aavitsland (cherry picked from commit 15051e205facddd8bc3f290c65ad854ec1b25091) Reviewed-by: Qt Cherry-pick Bot --- src/gui/image/qimage.cpp | 9 ++++++++- tests/auto/gui/image/qimage/tst_qimage.cpp | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 2770a04bcec..463a1e4a6d8 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 fd155fbf1c2..27eb6e411f2 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(); @@ -4099,6 +4100,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)