public void write_frame_header()
{
/* Emit DQT for each quantization table.
* Note that emit_dqt() suppresses any duplicate tables.
*/
int prec = 0;
for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
prec += emit_dqt(m_cinfo.Component_info[ci].Quant_tbl_no);
/* now prec is nonzero iff there are any 16-bit quant tables. */
/* Check for a non-baseline specification.
* Note we assume that Huffman table numbers won't be changed later.
*/
bool is_baseline;
if (m_cinfo.arith_code || m_cinfo.m_progressive_mode ||
m_cinfo.m_data_precision != 8 || m_cinfo.block_size != JpegConstants.DCTSIZE)
{
is_baseline = false;
}
else
{
is_baseline = true;
for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
{
if (m_cinfo.Component_info[ci].Dc_tbl_no > 1 || m_cinfo.Component_info[ci].Ac_tbl_no > 1)
is_baseline = false;
}
if (prec != 0 && is_baseline)
{
is_baseline = false;
/* If it's baseline except for quantizer size, warn the user */
m_cinfo.TRACEMS(0, J_MESSAGE_CODE.JTRC_16BIT_TABLES);
}
}
/* Emit the proper SOF marker */
if (m_cinfo.arith_code)
{
if (m_cinfo.m_progressive_mode)
emit_sof(JPEG_MARKER.SOF10); /* SOF code for progressive arithmetic */
else
emit_sof(JPEG_MARKER.SOF9); /* SOF code for sequential arithmetic */
}
else
{
if (m_cinfo.m_progressive_mode)
emit_sof(JPEG_MARKER.SOF2); /* SOF code for progressive Huffman */
else if (is_baseline)
emit_sof(JPEG_MARKER.SOF0); /* SOF code for baseline implementation */
else
emit_sof(JPEG_MARKER.SOF1); /* SOF code for non-baseline Huffman file */
}
/* Check to emit LSE inverse color transform specification marker */
if (m_cinfo.color_transform != J_COLOR_TRANSFORM.JCT_NONE)
emit_lse_ict();
/* Check to emit pseudo SOS marker */
if (m_cinfo.m_progressive_mode && m_cinfo.block_size != JpegConstants.DCTSIZE)
emit_pseudo_sos();
}