| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 // Parse headers of RIFF container, and check for valid Webp (VP8) content. | 53 // Parse headers of RIFF container, and check for valid Webp (VP8) content. |
| 54 static bool webp_parse_header(SkStream* stream, int* width, int* height, int* al
pha) { | 54 static bool webp_parse_header(SkStream* stream, int* width, int* height, int* al
pha) { |
| 55 unsigned char buffer[WEBP_VP8_HEADER_SIZE]; | 55 unsigned char buffer[WEBP_VP8_HEADER_SIZE]; |
| 56 size_t bytesToRead = WEBP_VP8_HEADER_SIZE; | 56 size_t bytesToRead = WEBP_VP8_HEADER_SIZE; |
| 57 size_t totalBytesRead = 0; | 57 size_t totalBytesRead = 0; |
| 58 do { | 58 do { |
| 59 unsigned char* dst = buffer + totalBytesRead; | 59 unsigned char* dst = buffer + totalBytesRead; |
| 60 const size_t bytesRead = stream->read(dst, bytesToRead); | 60 const size_t bytesRead = stream->read(dst, bytesToRead); |
| 61 if (0 == bytesRead) { | 61 if (0 == bytesRead) { |
| 62 // Could not read any bytes. Check to see if we are at the end (exit | 62 SkASSERT(stream->isAtEnd()); |
| 63 // condition), and continue reading if not. Important for streams | 63 break; |
| 64 // that do not have all the data ready. | |
| 65 continue; | |
| 66 } | 64 } |
| 67 bytesToRead -= bytesRead; | 65 bytesToRead -= bytesRead; |
| 68 totalBytesRead += bytesRead; | 66 totalBytesRead += bytesRead; |
| 69 SkASSERT(bytesToRead + totalBytesRead == WEBP_VP8_HEADER_SIZE); | 67 SkASSERT(bytesToRead + totalBytesRead == WEBP_VP8_HEADER_SIZE); |
| 70 } while (!stream->isAtEnd() && bytesToRead > 0); | 68 } while (!stream->isAtEnd() && bytesToRead > 0); |
| 71 | 69 |
| 72 WebPBitstreamFeatures features; | 70 WebPBitstreamFeatures features; |
| 73 VP8StatusCode status = WebPGetFeatures(buffer, totalBytesRead, &features); | 71 VP8StatusCode status = WebPGetFeatures(buffer, totalBytesRead, &features); |
| 74 if (VP8_STATUS_OK != status) { | 72 if (VP8_STATUS_OK != status) { |
| 75 return false; // Invalid WebP file. | 73 return false; // Invalid WebP file. |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 return SkImageDecoder::kUnknown_Format; | 668 return SkImageDecoder::kUnknown_Format; |
| 671 } | 669 } |
| 672 | 670 |
| 673 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { | 671 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { |
| 674 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; | 672 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; |
| 675 } | 673 } |
| 676 | 674 |
| 677 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory); | 675 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory); |
| 678 static SkImageDecoder_FormatReg gFormatReg(get_format_webp); | 676 static SkImageDecoder_FormatReg gFormatReg(get_format_webp); |
| 679 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory); | 677 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory); |
| OLD | NEW |