summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2019-10-28 14:53:58 +0100
committerEirik Aavitsland <eirik.aavitsland@qt.io>2019-10-29 08:18:05 +0100
commitff6cf6764ded8c028f693da70b876a00fbff2a5f (patch)
tree10b48a840a0eada95e7a783eb48fb7248d364e36 /src
parent2a10b412605a3f812de99f70ed0cb1bd92b633b2 (diff)
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 <allan.jensen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/imageformats/tiff/qtiffhandler.cpp7
1 files 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; i<tableSize ;++i) {
- const int red = redTable[i] / 257;
- const int green = greenTable[i] / 257;
- const int blue = blueTable[i] / 257;
+ // emulate libtiff behavior for 16->8 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);
}
}