Chromium Code Reviews| Index: src/codec/SkWebpCodec.cpp |
| diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp |
| index e4341421bbf8136844347aa27dbe9c90e75d2561..ed36d6a5196c8257d1115321cedb64b6cd69542a 100644 |
| --- a/src/codec/SkWebpCodec.cpp |
| +++ b/src/codec/SkWebpCodec.cpp |
| @@ -18,6 +18,7 @@ |
| // If moving libwebp out of skia source tree, path for webp headers must be |
| // updated accordingly. Here, we enforce using local copy in webp sub-directory. |
| #include "webp/decode.h" |
| +#include "webp/demux.h" |
| #include "webp/encode.h" |
| bool SkWebpCodec::IsWebp(const void* buf, size_t bytesRead) { |
| @@ -97,18 +98,37 @@ SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) { |
| return nullptr; |
| } |
| + // FIXME (msarett): |
| + // Temporary strategy for getting ICC profiles from webps. Once the incremental decoding |
| + // API lands, we will use the WebPDemuxer to manage the entire decode. |
| + sk_sp<SkColorSpace> colorSpace = nullptr; |
| + const void* memory = stream->getMemoryBase(); |
| + if (memory) { |
| + WebPData data = { (const uint8_t*) memory, stream->getLength() }; |
| + WebPDemuxState state; |
| + WebPDemuxer* demux = WebPDemuxPartial(&data, &state); |
|
mtklein
2016/08/24 12:56:50
Might want to see what this all looks like using a
msarett
2016/08/24 13:14:24
Done.
|
| + WebPChunkIterator chunkIterator; |
| + if (WebPDemuxGetChunk(demux, "ICCP", 1, &chunkIterator)) { |
| + const void* profileData = chunkIterator.chunk.bytes; |
| + size_t profileSize = chunkIterator.chunk.size; |
| + colorSpace = SkColorSpace::NewICC(profileData, profileSize); |
|
mtklein
2016/08/24 12:56:50
I might just skip some of the intermediate names h
msarett
2016/08/24 13:14:24
Done.
|
| + } |
| + WebPDemuxReleaseChunkIterator(&chunkIterator); |
| + WebPDemuxDelete(demux); |
| + } |
| + |
| + if (!colorSpace) { |
| + colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
| + } |
| + |
| SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8); |
| - return new SkWebpCodec(features.width, features.height, info, streamDeleter.release()); |
| + return new SkWebpCodec(features.width, features.height, info, colorSpace, |
| + streamDeleter.release()); |
| } |
| // This version is slightly different from SkCodecPriv's version of conversion_possible. It |
| // supports both byte orders for 8888. |
| static bool webp_conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) { |
| - // FIXME: skbug.com/4895 |
| - // Currently, we ignore the SkColorProfileType on the SkImageInfo. We |
| - // will treat the encoded data as linear regardless of what the client |
| - // requests. |
| - |
| if (!valid_alpha(dst.alphaType(), src.alphaType())) { |
| return false; |
| } |
| @@ -271,7 +291,7 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, |
| } |
| } |
| -SkWebpCodec::SkWebpCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream) |
| - // The spec says an unmarked image is sRGB, so we return that space here. |
| - // TODO: Add support for parsing ICC profiles from webps. |
| - : INHERITED(width, height, info, stream, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)) {} |
| +SkWebpCodec::SkWebpCodec(int width, int height, const SkEncodedInfo& info, |
| + sk_sp<SkColorSpace> colorSpace, SkStream* stream) |
| + : INHERITED(width, height, info, stream, colorSpace) |
| +{} |