rEFIt_UEFI/libeg/lodepng.cpp
/*
in: Adam7 interlaced image, with no padding bits between scanlines, but between
 reduced images so that each reduced image starts at a byte.
out: the same pixels, but re-ordered so that they're now a non-interlaced image with size w*h
bpp: bits per pixel
out has the following size in bits: w * h * bpp.
in is possibly bigger due to padding bits between reduced images.
out must be big enough AND must be 0 everywhere if bpp < 8 in the current implementation
(because that's likely a little bit faster)
NOTE: comments about padding bits are only relevant if bpp < 8
*/
Adam7 interlaced image, with no padding bits between scanlines, but between
reduced images so that each reduced image starts at a byte.
out: the same pixels, but re-ordered so that they're now a non-interlaced image with size w*h
bpp: bits per pixel
out has the following size in bits: w * h * bpp.
in is possibly bigger due to padding bits between reduced images.
out must be big enough AND must be 0 everywhere if bpp < 8 in the current implementation
(because that's likely a little bit faster)
NOTE: comments about padding bits are only relevant if bpp < 8
Adam7 interlaced image with no padding bits between scanlines but between reduced images so that each reduced image starts at a byte . out : the same pixels but re - ordered so that they ' re now a non - interlaced image with size w * h bpp : bits per pixel out has the following size in bits : w * h * bpp . in is possibly bigger due to padding bits between reduced images . out must be big enough AND must be 0 everywhere if bpp < 8 in the current implementation ( because that ' s likely a little bit faster ) NOTE : comments about padding bits are only relevant if bpp < 8
static void Adam7_deinterlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) {
  unsigned passw[7], passh[7];
  size_t filter_passstart[8], padded_passstart[8], passstart[8];
  unsigned i;
  Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
  if(bpp >= 8) {
    for(i = 0; i != 7; ++i) {
      unsigned x, y, b;
      size_t bytewidth = bpp / 8u;
      for(y = 0; y < passh[i]; ++y)
      for(x = 0; x < passw[i]; ++x) {
        size_t pixelinstart = passstart[i] + (y * passw[i] + x) * bytewidth;
        size_t pixeloutstart = ((ADAM7_IY[i] + (size_t)y * ADAM7_DY[i]) * (size_t)w
                             + ADAM7_IX[i] + (size_t)x * ADAM7_DX[i]) * bytewidth;
        for(b = 0; b < bytewidth; ++b) {
          out[pixeloutstart + b] = in[pixelinstart + b];
        }
      }
    }
  } else  {
    for(i = 0; i != 7; ++i) {
      unsigned x, y, b;
      unsigned ilinebits = bpp * passw[i];
      unsigned olinebits = bpp * w;
      size_t obp, ibp; 
      for(y = 0; y < passh[i]; ++y)
      for(x = 0; x < passw[i]; ++x) {
        ibp = (8 * passstart[i]) + (y * ilinebits + x * bpp);
        obp = (ADAM7_IY[i] + (size_t)y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + (size_t)x * ADAM7_DX[i]) * bpp;
        for(b = 0; b < bpp; ++b) {
          unsigned char bit = readBitFromReversedStream(&ibp, in);
          setBitOfReversedStream(&obp, out, bit);
        }
      }
    }
  }
}
static void Adam7_deinterlace ( unsigned char * out , const unsigned char * in , unsigned w , unsigned h , unsigned bpp ) { unsigned passw [ 7 ] , passh [ 7 ] ; size_t filter_passstart [ 8 ] , padded_passstart [ 8 ] , passstart [ 8 ] ; unsigned i ; Adam7_getpassvalues ( passw , passh , filter_passstart , padded_passstart , passstart , w , h , bpp ) ; if ( bpp >= 8 ) { for ( i = 0 ; i != 7 ; ++ i ) { unsigned x , y , b ; size_t bytewidth = bpp / 8u ; for ( y = 0 ; y < passh [ i ] ; ++ y ) for ( x = 0 ; x < passw [ i ] ; ++ x ) { size_t pixelinstart = passstart [ i ] + ( y * passw [ i ] + x ) * bytewidth ; size_t pixeloutstart = ( ( ADAM7_IY [ i ] + ( size_t ) y * ADAM7_DY [ i ] ) * ( size_t ) w + ADAM7_IX [ i ] + ( size_t ) x * ADAM7_DX [ i ] ) * bytewidth ; for ( b = 0 ; b < bytewidth ; ++ b ) { out [ pixeloutstart + b ] = in [ pixelinstart + b ] ; } } } } else { for ( i = 0 ; i != 7 ; ++ i ) { unsigned x , y , b ; unsigned ilinebits = bpp * passw [ i ] ; unsigned olinebits = bpp * w ; size_t obp , ibp ; for ( y = 0 ; y < passh [ i ] ; ++ y ) for ( x = 0 ; x < passw [ i ] ; ++ x ) { ibp = ( 8 * passstart [ i ] ) + ( y * ilinebits + x * bpp ) ; obp = ( ADAM7_IY [ i ] + ( size_t ) y * ADAM7_DY [ i ] ) * olinebits + ( ADAM7_IX [ i ] + ( size_t ) x * ADAM7_DX [ i ] ) * bpp ; for ( b = 0 ; b < bpp ; ++ b ) { unsigned char bit = readBitFromReversedStream ( & ibp , in ) ; setBitOfReversedStream ( & obp , out , bit ) ; } } } } }
in: Adam7 interlaced image, with no padding bits between scanlines, but between
reduced images so that each reduced image starts at a byte.
in : Adam7 interlaced image with no padding bits between scanlines but between reduced images so that each reduced image starts at a byte .
/*bpp < 8: Adam7 with pixels < 8 bit is a bit trickier: with bit pointers*/ /*bit pointers (for out and in buffer)*/