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

pre_process_WithoutContext() private method

Process some data in the simple no-context case. Preprocessor output data is counted in "row groups". A row group is defined to be v_samp_factor sample rows of each component. Downsampling will produce this much data from each max_v_samp_factor input rows.
private pre_process_WithoutContext ( byte input_buf, int &in_row_ctr, int in_rows_avail, byte output_buf, int &out_row_group_ctr, int out_row_groups_avail ) : void
input_buf byte
in_row_ctr int
in_rows_avail int
output_buf byte
out_row_group_ctr int
out_row_groups_avail int
return void
        private void pre_process_WithoutContext(byte[][] input_buf, ref int in_row_ctr, int in_rows_avail, byte[][][] output_buf, ref int out_row_group_ctr, int out_row_groups_avail)
        {
            while (in_row_ctr < in_rows_avail && out_row_group_ctr < out_row_groups_avail)
            {
                /* Do color conversion to fill the conversion buffer. */
                int inrows = in_rows_avail - in_row_ctr;
                int numrows = m_cinfo.m_max_v_samp_factor - m_next_buf_row;
                numrows = Math.Min(numrows, inrows);
                m_cinfo.m_cconvert.color_convert(input_buf, in_row_ctr, m_color_buf, m_colorBufRowsOffset + m_next_buf_row, numrows);
                in_row_ctr += numrows;
                m_next_buf_row += numrows;
                m_rows_to_go -= numrows;

                /* If at bottom of image, pad to fill the conversion buffer. */
                if (m_rows_to_go == 0 && m_next_buf_row < m_cinfo.m_max_v_samp_factor)
                {
                    for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
                        expand_bottom_edge(m_color_buf[ci], m_colorBufRowsOffset, m_cinfo.m_image_width, m_next_buf_row, m_cinfo.m_max_v_samp_factor);

                    m_next_buf_row = m_cinfo.m_max_v_samp_factor;
                }

                /* If we've filled the conversion buffer, empty it. */
                if (m_next_buf_row == m_cinfo.m_max_v_samp_factor)
                {
                    m_cinfo.m_downsample.downsample(m_color_buf, m_colorBufRowsOffset, output_buf, out_row_group_ctr);
                    m_next_buf_row = 0;
                    out_row_group_ctr++;
                }

                /* If at bottom of image, pad the output to a full iMCU height.
                 * Note we assume the caller is providing a one-iMCU-height output buffer!
                 */
                if (m_rows_to_go == 0 && out_row_group_ctr < out_row_groups_avail)
                {
                    for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
                    {
                        jpeg_component_info componentInfo = m_cinfo.Component_info[ci];
                        numrows = (componentInfo.V_samp_factor * componentInfo.DCT_v_scaled_size) / 
                            m_cinfo.min_DCT_v_scaled_size;

                        expand_bottom_edge(output_buf[ci], 0,
                            componentInfo.Width_in_blocks * componentInfo.DCT_h_scaled_size,
                            out_row_group_ctr * numrows,
                            out_row_groups_avail * numrows);
                    }

                    out_row_group_ctr = out_row_groups_avail;
                    break;          /* can exit outer loop without test */
                }
            }
        }