hphp/runtime/ext/gd/ext_gd.cpp
/* main loop to parse JPEG 2000 JP2 wrapper format structure */
main loop to parse JPEG 2000 JP2 wrapper format structure
main loop to parse JPEG 2000 JP2 wrapper format structure
static struct gfxinfo *php_handle_jp2(const req::ptr<File>& stream) {
  struct gfxinfo *result = nullptr;
  unsigned int box_length;
  unsigned int box_type;
  char jp2c_box_id[] = {(char)0x6a, (char)0x70, (char)0x32, (char)0x63};
  for (;;)
  {
    box_length = php_read4(stream); 
    String str = stream->read(sizeof(box_type));
    if (str.length() != sizeof(box_type)) {
      break;
    }
    memcpy(&box_type, str.c_str(), sizeof(box_type));
    if (box_length == 1) {
      return nullptr;
    }
    if (!memcmp(&box_type, jp2c_box_id, 4))
    {
      stream->seek(3, SEEK_CUR);
      result = php_handle_jpc(stream);
      break;
    }
    if ((int)box_length <= 0) {
      break;
    }
    if (!stream->seek(box_length - 8, SEEK_CUR)) {
      break;
    }
  }
  if (result == nullptr) {
    raise_warning("JP2 file has no codestreams at root level");
  }
  return result;
}
static struct gfxinfo * php_handle_jp2 ( const req :: ptr < File > & stream ) { struct gfxinfo * result = nullptr ; unsigned int box_length ; unsigned int box_type ; char jp2c_box_id [ ] = { ( char ) 0x6a , ( char ) 0x70 , ( char ) 0x32 , ( char ) 0x63 } ; for ( ; ; ) { box_length = php_read4 ( stream ) ; String str = stream -> read ( sizeof ( box_type ) ) ; if ( str . length ( ) != sizeof ( box_type ) ) { break ; } memcpy ( & box_type , str . c_str ( ) , sizeof ( box_type ) ) ; if ( box_length == 1 ) { return nullptr ; } if ( ! memcmp ( & box_type , jp2c_box_id , 4 ) ) { stream -> seek ( 3 , SEEK_CUR ) ; result = php_handle_jpc ( stream ) ; break ; } if ( ( int ) box_length <= 0 ) { break ; } if ( ! stream -> seek ( box_length - 8 , SEEK_CUR ) ) { break ; } } if ( result == nullptr ) { raise_warning ( " " ) ; } return result ; }
main loop to parse JPEG 2000 JP2 wrapper format structure
main loop to parse JPEG 2000 JP2 wrapper format structure
/* JP2 is a wrapper format for JPEG 2000. Data is contained within "boxes".
     Boxes themselves can be contained within "super-boxes". Super-Boxes can
     contain super-boxes which provides us with a hierarchical storage system.

     It is valid for a JP2 file to contain multiple individual codestreams.
     We'll just look for the first codestream at the root of the box structure
     and handle that.
  */ /* LBox */ /* TBox */ /* Use this as a general "out of stream" error */ /* We won't handle XLBoxes */ /* Skip the first 3 bytes to emulate the file type examination */ /* Stop if this was the last box */ /* Skip over LBox (Which includes both TBox and LBox itself */