diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp')
-rw-r--r-- | Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp | 158 |
1 files changed, 13 insertions, 145 deletions
diff --git a/Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp b/Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp index f7f8ca550..4a38f580b 100644 --- a/Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp +++ b/Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp @@ -10,7 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * 3. Neither the name of Apple Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -31,14 +31,6 @@ #if USE(WEBP) -#ifdef QCMS_WEBP_COLOR_CORRECTION -#include "qcms.h" -#include "webp/demux.h" -#else -#undef ICCP_FLAG -#define ICCP_FLAG 0 -#endif - // Backward emulation for earlier versions than 0.1.99. #if (WEBP_DECODER_ABI_VERSION < 0x0163) #define MODE_rgbA MODE_RGBA @@ -53,17 +45,10 @@ inline WEBP_CSP_MODE outputMode(bool hasAlpha) { return hasAlpha ? MODE_bgrA : M namespace WebCore { -WEBPImageDecoder::WEBPImageDecoder(ImageSource::AlphaOption alphaOption, - ImageSource::GammaAndColorProfileOption gammaAndColorProfileOption) +WEBPImageDecoder::WEBPImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption) : ImageDecoder(alphaOption, gammaAndColorProfileOption) , m_decoder(0) , m_hasAlpha(false) - , m_formatFlags(0) -#ifdef QCMS_WEBP_COLOR_CORRECTION - , m_haveReadProfile(false) - , m_transform(0) - , m_decodedHeight(0) -#endif { } @@ -74,11 +59,6 @@ WEBPImageDecoder::~WEBPImageDecoder() void WEBPImageDecoder::clear() { -#ifdef QCMS_WEBP_COLOR_CORRECTION - if (m_transform) - qcms_transform_release(m_transform); - m_transform = 0; -#endif if (m_decoder) WebPIDelete(m_decoder); m_decoder = 0; @@ -97,105 +77,15 @@ ImageFrame* WEBPImageDecoder::frameBufferAtIndex(size_t index) if (index) return 0; - if (m_frameBufferCache.isEmpty()) { + if (m_frameBufferCache.isEmpty()) m_frameBufferCache.resize(1); - m_frameBufferCache[0].setPremultiplyAlpha(m_premultiplyAlpha); - } ImageFrame& frame = m_frameBufferCache[0]; - if (frame.status() != ImageFrame::FrameComplete) + if (!frame.isComplete()) decode(false); return &frame; } -#ifdef QCMS_WEBP_COLOR_CORRECTION - -void WEBPImageDecoder::createColorTransform(const char* data, size_t size) -{ - if (m_transform) - qcms_transform_release(m_transform); - m_transform = 0; - - qcms_profile* deviceProfile = ImageDecoder::qcmsOutputDeviceProfile(); - if (!deviceProfile) - return; - qcms_profile* inputProfile = qcms_profile_from_memory(data, size); - if (!inputProfile) - return; - - // We currently only support color profiles for RGB profiled images. - ASSERT(icSigRgbData == qcms_profile_get_color_space(inputProfile)); - // The input image pixels are RGBA format. - qcms_data_type format = QCMS_DATA_RGBA_8; - // FIXME: Don't force perceptual intent if the image profile contains an intent. - m_transform = qcms_transform_create(inputProfile, format, deviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL); - - qcms_profile_release(inputProfile); -} - -void WEBPImageDecoder::readColorProfile(const uint8_t* data, size_t size) -{ - WebPChunkIterator chunkIterator; - WebPData inputData = { data, size }; - WebPDemuxState state; - - WebPDemuxer* demuxer = WebPDemuxPartial(&inputData, &state); - if (!WebPDemuxGetChunk(demuxer, "ICCP", 1, &chunkIterator)) { - WebPDemuxReleaseChunkIterator(&chunkIterator); - WebPDemuxDelete(demuxer); - return; - } - - const char* profileData = reinterpret_cast<const char*>(chunkIterator.chunk.bytes); - size_t profileSize = chunkIterator.chunk.size; - - // Only accept RGB color profiles from input class devices. - bool ignoreProfile = false; - if (profileSize < ImageDecoder::iccColorProfileHeaderLength) - ignoreProfile = true; - else if (!ImageDecoder::rgbColorProfile(profileData, profileSize)) - ignoreProfile = true; - else if (!ImageDecoder::inputDeviceColorProfile(profileData, profileSize)) - ignoreProfile = true; - - if (!ignoreProfile) - createColorTransform(profileData, profileSize); - - WebPDemuxReleaseChunkIterator(&chunkIterator); - WebPDemuxDelete(demuxer); -} - -void WEBPImageDecoder::applyColorProfile(const uint8_t* data, size_t size, ImageFrame& buffer) -{ - int width; - int decodedHeight; - if (!WebPIDecGetRGB(m_decoder, &decodedHeight, &width, 0, 0)) - return; // See also https://bugs.webkit.org/show_bug.cgi?id=74062 - if (decodedHeight <= 0) - return; - - if (!m_haveReadProfile) { - readColorProfile(data, size); - m_haveReadProfile = true; - } - - ASSERT(width == scaledSize().width()); - ASSERT(decodedHeight <= scaledSize().height()); - - for (int y = m_decodedHeight; y < decodedHeight; ++y) { - uint8_t* row = reinterpret_cast<uint8_t*>(buffer.getAddr(0, y)); - if (qcms_transform* transform = colorTransform()) - qcms_transform_data_type(transform, row, row, width, QCMS_OUTPUT_RGBX); - uint8_t* pixel = row; - for (int x = 0; x < width; ++x, pixel += 4) - buffer.setRGBA(x, y, pixel[0], pixel[1], pixel[2], pixel[3]); - } - - m_decodedHeight = decodedHeight; -} - -#endif // QCMS_WEBP_COLOR_CORRECTION - bool WEBPImageDecoder::decode(bool onlySize) { if (failed()) @@ -209,22 +99,7 @@ bool WEBPImageDecoder::decode(bool onlySize) if (dataSize < imageHeaderSize) return false; int width, height; -#ifdef QCMS_WEBP_COLOR_CORRECTION - WebPData inputData = { dataBytes, dataSize }; - WebPDemuxState state; - WebPDemuxer* demuxer = WebPDemuxPartial(&inputData, &state); - if (!demuxer) - return setFailed(); - - width = WebPDemuxGetI(demuxer, WEBP_FF_CANVAS_WIDTH); - height = WebPDemuxGetI(demuxer, WEBP_FF_CANVAS_HEIGHT); - m_formatFlags = WebPDemuxGetI(demuxer, WEBP_FF_FORMAT_FLAGS); - m_hasAlpha = !!(m_formatFlags & ALPHA_FLAG); - - WebPDemuxDelete(demuxer); - if (state <= WEBP_DEMUX_PARSING_HEADER) - return false; -#elif (WEBP_DECODER_ABI_VERSION >= 0x0163) +#if (WEBP_DECODER_ABI_VERSION >= 0x0163) WebPBitstreamFeatures features; if (WebPGetFeatures(dataBytes, dataSize, &features) != VP8_STATUS_OK) return setFailed(); @@ -237,7 +112,7 @@ bool WEBPImageDecoder::decode(bool onlySize) return setFailed(); m_hasAlpha = false; #endif - if (!setSize(width, height)) + if (!setSize(IntSize(width, height))) return setFailed(); } @@ -247,24 +122,21 @@ bool WEBPImageDecoder::decode(bool onlySize) ASSERT(!m_frameBufferCache.isEmpty()); ImageFrame& buffer = m_frameBufferCache[0]; - ASSERT(buffer.status() != ImageFrame::FrameComplete); + ASSERT(!buffer.isComplete()); - if (buffer.status() == ImageFrame::FrameEmpty) { - if (!buffer.setSize(size().width(), size().height())) + if (buffer.isEmpty()) { + if (!buffer.initialize(size(), m_premultiplyAlpha)) return setFailed(); - buffer.setStatus(ImageFrame::FramePartial); + buffer.setDecoding(ImageFrame::Decoding::Partial); buffer.setHasAlpha(m_hasAlpha); - buffer.setOriginalFrameRect(IntRect(IntPoint(), size())); } if (!m_decoder) { WEBP_CSP_MODE mode = outputMode(m_hasAlpha); if (!m_premultiplyAlpha) mode = outputMode(false); - if ((m_formatFlags & ICCP_FLAG) && !ignoresGammaAndColorProfile()) - mode = MODE_RGBA; // Decode to RGBA for input to libqcms. - int rowStride = size().width() * sizeof(ImageFrame::PixelData); - uint8_t* output = reinterpret_cast<uint8_t*>(buffer.getAddr(0, 0)); + int rowStride = size().width() * sizeof(RGBA32); + uint8_t* output = reinterpret_cast<uint8_t*>(buffer.backingStore()->pixelAt(0, 0)); int outputSize = size().height() * rowStride; m_decoder = WebPINewRGB(mode, output, outputSize, rowStride); if (!m_decoder) @@ -273,14 +145,10 @@ bool WEBPImageDecoder::decode(bool onlySize) switch (WebPIUpdate(m_decoder, dataBytes, dataSize)) { case VP8_STATUS_OK: - if ((m_formatFlags & ICCP_FLAG) && !ignoresGammaAndColorProfile()) - applyColorProfile(dataBytes, dataSize, buffer); - buffer.setStatus(ImageFrame::FrameComplete); + buffer.setDecoding(ImageFrame::Decoding::Complete); clear(); return true; case VP8_STATUS_SUSPENDED: - if ((m_formatFlags & ICCP_FLAG) && !ignoresGammaAndColorProfile()) - applyColorProfile(dataBytes, dataSize, buffer); return false; default: clear(); |