private void per_scan_setup()
{
if (m_cinfo.m_comps_in_scan == 1)
{
/* Noninterleaved (single-component) scan */
int compIndex = m_cinfo.m_cur_comp_info[0];
jpeg_component_info compptr = m_cinfo.Component_info[compIndex];
/* Overall image size in MCUs */
m_cinfo.m_MCUs_per_row = compptr.Width_in_blocks;
m_cinfo.m_MCU_rows_in_scan = compptr.height_in_blocks;
/* For noninterleaved scan, always one block per MCU */
compptr.MCU_width = 1;
compptr.MCU_height = 1;
compptr.MCU_blocks = 1;
compptr.MCU_sample_width = compptr.DCT_h_scaled_size;
compptr.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 = compptr.height_in_blocks % compptr.V_samp_factor;
if (tmp == 0)
tmp = compptr.V_samp_factor;
compptr.last_row_height = tmp;
/* 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.jpeg_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.jpeg_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++)
{
int compIndex = m_cinfo.m_cur_comp_info[ci];
jpeg_component_info compptr = m_cinfo.Component_info[compIndex];
/* Sampling factors give # of blocks of component in each MCU */
compptr.MCU_width = compptr.H_samp_factor;
compptr.MCU_height = compptr.V_samp_factor;
compptr.MCU_blocks = compptr.MCU_width * compptr.MCU_height;
compptr.MCU_sample_width = compptr.MCU_width * compptr.DCT_h_scaled_size;
/* Figure number of non-dummy blocks in last MCU column & row */
int tmp = compptr.Width_in_blocks % compptr.MCU_width;
if (tmp == 0)
tmp = compptr.MCU_width;
compptr.last_col_width = tmp;
tmp = compptr.height_in_blocks % compptr.MCU_height;
if (tmp == 0)
tmp = compptr.MCU_height;
compptr.last_row_height = tmp;
/* Prepare array describing MCU composition */
int mcublks = compptr.MCU_blocks;
if (m_cinfo.m_blocks_in_MCU + mcublks > JpegConstants.C_MAX_BLOCKS_IN_MCU)
m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_BAD_MCU_SIZE);
while (mcublks-- > 0)
m_cinfo.m_MCU_membership[m_cinfo.m_blocks_in_MCU++] = ci;
}
}
/* Convert restart specified in rows to actual MCU count. */
/* Note that count must fit in 16 bits, so we provide limiting. */
if (m_cinfo.m_restart_in_rows > 0)
{
int nominal = m_cinfo.m_restart_in_rows * m_cinfo.m_MCUs_per_row;
m_cinfo.m_restart_interval = Math.Min(nominal, 65535);
}
}
}