BitMiracle.LibJpeg.Classic.Internal.jpeg_d_coef_controller.consume_data C# (CSharp) Method

consume_data() public method

Consume input data and store it in the full-image coefficient buffer. We read as much as one fully interleaved MCU row ("iMCU" row) per call, ie, v_samp_factor block rows for each component in the scan.
public consume_data ( ) : ReadResult
return ReadResult
        public ReadResult consume_data()
        {
            if (m_useDummyConsumeData)
                return ReadResult.JPEG_SUSPENDED;  /* Always indicate nothing was done */

            JBLOCK[][][] buffer = new JBLOCK[JpegConstants.MAX_COMPS_IN_SCAN][][];

            /* Align the virtual buffers for the components used in this scan. */
            for (int ci = 0; ci < m_cinfo.m_comps_in_scan; ci++)
            {
                jpeg_component_info componentInfo = m_cinfo.Comp_info[m_cinfo.m_cur_comp_info[ci]];

                buffer[ci] = m_whole_image[componentInfo.Component_index].Access(
                    m_cinfo.m_input_iMCU_row * componentInfo.V_samp_factor, componentInfo.V_samp_factor);

                /* Note: entropy decoder expects buffer to be zeroed,
                 * but this is handled automatically by the memory manager
                 * because we requested a pre-zeroed array.
                 */
            }

            /* Loop to process one whole iMCU row */
            for (int yoffset = m_MCU_vert_offset; yoffset < m_MCU_rows_per_iMCU_row; yoffset++)
            {
                for (int MCU_col_num = m_MCU_ctr; MCU_col_num < m_cinfo.m_MCUs_per_row; MCU_col_num++)
                {
                    /* Construct list of pointers to DCT blocks belonging to this MCU */
                    int blkn = 0;           /* index of current DCT block within MCU */
                    for (int ci = 0; ci < m_cinfo.m_comps_in_scan; ci++)
                    {
                        jpeg_component_info componentInfo = m_cinfo.Comp_info[m_cinfo.m_cur_comp_info[ci]];
                        int start_col = MCU_col_num * componentInfo.MCU_width;
                        for (int yindex = 0; yindex < componentInfo.MCU_height; yindex++)
                        {
                            for (int xindex = 0; xindex < componentInfo.MCU_width; xindex++)
                            {
                                m_MCU_buffer[blkn] = buffer[ci][yindex + yoffset][start_col + xindex];
                                blkn++;
                            }
                        }
                    }

                    /* Try to fetch the MCU. */
                    if (!m_cinfo.m_entropy.decode_mcu(m_MCU_buffer))
                    {
                        /* Suspension forced; update state counters and exit */
                        m_MCU_vert_offset = yoffset;
                        m_MCU_ctr = MCU_col_num;
                        return ReadResult.JPEG_SUSPENDED;
                    }
                }

                /* Completed an MCU row, but perhaps not an iMCU row */
                m_MCU_ctr = 0;
            }

            /* Completed the iMCU row, advance counters for next one */
            m_cinfo.m_input_iMCU_row++;
            if (m_cinfo.m_input_iMCU_row < m_cinfo.m_total_iMCU_rows)
            {
                start_iMCU_row();
                return ReadResult.JPEG_ROW_COMPLETED;
            }

            /* Completed the scan */
            m_cinfo.m_inputctl.finish_input_pass();
            return ReadResult.JPEG_SCAN_COMPLETED;
        }