start_pass_huff_decoder (j_decompress_ptr cinfo) { huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; int ci, blkn, dctbl, actbl; d_derived_tbl **pdtbl; jpeg_component_info * compptr; /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG. * This ought to be an error condition, but we make it a warning because * there are some baseline files out there with all zeroes in these bytes. */ if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 || cinfo->Ah != 0 || cinfo->Al != 0) WARNMS(cinfo, JWRN_NOT_SEQUENTIAL); for (ci = 0; ci < cinfo->comps_in_scan; ci++) { compptr = cinfo->cur_comp_info[ci]; dctbl = compptr->dc_tbl_no; actbl = compptr->ac_tbl_no; /* Compute derived values for Huffman tables */ /* We may do this more than once for a table, but it's not expensive */ pdtbl = entropy->dc_derived_tbls + dctbl; jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl, pdtbl); pdtbl = entropy->ac_derived_tbls + actbl; jpeg_make_d_derived_tbl(cinfo, FALSE, actbl, pdtbl); /* Initialize DC predictions to 0 */ entropy->saved.last_dc_val[ci] = 0; } /* Precalculate decoding info for each block in an MCU of this scan */ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { ci = cinfo->MCU_membership[blkn]; compptr = cinfo->cur_comp_info[ci]; /* Precalculate which table to use for each block */ entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no]; entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no]; /* Decide whether we really care about the coefficient values */ if (compptr->component_needed) { entropy->dc_needed[blkn] = TRUE; /* we don't need the ACs if producing a 1/8th-size image */ entropy->ac_needed[blkn] = (compptr->_DCT_scaled_size > 1); } else { entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE; } } /* Initialize bitread state variables */ entropy->bitstate.bits_left = 0; entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ entropy->pub.insufficient_data = FALSE; /* Initialize restart counter */ entropy->restarts_to_go = cinfo->restart_interval; }
METHODDEF void start_pass_huff_decoder(j_decompress_ptr cinfo) { huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; int ci, dctbl, actbl; jpeg_component_info *compptr; /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG. * This ought to be an error condition, but we make it a warning because * there are some baseline files out there with all zeroes in these bytes. */ if(cinfo->Ss != 0 || cinfo->Se != DCTSIZE2 - 1 || cinfo->Ah != 0 || cinfo->Al != 0) { WARNMS(cinfo, JWRN_NOT_SEQUENTIAL); } for(ci = 0; ci < cinfo->comps_in_scan; ci++) { compptr = cinfo->cur_comp_info[ci]; dctbl = compptr->dc_tbl_no; actbl = compptr->ac_tbl_no; /* Make sure requested tables are present */ if(dctbl < 0 || dctbl >= NUM_HUFF_TBLS || cinfo->dc_huff_tbl_ptrs[dctbl] == NULL) { ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl); } if(actbl < 0 || actbl >= NUM_HUFF_TBLS || cinfo->ac_huff_tbl_ptrs[actbl] == NULL) { ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl); } /* Compute derived values for Huffman tables */ /* We may do this more than once for a table, but it's not expensive */ jpeg_make_d_derived_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[dctbl], &entropy->dc_derived_tbls[dctbl]); jpeg_make_d_derived_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[actbl], &entropy->ac_derived_tbls[actbl]); /* Initialize DC predictions to 0 */ entropy->saved.last_dc_val[ci] = 0; } /* Initialize bitread state variables */ entropy->bitstate.bits_left = 0; entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ entropy->bitstate.printed_eod = FALSE; /* Initialize restart counter */ entropy->restarts_to_go = cinfo->restart_interval; }
start_pass_huff_decoder (j_decompress_ptr cinfo) { huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; __boundcheck_metadata_store((void *)(&entropy),(void *)((size_t)(&entropy)+sizeof(entropy)*8-1)); int ci; __boundcheck_metadata_store((void *)(&ci),(void *)((size_t)(&ci)+sizeof(ci)*8-1)); int dctbl; __boundcheck_metadata_store((void *)(&dctbl),(void *)((size_t)(&dctbl)+sizeof(dctbl)*8-1)); int 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)); /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG. * This ought to be an error condition, but we make it a warning because * there are some baseline files out there with all zeroes in these bytes. */ if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 || cinfo->Ah != 0 || cinfo->Al != 0) WARNMS(cinfo, JWRN_NOT_SEQUENTIAL); for (ci = 0; ci < cinfo->comps_in_scan; ci++) { compptr = cinfo->cur_comp_info[_RV_insert_check(0,4,92,15,"start_pass_huff_decoder",ci)]; dctbl = compptr->dc_tbl_no; actbl = compptr->ac_tbl_no; /* Make sure requested tables are present */ if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS || cinfo->dc_huff_tbl_ptrs[_RV_insert_check(0,4,97,2,"start_pass_huff_decoder",dctbl)] == NULL) ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl); if (actbl < 0 || actbl >= NUM_HUFF_TBLS || cinfo->ac_huff_tbl_ptrs[_RV_insert_check(0,4,100,2,"start_pass_huff_decoder",actbl)] == NULL) ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl); /* Compute derived values for Huffman tables */ /* We may do this more than once for a table, but it's not expensive */ jpeg_make_d_derived_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[_RV_insert_check(0,4,104,36,"start_pass_huff_decoder",dctbl)], & entropy->dc_derived_tbls[_RV_insert_check(0,4,105,10,"start_pass_huff_decoder",dctbl)]); jpeg_make_d_derived_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[_RV_insert_check(0,4,106,36,"start_pass_huff_decoder",actbl)], & entropy->ac_derived_tbls[_RV_insert_check(0,4,107,10,"start_pass_huff_decoder",actbl)]); /* Initialize DC predictions to 0 */ entropy->saved.last_dc_val[_RV_insert_check(0,4,109,5,"start_pass_huff_decoder",ci)] = 0; } /* Initialize bitread state variables */ entropy->bitstate.bits_left = 0; entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ entropy->bitstate.printed_eod = FALSE; /* Initialize restart counter */ entropy->restarts_to_go = cinfo->restart_interval; }
start_pass_lhuff_decoder (j_decompress_ptr cinfo) { j_lossless_d_ptr losslsd = (j_lossless_d_ptr) cinfo->codec; lhuff_entropy_ptr entropy = (lhuff_entropy_ptr) losslsd->entropy_private; int ci, dctbl, sampn, ptrn, yoffset, xoffset; jpeg_component_info * compptr; for (ci = 0; ci < cinfo->comps_in_scan; ci++) { compptr = cinfo->cur_comp_info[ci]; dctbl = compptr->dc_tbl_no; /* Make sure requested tables are present */ if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS || cinfo->dc_huff_tbl_ptrs[dctbl] == NULL) ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl); /* Compute derived values for Huffman tables */ /* We may do this more than once for a table, but it's not expensive */ jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl, & entropy->derived_tbls[dctbl]); } /* Precalculate decoding info for each sample in an MCU of this scan */ for (sampn = 0, ptrn = 0; sampn < cinfo->data_units_in_MCU;) { compptr = cinfo->cur_comp_info[cinfo->MCU_membership[sampn]]; ci = compptr->component_index; for (yoffset = 0; yoffset < compptr->MCU_height; yoffset++, ptrn++) { /* Precalculate the setup info for each output pointer */ entropy->output_ptr_info[ptrn].ci = ci; entropy->output_ptr_info[ptrn].yoffset = yoffset; entropy->output_ptr_info[ptrn].MCU_width = compptr->MCU_width; for (xoffset = 0; xoffset < compptr->MCU_width; xoffset++, sampn++) { /* Precalculate the output pointer index for each sample */ entropy->output_ptr_index[sampn] = ptrn; /* Precalculate which table to use for each sample */ entropy->cur_tbls[sampn] = entropy->derived_tbls[compptr->dc_tbl_no]; } } } entropy->num_output_ptrs = ptrn; /* Initialize bitread state variables */ entropy->bitstate.bits_left = 0; entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ entropy->insufficient_data = FALSE; }
METHODDEF void start_pass_phuff_decoder(j_decompress_ptr cinfo) { phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; boolean is_DC_band, bad; int ci, coefi, tbl; int *coef_bit_ptr; jpeg_component_info *compptr; is_DC_band = (cinfo->Ss == 0); /* Validate scan parameters */ bad = FALSE; if(is_DC_band) { if(cinfo->Se != 0) bad = TRUE; } else { /* need not check Ss/Se < 0 since they came from unsigned bytes */ if(cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2) bad = TRUE; /* AC scans may have only one component */ if(cinfo->comps_in_scan != 1) bad = TRUE; } if(cinfo->Ah != 0) { /* Successive approximation refinement scan: must have Al = Ah-1. */ if(cinfo->Al != cinfo->Ah - 1) bad = TRUE; } if(cinfo->Al > 13) /* need not check for < 0 */ bad = TRUE; if(bad) ERREXIT4(cinfo, JERR_BAD_PROGRESSION, cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al); /* Update progression status, and verify that scan order is legal. * Note that inter-scan inconsistencies are treated as warnings * not fatal errors ... not clear if this is right way to behave. */ for(ci = 0; ci < cinfo->comps_in_scan; ci++) { int cindex = cinfo->cur_comp_info[ci]->component_index; coef_bit_ptr = &cinfo->coef_bits[cindex][0]; if(!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */ WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0); for(coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) { int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi]; if(cinfo->Ah != expected) WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi); coef_bit_ptr[coefi] = cinfo->Al; } } /* Select MCU decoding routine */ if(cinfo->Ah == 0) { if(is_DC_band) entropy->pub.decode_mcu = decode_mcu_DC_first; else entropy->pub.decode_mcu = decode_mcu_AC_first; } else { if(is_DC_band) entropy->pub.decode_mcu = decode_mcu_DC_refine; else entropy->pub.decode_mcu = decode_mcu_AC_refine; } for(ci = 0; ci < cinfo->comps_in_scan; ci++) { compptr = cinfo->cur_comp_info[ci]; /* Make sure requested tables are present, and compute derived tables. * We may build same derived table more than once, but it's not expensive. */ if(is_DC_band) { if(cinfo->Ah == 0) { /* DC refinement needs no table */ tbl = compptr->dc_tbl_no; if(tbl < 0 || tbl >= NUM_HUFF_TBLS || cinfo->dc_huff_tbl_ptrs[tbl] == NULL) ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl); jpeg_make_d_derived_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[tbl], &entropy->derived_tbls[tbl]); } } else { tbl = compptr->ac_tbl_no; if(tbl < 0 || tbl >= NUM_HUFF_TBLS || cinfo->ac_huff_tbl_ptrs[tbl] == NULL) ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl); jpeg_make_d_derived_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[tbl], &entropy->derived_tbls[tbl]); /* remember the single active table */ entropy->ac_derived_tbl = entropy->derived_tbls[tbl]; } /* Initialize DC predictions to 0 */ entropy->saved.last_dc_val[ci] = 0; } /* Initialize bitread state variables */ entropy->bitstate.bits_left = 0; entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ entropy->bitstate.printed_eod = FALSE; /* Initialize private state variables */ entropy->saved.EOBRUN = 0; /* Initialize restart counter */ entropy->restarts_to_go = cinfo->restart_interval; }
start_pass_phuff_decoder (j_decompress_ptr cinfo) { phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; boolean is_DC_band, bad; int ci, coefi, tbl; int *coef_bit_ptr; jpeg_component_info * compptr; is_DC_band = (cinfo->Ss == 0); /* Validate scan parameters */ bad = FALSE; if (is_DC_band) { if (cinfo->Se != 0) bad = TRUE; } else { /* need not check Ss/Se < 0 since they came from unsigned bytes */ if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2) bad = TRUE; /* AC scans may have only one component */ if (cinfo->comps_in_scan != 1) bad = TRUE; } if (cinfo->Ah != 0) { /* Successive approximation refinement scan: must have Al = Ah-1. */ if (cinfo->Al != cinfo->Ah-1) bad = TRUE; } if (cinfo->Al > 13) /* need not check for < 0 */ bad = TRUE; /* Arguably the maximum Al value should be less than 13 for 8-bit precision, * but the spec doesn't say so, and we try to be liberal about what we * accept. Note: large Al values could result in out-of-range DC * coefficients during early scans, leading to bizarre displays due to * overflows in the IDCT math. But we won't crash. */ if (bad) ERREXIT4(cinfo, JERR_BAD_PROGRESSION, cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al); /* Update progression status, and verify that scan order is legal. * Note that inter-scan inconsistencies are treated as warnings * not fatal errors ... not clear if this is right way to behave. */ for (ci = 0; ci < cinfo->comps_in_scan; ci++) { int cindex = cinfo->cur_comp_info[ci]->component_index; coef_bit_ptr = & cinfo->coef_bits[cindex][0]; if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */ WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0); for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) { int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi]; if (cinfo->Ah != expected) WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi); coef_bit_ptr[coefi] = cinfo->Al; } } /* Select MCU decoding routine */ if (cinfo->Ah == 0) { if (is_DC_band) entropy->pub.decode_mcu = decode_mcu_DC_first; else entropy->pub.decode_mcu = decode_mcu_AC_first; } else { if (is_DC_band) entropy->pub.decode_mcu = decode_mcu_DC_refine; else entropy->pub.decode_mcu = decode_mcu_AC_refine; } for (ci = 0; ci < cinfo->comps_in_scan; ci++) { compptr = cinfo->cur_comp_info[ci]; /* Make sure requested tables are present, and compute derived tables. * We may build same derived table more than once, but it's not expensive. */ if (is_DC_band) { if (cinfo->Ah == 0) { /* DC refinement needs no table */ tbl = compptr->dc_tbl_no; jpeg_make_d_derived_tbl(cinfo, TRUE, tbl, & entropy->derived_tbls[tbl]); } } else { tbl = compptr->ac_tbl_no; jpeg_make_d_derived_tbl(cinfo, FALSE, tbl, & entropy->derived_tbls[tbl]); /* remember the single active table */ entropy->ac_derived_tbl = entropy->derived_tbls[tbl]; } /* Initialize DC predictions to 0 */ entropy->saved.last_dc_val[ci] = 0; } /* Initialize bitread state variables */ entropy->bitstate.bits_left = 0; entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ entropy->pub.insufficient_data = FALSE; /* Initialize private state variables */ entropy->saved.EOBRUN = 0; /* Initialize restart counter */ entropy->restarts_to_go = cinfo->restart_interval; }