// Initialize for a Huffman-compressed scan using progressive JPEG. public override void start_pass(bool gather_statistics) { m_gather_statistics = gather_statistics; /* We assume the scan parameters are already validated. */ /* Select execution routines */ bool is_DC_band = (m_cinfo.m_Ss == 0); if (m_cinfo.m_Ah == 0) { if (is_DC_band) { m_MCUEncoder = MCUEncoder.mcu_DC_first_encoder; } else { m_MCUEncoder = MCUEncoder.mcu_AC_first_encoder; } } else { if (is_DC_band) { m_MCUEncoder = MCUEncoder.mcu_DC_refine_encoder; } else { m_MCUEncoder = MCUEncoder.mcu_AC_refine_encoder; /* AC refinement needs a correction bit buffer */ if (m_bit_buffer == null) { m_bit_buffer = new char[MAX_CORR_BITS]; } } } /* Only DC coefficients may be interleaved, so m_cinfo.comps_in_scan = 1 * for AC coefficients. */ for (int ci = 0; ci < m_cinfo.m_comps_in_scan; ci++) { jpeg_component_info componentInfo = m_cinfo.Component_info[m_cinfo.m_cur_comp_info[ci]]; /* Initialize DC predictions to 0 */ m_last_dc_val[ci] = 0; /* Get table index */ int tbl; if (is_DC_band) { if (m_cinfo.m_Ah != 0) /* DC refinement needs no table */ { continue; } tbl = componentInfo.Dc_tbl_no; } else { m_ac_tbl_no = componentInfo.Ac_tbl_no; tbl = componentInfo.Ac_tbl_no; } if (m_gather_statistics) { /* Check for invalid table index */ /* (make_c_derived_tbl does this in the other path) */ if (tbl < 0 || tbl >= JpegConstants.NUM_HUFF_TBLS) { m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_NO_HUFF_TABLE, tbl); } /* Allocate and zero the statistics tables */ /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */ if (m_count_ptrs[tbl] == null) { m_count_ptrs[tbl] = new long[257]; } Array.Clear(m_count_ptrs[tbl], 0, 257); } else { /* Compute derived values for Huffman table */ /* We may do this more than once for a table, but it's not expensive */ jpeg_make_c_derived_tbl(is_DC_band, tbl, ref m_derived_tbls[tbl]); } } /* Initialize AC stuff */ m_EOBRUN = 0; m_BE = 0; /* Initialize bit buffer to empty */ m_put_buffer = 0; m_put_bits = 0; /* Initialize restart stuff */ m_restarts_to_go = m_cinfo.m_restart_interval; m_next_restart_num = 0; }
// Initialize for a Huffman-compressed scan using progressive JPEG. public override void start_pass(bool gather_statistics) { m_gather_statistics = gather_statistics; /* We assume the scan parameters are already validated. */ /* Select execution routines */ bool is_DC_band = (m_cinfo.m_Ss == 0); if (m_cinfo.m_Ah == 0) { if (is_DC_band) m_MCUEncoder = MCUEncoder.mcu_DC_first_encoder; else m_MCUEncoder = MCUEncoder.mcu_AC_first_encoder; } else { if (is_DC_band) { m_MCUEncoder = MCUEncoder.mcu_DC_refine_encoder; } else { m_MCUEncoder = MCUEncoder.mcu_AC_refine_encoder; /* AC refinement needs a correction bit buffer */ if (m_bit_buffer == null) m_bit_buffer = new char[MAX_CORR_BITS]; } } /* Only DC coefficients may be interleaved, so m_cinfo.comps_in_scan = 1 * for AC coefficients. */ for (int ci = 0; ci < m_cinfo.m_comps_in_scan; ci++) { jpeg_component_info componentInfo = m_cinfo.Component_info[m_cinfo.m_cur_comp_info[ci]]; /* Initialize DC predictions to 0 */ m_last_dc_val[ci] = 0; /* Get table index */ int tbl; if (is_DC_band) { if (m_cinfo.m_Ah != 0) /* DC refinement needs no table */ continue; tbl = componentInfo.Dc_tbl_no; } else { m_ac_tbl_no = componentInfo.Ac_tbl_no; tbl = componentInfo.Ac_tbl_no; } if (m_gather_statistics) { /* Check for invalid table index */ /* (make_c_derived_tbl does this in the other path) */ if (tbl < 0 || tbl >= JpegConstants.NUM_HUFF_TBLS) m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_NO_HUFF_TABLE, tbl); /* Allocate and zero the statistics tables */ /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */ if (m_count_ptrs[tbl] == null) m_count_ptrs[tbl] = new long[257]; Array.Clear(m_count_ptrs[tbl], 0, 257); } else { /* Compute derived values for Huffman table */ /* We may do this more than once for a table, but it's not expensive */ jpeg_make_c_derived_tbl(is_DC_band, tbl, ref m_derived_tbls[tbl]); } } /* Initialize AC stuff */ m_EOBRUN = 0; m_BE = 0; /* Initialize bit buffer to empty */ m_put_buffer = 0; m_put_bits = 0; /* Initialize restart stuff */ m_restarts_to_go = m_cinfo.m_restart_interval; m_next_restart_num = 0; }