private void emit_sos()
{
emit_marker(JPEG_MARKER.SOS);
emit_2bytes(2 * m_cinfo.m_comps_in_scan + 2 + 1 + 3); /* length */
emit_byte(m_cinfo.m_comps_in_scan);
for (int i = 0; i < m_cinfo.m_comps_in_scan; i++)
{
int componentIndex = m_cinfo.m_cur_comp_info[i];
jpeg_component_info compptr = m_cinfo.Component_info[componentIndex];
emit_byte(compptr.Component_id);
/* We emit 0 for unused field(s); this is recommended by the P&M text
* but does not seem to be specified in the standard.
*/
/* DC needs no table for refinement scan */
int td = (m_cinfo.m_Ss == 0 && m_cinfo.m_Ah == 0) ? compptr.Dc_tbl_no : 0;
/* AC needs no table when not present */
int ta = (m_cinfo.m_Se != 0) ? compptr.Ac_tbl_no : 0;
emit_byte((td << 4) + ta);
}
emit_byte(m_cinfo.m_Ss);
emit_byte(m_cinfo.m_Se);
emit_byte((m_cinfo.m_Ah << 4) + m_cinfo.m_Al);
}