BitMiracle.LibJpeg.Classic.Internal.jpeg_downsampler.h2v2_downsample C# (CSharp) Method

h2v2_downsample() private method

Downsample pixel values of a single component. This version handles the standard case of 2:1 horizontal and 2:1 vertical, without smoothing.
private h2v2_downsample ( int componentIndex, byte input_data, int startInputRow, byte output_data, int startOutRow ) : void
componentIndex int
input_data byte
startInputRow int
output_data byte
startOutRow int
return void
        private void h2v2_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, m_cinfo.m_max_v_samp_factor, m_cinfo.m_image_width, output_cols * 2);

            int inrow = 0;
            int outrow = 0;
            while (inrow < m_cinfo.m_max_v_samp_factor)
            {
                /* bias = 1,2,1,2,... for successive samples */
                int bias = 1;
                int inputColumn = 0;
                for (int outcol = 0; outcol < output_cols; outcol++)
                {
                    output_data[startOutRow + outrow][outcol] = (byte)((
                        (int)input_data[startInputRow + inrow][inputColumn] +
                        (int)input_data[startInputRow + inrow][inputColumn + 1] +
                        (int)input_data[startInputRow + inrow + 1][inputColumn] +
                        (int)input_data[startInputRow + inrow + 1][inputColumn + 1] + bias) >> 2);

                    bias ^= 3;      /* 1=>2, 2=>1 */
                    inputColumn += 2;
                }

                inrow += 2;
                outrow++;
            }
        }