decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) { j_lossy_d_ptr lossyd = (j_lossy_d_ptr) cinfo->codec; phuff_entropy_ptr entropy = (phuff_entropy_ptr) lossyd->entropy_private; int Al = cinfo->Al; register int s, r; int blkn, ci; JBLOCKROW block; BITREAD_STATE_VARS; savable_state state; d_derived_tbl * tbl; jpeg_component_info * compptr; /* Process restart marker if needed; may have to suspend */ if (cinfo->restart_interval) { if (entropy->restarts_to_go == 0) if (! process_restart(cinfo)) return FALSE; } /* If we've run out of data, just leave the MCU set to zeroes. * This way, we return uniform gray for the remainder of the segment. */ if (! entropy->insufficient_data) { /* Load up working state */ BITREAD_LOAD_STATE(cinfo,entropy->bitstate); ASSIGN_STATE(state, entropy->saved); /* Outer loop handles each block in the MCU */ for (blkn = 0; blkn < cinfo->data_units_in_MCU; blkn++) { block = MCU_data[blkn]; ci = cinfo->MCU_membership[blkn]; compptr = cinfo->cur_comp_info[ci]; tbl = entropy->derived_tbls[compptr->dc_tbl_no]; /* Decode a single block's worth of coefficients */ /* Section F.2.2.1: decode the DC coefficient difference */ HUFF_DECODE(s, br_state, tbl, return FALSE, label1); if (s) { CHECK_BIT_BUFFER(br_state, s, return FALSE); r = GET_BITS(s); s = HUFF_EXTEND(r, s); } /* Convert DC difference to actual value, update last_dc_val */ s += state.last_dc_val[ci]; state.last_dc_val[ci] = s; /* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */ (*block)[0] = (JCOEF) (s << Al); } /* Completed MCU, so update state */ BITREAD_SAVE_STATE(cinfo,entropy->bitstate); ASSIGN_STATE(entropy->saved, state); }
METHODDEF boolean decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) { huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; register int s, k, r; int blkn, ci; JBLOCKROW block; working_state state; D_DERIVED_TBL * dctbl; D_DERIVED_TBL * actbl; jpeg_component_info * compptr; /* Process restart marker if needed; may have to suspend */ if (cinfo->restart_interval) { if (entropy->restarts_to_go == 0) if (! process_restart(cinfo)) return FALSE; } /* Load up working state */ state.unread_marker = cinfo->unread_marker; state.next_input_byte = cinfo->src->next_input_byte; state.bytes_in_buffer = cinfo->src->bytes_in_buffer; ASSIGN_STATE(state.cur, entropy->saved); state.cinfo = cinfo; /* Outer loop handles each block in the MCU */ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { block = MCU_data[blkn]; ci = cinfo->MCU_membership[blkn]; compptr = cinfo->cur_comp_info[ci]; dctbl = entropy->dc_derived_tbls[compptr->dc_tbl_no]; actbl = entropy->ac_derived_tbls[compptr->ac_tbl_no]; /* Decode a single block's worth of coefficients */ /* Section F.2.2.1: decode the DC coefficient difference */ huff_DECODE(s, state, dctbl, label1); if (s) { check_bit_buffer(state, s, return FALSE); r = get_bits(state, s); s = huff_EXTEND(r, s); } /* Shortcut if component's values are not interesting */ if (! compptr->component_needed) goto skip_ACs; /* Convert DC difference to actual value, update last_dc_val */ s += state.cur.last_dc_val[ci]; state.cur.last_dc_val[ci] = s; /* Output the DC coefficient (assumes ZAG[0] = 0) */ (*block)[0] = (JCOEF) s; /* Do we need to decode the AC coefficients for this component? */ if (compptr->DCT_scaled_size > 1) { /* Section F.2.2.2: decode the AC coefficients */ /* Since zeroes are skipped, output area must be cleared beforehand */ for (k = 1; k < DCTSIZE2; k++) { huff_DECODE(s, state, actbl, label2); r = s >> 4; s &= 15; if (s) { k += r; check_bit_buffer(state, s, return FALSE); r = get_bits(state, s); s = huff_EXTEND(r, s); /* Output coefficient in natural (dezigzagged) order */ (*block)[ZAG[k]] = (JCOEF) s; } else { if (r != 15) break; k += 15; } } } else {
decode_mcu_slow (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) { huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; BITREAD_STATE_VARS; int blkn; savable_state state; /* Outer loop handles each block in the MCU */ /* Load up working state */ BITREAD_LOAD_STATE(cinfo,entropy->bitstate); ASSIGN_STATE(state, entropy->saved); for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { JBLOCKROW block = MCU_data ? MCU_data[blkn] : NULL; d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn]; d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn]; register int s, k, r; /* Decode a single block's worth of coefficients */ /* Section F.2.2.1: decode the DC coefficient difference */ HUFF_DECODE(s, br_state, dctbl, return FALSE, label1); if (s) { CHECK_BIT_BUFFER(br_state, s, return FALSE); r = GET_BITS(s); s = HUFF_EXTEND(r, s); } if (entropy->dc_needed[blkn]) { /* Convert DC difference to actual value, update last_dc_val */ int ci = cinfo->MCU_membership[blkn]; s += state.last_dc_val[ci]; state.last_dc_val[ci] = s; if (block) { /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */ (*block)[0] = (JCOEF) s; } } if (entropy->ac_needed[blkn] && block) { /* Section F.2.2.2: decode the AC coefficients */ /* Since zeroes are skipped, output area must be cleared beforehand */ for (k = 1; k < DCTSIZE2; k++) { HUFF_DECODE(s, br_state, actbl, return FALSE, label2); r = s >> 4; s &= 15; if (s) { k += r; CHECK_BIT_BUFFER(br_state, s, return FALSE); r = GET_BITS(s); s = HUFF_EXTEND(r, s); /* Output coefficient in natural (dezigzagged) order. * Note: the extra entries in jpeg_natural_order[] will save us * if k >= DCTSIZE2, which could happen if the data is corrupted. */ (*block)[jpeg_natural_order[k]] = (JCOEF) s; } else { if (r != 15) break; k += 15; } } } else { /* Section F.2.2.2: decode the AC coefficients */ /* In this path we just discard the values */ for (k = 1; k < DCTSIZE2; k++) {
decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) { huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; register int s, k, r; int blkn, ci; JBLOCKROW block; BITREAD_STATE_VARS; savable_state state; d_derived_tbl * dctbl; d_derived_tbl * actbl; jpeg_component_info * compptr; /* Process restart marker if needed; may have to suspend */ if (cinfo->restart_interval) { if (entropy->restarts_to_go == 0) if (! process_restart(cinfo)) return FALSE; } /* Load up working state */ BITREAD_LOAD_STATE(cinfo,entropy->bitstate); ASSIGN_STATE(state, entropy->saved); /* Outer loop handles each block in the MCU */ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { block = MCU_data[blkn]; ci = cinfo->MCU_membership[blkn]; compptr = cinfo->cur_comp_info[ci]; dctbl = entropy->dc_derived_tbls[compptr->dc_tbl_no]; actbl = entropy->ac_derived_tbls[compptr->ac_tbl_no]; /* Decode a single block's worth of coefficients */ /* Section F.2.2.1: decode the DC coefficient difference */ HUFF_DECODE(s, br_state, dctbl, return FALSE, label1); if (s) { CHECK_BIT_BUFFER(br_state, s, return FALSE); r = GET_BITS(s); s = HUFF_EXTEND(r, s); } /* Shortcut if component's values are not interesting */ if (! compptr->component_needed) goto skip_ACs; /* Convert DC difference to actual value, update last_dc_val */ s += state.last_dc_val[ci]; state.last_dc_val[ci] = s; /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */ (*block)[0] = (JCOEF) s; /* Do we need to decode the AC coefficients for this component? */ if (compptr->DCT_scaled_size > 1) { /* Section F.2.2.2: decode the AC coefficients */ /* Since zeroes are skipped, output area must be cleared beforehand */ for (k = 1; k < DCTSIZE2; k++) { HUFF_DECODE(s, br_state, actbl, return FALSE, label2); r = s >> 4; s &= 15; if (s) { k += r; CHECK_BIT_BUFFER(br_state, s, return FALSE); r = GET_BITS(s); s = HUFF_EXTEND(r, s); /* Output coefficient in natural (dezigzagged) order. * Note: the extra entries in jpeg_natural_order[] will save us * if k >= DCTSIZE2, which could happen if the data is corrupted. */ (*block)[jpeg_natural_order[k]] = (JCOEF) s; } else { if (r != 15) break; k += 15; } } } else {
decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) { j_lossy_d_ptr lossyd = (j_lossy_d_ptr) cinfo->codec; shuff_entropy_ptr entropy = (shuff_entropy_ptr) lossyd->entropy_private; int blkn; BITREAD_STATE_VARS; savable_state state; /* Process restart marker if needed; may have to suspend */ if (cinfo->restart_interval) { if (entropy->restarts_to_go == 0) if (! process_restart(cinfo)) return FALSE; } /* If we've run out of data, just leave the MCU set to zeroes. * This way, we return uniform gray for the remainder of the segment. */ if (! entropy->insufficient_data) { /* Load up working state */ BITREAD_LOAD_STATE(cinfo,entropy->bitstate); ASSIGN_STATE(state, entropy->saved); /* Outer loop handles each block in the MCU */ for (blkn = 0; blkn < cinfo->data_units_in_MCU; blkn++) { JBLOCKROW block = MCU_data[blkn]; d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn]; d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn]; register int s, k, r; /* Decode a single block's worth of coefficients */ /* Section F.2.2.1: decode the DC coefficient difference */ HUFF_DECODE(s, br_state, dctbl, return FALSE, label1); if (s) { CHECK_BIT_BUFFER(br_state, s, return FALSE); r = GET_BITS(s); s = HUFF_EXTEND(r, s); } if (entropy->dc_needed[blkn]) { /* Convert DC difference to actual value, update last_dc_val */ int ci = cinfo->MCU_membership[blkn]; s += state.last_dc_val[ci]; state.last_dc_val[ci] = s; /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */ (*block)[0] = (JCOEF) s; } if (entropy->ac_needed[blkn]) { /* Section F.2.2.2: decode the AC coefficients */ /* Since zeroes are skipped, output area must be cleared beforehand */ for (k = 1; k < DCTSIZE2; k++) { HUFF_DECODE(s, br_state, actbl, return FALSE, label2); r = s >> 4; s &= 15; if (s) { k += r; CHECK_BIT_BUFFER(br_state, s, return FALSE); r = GET_BITS(s); s = HUFF_EXTEND(r, s); /* Output coefficient in natural (dezigzagged) order. * Note: the extra entries in jpeg_natural_order[] will save us * if k >= DCTSIZE2, which could happen if the data is corrupted. */ (*block)[jpeg_natural_order[k]] = (JCOEF) s; } else { if (r != 15) break; k += 15; } } } else { /* Section F.2.2.2: decode the AC coefficients */ /* In this path we just discard the values */ for (k = 1; k < DCTSIZE2; k++) {
decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) { huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; __boundcheck_metadata_store((void *)(&entropy),(void *)((size_t)(&entropy)+sizeof(entropy)*8-1)); register int s, k, r; int blkn; __boundcheck_metadata_store((void *)(&blkn),(void *)((size_t)(&blkn)+sizeof(blkn)*8-1)); int ci; __boundcheck_metadata_store((void *)(&ci),(void *)((size_t)(&ci)+sizeof(ci)*8-1)); JBLOCKROW block; __boundcheck_metadata_store((void *)(&block),(void *)((size_t)(&block)+sizeof(block)*8-1)); BITREAD_STATE_VARS; __boundcheck_metadata_store((void *)(&br_state),(void *)((size_t)(&br_state)+sizeof(br_state)*8-1)); savable_state state; __boundcheck_metadata_store((void *)(&state),(void *)((size_t)(&state)+sizeof(state)*8-1)); d_derived_tbl * dctbl; __boundcheck_metadata_store((void *)(&dctbl),(void *)((size_t)(&dctbl)+sizeof(dctbl)*8-1)); d_derived_tbl * actbl; __boundcheck_metadata_store((void *)(&actbl),(void *)((size_t)(&actbl)+sizeof(actbl)*8-1)); jpeg_component_info * compptr; __boundcheck_metadata_store((void *)(&compptr),(void *)((size_t)(&compptr)+sizeof(compptr)*8-1)); /* Process restart marker if needed; may have to suspend */ if (cinfo->restart_interval) { if (entropy->restarts_to_go == 0) if (! process_restart(cinfo)) return FALSE; } /* Load up working state */ BITREAD_LOAD_STATE(cinfo,entropy->bitstate); ASSIGN_STATE(state, entropy->saved); /* Outer loop handles each block in the MCU */ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { block = (*(JBLOCKROW *)(__boundcheck_ptr_reference(463,13,"decode_mcu",(void *)(&MCU_data[0]),(void *)(&MCU_data[blkn])))); ci = cinfo->MCU_membership[_RV_insert_check(0,10,464,10,"decode_mcu",blkn)]; compptr = cinfo->cur_comp_info[_RV_insert_check(0,4,465,15,"decode_mcu",ci)]; dctbl = entropy->dc_derived_tbls[_RV_insert_check(0,4,466,13,"decode_mcu",compptr->dc_tbl_no)]; actbl = entropy->ac_derived_tbls[_RV_insert_check(0,4,467,13,"decode_mcu",compptr->ac_tbl_no)]; /* Decode a single block's worth of coefficients */ /* Section F.2.2.1: decode the DC coefficient difference */ HUFF_DECODE(s, br_state, dctbl, return FALSE, label1); if (s) { CHECK_BIT_BUFFER(br_state, s, return FALSE); r = GET_BITS(s); s = HUFF_EXTEND(r, s); } /* Shortcut if component's values are not interesting */ if (! compptr->component_needed) goto skip_ACs; /* Convert DC difference to actual value, update last_dc_val */ s += state.last_dc_val[_RV_insert_check(0,4,484,10,"decode_mcu",ci)]; state.last_dc_val[_RV_insert_check(0,4,485,5,"decode_mcu",ci)] = s; /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */ (*(JBLOCKROW)(__boundcheck_ptr_reference(487,7,"decode_mcu",(void *)(block),(void *)(block))))[0] = (JCOEF) s; /* Do we need to decode the AC coefficients for this component? */ if (compptr->DCT_scaled_size > 1) { /* Section F.2.2.2: decode the AC coefficients */ /* Since zeroes are skipped, output area must be cleared beforehand */ for (k = 1; k < DCTSIZE2; k++) { HUFF_DECODE(s, br_state, actbl, return FALSE, label2); r = s >> 4; s &= 15; if (s) { k += r; CHECK_BIT_BUFFER(br_state, s, return FALSE); r = GET_BITS(s); s = HUFF_EXTEND(r, s); /* Output coefficient in natural (dezigzagged) order. * Note: the extra entries in jpeg_natural_order[] will save us * if k >= DCTSIZE2, which could happen if the data is corrupted. */ (*(JBLOCKROW)(__boundcheck_ptr_reference(509,6,"decode_mcu",(void *)(block),(void *)(block))))[(*(const int *)(__boundcheck_ptr_reference(509,13,"decode_mcu",(void *)(&jpeg_natural_order[0]),(void *)(&jpeg_natural_order[k]))))] = (JCOEF) s; } else { if (r != 15) break; k += 15; } } } else {
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) { phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; __boundcheck_metadata_store((void *)(&entropy),(void *)((size_t)(&entropy)+sizeof(entropy)*8-1)); int Al = cinfo->Al; __boundcheck_metadata_store((void *)(&Al),(void *)((size_t)(&Al)+sizeof(Al)*8-1)); register int s, r; int blkn; __boundcheck_metadata_store((void *)(&blkn),(void *)((size_t)(&blkn)+sizeof(blkn)*8-1)); int ci; __boundcheck_metadata_store((void *)(&ci),(void *)((size_t)(&ci)+sizeof(ci)*8-1)); JBLOCKROW block; __boundcheck_metadata_store((void *)(&block),(void *)((size_t)(&block)+sizeof(block)*8-1)); BITREAD_STATE_VARS; __boundcheck_metadata_store((void *)(&br_state),(void *)((size_t)(&br_state)+sizeof(br_state)*8-1)); savable_state state; __boundcheck_metadata_store((void *)(&state),(void *)((size_t)(&state)+sizeof(state)*8-1)); d_derived_tbl * tbl; __boundcheck_metadata_store((void *)(&tbl),(void *)((size_t)(&tbl)+sizeof(tbl)*8-1)); jpeg_component_info * compptr; __boundcheck_metadata_store((void *)(&compptr),(void *)((size_t)(&compptr)+sizeof(compptr)*8-1)); /* Process restart marker if needed; may have to suspend */ if (cinfo->restart_interval) { if (entropy->restarts_to_go == 0) if (! process_restart(cinfo)) return FALSE; } /* Load up working state */ BITREAD_LOAD_STATE(cinfo,entropy->bitstate); ASSIGN_STATE(state, entropy->saved); /* Outer loop handles each block in the MCU */ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { block = (*(JBLOCKROW *)(__boundcheck_ptr_reference(307,13,"decode_mcu_DC_first",(void *)(&MCU_data[0]),(void *)(&MCU_data[blkn])))); ci = cinfo->MCU_membership[_RV_insert_check(0,10,308,10,"decode_mcu_DC_first",blkn)]; compptr = cinfo->cur_comp_info[_RV_insert_check(0,4,309,15,"decode_mcu_DC_first",ci)]; tbl = entropy->derived_tbls[_RV_insert_check(0,4,310,11,"decode_mcu_DC_first",compptr->dc_tbl_no)]; /* Decode a single block's worth of coefficients */ /* Section F.2.2.1: decode the DC coefficient difference */ HUFF_DECODE(s, br_state, tbl, return FALSE, label1); if (s) { CHECK_BIT_BUFFER(br_state, s, return FALSE); r = GET_BITS(s); s = HUFF_EXTEND(r, s); } /* Convert DC difference to actual value, update last_dc_val */ s += state.last_dc_val[_RV_insert_check(0,4,323,10,"decode_mcu_DC_first",ci)]; state.last_dc_val[_RV_insert_check(0,4,324,5,"decode_mcu_DC_first",ci)] = s; /* Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) */ (*(JBLOCKROW)(__boundcheck_ptr_reference(326,7,"decode_mcu_DC_first",(void *)(block),(void *)(block))))[0] = (JCOEF) (s << Al); } /* Completed MCU, so update state */ BITREAD_SAVE_STATE(cinfo,entropy->bitstate); ASSIGN_STATE(entropy->saved, state); /* Account for restart interval (no-op if not using restarts) */ entropy->restarts_to_go--; return TRUE; }
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) { phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; int Al = cinfo->Al; int blkn; BITREAD_STATE_VARS; savable_state state; /* Process restart marker if needed; may have to suspend */ if (cinfo->restart_interval) { if (entropy->restarts_to_go == 0) if (! process_restart(cinfo)) return FALSE; } /* If we've run out of data, just leave the MCU set to zeroes. * This way, we return uniform gray for the remainder of the segment. */ if (! entropy->pub.insufficient_data) { /* Load up working state */ BITREAD_LOAD_STATE(cinfo,entropy->bitstate); ASSIGN_STATE(state, entropy->saved); /* Outer loop handles each block in the MCU */ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { JBLOCKROW block = MCU_data[blkn]; int ci = cinfo->MCU_membership[blkn]; d_derived_tbl * tbl = entropy->dc_derived_tbls[ci]; register int s; /* Decode a single block's worth of coefficients */ /* Section F.2.2.1: decode the DC coefficient difference */ { /* HUFFX_DECODE */ register int nb, look, t; if (bits_left < HUFFX_LOOKAHEAD) { register const JOCTET * next_input_byte = br_state.next_input_byte; register size_t bytes_in_buffer = br_state.bytes_in_buffer; if (cinfo->unread_marker == 0) { while (bits_left < MIN_GET_BITS) { register int c; if (bytes_in_buffer == 0 || (c = GETJOCTET(*next_input_byte)) == 0xFF) { goto label11; } bytes_in_buffer--; next_input_byte++; get_buffer = (get_buffer << 8) | c; bits_left += 8; } br_state.next_input_byte = next_input_byte; br_state.bytes_in_buffer = bytes_in_buffer; } else { label11: br_state.next_input_byte = next_input_byte; br_state.bytes_in_buffer = bytes_in_buffer; if (! jpeg_fill_bit_buffer(&br_state,get_buffer,bits_left, 0)) { return FALSE; } get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; if (bits_left < HUFFX_LOOKAHEAD) { nb = 1; goto label1; } } } look = PEEK_BITS(HUFFX_LOOKAHEAD); if ((nb = tbl->lookx_nbits[look]) != 0) { s = tbl->lookx_val[look]; if (nb <= HUFFX_LOOKAHEAD) { DROP_BITS(nb); } else { DROP_BITS(HUFFX_LOOKAHEAD); nb -= HUFFX_LOOKAHEAD; CHECK_BIT_BUFFER(br_state, nb, return FALSE); s += GET_BITS(nb); } } else { nb = HUFFX_LOOKAHEAD; label1: if ((s=jpeg_huff_decode(&br_state,get_buffer,bits_left,tbl,nb)) < 0) { return FALSE; } get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; if (s) { CHECK_BIT_BUFFER(br_state, s, return FALSE); t = GET_BITS(s); s = HUFF_EXTEND(t, s); } } }