diff options
-rw-r--r-- | src/plugins/imageformats/tiff/qtiffhandler.cpp | 15 | ||||
-rw-r--r-- | tests/auto/tiff/tst_qtiff.cpp | 1 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/plugins/imageformats/tiff/qtiffhandler.cpp b/src/plugins/imageformats/tiff/qtiffhandler.cpp index a6b87af..875ab16 100644 --- a/src/plugins/imageformats/tiff/qtiffhandler.cpp +++ b/src/plugins/imageformats/tiff/qtiffhandler.cpp @@ -251,8 +251,19 @@ bool QTiffHandlerPrivate::openForRead(QIODevice *device) format = QImage::Format_Indexed8; else if (samplesPerPixel < 4) format = QImage::Format_RGB32; - else - format = QImage::Format_ARGB32_Premultiplied; + else { + uint16 count; + uint16 *extrasamples; + // If there is any definition of the alpha-channel, libtiff will return premultiplied + // data to us. If there is none, libtiff will not touch it and we assume it to be + // non-premultiplied, matching behavior of tested image editors, and how older Qt + // versions used to save it. + bool gotField = TIFFGetField(tiff, TIFFTAG_EXTRASAMPLES, &count, &extrasamples); + if (!gotField || !count || extrasamples[0] == EXTRASAMPLE_UNSPECIFIED) + format = QImage::Format_ARGB32; + else + format = QImage::Format_ARGB32_Premultiplied; + } headersRead = true; return true; diff --git a/tests/auto/tiff/tst_qtiff.cpp b/tests/auto/tiff/tst_qtiff.cpp index a77a735..d309c8d 100644 --- a/tests/auto/tiff/tst_qtiff.cpp +++ b/tests/auto/tiff/tst_qtiff.cpp @@ -346,6 +346,7 @@ void tst_qtiff::writeImage() QImageWriter writer(&buf, format); QVERIFY(writer.write(image)); } + image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); QImage image2; { |