QImage: retain color space also through right angle roatations
The color space meta data was retained through most image conversion functions, but missed in the optimized code path for 90/180/270 degree rotations. Fixes: QTBUG-126575 Pick-to: 6.7 6.5 Change-Id: Icbd5aa71e88b4d2d79b00b3cadfe850e6714637b Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> (cherry picked from commit bea8beef85d1b5a163021ba4a671bbaddcc1738d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
bf97701fd8
commit
aba84d1e6b
@ -4718,7 +4718,7 @@ static QImage rotated90(const QImage &image)
|
||||
QImage out(image.height(), image.width(), image.format());
|
||||
if (out.isNull())
|
||||
return out;
|
||||
copyMetadata(&out, image);
|
||||
copyMetadata(QImageData::get(out), QImageData::get(image));
|
||||
if (image.colorCount() > 0)
|
||||
out.setColorTable(image.colorTable());
|
||||
int w = image.width();
|
||||
@ -4748,7 +4748,7 @@ static QImage rotated180(const QImage &image)
|
||||
QImage out(image.width(), image.height(), image.format());
|
||||
if (out.isNull())
|
||||
return out;
|
||||
copyMetadata(&out, image);
|
||||
copyMetadata(QImageData::get(out), QImageData::get(image));
|
||||
if (image.colorCount() > 0)
|
||||
out.setColorTable(image.colorTable());
|
||||
int w = image.width();
|
||||
@ -4762,7 +4762,7 @@ static QImage rotated270(const QImage &image)
|
||||
QImage out(image.height(), image.width(), image.format());
|
||||
if (out.isNull())
|
||||
return out;
|
||||
copyMetadata(&out, image);
|
||||
copyMetadata(QImageData::get(out), QImageData::get(image));
|
||||
if (image.colorCount() > 0)
|
||||
out.setColorTable(image.colorTable());
|
||||
int w = image.width();
|
||||
|
@ -3997,24 +3997,28 @@ void tst_QImage::metadataPassthrough()
|
||||
a.setDotsPerMeterX(100);
|
||||
a.setDotsPerMeterY(80);
|
||||
a.setDevicePixelRatio(2.0);
|
||||
a.setColorSpace(QColorSpace(QColorSpace::DisplayP3));
|
||||
|
||||
QImage scaled = a.scaled(QSize(32, 32), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
QCOMPARE(scaled.text(QStringLiteral("Test")), a.text(QStringLiteral("Test")));
|
||||
QCOMPARE(scaled.dotsPerMeterX(), a.dotsPerMeterX());
|
||||
QCOMPARE(scaled.dotsPerMeterY(), a.dotsPerMeterY());
|
||||
QCOMPARE(scaled.devicePixelRatio(), a.devicePixelRatio());
|
||||
QCOMPARE(scaled.colorSpace(), a.colorSpace());
|
||||
|
||||
scaled = a.scaled(QSize(128, 128), Qt::IgnoreAspectRatio, Qt::FastTransformation);
|
||||
QCOMPARE(scaled.text(QStringLiteral("Test")), a.text(QStringLiteral("Test")));
|
||||
QCOMPARE(scaled.dotsPerMeterX(), a.dotsPerMeterX());
|
||||
QCOMPARE(scaled.dotsPerMeterY(), a.dotsPerMeterY());
|
||||
QCOMPARE(scaled.devicePixelRatio(), a.devicePixelRatio());
|
||||
QCOMPARE(scaled.colorSpace(), a.colorSpace());
|
||||
|
||||
QImage mirrored = a.mirrored();
|
||||
QCOMPARE(mirrored.text(QStringLiteral("Test")), a.text(QStringLiteral("Test")));
|
||||
QCOMPARE(mirrored.dotsPerMeterX(), a.dotsPerMeterX());
|
||||
QCOMPARE(mirrored.dotsPerMeterY(), a.dotsPerMeterY());
|
||||
QCOMPARE(mirrored.devicePixelRatio(), a.devicePixelRatio());
|
||||
QCOMPARE(mirrored.colorSpace(), a.colorSpace());
|
||||
|
||||
QTransform t;
|
||||
t.rotate(90);
|
||||
@ -4023,18 +4027,21 @@ void tst_QImage::metadataPassthrough()
|
||||
QCOMPARE(rotated.dotsPerMeterX(), a.dotsPerMeterX());
|
||||
QCOMPARE(rotated.dotsPerMeterY(), a.dotsPerMeterY());
|
||||
QCOMPARE(rotated.devicePixelRatio(), a.devicePixelRatio());
|
||||
QCOMPARE(rotated.colorSpace(), a.colorSpace());
|
||||
|
||||
QImage swapped = a.rgbSwapped();
|
||||
QCOMPARE(swapped.text(QStringLiteral("Test")), a.text(QStringLiteral("Test")));
|
||||
QCOMPARE(swapped.dotsPerMeterX(), a.dotsPerMeterX());
|
||||
QCOMPARE(swapped.dotsPerMeterY(), a.dotsPerMeterY());
|
||||
QCOMPARE(swapped.devicePixelRatio(), a.devicePixelRatio());
|
||||
QCOMPARE(swapped.colorSpace(), a.colorSpace());
|
||||
|
||||
QImage converted = a.convertToFormat(QImage::Format_RGB32);
|
||||
QCOMPARE(converted.text(QStringLiteral("Test")), a.text(QStringLiteral("Test")));
|
||||
QCOMPARE(converted.dotsPerMeterX(), a.dotsPerMeterX());
|
||||
QCOMPARE(converted.dotsPerMeterY(), a.dotsPerMeterY());
|
||||
QCOMPARE(converted.devicePixelRatio(), a.devicePixelRatio());
|
||||
QCOMPARE(converted.colorSpace(), a.colorSpace());
|
||||
|
||||
QList<QRgb> clut({ 0xFFFF0000, 0xFF00FF00, 0xFF0000FF });
|
||||
QImage convertedWithClut = a.convertToFormat(QImage::Format_Indexed8, clut);
|
||||
@ -4042,12 +4049,14 @@ void tst_QImage::metadataPassthrough()
|
||||
QCOMPARE(convertedWithClut.dotsPerMeterX(), a.dotsPerMeterX());
|
||||
QCOMPARE(convertedWithClut.dotsPerMeterY(), a.dotsPerMeterY());
|
||||
QCOMPARE(convertedWithClut.devicePixelRatio(), a.devicePixelRatio());
|
||||
QCOMPARE(convertedWithClut.colorSpace(), a.colorSpace());
|
||||
|
||||
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());
|
||||
QCOMPARE(copied.dotsPerMeterY(), a.dotsPerMeterY());
|
||||
QCOMPARE(copied.devicePixelRatio(), a.devicePixelRatio());
|
||||
QCOMPARE(copied.colorSpace(), a.colorSpace());
|
||||
|
||||
QImage alphaMask = a.createAlphaMask();
|
||||
QCOMPARE(alphaMask.dotsPerMeterX(), a.dotsPerMeterX());
|
||||
|
Loading…
x
Reference in New Issue
Block a user