| OLD | NEW |
| 1 /* | 1 /* |
| 2 * jdhuff.c | 2 * jdhuff.c |
| 3 * | 3 * |
| 4 * This file was part of the Independent JPEG Group's software: | 4 * This file was part of the Independent JPEG Group's software: |
| 5 * Copyright (C) 1991-1997, Thomas G. Lane. | 5 * Copyright (C) 1991-1997, Thomas G. Lane. |
| 6 * libjpeg-turbo Modifications: | 6 * libjpeg-turbo Modifications: |
| 7 * Copyright (C) 2009-2011, D. R. Commander. | 7 * Copyright (C) 2009-2011, 2015, D. R. Commander. |
| 8 * For conditions of distribution and use, see the accompanying README file. | 8 * For conditions of distribution and use, see the accompanying README file. |
| 9 * | 9 * |
| 10 * This file contains Huffman entropy decoding routines. | 10 * This file contains Huffman entropy decoding routines. |
| 11 * | 11 * |
| 12 * Much of the complexity here has to do with supporting input suspension. | 12 * Much of the complexity here has to do with supporting input suspension. |
| 13 * If the data source module demands suspension, we want to be able to back | 13 * If the data source module demands suspension, we want to be able to back |
| 14 * up to the start of the current MCU. To do this, we copy state variables | 14 * up to the start of the current MCU. To do this, we copy state variables |
| 15 * into local working storage, and update them back to the permanent | 15 * into local working storage, and update them back to the permanent |
| 16 * storage only upon successful completion of an MCU. | 16 * storage only upon successful completion of an MCU. |
| 17 */ | 17 */ |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 BITREAD_STATE_VARS; | 554 BITREAD_STATE_VARS; |
| 555 int blkn; | 555 int blkn; |
| 556 savable_state state; | 556 savable_state state; |
| 557 /* Outer loop handles each block in the MCU */ | 557 /* Outer loop handles each block in the MCU */ |
| 558 | 558 |
| 559 /* Load up working state */ | 559 /* Load up working state */ |
| 560 BITREAD_LOAD_STATE(cinfo,entropy->bitstate); | 560 BITREAD_LOAD_STATE(cinfo,entropy->bitstate); |
| 561 ASSIGN_STATE(state, entropy->saved); | 561 ASSIGN_STATE(state, entropy->saved); |
| 562 | 562 |
| 563 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { | 563 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { |
| 564 JBLOCKROW block = MCU_data[blkn]; | 564 JBLOCKROW block = MCU_data ? MCU_data[blkn] : NULL; |
| 565 d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn]; | 565 d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn]; |
| 566 d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn]; | 566 d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn]; |
| 567 register int s, k, r; | 567 register int s, k, r; |
| 568 | 568 |
| 569 /* Decode a single block's worth of coefficients */ | 569 /* Decode a single block's worth of coefficients */ |
| 570 | 570 |
| 571 /* Section F.2.2.1: decode the DC coefficient difference */ | 571 /* Section F.2.2.1: decode the DC coefficient difference */ |
| 572 HUFF_DECODE(s, br_state, dctbl, return FALSE, label1); | 572 HUFF_DECODE(s, br_state, dctbl, return FALSE, label1); |
| 573 if (s) { | 573 if (s) { |
| 574 CHECK_BIT_BUFFER(br_state, s, return FALSE); | 574 CHECK_BIT_BUFFER(br_state, s, return FALSE); |
| 575 r = GET_BITS(s); | 575 r = GET_BITS(s); |
| 576 s = HUFF_EXTEND(r, s); | 576 s = HUFF_EXTEND(r, s); |
| 577 } | 577 } |
| 578 | 578 |
| 579 if (entropy->dc_needed[blkn]) { | 579 if (entropy->dc_needed[blkn]) { |
| 580 /* Convert DC difference to actual value, update last_dc_val */ | 580 /* Convert DC difference to actual value, update last_dc_val */ |
| 581 int ci = cinfo->MCU_membership[blkn]; | 581 int ci = cinfo->MCU_membership[blkn]; |
| 582 s += state.last_dc_val[ci]; | 582 s += state.last_dc_val[ci]; |
| 583 state.last_dc_val[ci] = s; | 583 state.last_dc_val[ci] = s; |
| 584 /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */ | 584 if (block) { |
| 585 (*block)[0] = (JCOEF) s; | 585 /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */ |
| 586 (*block)[0] = (JCOEF) s; |
| 587 } |
| 586 } | 588 } |
| 587 | 589 |
| 588 if (entropy->ac_needed[blkn]) { | 590 if (entropy->ac_needed[blkn] && block) { |
| 589 | 591 |
| 590 /* Section F.2.2.2: decode the AC coefficients */ | 592 /* Section F.2.2.2: decode the AC coefficients */ |
| 591 /* Since zeroes are skipped, output area must be cleared beforehand */ | 593 /* Since zeroes are skipped, output area must be cleared beforehand */ |
| 592 for (k = 1; k < DCTSIZE2; k++) { | 594 for (k = 1; k < DCTSIZE2; k++) { |
| 593 HUFF_DECODE(s, br_state, actbl, return FALSE, label2); | 595 HUFF_DECODE(s, br_state, actbl, return FALSE, label2); |
| 594 | 596 |
| 595 r = s >> 4; | 597 r = s >> 4; |
| 596 s &= 15; | 598 s &= 15; |
| 597 | 599 |
| 598 if (s) { | 600 if (s) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 if (s) { | 669 if (s) { |
| 668 FILL_BIT_BUFFER_FAST | 670 FILL_BIT_BUFFER_FAST |
| 669 r = GET_BITS(s); | 671 r = GET_BITS(s); |
| 670 s = HUFF_EXTEND(r, s); | 672 s = HUFF_EXTEND(r, s); |
| 671 } | 673 } |
| 672 | 674 |
| 673 if (entropy->dc_needed[blkn]) { | 675 if (entropy->dc_needed[blkn]) { |
| 674 int ci = cinfo->MCU_membership[blkn]; | 676 int ci = cinfo->MCU_membership[blkn]; |
| 675 s += state.last_dc_val[ci]; | 677 s += state.last_dc_val[ci]; |
| 676 state.last_dc_val[ci] = s; | 678 state.last_dc_val[ci] = s; |
| 677 (*block)[0] = (JCOEF) s; | 679 if (block) |
| 680 (*block)[0] = (JCOEF) s; |
| 678 } | 681 } |
| 679 | 682 |
| 680 if (entropy->ac_needed[blkn]) { | 683 if (entropy->ac_needed[blkn] && block) { |
| 681 | 684 |
| 682 for (k = 1; k < DCTSIZE2; k++) { | 685 for (k = 1; k < DCTSIZE2; k++) { |
| 683 HUFF_DECODE_FAST(s, l, actbl, slow_decode_mcu); | 686 HUFF_DECODE_FAST(s, l, actbl, slow_decode_mcu); |
| 684 r = s >> 4; | 687 r = s >> 4; |
| 685 s &= 15; | 688 s &= 15; |
| 686 | 689 |
| 687 if (s) { | 690 if (s) { |
| 688 k += r; | 691 k += r; |
| 689 FILL_BIT_BUFFER_FAST | 692 FILL_BIT_BUFFER_FAST |
| 690 r = GET_BITS(s); | 693 r = GET_BITS(s); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 SIZEOF(huff_entropy_decoder)); | 804 SIZEOF(huff_entropy_decoder)); |
| 802 cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; | 805 cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; |
| 803 entropy->pub.start_pass = start_pass_huff_decoder; | 806 entropy->pub.start_pass = start_pass_huff_decoder; |
| 804 entropy->pub.decode_mcu = decode_mcu; | 807 entropy->pub.decode_mcu = decode_mcu; |
| 805 | 808 |
| 806 /* Mark tables unallocated */ | 809 /* Mark tables unallocated */ |
| 807 for (i = 0; i < NUM_HUFF_TBLS; i++) { | 810 for (i = 0; i < NUM_HUFF_TBLS; i++) { |
| 808 entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL; | 811 entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL; |
| 809 } | 812 } |
| 810 } | 813 } |
| OLD | NEW |