public override void start_pass(bool gather_statistics)
{
m_gather_statistics = gather_statistics;
if (gather_statistics)
finish_pass = finish_pass_gather;
else
finish_pass = finish_pass_huff;
if (m_cinfo.m_progressive_mode)
{
/* We assume the scan parameters are already validated. */
/* Select execution routine */
if (m_cinfo.m_Ah == 0)
{
if (m_cinfo.m_Ss == 0)
encode_mcu = encode_mcu_DC_first;
else
encode_mcu = encode_mcu_AC_first;
}
else
{
if (m_cinfo.m_Ss == 0)
encode_mcu = encode_mcu_DC_refine;
else
{
encode_mcu = encode_mcu_AC_refine;
/* AC refinement needs a correction bit buffer */
if (bit_buffer == null)
bit_buffer = new char[MAX_CORR_BITS];
}
}
/* Initialize AC stuff */
ac_tbl_no = m_cinfo.Component_info[m_cinfo.m_cur_comp_info[0]].Ac_tbl_no;
EOBRUN = 0;
BE = 0;
}
else
{
if (gather_statistics)
encode_mcu = encode_mcu_gather;
else
encode_mcu = encode_mcu_huff;
}
for (int ci = 0; ci < m_cinfo.m_comps_in_scan; ci++)
{
jpeg_component_info compptr = m_cinfo.Component_info[m_cinfo.m_cur_comp_info[ci]];
/* DC needs no table for refinement scan */
if (m_cinfo.m_Ss == 0 && m_cinfo.m_Ah == 0)
{
int tbl = compptr.Dc_tbl_no;
if (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_dc_count_ptrs[tbl] == null)
m_dc_count_ptrs[tbl] = new long[257];
else
Array.Clear(m_dc_count_ptrs[tbl], 0, m_dc_count_ptrs[tbl].Length);
}
else
{
/* Compute derived values for Huffman tables */
/* We may do this more than once for a table, but it's not expensive */
jpeg_make_c_derived_tbl(true, tbl, ref m_dc_derived_tbls[tbl]);
}
/* Initialize DC predictions to 0 */
m_saved.last_dc_val[ci] = 0;
}
/* AC needs no table when not present */
if (m_cinfo.m_Se != 0)
{
int tbl = compptr.Ac_tbl_no;
if (gather_statistics)
{
if (tbl < 0 || tbl >= JpegConstants.NUM_HUFF_TBLS)
m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_NO_HUFF_TABLE, tbl);
if (m_ac_count_ptrs[tbl] == null)
m_ac_count_ptrs[tbl] = new long[257];
else
Array.Clear(m_ac_count_ptrs[tbl], 0, m_ac_count_ptrs[tbl].Length);
}
else
{
jpeg_make_c_derived_tbl(false, tbl, ref m_ac_derived_tbls[tbl]);
}
}
}
/* Initialize bit buffer to empty */
m_saved.put_buffer = 0;
m_saved.put_bits = 0;
/* Initialize restart stuff */
m_restarts_to_go = m_cinfo.m_restart_interval;
m_next_restart_num = 0;
}