agent/browser/ie/pagetest/PagetestReporting.cpp
/*-----------------------------------------------------------------------------
  Given a JPEG byte stream, find the next marker
-----------------------------------------------------------------------------*/
Given a JPEG byte stream, find the next marker
Given a JPEG byte stream find the next marker
bool CPagetestReporting::FindJPEGMarker(BYTE * buff, DWORD len, DWORD &pos,
                                        BYTE * &marker, DWORD &marker_len) {
  bool found = false;
  marker = NULL;
  marker_len = 0;
  BYTE sos = 0xda;
  if (pos < len) {
    BYTE val = buff[pos];
    if (val == 0xff) {
      while (val == 0xff && pos < len) {
        pos++;
        val = buff[pos];
      }
      marker = &buff[pos - 1];
      pos++;
      if ((val >= 0xd0 && val <= 0xd9) || val == 0x01) {
        found = true;
      } else if(val == sos) {
        DWORD marker_end = pos + 1;
        DWORD next_marker = len;
        while (marker_end < len - 1 && !found) {
          val = buff[marker_end];
          if (val == 0xff) {
            DWORD i = marker_end + 1;
            val = buff[i];
            if (val != 0x00) {   
              while (i < len - 1 && val == 0xff) {
                i++;
                val = buff[i];
              }
              next_marker = marker_end;
              found = true;
            }
          }
          marker_end++;
        }
        marker_len = next_marker - pos;
      } else if (pos + 1 < len) {
        BYTE v1 = buff[pos];
        BYTE v2 = buff[pos + 1];
        marker_len = (DWORD)v1 * 256 + (DWORD)v2;
        found = true;
      }
    }
  }
  return found;
}
bool CPagetestReporting :: FindJPEGMarker ( BYTE * buff , DWORD len , DWORD & pos , BYTE * & marker , DWORD & marker_len ) { bool found = false ; marker = NULL ; marker_len = 0 ; BYTE sos = 0xda ; if ( pos < len ) { BYTE val = buff [ pos ] ; if ( val == 0xff ) { while ( val == 0xff && pos < len ) { pos ++ ; val = buff [ pos ] ; } marker = & buff [ pos - 1 ] ; pos ++ ; if ( ( val >= 0xd0 && val <= 0xd9 ) || val == 0x01 ) { found = true ; } else if ( val == sos ) { DWORD marker_end = pos + 1 ; DWORD next_marker = len ; while ( marker_end < len - 1 && ! found ) { val = buff [ marker_end ] ; if ( val == 0xff ) { DWORD i = marker_end + 1 ; val = buff [ i ] ; if ( val != 0x00 ) { while ( i < len - 1 && val == 0xff ) { i ++ ; val = buff [ i ] ; } next_marker = marker_end ; found = true ; } } marker_end ++ ; } marker_len = next_marker - pos ; } else if ( pos + 1 < len ) { BYTE v1 = buff [ pos ] ; BYTE v2 = buff [ pos + 1 ] ; marker_len = ( DWORD ) v1 * 256 + ( DWORD ) v2 ; found = true ; } } } return found ; }
Given a JPEG byte stream, find the next marker
Given a JPEG byte stream find the next marker
// ff can repeat, the actual marker comes from the first non-ff
 // image data
 // escaping
