From c4f7a15b0d3f6c9d336d86db70ff82a771c66403 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Wed, 26 Feb 2025 23:20:31 +0100 Subject: [PATCH] Fix tiff reading for 16bpc grayscale with alpha sample Having bitPerSample=16 and samplesPerPixel=2, this format was wrongly identified as a 48bpp rgb image. Fixes: QTBUG-134112 Pick-to: 6.9 6.8 Change-Id: Ib62715f10fa5af899cc130c8951ec346939420b9 Reviewed-by: Allan Sandfeld Jensen --- src/plugins/imageformats/tiff/qtiffhandler.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/plugins/imageformats/tiff/qtiffhandler.cpp b/src/plugins/imageformats/tiff/qtiffhandler.cpp index 128a170..ab043d2 100644 --- a/src/plugins/imageformats/tiff/qtiffhandler.cpp +++ b/src/plugins/imageformats/tiff/qtiffhandler.cpp @@ -343,14 +343,15 @@ bool QTiffHandlerPrivate::readHeaders(QIODevice *device) format = QImage::Format_Grayscale16; else if ((grayscale || photometric == PHOTOMETRIC_PALETTE) && bitPerSample == 8 && samplesPerPixel == 1) format = QImage::Format_Indexed8; - else if (samplesPerPixel < 4) - if (bitPerSample == 16 && (photometric == PHOTOMETRIC_RGB || photometric == PHOTOMETRIC_MINISBLACK)) + else if (samplesPerPixel < 4) { + bool regular = (samplesPerPixel != 2) && (photometric == PHOTOMETRIC_RGB || photometric == PHOTOMETRIC_MINISBLACK); + if (bitPerSample == 16 && regular) format = floatingPoint ? QImage::Format_RGBX16FPx4 : QImage::Format_RGBX64; - else if (bitPerSample == 32 && floatingPoint && (photometric == PHOTOMETRIC_RGB || photometric == PHOTOMETRIC_MINISBLACK)) + else if (bitPerSample == 32 && floatingPoint && regular) format = QImage::Format_RGBX32FPx4; else format = QImage::Format_RGB32; - else { + } else { uint16_t count; uint16_t *extrasamples; // If there is any definition of the alpha-channel, libtiff will return premultiplied