summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-07-24 18:27:46 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-08-17 10:09:08 +0200
commitd63c1d05e455921b1ea4e351e770316c3494ee63 (patch)
tree873e5b46ade5e37f77ab18e4665de7bade84a1eb
parenta1e413909fed9a013178e62b922ff5b98326eb6b (diff)
Read/write ICC profile in TIFF plugin
Adds reading and writing of embedded color spaces on the TIFF plugin. Change-Id: I53e8a16ff65f7986e9d51a5b543335e27b43e346 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
-rw-r--r--src/plugins/imageformats/tiff/qtiffhandler.cpp19
-rw-r--r--tests/auto/tiff/tst_qtiff.cpp39
2 files changed, 57 insertions, 1 deletions
diff --git a/src/plugins/imageformats/tiff/qtiffhandler.cpp b/src/plugins/imageformats/tiff/qtiffhandler.cpp
index 3d404bd..0d0a133 100644
--- a/src/plugins/imageformats/tiff/qtiffhandler.cpp
+++ b/src/plugins/imageformats/tiff/qtiffhandler.cpp
@@ -39,6 +39,7 @@
#include "qtiffhandler_p.h"
#include <qvariant.h>
+#include <qcolorspace.h>
#include <qdebug.h>
#include <qimage.h>
#include <qglobal.h>
@@ -487,6 +488,15 @@ bool QTiffHandler::read(QImage *image)
}
}
+ uint32 count;
+ void *profile;
+ if (TIFFGetField(tiff, TIFFTAG_ICCPROFILE, &count, &profile)) {
+ QByteArray iccProfile(reinterpret_cast<const char *>(profile), count);
+ image->setColorSpace(QColorSpace::fromIccProfile(iccProfile));
+ }
+ // We do not handle colorimetric metadat not on ICC profile form, it seems to be a lot
+ // less common, and would need additional API in QColorSpace.
+
return true;
}
@@ -591,7 +601,14 @@ bool QTiffHandler::write(const QImage &image)
TIFFClose(tiff);
return false;
}
-
+ // set color space
+ if (image.colorSpace().isValid()) {
+ QByteArray iccProfile = image.colorSpace().iccProfile();
+ if (!TIFFSetField(tiff, TIFFTAG_ICCPROFILE, iccProfile.size(), reinterpret_cast<const void *>(iccProfile.constData()))) {
+ TIFFClose(tiff);
+ return false;
+ }
+ }
// configure image depth
const QImage::Format format = image.format();
if (format == QImage::Format_Mono || format == QImage::Format_MonoLSB) {
diff --git a/tests/auto/tiff/tst_qtiff.cpp b/tests/auto/tiff/tst_qtiff.cpp
index a8a0ef2..61d49db 100644
--- a/tests/auto/tiff/tst_qtiff.cpp
+++ b/tests/auto/tiff/tst_qtiff.cpp
@@ -87,6 +87,9 @@ private slots:
void readRgba64();
void readGray16();
+ void colorSpace_data();
+ void colorSpace();
+
private:
QString prefix;
};
@@ -627,5 +630,41 @@ void tst_qtiff::readGray16()
QCOMPARE(image.format(), QImage::Format_Grayscale16);
}
+void tst_qtiff::colorSpace_data()
+{
+ QTest::addColumn<QColorSpace::ColorSpaceId>("colorspaceId");
+
+ QTest::newRow("Undefined") << QColorSpace::Undefined;
+ QTest::newRow("sRGB") << QColorSpace::SRgb;
+ QTest::newRow("sRGB(linear)") << QColorSpace::SRgbLinear;
+ QTest::newRow("AdobeRGB") << QColorSpace::AdobeRgb;
+ QTest::newRow("DisplayP3") << QColorSpace::DisplayP3;
+ QTest::newRow("ProPhotoRgb") << QColorSpace::ProPhotoRgb;
+}
+
+void tst_qtiff::colorSpace()
+{
+ QFETCH(QColorSpace::ColorSpaceId, colorspaceId);
+
+ QImage image(prefix + "colorful.bmp");
+ QVERIFY(!image.isNull());
+
+ image.setColorSpace(colorspaceId);
+
+ QByteArray output;
+ QBuffer buf(&output);
+ QVERIFY(buf.open(QIODevice::WriteOnly));
+ QImageWriter writer(&buf, "tiff");
+ writer.write(image);
+ buf.close();
+
+ QVERIFY(buf.open(QIODevice::ReadOnly));
+ QImageReader reader(&buf);
+ QImage image2 = reader.read();
+
+ QCOMPARE(image2.colorSpace(), QColorSpace(colorspaceId));
+ QCOMPARE(image2, image);
+}
+
QTEST_MAIN(tst_qtiff)
#include "tst_qtiff.moc"