diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-07-24 18:27:46 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-17 10:09:08 +0200 |
commit | d63c1d05e455921b1ea4e351e770316c3494ee63 (patch) | |
tree | 873e5b46ade5e37f77ab18e4665de7bade84a1eb /src/plugins/imageformats | |
parent | a1e413909fed9a013178e62b922ff5b98326eb6b (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>
Diffstat (limited to 'src/plugins/imageformats')
-rw-r--r-- | src/plugins/imageformats/tiff/qtiffhandler.cpp | 19 |
1 files changed, 18 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) { |