summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2010-09-07 10:07:34 (GMT)
committerSamuel Rødal <samuel.rodal@nokia.com>2010-09-14 13:04:12 (GMT)
commitcb6380beb81ab9571c547270c144988781fed465 (patch)
tree88d2feb9528b3cb3ac5da8cd13b792f8bf77001b /src/gui
parent84066a357e868b7d3f774f4847840014d3bf9e51 (diff)
downloadQt-cb6380beb81ab9571c547270c144988781fed465.zip
Qt-cb6380beb81ab9571c547270c144988781fed465.tar.gz
Qt-cb6380beb81ab9571c547270c144988781fed465.tar.bz2
fix tiff reader to handle TIFFTAG_SAMPLESPERPIXEL for grayscale images
This commit fixes reading a .tiff file from ImageMagick which reports the following: TIFFTAG_BITSPERSAMPLE = 8 TIFFTAG_SAMPLESPERPIXEL = 2 TIFFTAG_PHOTOMETRIC = PHOTOMETRIC_MINISBLACK The reader uses QImage::Format_Indexed8, but since the samples per pixel value this should be (non-existent) QImage::Format_Indexed16, causing memory corruption. The fix falls back to the "normal" way of reading tiff images. Merge-request: 2467 Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/image/qtiffhandler.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/gui/image/qtiffhandler.cpp b/src/gui/image/qtiffhandler.cpp
index de4f680..2e8b998 100644
--- a/src/gui/image/qtiffhandler.cpp
+++ b/src/gui/image/qtiffhandler.cpp
@@ -196,9 +196,12 @@ bool QTiffHandler::read(QImage *image)
uint16 bitPerSample;
if (!TIFFGetField(tiff, TIFFTAG_BITSPERSAMPLE, &bitPerSample))
bitPerSample = 1;
+ uint16 samplesPerPixel; // they may be e.g. grayscale with 2 samples per pixel
+ if (!TIFFGetField(tiff, TIFFTAG_SAMPLESPERPIXEL, &samplesPerPixel))
+ samplesPerPixel = 1;
bool grayscale = photometric == PHOTOMETRIC_MINISBLACK || photometric == PHOTOMETRIC_MINISWHITE;
- if (grayscale && bitPerSample == 1) {
+ if (grayscale && bitPerSample == 1 && samplesPerPixel == 1) {
if (image->size() != QSize(width, height) || image->format() != QImage::Format_Mono)
*image = QImage(width, height, QImage::Format_Mono);
QVector<QRgb> colortable(2);
@@ -220,7 +223,7 @@ bool QTiffHandler::read(QImage *image)
}
}
} else {
- if ((grayscale || photometric == PHOTOMETRIC_PALETTE) && bitPerSample == 8) {
+ if ((grayscale || photometric == PHOTOMETRIC_PALETTE) && bitPerSample == 8 && samplesPerPixel == 1) {
if (image->size() != QSize(width, height) || image->format() != QImage::Format_Indexed8)
*image = QImage(width, height, QImage::Format_Indexed8);
if (!image->isNull()) {