private void per_scan_setup()
{
if (m_cinfo.m_comps_in_scan == 1)
{
/* Noninterleaved (single-component) scan */
jpeg_component_info componentInfo = m_cinfo.Comp_info[m_cinfo.m_cur_comp_info[0]];
/* Overall image size in MCUs */
m_cinfo.m_MCUs_per_row = componentInfo.Width_in_blocks;
m_cinfo.m_MCU_rows_in_scan = componentInfo.height_in_blocks;
/* For noninterleaved scan, always one block per MCU */
componentInfo.MCU_width = 1;
componentInfo.MCU_height = 1;
componentInfo.MCU_blocks = 1;
componentInfo.MCU_sample_width = componentInfo.DCT_h_scaled_size;
componentInfo.last_col_width = 1;
/* For noninterleaved scans, it is convenient to define last_row_height
* as the number of block rows present in the last iMCU row.
*/
int tmp = componentInfo.height_in_blocks % componentInfo.V_samp_factor;
if (tmp == 0)
tmp = componentInfo.V_samp_factor;
componentInfo.last_row_height = tmp;
m_cinfo.Comp_info[m_cinfo.m_cur_comp_info[0]] = componentInfo;
/* Prepare array describing MCU composition */
m_cinfo.m_blocks_in_MCU = 1;
m_cinfo.m_MCU_membership[0] = 0;
}
else
{
/* Interleaved (multi-component) scan */
if (m_cinfo.m_comps_in_scan <= 0 || m_cinfo.m_comps_in_scan > JpegConstants.MAX_COMPS_IN_SCAN)
m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_COMPONENT_COUNT, m_cinfo.m_comps_in_scan, JpegConstants.MAX_COMPS_IN_SCAN);
/* Overall image size in MCUs */
m_cinfo.m_MCUs_per_row = (int)JpegUtils.jdiv_round_up(
m_cinfo.m_image_width, m_cinfo.m_max_h_samp_factor * m_cinfo.block_size);
m_cinfo.m_MCU_rows_in_scan = (int)JpegUtils.jdiv_round_up(
m_cinfo.m_image_height, m_cinfo.m_max_v_samp_factor * m_cinfo.block_size);
m_cinfo.m_blocks_in_MCU = 0;
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]];
/* Sampling factors give # of blocks of component in each MCU */
componentInfo.MCU_width = componentInfo.H_samp_factor;
componentInfo.MCU_height = componentInfo.V_samp_factor;
componentInfo.MCU_blocks = componentInfo.MCU_width * componentInfo.MCU_height;
componentInfo.MCU_sample_width = componentInfo.MCU_width * componentInfo.DCT_h_scaled_size;
/* Figure number of non-dummy blocks in last MCU column & row */
int tmp = componentInfo.Width_in_blocks % componentInfo.MCU_width;
if (tmp == 0)
tmp = componentInfo.MCU_width;
componentInfo.last_col_width = tmp;
tmp = componentInfo.height_in_blocks % componentInfo.MCU_height;
if (tmp == 0)
tmp = componentInfo.MCU_height;
componentInfo.last_row_height = tmp;
/* Prepare array describing MCU composition */
int mcublks = componentInfo.MCU_blocks;
if (m_cinfo.m_blocks_in_MCU + mcublks > JpegConstants.D_MAX_BLOCKS_IN_MCU)
m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_BAD_MCU_SIZE);
m_cinfo.Comp_info[m_cinfo.m_cur_comp_info[ci]] = componentInfo;
while (mcublks-- > 0)
m_cinfo.m_MCU_membership[m_cinfo.m_blocks_in_MCU++] = ci;
}
}
}
}