summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-12-11 10:48:15 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-01-03 09:36:03 +0000
commit9f69817344eb75fbc4613892c1f54ee69cae2e66 (patch)
tree8c6edc785b80e373983c85808cb4e3ce86e58fe8 /src
parent0f8ac893a7fad1d3cdfcc55b511b2d88e4645ba9 (diff)
Add Grayscale16 support to TIFF
Change-Id: I927d9ab0af78baf90d8fd8d44088218dff0e7082 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/imageformats/tiff/qtiffhandler.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/plugins/imageformats/tiff/qtiffhandler.cpp b/src/plugins/imageformats/tiff/qtiffhandler.cpp
index edb5443..837f9ff 100644
--- a/src/plugins/imageformats/tiff/qtiffhandler.cpp
+++ b/src/plugins/imageformats/tiff/qtiffhandler.cpp
@@ -272,6 +272,8 @@ bool QTiffHandlerPrivate::readHeaders(QIODevice *device)
format = QImage::Format_Mono;
else if (photometric == PHOTOMETRIC_MINISBLACK && bitPerSample == 8 && samplesPerPixel == 1)
format = QImage::Format_Grayscale8;
+ else if (photometric == PHOTOMETRIC_MINISBLACK && bitPerSample == 16 && samplesPerPixel == 1)
+ format = QImage::Format_Grayscale16;
else if ((grayscale || photometric == PHOTOMETRIC_PALETTE) && bitPerSample == 8 && samplesPerPixel == 1)
format = QImage::Format_Indexed8;
else if (samplesPerPixel < 4)
@@ -402,9 +404,11 @@ bool QTiffHandler::read(QImage *image)
}
}
bool format8bit = (format == QImage::Format_Mono || format == QImage::Format_Indexed8 || format == QImage::Format_Grayscale8);
+ bool format16bit = (format == QImage::Format_Grayscale16);
bool format64bit = (format == QImage::Format_RGBX64 || format == QImage::Format_RGBA64 || format == QImage::Format_RGBA64_Premultiplied);
- if (format8bit || format64bit) {
+ // Formats we read directly, instead of over RGBA32:
+ if (format8bit || format16bit || format64bit) {
int bytesPerPixel = image->depth() / 8;
if (format == QImage::Format_RGBX64)
bytesPerPixel = 6;
@@ -513,6 +517,7 @@ static QVector<QRgb> effectiveColorTable(const QImage &image)
colors[i] = qRgba(0, 0, 0, i);
break;
case QImage::Format_Grayscale8:
+ case QImage::Format_Grayscale16:
colors.resize(256);
for (int i = 0; i < 256; ++i)
colors[i] = qRgb(i, i, i);
@@ -622,6 +627,7 @@ bool QTiffHandler::write(const QImage &image)
TIFFClose(tiff);
} else if (format == QImage::Format_Indexed8
|| format == QImage::Format_Grayscale8
+ || format == QImage::Format_Grayscale16
|| format == QImage::Format_Alpha8) {
QVector<QRgb> colorTable = effectiveColorTable(image);
bool isGrayscale = checkGrayscale(colorTable);
@@ -631,7 +637,7 @@ bool QTiffHandler::write(const QImage &image)
photometric = PHOTOMETRIC_MINISWHITE;
if (!TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, photometric)
|| !TIFFSetField(tiff, TIFFTAG_COMPRESSION, compression == NoCompression ? COMPRESSION_NONE : COMPRESSION_LZW)
- || !TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8)
+ || !TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, image.depth())
|| !TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, defaultStripSize(tiff))) {
TIFFClose(tiff);
return false;