diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-07-29 13:32:17 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-19 11:30:56 +0200 |
commit | 25e60237a576f975d72605d5459b2477ee1f555b (patch) | |
tree | dc6c93a13d30afb3b5333732892bed23ddf8d25d | |
parent | d63c1d05e455921b1ea4e351e770316c3494ee63 (diff) |
Read color space from WebP
Change-Id: If1b9645fe07fb2cf15dbf2421d6c66b20f02bdb6
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
-rw-r--r-- | src/plugins/imageformats/webp/qwebphandler.cpp | 15 | ||||
-rw-r--r-- | src/plugins/imageformats/webp/qwebphandler_p.h | 3 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/plugins/imageformats/webp/qwebphandler.cpp b/src/plugins/imageformats/webp/qwebphandler.cpp index 454d654..d56d28c 100644 --- a/src/plugins/imageformats/webp/qwebphandler.cpp +++ b/src/plugins/imageformats/webp/qwebphandler.cpp @@ -51,6 +51,7 @@ QWebpHandler::QWebpHandler() : m_quality(75), m_scanState(ScanNotScanned), m_features(), + m_formatFlags(0), m_loop(0), m_frameCount(0), m_demuxer(NULL), @@ -151,6 +152,7 @@ bool QWebpHandler::ensureDemuxer() if (m_demuxer == NULL) return false; + m_formatFlags = WebPDemuxGetI(m_demuxer, WEBP_FF_FORMAT_FLAGS); return true; } @@ -160,6 +162,18 @@ bool QWebpHandler::read(QImage *image) return false; if (m_iter.frame_num == 0) { + // Read global meta-data chunks first + WebPChunkIterator metaDataIter; + if ((m_formatFlags & ICCP_FLAG) && WebPDemuxGetChunk(m_demuxer, "ICCP", 1, &metaDataIter)) { + const QByteArray iccProfile = QByteArray::fromRawData(reinterpret_cast<const char *>(metaDataIter.chunk.bytes), + metaDataIter.chunk.size); + m_colorSpace = QColorSpace::fromIccProfile(iccProfile); + // ### consider parsing EXIF and/or XMP metadata too. + WebPDemuxReleaseChunkIterator(&metaDataIter); + } else { + m_colorSpace = QColorSpace::Undefined; + } + // Go to first frame if (!WebPDemuxGetFrame(m_demuxer, 1, &m_iter)) return false; @@ -201,6 +215,7 @@ bool QWebpHandler::read(QImage *image) *image = *m_composited; } + image->setColorSpace(m_colorSpace); return true; } diff --git a/src/plugins/imageformats/webp/qwebphandler_p.h b/src/plugins/imageformats/webp/qwebphandler_p.h index 31574b4..96a8811 100644 --- a/src/plugins/imageformats/webp/qwebphandler_p.h +++ b/src/plugins/imageformats/webp/qwebphandler_p.h @@ -41,6 +41,7 @@ #define QWEBPHANDLER_P_H #include <QtGui/qcolor.h> +#include <QtGui/qcolorspace.h> #include <QtGui/qimage.h> #include <QtGui/qimageiohandler.h> #include <QtCore/qbytearray.h> @@ -90,6 +91,7 @@ private: int m_quality; mutable ScanState m_scanState; WebPBitstreamFeatures m_features; + uint32_t m_formatFlags; int m_loop; int m_frameCount; QColor m_bgColor; @@ -97,6 +99,7 @@ private: WebPData m_webpData; WebPDemuxer *m_demuxer; WebPIterator m_iter; + QColorSpace m_colorSpace; QImage *m_composited; // For animation frames composition }; |