From 1904df0413b9b665a5f8be7a4614abe5f2e30d21 Mon Sep 17 00:00:00 2001 From: "jvanverth@google.com" Date: Fri, 9 Aug 2013 14:24:30 +0000 Subject: Reverting r10651: Make WebP decoding independent of stream length. git-svn-id: http://skia.googlecode.com/svn/trunk@10656 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/images/SkImageDecoder_libwebp.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/images/SkImageDecoder_libwebp.cpp b/src/images/SkImageDecoder_libwebp.cpp index 4b5081b436..b0fa7f7053 100644 --- a/src/images/SkImageDecoder_libwebp.cpp +++ b/src/images/SkImageDecoder_libwebp.cpp @@ -203,27 +203,31 @@ static bool webp_idecode(SkStream* stream, WebPDecoderConfig* config) { return false; } - bool success = true; - VP8StatusCode status = VP8_STATUS_SUSPENDED; - do { - const uint32_t bytesToRead = WEBP_IDECODE_BUFFER_SZ; + uint32_t bytesRemaining = contentSize; + while (bytesRemaining > 0) { + const uint32_t bytesToRead = (bytesRemaining < WEBP_IDECODE_BUFFER_SZ) ? + bytesRemaining : WEBP_IDECODE_BUFFER_SZ; const size_t bytesRead = stream->read(input, bytesToRead); if (0 == bytesRead) { - success = false; break; } - status = WebPIAppend(idec, input, bytesRead); - if (VP8_STATUS_OK != status && VP8_STATUS_SUSPENDED != status) { - success = false; + VP8StatusCode status = WebPIAppend(idec, input, bytesRead); + if (VP8_STATUS_OK == status || VP8_STATUS_SUSPENDED == status) { + bytesRemaining -= bytesRead; + } else { break; } - } while (VP8_STATUS_OK != status); + } srcStorage.free(); WebPIDelete(idec); WebPFreeDecBuffer(&config->output); - return success; + if (bytesRemaining > 0) { + return false; + } else { + return true; + } } static bool webp_get_config_resize(WebPDecoderConfig* config, -- cgit v1.2.3