| OLD | NEW |
| 1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Use of this source code is governed by a BSD-style license | 3 // Use of this source code is governed by a BSD-style license |
| 4 // that can be found in the COPYING file in the root of the source | 4 // that can be found in the COPYING file in the root of the source |
| 5 // tree. An additional intellectual property rights grant can be found | 5 // tree. An additional intellectual property rights grant can be found |
| 6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
| 7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
| 8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 9 // | 9 // |
| 10 // main entry for the decoder | 10 // main entry for the decoder |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } else { | 227 } else { |
| 228 const int length = use_prev ? prev_code_len : 0; | 228 const int length = use_prev ? prev_code_len : 0; |
| 229 while (repeat-- > 0) code_lengths[symbol++] = length; | 229 while (repeat-- > 0) code_lengths[symbol++] = length; |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 ok = 1; | 233 ok = 1; |
| 234 | 234 |
| 235 End: | 235 End: |
| 236 VP8LHuffmanTreeFree(&tree); | 236 VP8LHuffmanTreeFree(&tree); |
| 237 if (!ok) dec->status_ = VP8_STATUS_BITSTREAM_ERROR; |
| 237 return ok; | 238 return ok; |
| 238 } | 239 } |
| 239 | 240 |
| 240 // 'code_lengths' is pre-allocated temporary buffer, used for creating Huffman | 241 // 'code_lengths' is pre-allocated temporary buffer, used for creating Huffman |
| 241 // tree. | 242 // tree. |
| 242 static int ReadHuffmanCode(int alphabet_size, VP8LDecoder* const dec, | 243 static int ReadHuffmanCode(int alphabet_size, VP8LDecoder* const dec, |
| 243 int* const code_lengths, int* const huff_codes, | 244 int* const code_lengths, int* const huff_codes, |
| 244 HuffmanTree* const tree) { | 245 HuffmanTree* const tree) { |
| 245 int ok = 0; | 246 int ok = 0; |
| 246 VP8LBitReader* const br = &dec->br_; | 247 VP8LBitReader* const br = &dec->br_; |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 ExtractPalettedAlphaRows(dec, row); | 795 ExtractPalettedAlphaRows(dec, row); |
| 795 } | 796 } |
| 796 } | 797 } |
| 797 if (pos < last && (col & mask)) { | 798 if (pos < last && (col & mask)) { |
| 798 htree_group = GetHtreeGroupForPos(hdr, col, row); | 799 htree_group = GetHtreeGroupForPos(hdr, col, row); |
| 799 } | 800 } |
| 800 } else { // Not reached | 801 } else { // Not reached |
| 801 ok = 0; | 802 ok = 0; |
| 802 goto End; | 803 goto End; |
| 803 } | 804 } |
| 805 assert(br->eos_ == VP8LIsEndOfStream(br)); |
| 804 ok = !br->error_; | 806 ok = !br->error_; |
| 805 if (!ok) goto End; | 807 if (!ok) goto End; |
| 806 } | 808 } |
| 807 // Process the remaining rows corresponding to last row-block. | 809 // Process the remaining rows corresponding to last row-block. |
| 808 ExtractPalettedAlphaRows(dec, row); | 810 ExtractPalettedAlphaRows(dec, row); |
| 809 | 811 |
| 810 End: | 812 End: |
| 811 if (br->error_ || !ok || (br->eos_ && pos < end)) { | 813 if (br->error_ || !ok || (br->eos_ && pos < end)) { |
| 812 ok = 0; | 814 ok = 0; |
| 813 dec->status_ = br->eos_ ? VP8_STATUS_SUSPENDED | 815 dec->status_ = br->eos_ ? VP8_STATUS_SUSPENDED |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 assert(color_cache != NULL); | 913 assert(color_cache != NULL); |
| 912 while (last_cached < src) { | 914 while (last_cached < src) { |
| 913 VP8LColorCacheInsert(color_cache, *last_cached++); | 915 VP8LColorCacheInsert(color_cache, *last_cached++); |
| 914 } | 916 } |
| 915 *src = VP8LColorCacheLookup(color_cache, key); | 917 *src = VP8LColorCacheLookup(color_cache, key); |
| 916 goto AdvanceByOne; | 918 goto AdvanceByOne; |
| 917 } else { // Not reached | 919 } else { // Not reached |
| 918 ok = 0; | 920 ok = 0; |
| 919 goto End; | 921 goto End; |
| 920 } | 922 } |
| 923 assert(br->eos_ == VP8LIsEndOfStream(br)); |
| 921 ok = !br->error_; | 924 ok = !br->error_; |
| 922 if (!ok) goto End; | 925 if (!ok) goto End; |
| 923 } | 926 } |
| 924 // Process the remaining rows corresponding to last row-block. | 927 // Process the remaining rows corresponding to last row-block. |
| 925 if (process_func != NULL) process_func(dec, row); | 928 if (process_func != NULL) process_func(dec, row); |
| 926 | 929 |
| 927 End: | 930 End: |
| 928 if (br->error_ || !ok || (br->eos_ && src < src_end)) { | 931 if (br->error_ || !ok || (br->eos_ && src < src_end)) { |
| 929 ok = 0; | 932 ok = 0; |
| 930 dec->status_ = br->eos_ ? VP8_STATUS_SUSPENDED | 933 dec->status_ = br->eos_ ? VP8_STATUS_SUSPENDED |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1347 return 0; | 1350 return 0; |
| 1348 } | 1351 } |
| 1349 | 1352 |
| 1350 int VP8LDecodeImage(VP8LDecoder* const dec) { | 1353 int VP8LDecodeImage(VP8LDecoder* const dec) { |
| 1351 VP8Io* io = NULL; | 1354 VP8Io* io = NULL; |
| 1352 WebPDecParams* params = NULL; | 1355 WebPDecParams* params = NULL; |
| 1353 | 1356 |
| 1354 // Sanity checks. | 1357 // Sanity checks. |
| 1355 if (dec == NULL) return 0; | 1358 if (dec == NULL) return 0; |
| 1356 | 1359 |
| 1360 dec->status_ = VP8_STATUS_BITSTREAM_ERROR; |
| 1361 assert(dec->hdr_.htree_groups_ != NULL); |
| 1362 assert(dec->hdr_.num_htree_groups_ > 0); |
| 1363 |
| 1357 io = dec->io_; | 1364 io = dec->io_; |
| 1358 assert(io != NULL); | 1365 assert(io != NULL); |
| 1359 params = (WebPDecParams*)io->opaque; | 1366 params = (WebPDecParams*)io->opaque; |
| 1360 assert(params != NULL); | 1367 assert(params != NULL); |
| 1361 dec->output_ = params->output; | 1368 dec->output_ = params->output; |
| 1362 assert(dec->output_ != NULL); | 1369 assert(dec->output_ != NULL); |
| 1363 | 1370 |
| 1364 // Initialization. | 1371 // Initialization. |
| 1365 if (!WebPIoInitFromOptions(params->options, io, MODE_BGRA)) { | 1372 if (!WebPIoInitFromOptions(params->options, io, MODE_BGRA)) { |
| 1366 dec->status_ = VP8_STATUS_INVALID_PARAM; | 1373 dec->status_ = VP8_STATUS_INVALID_PARAM; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1388 VP8LClear(dec); | 1395 VP8LClear(dec); |
| 1389 return 1; | 1396 return 1; |
| 1390 | 1397 |
| 1391 Err: | 1398 Err: |
| 1392 VP8LClear(dec); | 1399 VP8LClear(dec); |
| 1393 assert(dec->status_ != VP8_STATUS_OK); | 1400 assert(dec->status_ != VP8_STATUS_OK); |
| 1394 return 0; | 1401 return 0; |
| 1395 } | 1402 } |
| 1396 | 1403 |
| 1397 //------------------------------------------------------------------------------ | 1404 //------------------------------------------------------------------------------ |
| OLD | NEW |