From ff6cf6764ded8c028f693da70b876a00fbff2a5f Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Mon, 28 Oct 2019 14:53:58 +0100 Subject: Tiff: Align 16 to 8 bit colormap conversion to libtiff For paletted images, tiff stores a color map with 16 bit deep entries. When reading such images, the tiff handler tried to be clever in the 16 to 8 bit mapping, but this resulted in slightly different result than what libtiff itself produces if asked to read and convert such an image (TIFFReadRGBAImageOriented()). libtiff simply ignores the lower 8 bits, so we should do the same. Importantly, this makes no difference when 8 bit original data is stored in the orthodox 16 bit way, where e.g. 0xAB is stored as 0xABAB - like we do. However, the alternative storages 0xAB00 and 0xABFF exist in the wild, even in sample images in Qt repos. Also, if we later should want to support proper 16 bit data here, the previous code was anyway wrong: just dividing with 257 is highly unorthodox. The correct way would be to use proper rounding like QRgba64::toArgb32(). Fixes: QTBUG-79522 Change-Id: I7bd90ad7b89a923bd431781f4927b13ad0544407 Reviewed-by: Allan Sandfeld Jensen --- src/plugins/imageformats/tiff/qtiffhandler.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/imageformats/tiff/qtiffhandler.cpp b/src/plugins/imageformats/tiff/qtiffhandler.cpp index d7e46cd..65873e1 100644 --- a/src/plugins/imageformats/tiff/qtiffhandler.cpp +++ b/src/plugins/imageformats/tiff/qtiffhandler.cpp @@ -394,9 +394,10 @@ bool QTiffHandler::read(QImage *image) } for (int i = 0; i8 bit color map conversion: just ignore the lower 8 bits + const int red = redTable[i] >> 8; + const int green = greenTable[i] >> 8; + const int blue = blueTable[i] >> 8; qtColorTable[i] = qRgb(red, green, blue); } } -- cgit v1.2.3