Preserve QImage metadata when converting format with color table

Unlike the other conversion functions, convertWithPalette() did not
call copyMetadata().

Fixes: QTBUG-96926
Pick-to: 6.2 5.15
Change-Id: I2b171cec16bc5a90d33e80d6fe178c650ed3fe36
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
Eirik Aavitsland 2021-09-28 11:15:28 +02:00
parent a2ab67c8b2
commit 66a44f4eba
2 changed files with 8 additions and 1 deletions

View File

@ -2231,7 +2231,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();

View File

@ -3671,6 +3671,13 @@ void tst_QImage::metadataPassthrough()
QCOMPARE(converted.dotsPerMeterY(), a.dotsPerMeterY());
QCOMPARE(converted.devicePixelRatio(), a.devicePixelRatio());
QList<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());