public bool next_marker()
{
int c;
for (;;)
{
if (!m_cinfo.m_src.GetByte(out c))
return false;
/* Skip any non-FF bytes.
* This may look a bit inefficient, but it will not occur in a valid file.
* We sync after each discarded byte so that a suspending data source
* can discard the byte from its buffer.
*/
while (c != 0xFF)
{
m_cinfo.m_marker.m_discarded_bytes++;
if (!m_cinfo.m_src.GetByte(out c))
return false;
}
/* This loop swallows any duplicate FF bytes. Extra FFs are legal as
* pad bytes, so don't count them in discarded_bytes. We assume there
* will not be so many consecutive FF bytes as to overflow a suspending
* data source's input buffer.
*/
do
{
if (!m_cinfo.m_src.GetByte(out c))
return false;
}
while (c == 0xFF);
if (c != 0)
{
/* found a valid marker, exit loop */
break;
}
/* Reach here if we found a stuffed-zero data sequence (FF/00).
* Discard it and loop back to try again.
*/
m_cinfo.m_marker.m_discarded_bytes += 2;
}
if (m_cinfo.m_marker.m_discarded_bytes != 0)
{
m_cinfo.WARNMS(J_MESSAGE_CODE.JWRN_EXTRANEOUS_DATA, m_cinfo.m_marker.m_discarded_bytes, c);
m_cinfo.m_marker.m_discarded_bytes = 0;
}
m_cinfo.m_unread_marker = c;
return true;
}