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

Function getPixelColorRGBA8

src/lodepng.cpp:3100–3206  ·  view source on GitHub ↗

Get RGBA8 color of pixel with index i (y * width + x) from the raw image with given color type.*/

Source from the content-addressed store, hash-verified

3098
3099/*Get RGBA8 color of pixel with index i (y * width + x) from the raw image with given color type.*/
3100static unsigned getPixelColorRGBA8(unsigned char* r, unsigned char* g,
3101 unsigned char* b, unsigned char* a,
3102 const unsigned char* in, size_t i,
3103 const LodePNGColorMode* mode,
3104 unsigned fix_png)
3105{
3106 if(mode->colortype == LCT_GREY)
3107 {
3108 if(mode->bitdepth == 8)
3109 {
3110 *r = *g = *b = in[i];
3111 if(mode->key_defined && *r == mode->key_r) *a = 0;
3112 else *a = 255;
3113 }
3114 else if(mode->bitdepth == 16)
3115 {
3116 *r = *g = *b = in[i * 2 + 0];
3117 if(mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0;
3118 else *a = 255;
3119 }
3120 else
3121 {
3122 unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/
3123 size_t j = i * mode->bitdepth;
3124 unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth);
3125 *r = *g = *b = (value * 255) / highest;
3126 if(mode->key_defined && value == mode->key_r) *a = 0;
3127 else *a = 255;
3128 }
3129 }
3130 else if(mode->colortype == LCT_RGB)
3131 {
3132 if(mode->bitdepth == 8)
3133 {
3134 *r = in[i * 3 + 0]; *g = in[i * 3 + 1]; *b = in[i * 3 + 2];
3135 if(mode->key_defined && *r == mode->key_r && *g == mode->key_g && *b == mode->key_b) *a = 0;
3136 else *a = 255;
3137 }
3138 else
3139 {
3140 *r = in[i * 6 + 0];
3141 *g = in[i * 6 + 2];
3142 *b = in[i * 6 + 4];
3143 if(mode->key_defined && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r
3144 && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g
3145 && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b) *a = 0;
3146 else *a = 255;
3147 }
3148 }
3149 else if(mode->colortype == LCT_PALETTE)
3150 {
3151 unsigned index;
3152 if(mode->bitdepth == 8) index = in[i];
3153 else
3154 {
3155 size_t j = i * mode->bitdepth;
3156 index = readBitsFromReversedStream(&j, in, mode->bitdepth);
3157 }

Callers 2

lodepng_convertFunction · 0.85
get_color_profileFunction · 0.85

Calls 1

Tested by

no test coverage detected