Chromium Code Reviews| Index: src/codec/SkWebpCodec.cpp |
| diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp |
| index e40c3f237792fa38454f72c1fb2d5f2e150ae672..883930b5c6cc6ee4b41ebd621e94b8182f13a712 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, int* width, int* height, SkEncodedInfo* info) { |
| +bool SkWebpCodec::ReadHeader(SkStream* stream, SkCodec** outCodec) { |
| unsigned char buffer[WEBP_VP8_HEADER_SIZE]; |
| SkASSERT(WEBP_VP8_HEADER_SIZE <= SkCodec::MinBufferedBytesNeeded()); |
| @@ -61,7 +61,7 @@ static bool webp_parse_header(SkStream* stream, int* width, int* height, SkEncod |
| } |
| } |
| - if (info) { |
| + if (outCodec) { |
| SkEncodedInfo::Color color; |
| SkEncodedInfo::Alpha alpha; |
| switch (features.format) { |
| @@ -98,19 +98,20 @@ static bool webp_parse_header(SkStream* stream, int* width, int* height, SkEncod |
| return false; |
| } |
| - *width = features.width; |
| - *height = features.height; |
| - *info = SkEncodedInfo::Make(color, alpha, 8); |
| + SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8); |
| + *outCodec = new SkWebpCodec(features.width, features.height, info, stream); |
| } |
| return true; |
| } |
| SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) { |
| SkAutoTDelete<SkStream> streamDeleter(stream); |
| - int width, height; |
| - SkEncodedInfo info; |
| - if (webp_parse_header(stream, &width, &height, &info)) { |
| - return new SkWebpCodec(width, height, info, streamDeleter.release()); |
| + SkCodec* outCodec; |
| + if (SkWebpCodec::ReadHeader(stream, &outCodec)) { |
|
scroggo
2016/04/25 15:10:43
Since ReadHeader is used only in this method, I do
msarett
2016/04/25 15:18:21
Of course, that's much better :).
|
| + // Codec has taken ownership of the stream. |
| + SkASSERT(outCodec); |
| + streamDeleter.release(); |
| + return outCodec; |
| } |
| return nullptr; |
| } |