private bool decode_mcu_DC_first(JBLOCK[] MCU_data)
{
/* Process restart marker if needed; may have to suspend */
if (m_cinfo.m_restart_interval != 0)
{
if (m_restarts_to_go == 0)
{
if (!process_restart())
return false;
}
}
/* If we've run out of data, just leave the MCU set to zeroes.
* This way, we return uniform gray for the remainder of the segment.
*/
if (!m_insufficient_data)
{
/* Load up working state */
int get_buffer;
int bits_left;
bitread_working_state br_state = new bitread_working_state();
BITREAD_LOAD_STATE(m_bitstate, out get_buffer, out bits_left, ref br_state);
savable_state state = new savable_state();
state.Assign(m_saved);
/* Outer loop handles each block in the MCU */
for (int blkn = 0; blkn < m_cinfo.m_blocks_in_MCU; blkn++)
{
int ci = m_cinfo.m_MCU_membership[blkn];
/* Decode a single block's worth of coefficients */
/* Section F.2.2.1: decode the DC coefficient difference */
int s;
if (!HUFF_DECODE(out s, ref br_state, derived_tbls[m_cinfo.Comp_info[m_cinfo.m_cur_comp_info[ci]].Dc_tbl_no], ref get_buffer, ref bits_left))
return false;
if (s != 0)
{
if (!CHECK_BIT_BUFFER(ref br_state, s, ref get_buffer, ref bits_left))
return false;
int r = GET_BITS(s, get_buffer, ref bits_left);
s = HUFF_EXTEND(r, s);
}
/* Convert DC difference to actual value, update last_dc_val */
s += state.last_dc_val[ci];
state.last_dc_val[ci] = s;
/* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */
MCU_data[blkn][0] = (short)(s << m_cinfo.m_Al);
}
/* Completed MCU, so update state */
BITREAD_SAVE_STATE(ref m_bitstate, get_buffer, bits_left);
m_saved.Assign(state);
}
/* Account for restart interval (no-op if not using restarts) */
m_restarts_to_go--;
return true;
}