Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: src/images/SkImageDecoder_libwebp.cpp

Issue 22672003: Make WebP decoding independent of stream length. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: style fixes Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2010, The Android Open Source Project 2 * Copyright 2010, The Android Open Source Project
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 8 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 const uint32_t readBufferSize = (contentSize < WEBP_IDECODE_BUFFER_SZ) ? 196 const uint32_t readBufferSize = (contentSize < WEBP_IDECODE_BUFFER_SZ) ?
197 contentSize : WEBP_IDECODE_BUFFER_SZ; 197 contentSize : WEBP_IDECODE_BUFFER_SZ;
198 SkAutoMalloc srcStorage(readBufferSize); 198 SkAutoMalloc srcStorage(readBufferSize);
199 unsigned char* input = (uint8_t*)srcStorage.get(); 199 unsigned char* input = (uint8_t*)srcStorage.get();
200 if (NULL == input) { 200 if (NULL == input) {
201 WebPIDelete(idec); 201 WebPIDelete(idec);
202 WebPFreeDecBuffer(&config->output); 202 WebPFreeDecBuffer(&config->output);
203 return false; 203 return false;
204 } 204 }
205 205
206 uint32_t bytesRemaining = contentSize; 206 bool success = true;
207 while (bytesRemaining > 0) { 207 VP8StatusCode status = VP8_STATUS_SUSPENDED;
208 const uint32_t bytesToRead = (bytesRemaining < WEBP_IDECODE_BUFFER_SZ) ? 208 do {
209 bytesRemaining : WEBP_IDECODE_BUFFER_SZ; 209 const uint32_t bytesToRead = WEBP_IDECODE_BUFFER_SZ;
210 const size_t bytesRead = stream->read(input, bytesToRead); 210 const size_t bytesRead = stream->read(input, bytesToRead);
211 if (0 == bytesRead) { 211 if (0 == bytesRead) {
212 success = false;
212 break; 213 break;
213 } 214 }
214 215
215 VP8StatusCode status = WebPIAppend(idec, input, bytesRead); 216 status = WebPIAppend(idec, input, bytesRead);
216 if (VP8_STATUS_OK == status || VP8_STATUS_SUSPENDED == status) { 217 if (VP8_STATUS_OK != status && VP8_STATUS_SUSPENDED != status) {
217 bytesRemaining -= bytesRead; 218 success = false;
218 } else {
219 break; 219 break;
220 } 220 }
221 } 221 } while (VP8_STATUS_OK != status);
222 srcStorage.free(); 222 srcStorage.free();
223 WebPIDelete(idec); 223 WebPIDelete(idec);
224 WebPFreeDecBuffer(&config->output); 224 WebPFreeDecBuffer(&config->output);
225 225
226 if (bytesRemaining > 0) { 226 return success;
227 return false;
228 } else {
229 return true;
230 }
231 } 227 }
232 228
233 static bool webp_get_config_resize(WebPDecoderConfig* config, 229 static bool webp_get_config_resize(WebPDecoderConfig* config,
234 SkBitmap* decodedBitmap, 230 SkBitmap* decodedBitmap,
235 int width, int height, bool premultiply) { 231 int width, int height, bool premultiply) {
236 WEBP_CSP_MODE mode = webp_decode_mode(decodedBitmap, premultiply); 232 WEBP_CSP_MODE mode = webp_decode_mode(decodedBitmap, premultiply);
237 if (MODE_LAST == mode) { 233 if (MODE_LAST == mode) {
238 return false; 234 return false;
239 } 235 }
240 236
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 return SkImageDecoder::kUnknown_Format; 589 return SkImageDecoder::kUnknown_Format;
594 } 590 }
595 591
596 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { 592 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) {
597 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL L; 593 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL L;
598 } 594 }
599 595
600 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory); 596 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory);
601 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_webp ); 597 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_webp );
602 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efact ory); 598 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efact ory);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698