OLD | NEW |
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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 192 |
193 // Incremental WebP image decoding. Reads input buffer of 64K size iteratively | 193 // Incremental WebP image decoding. Reads input buffer of 64K size iteratively |
194 // and decodes this block to appropriate color-space as per config object. | 194 // and decodes this block to appropriate color-space as per config object. |
195 static bool webp_idecode(SkStream* stream, WebPDecoderConfig* config) { | 195 static bool webp_idecode(SkStream* stream, WebPDecoderConfig* config) { |
196 WebPIDecoder* idec = WebPIDecode(NULL, 0, config); | 196 WebPIDecoder* idec = WebPIDecode(NULL, 0, config); |
197 if (NULL == idec) { | 197 if (NULL == idec) { |
198 WebPFreeDecBuffer(&config->output); | 198 WebPFreeDecBuffer(&config->output); |
199 return false; | 199 return false; |
200 } | 200 } |
201 | 201 |
202 stream->rewind(); | 202 if (!stream->rewind()) { |
| 203 SkDebugf("Failed to rewind webp stream!"); |
| 204 return false; |
| 205 } |
203 const size_t readBufferSize = stream->hasLength() ? | 206 const size_t readBufferSize = stream->hasLength() ? |
204 SkTMin(stream->getLength(), WEBP_IDECODE_BUFFER_SZ) : WEBP_IDECODE_B
UFFER_SZ; | 207 SkTMin(stream->getLength(), WEBP_IDECODE_BUFFER_SZ) : WEBP_IDECODE_B
UFFER_SZ; |
205 SkAutoMalloc srcStorage(readBufferSize); | 208 SkAutoMalloc srcStorage(readBufferSize); |
206 unsigned char* input = (uint8_t*)srcStorage.get(); | 209 unsigned char* input = (uint8_t*)srcStorage.get(); |
207 if (NULL == input) { | 210 if (NULL == input) { |
208 WebPIDelete(idec); | 211 WebPIDelete(idec); |
209 WebPFreeDecBuffer(&config->output); | 212 WebPFreeDecBuffer(&config->output); |
210 return false; | 213 return false; |
211 } | 214 } |
212 | 215 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 return true; | 307 return true; |
305 } | 308 } |
306 | 309 |
307 bool SkWEBPImageDecoder::onBuildTileIndex(SkStream* stream, | 310 bool SkWEBPImageDecoder::onBuildTileIndex(SkStream* stream, |
308 int *width, int *height) { | 311 int *width, int *height) { |
309 int origWidth, origHeight, hasAlpha; | 312 int origWidth, origHeight, hasAlpha; |
310 if (!webp_parse_header(stream, &origWidth, &origHeight, &hasAlpha)) { | 313 if (!webp_parse_header(stream, &origWidth, &origHeight, &hasAlpha)) { |
311 return false; | 314 return false; |
312 } | 315 } |
313 | 316 |
314 stream->rewind(); | 317 if (!stream->rewind()) { |
| 318 SkDebugf("Failed to rewind webp stream!"); |
| 319 return false; |
| 320 } |
| 321 |
315 *width = origWidth; | 322 *width = origWidth; |
316 *height = origHeight; | 323 *height = origHeight; |
317 | 324 |
318 SkRefCnt_SafeAssign(this->fInputStream, stream); | 325 SkRefCnt_SafeAssign(this->fInputStream, stream); |
319 this->fOrigWidth = origWidth; | 326 this->fOrigWidth = origWidth; |
320 this->fOrigHeight = origHeight; | 327 this->fOrigHeight = origHeight; |
321 this->fHasAlpha = hasAlpha; | 328 this->fHasAlpha = hasAlpha; |
322 | 329 |
323 return true; | 330 return true; |
324 } | 331 } |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 return SkImageDecoder::kUnknown_Format; | 602 return SkImageDecoder::kUnknown_Format; |
596 } | 603 } |
597 | 604 |
598 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { | 605 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { |
599 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; | 606 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; |
600 } | 607 } |
601 | 608 |
602 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory); | 609 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory); |
603 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_webp
); | 610 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_webp
); |
604 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efact
ory); | 611 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efact
ory); |
OLD | NEW |