Chromium Code Reviews| Index: src/codec/SkWebpCodec.cpp |
| diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp |
| index a795fdd6d551637467cdf95fae5b4cffb07691d8..ef3351ecf94278cbfede42e1ea6af77cd7cf1b4a 100644 |
| --- a/src/codec/SkWebpCodec.cpp |
| +++ b/src/codec/SkWebpCodec.cpp |
| @@ -31,7 +31,7 @@ bool SkWebpCodec::IsWebp(const void* buf, size_t bytesRead) { |
| // Parse headers of RIFF container, and check for valid Webp (VP8) content. |
| // NOTE: This calls peek instead of read, since onGetPixels will need these |
| // bytes again. |
| -static bool webp_parse_header(SkStream* stream, SkImageInfo* info) { |
| +static bool webp_parse_header(SkStream* stream, SkEncodedInfo* info) { |
| unsigned char buffer[WEBP_VP8_HEADER_SIZE]; |
| SkASSERT(WEBP_VP8_HEADER_SIZE <= SkCodec::MinBufferedBytesNeeded()); |
| @@ -62,20 +62,47 @@ static bool webp_parse_header(SkStream* stream, SkImageInfo* info) { |
| } |
| if (info) { |
| - // FIXME: Is N32 the right type? |
| - // Is unpremul the right type? Clients of SkCodec may assume it's the |
| - // best type, when Skia currently cannot draw unpremul (and raster is faster |
| - // with premul). |
| - *info = SkImageInfo::Make(features.width, features.height, kN32_SkColorType, |
| - SkToBool(features.has_alpha) ? kUnpremul_SkAlphaType |
| - : kOpaque_SkAlphaType); |
| + SkEncodedInfo::Color color; |
| + SkEncodedInfo::Alpha alpha; |
| + switch (features.format) { |
| + case 0: |
| + // This indicates a "mixed" format. We would see this for |
| + // animated webps or for webps encoded in multiple fragments. |
| + // I believe that this is a rare case. |
| + // We could also guess kYUV here, but I think it makes more |
| + // sense to guess kBGRA which is likely closer to the final |
| + // output. Otherwise, we might end up converting |
| + // BGRA->YUVA->BGRA. |
| + color = SkEncodedInfo::kBGRA_Color; |
| + alpha = SkEncodedInfo::kUnpremul_Alpha; |
| + break; |
| + case 1: |
| + // This is the lossy format (YUV). |
| + color = SkToBool(features.has_alpha) ? SkEncodedInfo::kYUVA_Color : |
|
scroggo
2016/03/24 20:51:04
nit: I would find this a little clearer as
if (ha
msarett
2016/03/24 22:42:07
Done.
|
| + SkEncodedInfo::kYUV_Color; |
| + alpha = SkToBool(features.has_alpha) ? SkEncodedInfo::kUnpremul_Alpha : |
| + SkEncodedInfo::kOpaque_Alpha; |
| + break; |
| + case 2: |
| + // This is the lossless format (BGRA). |
| + // FIXME: Should we check the has_alpha flag here? It looks |
|
msarett
2016/03/24 16:21:40
Forgot to mention that I emailed webp-discuss abou
|
| + // like the image is encoded with an alpha channel |
| + // regardless of whether or not the alpha flag is set. |
| + color = SkEncodedInfo::kBGRA_Color; |
| + alpha = SkEncodedInfo::kUnpremul_Alpha; |
| + break; |
| + default: |
| + return false; |
| + } |
| + |
| + *info = SkEncodedInfo::Make(features.width, features.height, color, alpha, 8); |
| } |
| return true; |
| } |
| SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) { |
| SkAutoTDelete<SkStream> streamDeleter(stream); |
| - SkImageInfo info; |
| + SkEncodedInfo info; |
| if (webp_parse_header(stream, &info)) { |
| return new SkWebpCodec(info, streamDeleter.release()); |
| } |
| @@ -251,5 +278,5 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, |
| } |
| } |
| -SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) |
| +SkWebpCodec::SkWebpCodec(const SkEncodedInfo& info, SkStream* stream) |
| : INHERITED(info, stream) {} |