summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2018-10-24 11:36:02 +0200
committerEirik Aavitsland <eirik.aavitsland@qt.io>2018-10-25 12:19:14 +0000
commit8455ab6cb29fcccf44977c517689a8ad26781140 (patch)
tree9064ae1afb3dc3a42b7227b13f5b636832936dbb
parent80017a1c7f829355edce61d5d50196cd1e13dcdd (diff)
tiffhandler: improve stripsize
libtiff's default stripsize is tiny (8KB), so splitting the image into such strips on writing would significantly hurt the compression rate. Aim for 4MB strips instead. Task-number: QTBUG-70820 Change-Id: I07a9a8c81edf62e802b4ae8d6729a76df15e42ac Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/plugins/imageformats/tiff/qtiffhandler.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/plugins/imageformats/tiff/qtiffhandler.cpp b/src/plugins/imageformats/tiff/qtiffhandler.cpp
index 84221d6..d321554 100644
--- a/src/plugins/imageformats/tiff/qtiffhandler.cpp
+++ b/src/plugins/imageformats/tiff/qtiffhandler.cpp
@@ -495,6 +495,15 @@ static QVector<QRgb> effectiveColorTable(const QImage &image)
return colors;
}
+static quint32 defaultStripSize(TIFF *tiff)
+{
+ // Aim for 4MB strips
+ qint64 scanSize = qMax(tmsize_t(1), TIFFScanlineSize(tiff));
+ qint64 numRows = (4 * 1024 * 1024) / scanSize;
+ quint32 reqSize = static_cast<quint32>(qBound(qint64(1), numRows, qint64(UINT_MAX)));
+ return TIFFDefaultStripSize(tiff, reqSize);
+}
+
bool QTiffHandler::write(const QImage &image)
{
if (!device()->isWritable())
@@ -559,7 +568,7 @@ bool QTiffHandler::write(const QImage &image)
if (!TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, photometric)
|| !TIFFSetField(tiff, TIFFTAG_COMPRESSION, compression == NoCompression ? COMPRESSION_NONE : COMPRESSION_LZW)
|| !TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 1)
- || !TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tiff, 0))) {
+ || !TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, defaultStripSize(tiff))) {
TIFFClose(tiff);
return false;
}
@@ -595,7 +604,7 @@ bool QTiffHandler::write(const QImage &image)
if (!TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, photometric)
|| !TIFFSetField(tiff, TIFFTAG_COMPRESSION, compression == NoCompression ? COMPRESSION_NONE : COMPRESSION_LZW)
|| !TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8)
- || !TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tiff, 0))) {
+ || !TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, defaultStripSize(tiff))) {
TIFFClose(tiff);
return false;
}
@@ -603,7 +612,7 @@ bool QTiffHandler::write(const QImage &image)
if (!TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_PALETTE)
|| !TIFFSetField(tiff, TIFFTAG_COMPRESSION, compression == NoCompression ? COMPRESSION_NONE : COMPRESSION_LZW)
|| !TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8)
- || !TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tiff, 0))) {
+ || !TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, defaultStripSize(tiff))) {
TIFFClose(tiff);
return false;
}
@@ -656,7 +665,7 @@ bool QTiffHandler::write(const QImage &image)
|| !TIFFSetField(tiff, TIFFTAG_COMPRESSION, compression == NoCompression ? COMPRESSION_NONE : COMPRESSION_LZW)
|| !TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 3)
|| !TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8)
- || !TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tiff, 0))) {
+ || !TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, defaultStripSize(tiff))) {
TIFFClose(tiff);
return false;
}
@@ -688,7 +697,7 @@ bool QTiffHandler::write(const QImage &image)
|| !TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 4)
|| !TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8)
|| !TIFFSetField(tiff, TIFFTAG_EXTRASAMPLES, 1, &extrasamples)
- || !TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tiff, 0))) {
+ || !TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, defaultStripSize(tiff))) {
TIFFClose(tiff);
return false;
}