private void quantize_ord_dither(byte[][] input_buf, int in_row, byte[][] output_buf, int out_row, int num_rows)
{
int nc = m_cinfo.m_out_color_components;
int width = m_cinfo.m_output_width;
for (int row = 0; row < num_rows; row++)
{
/* Initialize output values to 0 so can process components separately */
Array.Clear(output_buf[out_row + row], 0, width);
int row_index = m_row_index;
for (int ci = 0; ci < nc; ci++)
{
int inputIndex = ci;
int outIndex = 0;
int outRow = out_row + row;
int col_index = 0;
for (int col = width; col > 0; col--)
{
/* Form pixel value + dither, range-limit to 0..MAXJSAMPLE,
* select output value, accumulate into output code for this pixel.
* Range-limiting need not be done explicitly, as we have extended
* the colorindex table to produce the right answers for out-of-range
* inputs. The maximum dither is +- MAXJSAMPLE; this sets the
* required amount of padding.
*/
output_buf[outRow][outIndex] += m_colorindex[ci][m_colorindexOffset[ci] + input_buf[in_row + row][inputIndex] + m_odither[ci][row_index][col_index]];
inputIndex += nc;
outIndex++;
col_index = (col_index + 1) & ODITHER_MASK;
}
}
/* Advance row index for next row */
row_index = (row_index + 1) & ODITHER_MASK;
m_row_index = row_index;
}
}