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

int_downsample() private method

Downsample pixel values of a single component. One row group is processed per call. This version handles arbitrary integral sampling ratios, without smoothing. Note that this version is not actually used for customary sampling ratios.
private int_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 int_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;
            int h_expand = this.h_expand[compptr.Component_index];
            expand_right_edge(input_data, startInputRow, m_cinfo.m_max_v_samp_factor, m_cinfo.m_image_width, output_cols * h_expand);

            int v_expand = this.v_expand[compptr.Component_index];
            int numpix = h_expand * v_expand;
            int numpix2 = numpix / 2;
            int inrow = 0;
            int outrow = 0;
            while (inrow < m_cinfo.m_max_v_samp_factor)
            {
                for (int outcol = 0, outcol_h = 0; outcol < output_cols; outcol++, outcol_h += h_expand)
                {
                    int outvalue = 0;
                    for (int v = 0; v < v_expand; v++)
                    {
                        for (int h = 0; h < h_expand; h++)
                            outvalue += input_data[startInputRow + inrow + v][outcol_h + h];
                    }

                    output_data[startOutRow + outrow][outcol] = (byte)((outvalue + numpix2) / numpix);
                }

                inrow += v_expand;
                outrow++;
            }
        }