private void fullsize_smooth_downsample(int componentIndex, byte[][] input_data, int startInputRow, byte[][] output_data, int startOutRow)
{
/* Expand input data enough to let all the output samples be generated
* by the standard loop. Special-casing padded output would be more
* efficient.
*/
jpeg_component_info compptr = m_cinfo.Component_info[componentIndex];
int output_cols = compptr.Width_in_blocks * compptr.DCT_h_scaled_size;
expand_right_edge(input_data, startInputRow - 1, m_cinfo.m_max_v_samp_factor + 2, m_cinfo.m_image_width, output_cols);
/* Each of the eight neighbor pixels contributes a fraction SF to the
* smoothed pixel, while the main pixel contributes (1-8*SF). In order
* to use integer arithmetic, these factors are multiplied by 2^16 = 65536.
* Also recall that SF = smoothing_factor / 1024.
*/
int memberscale = 65536 - m_cinfo.m_smoothing_factor * 512; /* scaled 1-8*SF */
int neighscale = m_cinfo.m_smoothing_factor * 64; /* scaled SF */
for (int outrow = 0; outrow < m_cinfo.m_max_v_samp_factor; outrow++)
{
int outIndex = 0;
int inIndex = 0;
int aboveIndex = 0;
int belowIndex = 0;
/* Special case for first column */
int colsum = input_data[startInputRow + outrow - 1][aboveIndex] +
input_data[startInputRow + outrow + 1][belowIndex] +
input_data[startInputRow + outrow][inIndex];
aboveIndex++;
belowIndex++;
int membersum = input_data[startInputRow + outrow][inIndex];
inIndex++;
int nextcolsum = input_data[startInputRow + outrow - 1][aboveIndex] +
input_data[startInputRow + outrow + 1][belowIndex] +
input_data[startInputRow + outrow][inIndex];
int neighsum = colsum + (colsum - membersum) + nextcolsum;
membersum = membersum * memberscale + neighsum * neighscale;
output_data[startOutRow + outrow][outIndex] = (byte)((membersum + 32768) >> 16);
outIndex++;
int lastcolsum = colsum;
colsum = nextcolsum;
for (int colctr = output_cols - 2; colctr > 0; colctr--)
{
membersum = input_data[startInputRow + outrow][inIndex];
inIndex++;
aboveIndex++;
belowIndex++;
nextcolsum = input_data[startInputRow + outrow - 1][aboveIndex] +
input_data[startInputRow + outrow + 1][belowIndex] +
input_data[startInputRow + outrow][inIndex];
neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
membersum = membersum * memberscale + neighsum * neighscale;
output_data[startOutRow + outrow][outIndex] = (byte)((membersum + 32768) >> 16);
outIndex++;
lastcolsum = colsum;
colsum = nextcolsum;
}
/* Special case for last column */
membersum = input_data[startInputRow + outrow][inIndex];
neighsum = lastcolsum + (colsum - membersum) + colsum;
membersum = membersum * memberscale + neighsum * neighscale;
output_data[startOutRow + outrow][outIndex] = (byte)((membersum + 32768) >> 16);
}
}