MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / rgba8ToPixel

Function rgba8ToPixel

src/lodepng.cpp:2982–3053  ·  view source on GitHub ↗

put a pixel, given its RGBA color, into image of any color type*/

Source from the content-addressed store, hash-verified

2980
2981/*put a pixel, given its RGBA color, into image of any color type*/
2982static unsigned rgba8ToPixel(unsigned char* out, size_t i,
2983 const LodePNGColorMode* mode, ColorTree* tree /*for palette*/,
2984 unsigned char r, unsigned char g, unsigned char b, unsigned char a)
2985{
2986 if(mode->colortype == LCT_GREY)
2987 {
2988 unsigned char grey = r; /*((unsigned short)r + g + b) / 3*/;
2989 if(mode->bitdepth == 8) out[i] = grey;
2990 else if(mode->bitdepth == 16) out[i * 2 + 0] = out[i * 2 + 1] = grey;
2991 else
2992 {
2993 /*take the most significant bits of grey*/
2994 grey = (grey >> (8 - mode->bitdepth)) & ((1 << mode->bitdepth) - 1);
2995 addColorBits(out, i, mode->bitdepth, grey);
2996 }
2997 }
2998 else if(mode->colortype == LCT_RGB)
2999 {
3000 if(mode->bitdepth == 8)
3001 {
3002 out[i * 3 + 0] = r;
3003 out[i * 3 + 1] = g;
3004 out[i * 3 + 2] = b;
3005 }
3006 else
3007 {
3008 out[i * 6 + 0] = out[i * 6 + 1] = r;
3009 out[i * 6 + 2] = out[i * 6 + 3] = g;
3010 out[i * 6 + 4] = out[i * 6 + 5] = b;
3011 }
3012 }
3013 else if(mode->colortype == LCT_PALETTE)
3014 {
3015 int index = color_tree_get(tree, r, g, b, a);
3016 if(index < 0) return 82; /*color not in palette*/
3017 if(mode->bitdepth == 8) out[i] = index;
3018 else addColorBits(out, i, mode->bitdepth, index);
3019 }
3020 else if(mode->colortype == LCT_GREY_ALPHA)
3021 {
3022 unsigned char grey = r; /*((unsigned short)r + g + b) / 3*/;
3023 if(mode->bitdepth == 8)
3024 {
3025 out[i * 2 + 0] = grey;
3026 out[i * 2 + 1] = a;
3027 }
3028 else if(mode->bitdepth == 16)
3029 {
3030 out[i * 4 + 0] = out[i * 4 + 1] = grey;
3031 out[i * 4 + 2] = out[i * 4 + 3] = a;
3032 }
3033 }
3034 else if(mode->colortype == LCT_RGBA)
3035 {
3036 if(mode->bitdepth == 8)
3037 {
3038 out[i * 4 + 0] = r;
3039 out[i * 4 + 1] = g;

Callers 1

lodepng_convertFunction · 0.85

Calls 2

addColorBitsFunction · 0.85
color_tree_getFunction · 0.85

Tested by

no test coverage detected