diff options
author | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2017-03-15 09:23:42 +0100 |
---|---|---|
committer | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2017-03-15 11:53:40 +0000 |
commit | 30301436b59efe7ff25991cbbaa388f6f1b4d66e (patch) | |
tree | 0b1fb2ff46e85d53ae3eb0819098204777c5fbe1 | |
parent | d6e5ba97fa15f6182ce2ce9b04ee28fa7a4d9015 (diff) | |
download | qtimageformats-30301436b59efe7ff25991cbbaa388f6f1b4d66e.tar.gz |
Add support for tiled, color indexed tiff files
For color index images, the tiff handler uses scanline based
reading. The tiff decoder does not support that if the image is stored
in tiled format. This commit adds tile based reading for such cases.
[ChangeLog][TIFF] Added support for tiled, color indexed tiff files
Task-number: QTBUG-12636
Change-Id: Ic759903c75c8252267429f01e3dd9706fc516f8f
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r-- | src/plugins/imageformats/tiff/qtiffhandler.cpp | 31 | ||||
-rw-r--r-- | tests/auto/tiff/tst_qtiff.cpp | 22 | ||||
-rw-r--r-- | tests/shared/images/tiff.qrc | 2 | ||||
-rw-r--r-- | tests/shared/images/tiff/indexed_nontiled.tif | bin | 0 -> 119486 bytes | |||
-rw-r--r-- | tests/shared/images/tiff/indexed_tiled.tif | bin | 0 -> 209220 bytes |
5 files changed, 53 insertions, 2 deletions
diff --git a/src/plugins/imageformats/tiff/qtiffhandler.cpp b/src/plugins/imageformats/tiff/qtiffhandler.cpp index b5d80f9..e34ea25 100644 --- a/src/plugins/imageformats/tiff/qtiffhandler.cpp +++ b/src/plugins/imageformats/tiff/qtiffhandler.cpp @@ -385,11 +385,38 @@ bool QTiffHandler::read(QImage *image) } image->setColorTable(qtColorTable); - for (uint32 y=0; y<height; ++y) { - if (TIFFReadScanline(tiff, image->scanLine(y), y, 0) < 0) { + + if (TIFFIsTiled(tiff)) { + quint32 tileWidth, tileLength; + TIFFGetField(tiff, TIFFTAG_TILEWIDTH, &tileWidth); + TIFFGetField(tiff, TIFFTAG_TILELENGTH, &tileLength); + uchar *buf = (uchar *)_TIFFmalloc(TIFFTileSize(tiff)); + if (!tileWidth || !tileLength || !buf) { + _TIFFfree(buf); d->close(); return false; } + for (quint32 y = 0; y < height; y += tileLength) { + for (quint32 x = 0; x < width; x += tileWidth) { + if (TIFFReadTile(tiff, buf, x, y, 0, 0) < 0) { + _TIFFfree(buf); + d->close(); + return false; + } + quint32 linesToCopy = qMin(tileLength, height - y); + quint32 widthToCopy = qMin(tileWidth, width - x); + for (quint32 i = 0; i < linesToCopy; i++) + ::memcpy(image->scanLine(y + i) + x, buf + (i * tileWidth), widthToCopy); + } + } + _TIFFfree(buf); + } else { + for (uint32 y=0; y<height; ++y) { + if (TIFFReadScanline(tiff, image->scanLine(y), y, 0) < 0) { + d->close(); + return false; + } + } } // free redTable, greenTable and greenTable done by libtiff diff --git a/tests/auto/tiff/tst_qtiff.cpp b/tests/auto/tiff/tst_qtiff.cpp index 65cc56c..bec2ca2 100644 --- a/tests/auto/tiff/tst_qtiff.cpp +++ b/tests/auto/tiff/tst_qtiff.cpp @@ -81,6 +81,9 @@ private slots: void multipage_data(); void multipage(); + void tiled_data(); + void tiled(); + private: QString prefix; }; @@ -153,6 +156,8 @@ void tst_qtiff::readImage_data() QTest::newRow("rgb_orientation_7") << QString("rgb_orientation_7.tiff") << QSize(64, 64); QTest::newRow("rgb_orientation_8") << QString("rgb_orientation_8.tiff") << QSize(64, 64); QTest::newRow("teapot") << QString("teapot.tiff") << QSize(256, 256); + QTest::newRow("indexed_nontiled") << QString("indexed_nontiled.tif") << QSize(512, 384); + QTest::newRow("indexed_tiled") << QString("indexed_tiled.tif") << QSize(512, 384); } void tst_qtiff::readImage() @@ -557,5 +562,22 @@ void tst_qtiff::multipage() QCOMPARE(reader.jumpToNextImage(), false); } +void tst_qtiff::tiled_data() +{ + QTest::addColumn<QString>("expectedFile"); + QTest::addColumn<QString>("tiledFile"); + QTest::newRow("Indexed") << "indexed_nontiled.tif" << "indexed_tiled.tif"; +} + +void tst_qtiff::tiled() +{ + QFETCH(QString, expectedFile); + QFETCH(QString, tiledFile); + + QImage expectedImage(prefix + expectedFile); + QImage tiledImage(prefix + tiledFile); + QCOMPARE(expectedImage, tiledImage); +} + QTEST_MAIN(tst_qtiff) #include "tst_qtiff.moc" diff --git a/tests/shared/images/tiff.qrc b/tests/shared/images/tiff.qrc index c98a72c..258acf0 100644 --- a/tests/shared/images/tiff.qrc +++ b/tests/shared/images/tiff.qrc @@ -41,5 +41,7 @@ <file>tiff/rgb_orientation_8.tiff</file> <file>tiff/teapot.tiff</file> <file>tiff/colorful.bmp</file> + <file>tiff/indexed_tiled.tif</file> + <file>tiff/indexed_nontiled.tif</file> </qresource> </RCC> diff --git a/tests/shared/images/tiff/indexed_nontiled.tif b/tests/shared/images/tiff/indexed_nontiled.tif Binary files differnew file mode 100644 index 0000000..d0b7cef --- /dev/null +++ b/tests/shared/images/tiff/indexed_nontiled.tif diff --git a/tests/shared/images/tiff/indexed_tiled.tif b/tests/shared/images/tiff/indexed_tiled.tif Binary files differnew file mode 100644 index 0000000..4ed11dd --- /dev/null +++ b/tests/shared/images/tiff/indexed_tiled.tif |