rEFIt_UEFI/libeg/lodepng.cpp
/*read the information from the header and store it in the LodePNGInfo. return value is error*/
read the information from the header and store it in the LodePNGInfo. return value is error
read the information from the header and store it in the LodePNGInfo . return value is error
unsigned lodepng_inspect(unsigned* w, unsigned* h, LodePNGState* state,
                         const unsigned char* in, size_t insize) {
  unsigned width, height;
  LodePNGInfo* info = &state->info_png;
  if(insize == 0 || in == 0) {
    CERROR_RETURN_ERROR(state->error, 48); 
  }
  if(insize < 33) {
    CERROR_RETURN_ERROR(state->error, 27); 
  }
  lodepng_info_cleanup(info);
  lodepng_info_init(info);
  if(in[0] != 137 || in[1] != 80 || in[2] != 78 || in[3] != 71
     || in[4] != 13 || in[5] != 10 || in[6] != 26 || in[7] != 10) {
    CERROR_RETURN_ERROR(state->error, 28); 
  }
  if(lodepng_chunk_length(in + 8) != 13) {
    CERROR_RETURN_ERROR(state->error, 94); 
  }
  if(!lodepng_chunk_type_equals(in + 8, "IHDR")) {
    CERROR_RETURN_ERROR(state->error, 29); 
  }
  width = lodepng_read32bitInt(&in[16]);
  height = lodepng_read32bitInt(&in[20]);
  if(w) *w = width;
  if(h) *h = height;
  info->color.bitdepth = in[24];
  info->color.colortype = (LodePNGColorType)in[25];
  info->compression_method = in[26];
  info->filter_method = in[27];
  info->interlace_method = in[28];
  if(width == 0 || height == 0) CERROR_RETURN_ERROR(state->error, 93);
  state->error = checkColorValidity(info->color.colortype, info->color.bitdepth);
  if(state->error) return state->error;
  if(info->compression_method != 0) CERROR_RETURN_ERROR(state->error, 32);
  if(info->filter_method != 0) CERROR_RETURN_ERROR(state->error, 33);
  if(info->interlace_method > 1) CERROR_RETURN_ERROR(state->error, 34);
  if(!state->decoder.ignore_crc) {
    unsigned CRC = lodepng_read32bitInt(&in[29]);
    unsigned checksum = lodepng_crc32(&in[12], 17);
    if(CRC != checksum) {
      CERROR_RETURN_ERROR(state->error, 57); 
    }
  }
  return state->error;
}
unsigned lodepng_inspect ( unsigned * w , unsigned * h , LodePNGState * state , const unsigned char * in , size_t insize ) { unsigned width , height ; LodePNGInfo * info = & state -> info_png ; if ( insize == 0 || in == 0 ) { CERROR_RETURN_ERROR ( state -> error , 48 ) ; } if ( insize < 33 ) { CERROR_RETURN_ERROR ( state -> error , 27 ) ; } lodepng_info_cleanup ( info ) ; lodepng_info_init ( info ) ; if ( in [ 0 ] != 137 || in [ 1 ] != 80 || in [ 2 ] != 78 || in [ 3 ] != 71 || in [ 4 ] != 13 || in [ 5 ] != 10 || in [ 6 ] != 26 || in [ 7 ] != 10 ) { CERROR_RETURN_ERROR ( state -> error , 28 ) ; } if ( lodepng_chunk_length ( in + 8 ) != 13 ) { CERROR_RETURN_ERROR ( state -> error , 94 ) ; } if ( ! lodepng_chunk_type_equals ( in + 8 , " " ) ) { CERROR_RETURN_ERROR ( state -> error , 29 ) ; } width = lodepng_read32bitInt ( & in [ 16 ] ) ; height = lodepng_read32bitInt ( & in [ 20 ] ) ; if ( w ) * w = width ; if ( h ) * h = height ; info -> color . bitdepth = in [ 24 ] ; info -> color . colortype = ( LodePNGColorType ) in [ 25 ] ; info -> compression_method = in [ 26 ] ; info -> filter_method = in [ 27 ] ; info -> interlace_method = in [ 28 ] ; if ( width == 0 || height == 0 ) CERROR_RETURN_ERROR ( state -> error , 93 ) ; state -> error = checkColorValidity ( info -> color . colortype , info -> color . bitdepth ) ; if ( state -> error ) return state -> error ; if ( info -> compression_method != 0 ) CERROR_RETURN_ERROR ( state -> error , 32 ) ; if ( info -> filter_method != 0 ) CERROR_RETURN_ERROR ( state -> error , 33 ) ; if ( info -> interlace_method > 1 ) CERROR_RETURN_ERROR ( state -> error , 34 ) ; if ( ! state -> decoder . ignore_crc ) { unsigned CRC = lodepng_read32bitInt ( & in [ 29 ] ) ; unsigned checksum = lodepng_crc32 ( & in [ 12 ] , 17 ) ; if ( CRC != checksum ) { CERROR_RETURN_ERROR ( state -> error , 57 ) ; } } return state -> error ; }
read the information from the header and store it in the LodePNGInfo.
read the information from the header and store it in the LodePNGInfo .
/*error: the given data is empty*/ /*error: the data length is smaller than the length of a PNG header*/ /*when decoding a new PNG image, make sure all parameters created after previous decoding are reset*/ /* TODO: remove this. One should use a new LodePNGState for new sessions */ /*error: the first 8 bytes are not the correct PNG signature*/ /*error: header size must be 13 bytes*/ /*error: it doesn't start with a IHDR chunk!*/ /*read the values given in the header*/ /*TODO: remove the undocumented feature that allows to give null pointers to width or height*/ /*errors returned only after the parsing so other values are still output*/ /*error: invalid image size*/ /*error: invalid colortype or bitdepth combination*/ /*error: only compression method 0 is allowed in the specification*/ /*error: only filter method 0 is allowed in the specification*/ /*error: only interlace methods 0 and 1 exist in the specification*/ /*invalid CRC*/