aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/images
diff options
context:
space:
mode:
authorGravatar djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-09 12:32:48 +0000
committerGravatar djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-09 12:32:48 +0000
commit1f617a765b396b2a7b7074b13cf84f77e9732d98 (patch)
tree202a2efedc805d710770de938cddf4f2f07d37a6 /src/images
parent17f1ae63d57a3f3d3a0ae50e1b25b3f8b18fd328 (diff)
Make WebP decoding independent of stream length.
There's a case in Android, when the SkStream passed to WebP decoder may have incorrect length (stream->getLength()). This is observed, if the App decodes an image (size > 80KB) using: 'ParcelFileDescriptor --> BitmapFactory.decodeStream()'. This CL updates the WebP incremental decoding loop to not rely on stream->getLength(). R=scroggo@google.com, vikasa@google.com Review URL: https://codereview.chromium.org/22672003 git-svn-id: http://skia.googlecode.com/svn/trunk@10651 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/images')
-rw-r--r--src/images/SkImageDecoder_libwebp.cpp24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/images/SkImageDecoder_libwebp.cpp b/src/images/SkImageDecoder_libwebp.cpp
index b0fa7f7053..4b5081b436 100644
--- a/src/images/SkImageDecoder_libwebp.cpp
+++ b/src/images/SkImageDecoder_libwebp.cpp
@@ -203,31 +203,27 @@ static bool webp_idecode(SkStream* stream, WebPDecoderConfig* config) {
return false;
}
- uint32_t bytesRemaining = contentSize;
- while (bytesRemaining > 0) {
- const uint32_t bytesToRead = (bytesRemaining < WEBP_IDECODE_BUFFER_SZ) ?
- bytesRemaining : WEBP_IDECODE_BUFFER_SZ;
+ bool success = true;
+ VP8StatusCode status = VP8_STATUS_SUSPENDED;
+ do {
+ const uint32_t bytesToRead = WEBP_IDECODE_BUFFER_SZ;
const size_t bytesRead = stream->read(input, bytesToRead);
if (0 == bytesRead) {
+ success = false;
break;
}
- VP8StatusCode status = WebPIAppend(idec, input, bytesRead);
- if (VP8_STATUS_OK == status || VP8_STATUS_SUSPENDED == status) {
- bytesRemaining -= bytesRead;
- } else {
+ status = WebPIAppend(idec, input, bytesRead);
+ if (VP8_STATUS_OK != status && VP8_STATUS_SUSPENDED != status) {
+ success = false;
break;
}
- }
+ } while (VP8_STATUS_OK != status);
srcStorage.free();
WebPIDelete(idec);
WebPFreeDecBuffer(&config->output);
- if (bytesRemaining > 0) {
- return false;
- } else {
- return true;
- }
+ return success;
}
static bool webp_get_config_resize(WebPDecoderConfig* config,