MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / getPixelColorRGBA8

Function getPixelColorRGBA8

dependency/densecrf/examples/lodepng.cpp:3181–3284  ·  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

3179
3180/*Get RGBA8 color of pixel with index i (y * width + x) from the raw image with given color type.*/
3181static void getPixelColorRGBA8(unsigned char* r, unsigned char* g,
3182 unsigned char* b, unsigned char* a,
3183 const unsigned char* in, size_t i,
3184 const LodePNGColorMode* mode)
3185{
3186 if(mode->colortype == LCT_GREY)
3187 {
3188 if(mode->bitdepth == 8)
3189 {
3190 *r = *g = *b = in[i];
3191 if(mode->key_defined && *r == mode->key_r) *a = 0;
3192 else *a = 255;
3193 }
3194 else if(mode->bitdepth == 16)
3195 {
3196 *r = *g = *b = in[i * 2 + 0];
3197 if(mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0;
3198 else *a = 255;
3199 }
3200 else
3201 {
3202 unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/
3203 size_t j = i * mode->bitdepth;
3204 unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth);
3205 *r = *g = *b = (value * 255) / highest;
3206 if(mode->key_defined && value == mode->key_r) *a = 0;
3207 else *a = 255;
3208 }
3209 }
3210 else if(mode->colortype == LCT_RGB)
3211 {
3212 if(mode->bitdepth == 8)
3213 {
3214 *r = in[i * 3 + 0]; *g = in[i * 3 + 1]; *b = in[i * 3 + 2];
3215 if(mode->key_defined && *r == mode->key_r && *g == mode->key_g && *b == mode->key_b) *a = 0;
3216 else *a = 255;
3217 }
3218 else
3219 {
3220 *r = in[i * 6 + 0];
3221 *g = in[i * 6 + 2];
3222 *b = in[i * 6 + 4];
3223 if(mode->key_defined && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r
3224 && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g
3225 && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b) *a = 0;
3226 else *a = 255;
3227 }
3228 }
3229 else if(mode->colortype == LCT_PALETTE)
3230 {
3231 unsigned index;
3232 if(mode->bitdepth == 8) index = in[i];
3233 else
3234 {
3235 size_t j = i * mode->bitdepth;
3236 index = readBitsFromReversedStream(&j, in, mode->bitdepth);
3237 }
3238

Callers 2

lodepng_convertFunction · 0.85

Calls 1

Tested by

no test coverage detected