From cb6380beb81ab9571c547270c144988781fed465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Tue, 7 Sep 2010 12:07:34 +0200 Subject: fix tiff reader to handle TIFFTAG_SAMPLESPERPIXEL for grayscale images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/gui/image/qtiffhandler.cpp | 7 +++++-- 1 file 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 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()) { -- cgit v0.12