private void forwardDCTImpl(jpeg_component_info compptr, byte[][] sample_data, JBLOCK[] coef_blocks, int start_row, int start_col, int num_blocks)
{
/* This routine is heavily used, so it's worth coding it tightly. */
forward_DCT_method_ptr do_dct = this.do_dct[compptr.Component_index];
int[] divisors = m_dctTables[compptr.Component_index].int_array;
int[] workspace = new int[JpegConstants.DCTSIZE2]; /* work area for FDCT subroutine */
for (int bi = 0; bi < num_blocks; bi++, start_col += compptr.DCT_h_scaled_size)
{
/* Perform the DCT */
do_dct(workspace, sample_data, start_row, start_col);
/* Quantize/descale the coefficients, and store into coef_blocks[] */
for (int i = 0; i < JpegConstants.DCTSIZE2; i++)
{
int qval = divisors[i];
int temp = workspace[i];
if (temp < 0)
{
temp = -temp;
temp += qval >> 1; /* for rounding */
if (temp >= qval)
temp /= qval;
else
temp = 0;
temp = -temp;
}
else
{
temp += qval >> 1; /* for rounding */
if (temp >= qval)
temp /= qval;
else
temp = 0;
}
coef_blocks[bi][i] = (short)temp;
}
}
}