rEFIt_UEFI/libeg/lodepng.cpp
/*out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the full image.
return value is error**/
out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the full image.
return value is error
out must be buffer big enough to contain uncompressed IDAT chunk data and in must contain the full image . return value is error
static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const unsigned char* in,
                                    unsigned w, unsigned h,
                                    const LodePNGInfo* info_png, const LodePNGEncoderSettings* settings) {
  unsigned bpp = lodepng_get_bpp(&info_png->color);
  unsigned error = 0;
  if(info_png->interlace_method == 0) {
    *outsize = h + (h * ((w * bpp + 7u) / 8u)); 
    *out = (unsigned char*)lodepng_malloc(*outsize);
    if(!(*out) && (*outsize)) error = 83; 
    if(!error) {
      if(bpp < 8 && w * bpp != ((w * bpp + 7u) / 8u) * 8u) {
        unsigned char* padded = (unsigned char*)lodepng_malloc(h * ((w * bpp + 7u) / 8u));
        if(!padded) error = 83; 
        if(!error) {
          addPaddingBits(padded, in, ((w * bpp + 7u) / 8u) * 8u, w * bpp, h);
          error = filter(*out, padded, w, h, &info_png->color, settings);
        }
        lodepng_free(padded);
      } else {
        error = filter(*out, in, w, h, &info_png->color, settings);
      }
    }
  } else  {
    unsigned passw[7], passh[7];
    size_t filter_passstart[8], padded_passstart[8], passstart[8];
    unsigned char* adam7;
    Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
    *outsize = filter_passstart[7]; 
    *out = (unsigned char*)lodepng_malloc(*outsize);
    if(!(*out)) error = 83; 
    adam7 = (unsigned char*)lodepng_malloc(passstart[7]);
    if(!adam7 && passstart[7]) error = 83; 
    if(!error) {
      unsigned i;
      Adam7_interlace(adam7, in, w, h, bpp);
      for(i = 0; i != 7; ++i) {
        if(bpp < 8) {
          unsigned char* padded = (unsigned char*)lodepng_malloc(padded_passstart[i + 1] - padded_passstart[i]);
          if(!padded) ERROR_BREAK(83); 
          addPaddingBits(padded, &adam7[passstart[i]],
                         ((passw[i] * bpp + 7u) / 8u) * 8u, passw[i] * bpp, passh[i]);
          error = filter(&(*out)[filter_passstart[i]], padded,
                         passw[i], passh[i], &info_png->color, settings);
          lodepng_free(padded);
        } else {
          error = filter(&(*out)[filter_passstart[i]], &adam7[padded_passstart[i]],
                         passw[i], passh[i], &info_png->color, settings);
        }
        if(error) break;
      }
    }
    lodepng_free(adam7);
  }
  return error;
}
static unsigned preProcessScanlines ( unsigned char * * out , size_t * outsize , const unsigned char * in , unsigned w , unsigned h , const LodePNGInfo * info_png , const LodePNGEncoderSettings * settings ) { unsigned bpp = lodepng_get_bpp ( & info_png -> color ) ; unsigned error = 0 ; if ( info_png -> interlace_method == 0 ) { * outsize = h + ( h * ( ( w * bpp + 7u ) / 8u ) ) ; * out = ( unsigned char * ) lodepng_malloc ( * outsize ) ; if ( ! ( * out ) && ( * outsize ) ) error = 83 ; if ( ! error ) { if ( bpp < 8 && w * bpp != ( ( w * bpp + 7u ) / 8u ) * 8u ) { unsigned char * padded = ( unsigned char * ) lodepng_malloc ( h * ( ( w * bpp + 7u ) / 8u ) ) ; if ( ! padded ) error = 83 ; if ( ! error ) { addPaddingBits ( padded , in , ( ( w * bpp + 7u ) / 8u ) * 8u , w * bpp , h ) ; error = filter ( * out , padded , w , h , & info_png -> color , settings ) ; } lodepng_free ( padded ) ; } else { error = filter ( * out , in , w , h , & info_png -> color , settings ) ; } } } else { unsigned passw [ 7 ] , passh [ 7 ] ; size_t filter_passstart [ 8 ] , padded_passstart [ 8 ] , passstart [ 8 ] ; unsigned char * adam7 ; Adam7_getpassvalues ( passw , passh , filter_passstart , padded_passstart , passstart , w , h , bpp ) ; * outsize = filter_passstart [ 7 ] ; * out = ( unsigned char * ) lodepng_malloc ( * outsize ) ; if ( ! ( * out ) ) error = 83 ; adam7 = ( unsigned char * ) lodepng_malloc ( passstart [ 7 ] ) ; if ( ! adam7 && passstart [ 7 ] ) error = 83 ; if ( ! error ) { unsigned i ; Adam7_interlace ( adam7 , in , w , h , bpp ) ; for ( i = 0 ; i != 7 ; ++ i ) { if ( bpp < 8 ) { unsigned char * padded = ( unsigned char * ) lodepng_malloc ( padded_passstart [ i + 1 ] - padded_passstart [ i ] ) ; if ( ! padded ) ERROR_BREAK ( 83 ) ; addPaddingBits ( padded , & adam7 [ passstart [ i ] ] , ( ( passw [ i ] * bpp + 7u ) / 8u ) * 8u , passw [ i ] * bpp , passh [ i ] ) ; error = filter ( & ( * out ) [ filter_passstart [ i ] ] , padded , passw [ i ] , passh [ i ] , & info_png -> color , settings ) ; lodepng_free ( padded ) ; } else { error = filter ( & ( * out ) [ filter_passstart [ i ] ] , & adam7 [ padded_passstart [ i ] ] , passw [ i ] , passh [ i ] , & info_png -> color , settings ) ; } if ( error ) break ; } } lodepng_free ( adam7 ) ; } return error ; }
out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the full image.
out must be buffer big enough to contain uncompressed IDAT chunk data and in must contain the full image .
/*
  This function converts the pure 2D image with the PNG's colortype, into filtered-padded-interlaced data. Steps:
  *) if no Adam7: 1) add padding bits (= possible extra bits per scanline if bpp < 8) 2) filter
  *) if adam7: 1) Adam7_interlace 2) 7x add padding bits 3) 7x filter
  */ /*image size plus an extra byte per scanline + possible padding bits*/ /*alloc fail*/ /*non multiple of 8 bits per scanline, padding bits needed per scanline*/ /*alloc fail*/ /*we can immediately filter into the out buffer, no other steps needed*/ /*interlace_method is 1 (Adam7)*/ /*image size plus an extra byte per scanline + possible padding bits*/ /*alloc fail*/ /*alloc fail*/ /*alloc fail*/