rEFIt_UEFI/libeg/lodepng.cpp
/*put a pixel, given its RGBA color, into image of any color type*/
put a pixel, given its RGBA color, into image of any color type
put a pixel given its RGBA color into image of any color type
static unsigned rgba8ToPixel(unsigned char* out, size_t i,
                             const LodePNGColorMode* mode, ColorTree* tree ,
                             unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
  if(mode->colortype == LCT_GREY) {
    unsigned char gray = r; 
    if(mode->bitdepth == 8) out[i] = gray;
    else if(mode->bitdepth == 16) out[i * 2 + 0] = out[i * 2 + 1] = gray;
    else {
      gray = ((unsigned)gray >> (8u - mode->bitdepth)) & ((1u << mode->bitdepth) - 1u);
      addColorBits(out, i, mode->bitdepth, gray);
    }
  } else if(mode->colortype == LCT_RGB) {
    if(mode->bitdepth == 8) {
      out[i * 3 + 0] = r;
      out[i * 3 + 1] = g;
      out[i * 3 + 2] = b;
    } else {
      out[i * 6 + 0] = out[i * 6 + 1] = r;
      out[i * 6 + 2] = out[i * 6 + 3] = g;
      out[i * 6 + 4] = out[i * 6 + 5] = b;
    }
  } else if(mode->colortype == LCT_PALETTE) {
    int index = color_tree_get(tree, r, g, b, a);
    if(index < 0) return 82; 
    if(mode->bitdepth == 8) out[i] = index;
    else addColorBits(out, i, mode->bitdepth, (unsigned)index);
  } else if(mode->colortype == LCT_GREY_ALPHA) {
    unsigned char gray = r; 
    if(mode->bitdepth == 8) {
      out[i * 2 + 0] = gray;
      out[i * 2 + 1] = a;
    } else if(mode->bitdepth == 16) {
      out[i * 4 + 0] = out[i * 4 + 1] = gray;
      out[i * 4 + 2] = out[i * 4 + 3] = a;
    }
  } else if(mode->colortype == LCT_RGBA) {
    if(mode->bitdepth == 8) {
      out[i * 4 + 0] = r;
      out[i * 4 + 1] = g;
      out[i * 4 + 2] = b;
      out[i * 4 + 3] = a;
    } else {
      out[i * 8 + 0] = out[i * 8 + 1] = r;
      out[i * 8 + 2] = out[i * 8 + 3] = g;
      out[i * 8 + 4] = out[i * 8 + 5] = b;
      out[i * 8 + 6] = out[i * 8 + 7] = a;
    }
  }
  return 0; 
}
static unsigned rgba8ToPixel ( unsigned char * out , size_t i , const LodePNGColorMode * mode , ColorTree * tree , unsigned char r , unsigned char g , unsigned char b , unsigned char a ) { if ( mode -> colortype == LCT_GREY ) { unsigned char gray = r ; if ( mode -> bitdepth == 8 ) out [ i ] = gray ; else if ( mode -> bitdepth == 16 ) out [ i * 2 + 0 ] = out [ i * 2 + 1 ] = gray ; else { gray = ( ( unsigned ) gray >> ( 8u - mode -> bitdepth ) ) & ( ( 1u << mode -> bitdepth ) - 1u ) ; addColorBits ( out , i , mode -> bitdepth , gray ) ; } } else if ( mode -> colortype == LCT_RGB ) { if ( mode -> bitdepth == 8 ) { out [ i * 3 + 0 ] = r ; out [ i * 3 + 1 ] = g ; out [ i * 3 + 2 ] = b ; } else { out [ i * 6 + 0 ] = out [ i * 6 + 1 ] = r ; out [ i * 6 + 2 ] = out [ i * 6 + 3 ] = g ; out [ i * 6 + 4 ] = out [ i * 6 + 5 ] = b ; } } else if ( mode -> colortype == LCT_PALETTE ) { int index = color_tree_get ( tree , r , g , b , a ) ; if ( index < 0 ) return 82 ; if ( mode -> bitdepth == 8 ) out [ i ] = index ; else addColorBits ( out , i , mode -> bitdepth , ( unsigned ) index ) ; } else if ( mode -> colortype == LCT_GREY_ALPHA ) { unsigned char gray = r ; if ( mode -> bitdepth == 8 ) { out [ i * 2 + 0 ] = gray ; out [ i * 2 + 1 ] = a ; } else if ( mode -> bitdepth == 16 ) { out [ i * 4 + 0 ] = out [ i * 4 + 1 ] = gray ; out [ i * 4 + 2 ] = out [ i * 4 + 3 ] = a ; } } else if ( mode -> colortype == LCT_RGBA ) { if ( mode -> bitdepth == 8 ) { out [ i * 4 + 0 ] = r ; out [ i * 4 + 1 ] = g ; out [ i * 4 + 2 ] = b ; out [ i * 4 + 3 ] = a ; } else { out [ i * 8 + 0 ] = out [ i * 8 + 1 ] = r ; out [ i * 8 + 2 ] = out [ i * 8 + 3 ] = g ; out [ i * 8 + 4 ] = out [ i * 8 + 5 ] = b ; out [ i * 8 + 6 ] = out [ i * 8 + 7 ] = a ; } } return 0 ; }
put a pixel, given its RGBA color, into image of any color type
put a pixel given its RGBA color into image of any color type
/*for palette*/ /*((unsigned short)r + g + b) / 3u;*/ /*take the most significant bits of gray*/ /*color not in palette*/ /*((unsigned short)r + g + b) / 3u;*/ /*no error*/