diff options
author | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2021-09-28 11:15:28 +0200 |
---|---|---|
committer | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2021-09-28 15:02:40 +0000 |
commit | c9b23b6d282e5b4e1cc596083ec11ed26cf8dcdf (patch) | |
tree | c5224faded5656f62285f00dac0b65291214b23e | |
parent | f03051e477b6fed85538f83620f420d3d4e326e8 (diff) |
Preserve QImage metadata when converting format with color table
Unlike the other conversion functions, convertWithPalette() did not
call copyMetadata().
Fixes: QTBUG-96926
Change-Id: I2b171cec16bc5a90d33e80d6fe178c650ed3fe36
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
(cherry picked from commit 66a44f4ebac0dc20422477afe794fa712dea01bc)
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
-rw-r--r-- | src/gui/image/qimage.cpp | 2 | ||||
-rw-r--r-- | tests/auto/gui/image/qimage/tst_qimage.cpp | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 4d3255661e..d86b9764dd 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -2157,7 +2157,7 @@ static QImage convertWithPalette(const QImage &src, QImage::Format format, QImage dest(src.size(), format); dest.setColorTable(clut); - QImageData::get(dest)->text = QImageData::get(src)->text; + copyMetadata(QImageData::get(dest), QImageData::get(src)); int h = src.height(); int w = src.width(); diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index a36f538515..01971ee3c1 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -3572,6 +3572,13 @@ void tst_QImage::metadataPassthrough() QCOMPARE(converted.dotsPerMeterY(), a.dotsPerMeterY()); QCOMPARE(converted.devicePixelRatio(), a.devicePixelRatio()); + QVector<QRgb> clut({ 0xFFFF0000, 0xFF00FF00, 0xFF0000FF }); + QImage convertedWithClut = a.convertToFormat(QImage::Format_Indexed8, clut); + QCOMPARE(convertedWithClut.text(QStringLiteral("Test")), a.text(QStringLiteral("Test"))); + QCOMPARE(convertedWithClut.dotsPerMeterX(), a.dotsPerMeterX()); + QCOMPARE(convertedWithClut.dotsPerMeterY(), a.dotsPerMeterY()); + QCOMPARE(convertedWithClut.devicePixelRatio(), a.devicePixelRatio()); + QImage copied = a.copy(0, 0, a.width() / 2, a.height() / 2); QCOMPARE(copied.text(QStringLiteral("Test")), a.text(QStringLiteral("Test"))); QCOMPARE(copied.dotsPerMeterX(), a.dotsPerMeterX()); |