Get RGBA8 color of pixel with index i (y * width + x) from the raw image with given color type.*/
| 3225 | |
| 3226 | /*Get RGBA8 color of pixel with index i (y * width + x) from the raw image with given color type.*/ |
| 3227 | static void getPixelColorRGBA8(unsigned char* r, unsigned char* g, |
| 3228 | unsigned char* b, unsigned char* a, |
| 3229 | const unsigned char* in, size_t i, |
| 3230 | const LodePNGColorMode* mode) |
| 3231 | { |
| 3232 | if(mode->colortype == LCT_GREY) |
| 3233 | { |
| 3234 | if(mode->bitdepth == 8) |
| 3235 | { |
| 3236 | *r = *g = *b = in[i]; |
| 3237 | if(mode->key_defined && *r == mode->key_r) *a = 0; |
| 3238 | else *a = 255; |
| 3239 | } |
| 3240 | else if(mode->bitdepth == 16) |
| 3241 | { |
| 3242 | *r = *g = *b = in[i * 2 + 0]; |
| 3243 | if(mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0; |
| 3244 | else *a = 255; |
| 3245 | } |
| 3246 | else |
| 3247 | { |
| 3248 | unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/ |
| 3249 | size_t j = i * mode->bitdepth; |
| 3250 | unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); |
| 3251 | *r = *g = *b = (value * 255) / highest; |
| 3252 | if(mode->key_defined && value == mode->key_r) *a = 0; |
| 3253 | else *a = 255; |
| 3254 | } |
| 3255 | } |
| 3256 | else if(mode->colortype == LCT_RGB) |
| 3257 | { |
| 3258 | if(mode->bitdepth == 8) |
| 3259 | { |
| 3260 | *r = in[i * 3 + 0]; *g = in[i * 3 + 1]; *b = in[i * 3 + 2]; |
| 3261 | if(mode->key_defined && *r == mode->key_r && *g == mode->key_g && *b == mode->key_b) *a = 0; |
| 3262 | else *a = 255; |
| 3263 | } |
| 3264 | else |
| 3265 | { |
| 3266 | *r = in[i * 6 + 0]; |
| 3267 | *g = in[i * 6 + 2]; |
| 3268 | *b = in[i * 6 + 4]; |
| 3269 | if(mode->key_defined && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r |
| 3270 | && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g |
| 3271 | && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b) *a = 0; |
| 3272 | else *a = 255; |
| 3273 | } |
| 3274 | } |
| 3275 | else if(mode->colortype == LCT_PALETTE) |
| 3276 | { |
| 3277 | unsigned index; |
| 3278 | if(mode->bitdepth == 8) index = in[i]; |
| 3279 | else |
| 3280 | { |
| 3281 | size_t j = i * mode->bitdepth; |
| 3282 | index = readBitsFromReversedStream(&j, in, mode->bitdepth); |
| 3283 | } |
| 3284 |
no test coverage detected