public ReadResult read_markers()
{
/* Outer loop repeats once for each marker. */
for (;;)
{
/* Collect the marker proper, unless we already did. */
/* NB: first_marker() enforces the requirement that SOI appear first. */
if (m_cinfo.m_unread_marker == 0)
{
if (!m_cinfo.m_marker.m_saw_SOI)
{
if (!first_marker())
return ReadResult.JPEG_SUSPENDED;
}
else
{
if (!next_marker())
return ReadResult.JPEG_SUSPENDED;
}
}
/* At this point m_cinfo.unread_marker contains the marker code and the
* input point is just past the marker proper, but before any parameters.
* A suspension will cause us to return with this state still true.
*/
switch ((JPEG_MARKER)m_cinfo.m_unread_marker)
{
case JPEG_MARKER.SOI:
if (!get_soi())
return ReadResult.JPEG_SUSPENDED;
break;
case JPEG_MARKER.SOF0:
/* Baseline */
if (!get_sof(true, false, false))
return ReadResult.JPEG_SUSPENDED;
break;
case JPEG_MARKER.SOF1:
/* Extended sequential, Huffman */
if (!get_sof(false, false, false))
return ReadResult.JPEG_SUSPENDED;
break;
case JPEG_MARKER.SOF2:
/* Progressive, Huffman */
if (!get_sof(false, true, false))
return ReadResult.JPEG_SUSPENDED;
break;
case JPEG_MARKER.SOF9:
/* Extended sequential, arithmetic */
if (!get_sof(false, false, true))
return ReadResult.JPEG_SUSPENDED;
break;
case JPEG_MARKER.SOF10:
/* Progressive, arithmetic */
if (!get_sof(false, true, true))
return ReadResult.JPEG_SUSPENDED;
break;
/* Currently unsupported SOFn types */
case JPEG_MARKER.SOF3:
/* Lossless, Huffman */
case JPEG_MARKER.SOF5:
/* Differential sequential, Huffman */
case JPEG_MARKER.SOF6:
/* Differential progressive, Huffman */
case JPEG_MARKER.SOF7:
/* Differential lossless, Huffman */
case JPEG_MARKER.JPG:
/* Reserved for JPEG extensions */
case JPEG_MARKER.SOF11:
/* Lossless, arithmetic */
case JPEG_MARKER.SOF13:
/* Differential sequential, arithmetic */
case JPEG_MARKER.SOF14:
/* Differential progressive, arithmetic */
case JPEG_MARKER.SOF15:
/* Differential lossless, arithmetic */
m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_SOF_UNSUPPORTED, m_cinfo.m_unread_marker);
break;
case JPEG_MARKER.SOS:
if (!get_sos())
return ReadResult.JPEG_SUSPENDED;
m_cinfo.m_unread_marker = 0; /* processed the marker */
return ReadResult.JPEG_REACHED_SOS;
case JPEG_MARKER.EOI:
m_cinfo.TRACEMS(1, J_MESSAGE_CODE.JTRC_EOI);
m_cinfo.m_unread_marker = 0; /* processed the marker */
return ReadResult.JPEG_REACHED_EOI;
case JPEG_MARKER.DAC:
if (!get_dac())
return ReadResult.JPEG_SUSPENDED;
break;
case JPEG_MARKER.DHT:
if (!get_dht())
return ReadResult.JPEG_SUSPENDED;
break;
case JPEG_MARKER.DQT:
if (!get_dqt())
return ReadResult.JPEG_SUSPENDED;
break;
case JPEG_MARKER.DRI:
if (!get_dri())
return ReadResult.JPEG_SUSPENDED;
break;
case JPEG_MARKER.JPG8:
if (!get_lse())
return ReadResult.JPEG_SUSPENDED;
break;
case JPEG_MARKER.APP0:
case JPEG_MARKER.APP1:
case JPEG_MARKER.APP2:
case JPEG_MARKER.APP3:
case JPEG_MARKER.APP4:
case JPEG_MARKER.APP5:
case JPEG_MARKER.APP6:
case JPEG_MARKER.APP7:
case JPEG_MARKER.APP8:
case JPEG_MARKER.APP9:
case JPEG_MARKER.APP10:
case JPEG_MARKER.APP11:
case JPEG_MARKER.APP12:
case JPEG_MARKER.APP13:
case JPEG_MARKER.APP14:
case JPEG_MARKER.APP15:
if (!m_cinfo.m_marker.m_process_APPn[m_cinfo.m_unread_marker - (int)JPEG_MARKER.APP0](m_cinfo))
return ReadResult.JPEG_SUSPENDED;
break;
case JPEG_MARKER.COM:
if (!m_cinfo.m_marker.m_process_COM(m_cinfo))
return ReadResult.JPEG_SUSPENDED;
break;
/* these are all parameterless */
case JPEG_MARKER.RST0:
case JPEG_MARKER.RST1:
case JPEG_MARKER.RST2:
case JPEG_MARKER.RST3:
case JPEG_MARKER.RST4:
case JPEG_MARKER.RST5:
case JPEG_MARKER.RST6:
case JPEG_MARKER.RST7:
case JPEG_MARKER.TEM:
m_cinfo.TRACEMS(1, J_MESSAGE_CODE.JTRC_PARMLESS_MARKER, m_cinfo.m_unread_marker);
break;
case JPEG_MARKER.DNL:
/* Ignore DNL ... perhaps the wrong thing */
if (!skip_variable(m_cinfo))
return ReadResult.JPEG_SUSPENDED;
break;
default:
/* must be DHP, EXP, JPGn, or RESn */
/* For now, we treat the reserved markers as fatal errors since they are
* likely to be used to signal incompatible JPEG Part 3 extensions.
* Once the JPEG 3 version-number marker is well defined, this code
* ought to change!
*/
m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_UNKNOWN_MARKER, m_cinfo.m_unread_marker);
break;
}
/* Successfully processed marker, so reset state variable */
m_cinfo.m_unread_marker = 0;
} /* end loop */
}