hphp/runtime/ext/gd/ext_gd.cpp
/* Main loop to parse JPEG2000 raw codestream structure */
Main loop to parse JPEG2000 raw codestream structure
Main loop to parse JPEG2000 raw codestream structure
static struct gfxinfo *php_handle_jpc(const req::ptr<File>& file) {
  struct gfxinfo *result = nullptr;
  int highest_bit_depth, bit_depth;
  unsigned char first_marker_id;
  unsigned int i;
  first_marker_id = file->getc();
  if (first_marker_id != JPEG2000_MARKER_SIZ) {
    raise_warning("JPEG2000 codestream corrupt(Expected SIZ marker "
                    "not found after SOC)");
    return nullptr;
  }
  result = (struct gfxinfo *)IM_CALLOC(1, sizeof(struct gfxinfo));
  CHECK_ALLOC_R(result, sizeof (struct gfxinfo), nullptr);
  php_read2(file); 
  php_read2(file); 
  result->width = php_read4(file); 
  result->height = php_read4(file); 
#if MBO_0
  php_read4(file); 
  php_read4(file); 
  php_read4(file); 
  php_read4(file); 
  php_read4(file); 
  php_read4(file); 
#else
  if (!file->seek(24, SEEK_CUR)) {
    IM_FREE(result);
    return nullptr;
  }
#endif
  result->channels = php_read2(file); 
  if (result->channels > 256) {
    IM_FREE(result);
    return nullptr;
  }
  highest_bit_depth = bit_depth = 0;
  for (i = 0; i < result->channels; i++) {
    bit_depth = file->getc(); 
    bit_depth++;
    if (bit_depth > highest_bit_depth) {
      highest_bit_depth = bit_depth;
    }
    file->getc(); 
    file->getc(); 
  }
  result->bits = highest_bit_depth;
  return result;
}
static struct gfxinfo * php_handle_jpc ( const req :: ptr < File > & file ) { struct gfxinfo * result = nullptr ; int highest_bit_depth , bit_depth ; unsigned char first_marker_id ; unsigned int i ; first_marker_id = file -> getc ( ) ; if ( first_marker_id != JPEG2000_MARKER_SIZ ) { raise_warning ( " " " " ) ; return nullptr ; } result = ( struct gfxinfo * ) IM_CALLOC ( 1 , sizeof ( struct gfxinfo ) ) ; CHECK_ALLOC_R ( result , sizeof ( struct gfxinfo ) , nullptr ) ; php_read2 ( file ) ; php_read2 ( file ) ; result -> width = php_read4 ( file ) ; result -> height = php_read4 ( file ) ; #if MBO_0 php_read4 ( file ) ; php_read4 ( file ) ; php_read4 ( file ) ; php_read4 ( file ) ; php_read4 ( file ) ; php_read4 ( file ) ; #else if ( ! file -> seek ( 24 , SEEK_CUR ) ) { IM_FREE ( result ) ; return nullptr ; } #endif result -> channels = php_read2 ( file ) ; if ( result -> channels > 256 ) { IM_FREE ( result ) ; return nullptr ; } highest_bit_depth = bit_depth = 0 ; for ( i = 0 ; i < result -> channels ; i ++ ) { bit_depth = file -> getc ( ) ; bit_depth ++ ; if ( bit_depth > highest_bit_depth ) { highest_bit_depth = bit_depth ; } file -> getc ( ) ; file -> getc ( ) ; } result -> bits = highest_bit_depth ; return result ; }
Main loop to parse JPEG2000 raw codestream structure
Main loop to parse JPEG2000 raw codestream structure
/* JPEG 2000 components can be vastly different from one another.
     Each component can be sampled at a different resolution, use
     a different colour space, have a separate colour depth, and
     be compressed totally differently! This makes giving a single
     "bit depth" answer somewhat problematic. For this implementation
     we'll use the highest depth encountered. */ /* Get the single byte that remains after the file type indentification */ /* Ensure that this marker is SIZ (as is mandated by the standard) */ /* Lsiz */ /* Rsiz */ /* Xsiz */ /* Ysiz */ /* XOsiz */ /* YOsiz */ /* XTsiz */ /* YTsiz */ /* XTOsiz */ /* YTOsiz */ /* Csiz */ /* Collect bit depth info */ /* Ssiz[i] */ /* XRsiz[i] */ /* YRsiz[i] */