private void pre_process_context(byte[][] input_buf, ref int in_row_ctr, int in_rows_avail, byte[][][] output_buf, ref int out_row_group_ctr, int out_row_groups_avail)
{
while (out_row_group_ctr < out_row_groups_avail)
{
if (in_row_ctr < in_rows_avail)
{
/* Do color conversion to fill the conversion buffer. */
int inrows = in_rows_avail - in_row_ctr;
int numrows = m_next_buf_stop - m_next_buf_row;
numrows = Math.Min(numrows, inrows);
m_cinfo.m_cconvert.color_convert(input_buf, in_row_ctr, m_color_buf, m_colorBufRowsOffset + m_next_buf_row, numrows);
/* Pad at top of image, if first time through */
if (m_rows_to_go == m_cinfo.m_image_height)
{
for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
{
for (int row = 1; row <= m_cinfo.m_max_v_samp_factor; row++)
JpegUtils.jcopy_sample_rows(m_color_buf[ci], m_colorBufRowsOffset, m_color_buf[ci], m_colorBufRowsOffset - row, 1, m_cinfo.m_image_width);
}
}
in_row_ctr += numrows;
m_next_buf_row += numrows;
m_rows_to_go -= numrows;
}
else
{
/* Return for more data, unless we are at the bottom of the image. */
if (m_rows_to_go != 0)
break;
/* When at bottom of image, pad to fill the conversion buffer. */
if (m_next_buf_row < m_next_buf_stop)
{
for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
expand_bottom_edge(m_color_buf[ci], m_colorBufRowsOffset, m_cinfo.m_image_width, m_next_buf_row, m_next_buf_stop);
m_next_buf_row = m_next_buf_stop;
}
}
/* If we've gotten enough data, downsample a row group. */
if (m_next_buf_row == m_next_buf_stop)
{
m_cinfo.m_downsample.downsample(m_color_buf, m_colorBufRowsOffset + m_this_row_group, output_buf, out_row_group_ctr);
out_row_group_ctr++;
/* Advance pointers with wraparound as necessary. */
m_this_row_group += m_cinfo.m_max_v_samp_factor;
int buf_height = m_cinfo.m_max_v_samp_factor * 3;
if (m_this_row_group >= buf_height)
m_this_row_group = 0;
if (m_next_buf_row >= buf_height)
m_next_buf_row = 0;
m_next_buf_stop = m_next_buf_row + m_cinfo.m_max_v_samp_factor;
}
}
}