| OLD | NEW |
| 1 // Copyright 2010 Google Inc. All Rights Reserved. | 1 // Copyright 2010 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // This code is licensed under the same terms as WebM: | 3 // Use of this source code is governed by a BSD-style license |
| 4 // Software License Agreement: http://www.webmproject.org/license/software/ | 4 // that can be found in the COPYING file in the root of the source |
| 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ | 5 // tree. An additional intellectual property rights grant can be found |
| 6 // in the file PATENTS. All contributing project authors may |
| 7 // be found in the AUTHORS file in the root of the source tree. |
| 6 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 7 // | 9 // |
| 8 // Main decoding functions for WEBP images. | 10 // Main decoding functions for WEBP images. |
| 9 // | 11 // |
| 10 // Author: Skal (pascal.massimino@gmail.com) | 12 // Author: Skal (pascal.massimino@gmail.com) |
| 11 | 13 |
| 12 #include <stdlib.h> | 14 #include <stdlib.h> |
| 13 | 15 |
| 14 #include "./vp8i.h" | 16 #include "./vp8i.h" |
| 15 #include "./vp8li.h" | 17 #include "./vp8li.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 187 } |
| 186 // For odd-sized chunk-payload, there's one byte padding at the end. | 188 // For odd-sized chunk-payload, there's one byte padding at the end. |
| 187 disk_chunk_size = (CHUNK_HEADER_SIZE + chunk_size + 1) & ~1; | 189 disk_chunk_size = (CHUNK_HEADER_SIZE + chunk_size + 1) & ~1; |
| 188 total_size += disk_chunk_size; | 190 total_size += disk_chunk_size; |
| 189 | 191 |
| 190 // Check that total bytes skipped so far does not exceed riff_size. | 192 // Check that total bytes skipped so far does not exceed riff_size. |
| 191 if (riff_size > 0 && (total_size > riff_size)) { | 193 if (riff_size > 0 && (total_size > riff_size)) { |
| 192 return VP8_STATUS_BITSTREAM_ERROR; // Not a valid chunk size. | 194 return VP8_STATUS_BITSTREAM_ERROR; // Not a valid chunk size. |
| 193 } | 195 } |
| 194 | 196 |
| 197 // Start of a (possibly incomplete) VP8/VP8L chunk implies that we have |
| 198 // parsed all the optional chunks. |
| 199 // Note: This check must occur before the check 'buf_size < disk_chunk_size' |
| 200 // below to allow incomplete VP8/VP8L chunks. |
| 201 if (!memcmp(buf, "VP8 ", TAG_SIZE) || |
| 202 !memcmp(buf, "VP8L", TAG_SIZE)) { |
| 203 return VP8_STATUS_OK; |
| 204 } |
| 205 |
| 195 if (buf_size < disk_chunk_size) { // Insufficient data. | 206 if (buf_size < disk_chunk_size) { // Insufficient data. |
| 196 return VP8_STATUS_NOT_ENOUGH_DATA; | 207 return VP8_STATUS_NOT_ENOUGH_DATA; |
| 197 } | 208 } |
| 198 | 209 |
| 199 if (!memcmp(buf, "ALPH", TAG_SIZE)) { // A valid ALPH header. | 210 if (!memcmp(buf, "ALPH", TAG_SIZE)) { // A valid ALPH header. |
| 200 *alpha_data = buf + CHUNK_HEADER_SIZE; | 211 *alpha_data = buf + CHUNK_HEADER_SIZE; |
| 201 *alpha_size = chunk_size; | 212 *alpha_size = chunk_size; |
| 202 } else if (!memcmp(buf, "VP8 ", TAG_SIZE) || | |
| 203 !memcmp(buf, "VP8L", TAG_SIZE)) { // A valid VP8/VP8L header. | |
| 204 return VP8_STATUS_OK; // Found. | |
| 205 } | 213 } |
| 206 | 214 |
| 207 // We have a full and valid chunk; skip it. | 215 // We have a full and valid chunk; skip it. |
| 208 buf += disk_chunk_size; | 216 buf += disk_chunk_size; |
| 209 buf_size -= disk_chunk_size; | 217 buf_size -= disk_chunk_size; |
| 210 } | 218 } |
| 211 } | 219 } |
| 212 | 220 |
| 213 // Validates the VP8/VP8L Header ("VP8 nnnn" or "VP8L nnnn") and skips over it. | 221 // Validates the VP8/VP8L Header ("VP8 nnnn" or "VP8L nnnn") and skips over it. |
| 214 // Returns VP8_STATUS_BITSTREAM_ERROR for invalid (chunk larger than | 222 // Returns VP8_STATUS_BITSTREAM_ERROR for invalid (chunk larger than |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 io->fancy_upsampling = 0; | 782 io->fancy_upsampling = 0; |
| 775 } | 783 } |
| 776 return 1; | 784 return 1; |
| 777 } | 785 } |
| 778 | 786 |
| 779 //------------------------------------------------------------------------------ | 787 //------------------------------------------------------------------------------ |
| 780 | 788 |
| 781 #if defined(__cplusplus) || defined(c_plusplus) | 789 #if defined(__cplusplus) || defined(c_plusplus) |
| 782 } // extern "C" | 790 } // extern "C" |
| 783 #endif | 791 #endif |
| OLD | NEW |