private bool get_sof(bool is_baseline, bool is_prog, bool is_arith)
{
m_cinfo.is_baseline = is_baseline;
m_cinfo.m_progressive_mode = is_prog;
m_cinfo.arith_code = is_arith;
int length;
if (!m_cinfo.m_src.GetTwoBytes(out length))
return false;
if (!m_cinfo.m_src.GetByte(out m_cinfo.m_data_precision))
return false;
int temp = 0;
if (!m_cinfo.m_src.GetTwoBytes(out temp))
return false;
m_cinfo.m_image_height = temp;
if (!m_cinfo.m_src.GetTwoBytes(out temp))
return false;
m_cinfo.m_image_width = temp;
if (!m_cinfo.m_src.GetByte(out m_cinfo.m_num_components))
return false;
length -= 8;
m_cinfo.TRACEMS(1, J_MESSAGE_CODE.JTRC_SOF, m_cinfo.m_unread_marker,
m_cinfo.m_image_width, m_cinfo.m_image_height, m_cinfo.m_num_components);
if (m_cinfo.m_marker.m_saw_SOF)
m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_SOF_DUPLICATE);
/* We don't support files in which the image height is initially specified */
/* as 0 and is later redefined by DNL. As long as we have to check that, */
/* might as well have a general sanity check. */
if (m_cinfo.m_image_height <= 0 || m_cinfo.m_image_width <= 0 || m_cinfo.m_num_components <= 0)
m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_EMPTY_IMAGE);
if (length != (m_cinfo.m_num_components * 3))
m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_BAD_LENGTH);
if (m_cinfo.Comp_info == null)
{
/* do only once, even if suspend */
m_cinfo.Comp_info = jpeg_component_info.createArrayOfComponents(m_cinfo.m_num_components);
}
for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
{
//jpeg_component_info compptr = m_cinfo.Comp_info[ci];
int c;
if (!m_cinfo.m_src.GetByte(out c))
return false;
/* Check to see whether component id has already been seen */
/* (in violation of the spec, but unfortunately seen in some */
/* files). If so, create "fake" component id equal to the */
/* max id seen so far + 1. */
int componentInfoIndex = 0;
jpeg_component_info compptr = null;
for (int i = 0; i < ci; i++, componentInfoIndex++)
{
compptr = m_cinfo.Comp_info[componentInfoIndex];
if (c == compptr.Component_id)
{
componentInfoIndex = 0;
compptr = m_cinfo.Comp_info[componentInfoIndex];
c = compptr.Component_id;
componentInfoIndex++;
compptr = m_cinfo.Comp_info[componentInfoIndex];
for (i = 1; i < ci; i++, componentInfoIndex++)
{
compptr = m_cinfo.Comp_info[componentInfoIndex];
if (compptr.Component_id > c)
c = compptr.Component_id;
}
c++;
break;
}
}
compptr = m_cinfo.Comp_info[componentInfoIndex];
compptr.Component_id = c;
compptr.Component_index = ci;
if (!m_cinfo.m_src.GetByte(out c))
return false;
compptr.H_samp_factor = (c >> 4) & 15;
compptr.V_samp_factor = (c) & 15;
int quant_tbl_no;
if (!m_cinfo.m_src.GetByte(out quant_tbl_no))
return false;
compptr.Quant_tbl_no = quant_tbl_no;
m_cinfo.TRACEMS(1, J_MESSAGE_CODE.JTRC_SOF_COMPONENT, compptr.Component_id,
compptr.H_samp_factor, compptr.V_samp_factor,
compptr.Quant_tbl_no);
}
m_cinfo.m_marker.m_saw_SOF = true;
return true;
}