public virtual void start_pass(bool is_pre_scan)
{
/* Only F-S dithering or no dithering is supported. */
/* If user asks for ordered dither, give him F-S. */
if (m_cinfo.m_dither_mode != J_DITHER_MODE.JDITHER_NONE)
m_cinfo.m_dither_mode = J_DITHER_MODE.JDITHER_FS;
if (is_pre_scan)
{
/* Set up method pointers */
m_quantizer = QuantizerType.prescan_quantizer;
m_useFinishPass1 = true;
m_needs_zeroed = true; /* Always zero histogram */
}
else
{
/* Set up method pointers */
if (m_cinfo.m_dither_mode == J_DITHER_MODE.JDITHER_FS)
m_quantizer = QuantizerType.pass2_fs_dither_quantizer;
else
m_quantizer = QuantizerType.pass2_no_dither_quantizer;
m_useFinishPass1 = false;
/* Make sure color count is acceptable */
int i = m_cinfo.m_actual_number_of_colors;
if (i < 1)
m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_QUANT_FEW_COLORS, 1);
if (i > MAXNUMCOLORS)
m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
if (m_cinfo.m_dither_mode == J_DITHER_MODE.JDITHER_FS)
{
/* Allocate Floyd-Steinberg workspace if we didn't already. */
if (m_fserrors == null)
{
int arraysize = (m_cinfo.m_output_width + 2) * 3;
m_fserrors = new short[arraysize];
}
else
{
/* Initialize the propagated errors to zero. */
Array.Clear(m_fserrors, 0, m_fserrors.Length);
}
/* Make the error-limit table if we didn't already. */
if (m_error_limiter == null)
init_error_limit();
m_on_odd_row = false;
}
}
/* Zero the histogram or inverse color map, if necessary */
if (m_needs_zeroed)
{
for (int i = 0; i < HIST_C0_ELEMS; i++)
Array.Clear(m_histogram[i], 0, m_histogram[i].Length);
m_needs_zeroed = false;
}
}