BitMiracle.LibJpeg.Classic.Internal.jpeg_c_prep_controller.create_context_buffer C# (CSharp) Method

create_context_buffer() private method

Create the wrapped-around downsampling input buffer needed for context mode.
private create_context_buffer ( ) : void
return void
        private void create_context_buffer()
        {
            int rgroup_height = m_cinfo.m_max_v_samp_factor;
            for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
            {
                int samplesPerRow = (m_cinfo.Component_info[ci].Width_in_blocks *
                    m_cinfo.min_DCT_h_scaled_size * m_cinfo.m_max_h_samp_factor) / 
                    m_cinfo.Component_info[ci].H_samp_factor;

                byte[][] fake_buffer = new byte[5 * rgroup_height][];
                for (int i = 1; i < 4 * rgroup_height; i++)
                    fake_buffer[i] = new byte[samplesPerRow];

                /* Allocate the actual buffer space (3 row groups) for this component.
                 * We make the buffer wide enough to allow the downsampler to edge-expand
                 * horizontally within the buffer, if it so chooses.
                 */
                byte[][] true_buffer = jpeg_common_struct.AllocJpegSamples(samplesPerRow, 3 * rgroup_height);

                /* Copy true buffer row pointers into the middle of the fake row array */
                for (int i = 0; i < 3 * rgroup_height; i++)
                    fake_buffer[rgroup_height + i] = true_buffer[i];

                /* Fill in the above and below wraparound pointers */
                for (int i = 0; i < rgroup_height; i++)
                {
                    fake_buffer[i] = true_buffer[2 * rgroup_height + i];
                    fake_buffer[4 * rgroup_height + i] = true_buffer[i];
                }

                m_color_buf[ci] = fake_buffer;
                m_colorBufRowsOffset = rgroup_height;
            }
        }