Fix PNGs saved from QImage transform of 8-bit images

Fixes two separate errors. QImage::transform was incorrectly adding
colors to the color-table of the returned image when the converted image
would not be indexed, and qpnghandler was looking at non-empty color-
table instead of color format.

Task-number: QTBUG-43708
Change-Id: Ife14b6428ca65ac7d3a0b36a89a73e56d64586b4
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2017-04-12 16:38:40 +02:00
parent 288bfb0bbd
commit ee3ac3a3bf
3 changed files with 16 additions and 2 deletions

View File

@ -4671,7 +4671,7 @@ QImage QImage::transformed(const QTransform &matrix, Qt::TransformationMode mode
}
// initizialize the data
if (d->format == QImage::Format_Indexed8) {
if (target_format == QImage::Format_Indexed8) {
if (dImage.d->colortable.size() < 256) {
// colors are left in the color table, so pick that one as transparent
dImage.d->colortable.append(0x0);

View File

@ -830,7 +830,7 @@ bool QPNGImageWriter::writeImage(const QImage& image, volatile int quality_in, c
int color_type = 0;
if (image.colorCount()) {
if (image.format() <= QImage::Format_Indexed8) {
if (image.isGrayscale())
color_type = PNG_COLOR_TYPE_GRAY;
else

View File

@ -211,6 +211,8 @@ private slots:
void reinterpretAsFormat2();
void complexTransform8bit();
#ifdef Q_OS_DARWIN
void toCGImage_data();
void toCGImage();
@ -3366,6 +3368,18 @@ void tst_QImage::reinterpretAsFormat2()
}
}
void tst_QImage::complexTransform8bit()
{
QImage img1(100, 100, QImage::Format_RGB32);
img1.fill(Qt::green);
img1 = img1.convertToFormat(QImage::Format_Indexed8);
QImage img2 = img1.transformed(QTransform().rotate(45), Qt::SmoothTransformation);
// Currently the format is always QImage::Format_ARGB32_Premultiplied, but it
// doesn't have to be, and if it becomes indexed this test is no longer be valid.
QVERIFY(img2.format() > QImage::Format_Indexed8);
QCOMPARE(img2.colorCount(), 0);
}
#ifdef Q_OS_DARWIN
void tst_QImage::toCGImage_data()