/// <summary> /// Initialize for a Huffman-compressed scan. /// </summary> public override void start_pass() { /* Validate scan parameters */ bool bad = false; bool is_DC_band = (m_cinfo.m_Ss == 0); if (is_DC_band) { if (m_cinfo.m_Se != 0) bad = true; } else { /* need not check Ss/Se < 0 since they came from unsigned bytes */ if (m_cinfo.m_Ss > m_cinfo.m_Se || m_cinfo.m_Se >= JpegConstants.DCTSIZE2) bad = true; /* AC scans may have only one component */ if (m_cinfo.m_comps_in_scan != 1) bad = true; } if (m_cinfo.m_Ah != 0) { /* Successive approximation refinement scan: must have Al = Ah-1. */ if (m_cinfo.m_Al != m_cinfo.m_Ah - 1) bad = true; } if (m_cinfo.m_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) m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_BAD_PROGRESSION, m_cinfo.m_Ss, m_cinfo.m_Se, m_cinfo.m_Ah, m_cinfo.m_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 (int ci = 0; ci < m_cinfo.m_comps_in_scan; ci++) { int cindex = m_cinfo.Comp_info[m_cinfo.m_cur_comp_info[ci]].Component_index; if (!is_DC_band && m_cinfo.m_coef_bits[cindex][0] < 0) /* AC without prior DC scan */ m_cinfo.WARNMS(J_MESSAGE_CODE.JWRN_BOGUS_PROGRESSION, cindex, 0); for (int coefi = m_cinfo.m_Ss; coefi <= m_cinfo.m_Se; coefi++) { int expected = m_cinfo.m_coef_bits[cindex][coefi]; if (expected < 0) expected = 0; if (m_cinfo.m_Ah != expected) m_cinfo.WARNMS(J_MESSAGE_CODE.JWRN_BOGUS_PROGRESSION, cindex, coefi); m_cinfo.m_coef_bits[cindex][coefi] = m_cinfo.m_Al; } } /* Select MCU decoding routine */ if (m_cinfo.m_Ah == 0) { if (is_DC_band) m_decoder = MCUDecoder.mcu_DC_first_decoder; else m_decoder = MCUDecoder.mcu_AC_first_decoder; } else { if (is_DC_band) m_decoder = MCUDecoder.mcu_DC_refine_decoder; else m_decoder = MCUDecoder.mcu_AC_refine_decoder; } for (int ci = 0; ci < m_cinfo.m_comps_in_scan; ci++) { jpeg_component_info componentInfo = m_cinfo.Comp_info[m_cinfo.m_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 (m_cinfo.m_Ah == 0) { /* DC refinement needs no table */ jpeg_make_d_derived_tbl(true, componentInfo.Dc_tbl_no, ref m_derived_tbls[componentInfo.Dc_tbl_no]); } } else { jpeg_make_d_derived_tbl(false, componentInfo.Ac_tbl_no, ref m_derived_tbls[componentInfo.Ac_tbl_no]); /* remember the single active table */ m_ac_derived_tbl = m_derived_tbls[componentInfo.Ac_tbl_no]; } /* Initialize DC predictions to 0 */ m_saved.last_dc_val[ci] = 0; } /* Initialize bitread state variables */ m_bitstate.bits_left = 0; m_bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ m_insufficient_data = false; /* Initialize private state variables */ m_saved.EOBRUN = 0; /* Initialize restart counter */ m_restarts_to_go = m_cinfo.m_restart_interval; }
/// <summary> /// Initialize for a Huffman-compressed scan. /// </summary> public override void start_pass() { /* Validate scan parameters */ bool bad = false; bool is_DC_band = (m_cinfo.m_Ss == 0); if (is_DC_band) { if (m_cinfo.m_Se != 0) { bad = true; } } else { /* need not check Ss/Se < 0 since they came from unsigned bytes */ if (m_cinfo.m_Ss > m_cinfo.m_Se || m_cinfo.m_Se >= JpegConstants.DCTSIZE2) { bad = true; } /* AC scans may have only one component */ if (m_cinfo.m_comps_in_scan != 1) { bad = true; } } if (m_cinfo.m_Ah != 0) { /* Successive approximation refinement scan: must have Al = Ah-1. */ if (m_cinfo.m_Al != m_cinfo.m_Ah - 1) { bad = true; } } if (m_cinfo.m_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) { m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_BAD_PROGRESSION, m_cinfo.m_Ss, m_cinfo.m_Se, m_cinfo.m_Ah, m_cinfo.m_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 (int ci = 0; ci < m_cinfo.m_comps_in_scan; ci++) { int cindex = m_cinfo.Comp_info[m_cinfo.m_cur_comp_info[ci]].Component_index; if (!is_DC_band && m_cinfo.m_coef_bits[cindex][0] < 0) /* AC without prior DC scan */ { m_cinfo.WARNMS(J_MESSAGE_CODE.JWRN_BOGUS_PROGRESSION, cindex, 0); } for (int coefi = m_cinfo.m_Ss; coefi <= m_cinfo.m_Se; coefi++) { int expected = m_cinfo.m_coef_bits[cindex][coefi]; if (expected < 0) { expected = 0; } if (m_cinfo.m_Ah != expected) { m_cinfo.WARNMS(J_MESSAGE_CODE.JWRN_BOGUS_PROGRESSION, cindex, coefi); } m_cinfo.m_coef_bits[cindex][coefi] = m_cinfo.m_Al; } } /* Select MCU decoding routine */ if (m_cinfo.m_Ah == 0) { if (is_DC_band) { m_decoder = MCUDecoder.mcu_DC_first_decoder; } else { m_decoder = MCUDecoder.mcu_AC_first_decoder; } } else { if (is_DC_band) { m_decoder = MCUDecoder.mcu_DC_refine_decoder; } else { m_decoder = MCUDecoder.mcu_AC_refine_decoder; } } for (int ci = 0; ci < m_cinfo.m_comps_in_scan; ci++) { jpeg_component_info componentInfo = m_cinfo.Comp_info[m_cinfo.m_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 (m_cinfo.m_Ah == 0) { /* DC refinement needs no table */ jpeg_make_d_derived_tbl(true, componentInfo.Dc_tbl_no, ref m_derived_tbls[componentInfo.Dc_tbl_no]); } } else { jpeg_make_d_derived_tbl(false, componentInfo.Ac_tbl_no, ref m_derived_tbls[componentInfo.Ac_tbl_no]); /* remember the single active table */ m_ac_derived_tbl = m_derived_tbls[componentInfo.Ac_tbl_no]; } /* Initialize DC predictions to 0 */ m_saved.last_dc_val[ci] = 0; } /* Initialize bitread state variables */ m_bitstate.bits_left = 0; m_bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ m_insufficient_data = false; /* Initialize private state variables */ m_saved.EOBRUN = 0; /* Initialize restart counter */ m_restarts_to_go = m_cinfo.m_restart_interval; }