Get RGBA16 color of pixel with index i (y * width + x) from the raw image with given color type, but the given color type must be 16-bit itself.*/
| 3373 | /*Get RGBA16 color of pixel with index i (y * width + x) from the raw image with |
| 3374 | given color type, but the given color type must be 16-bit itself.*/ |
| 3375 | static unsigned getPixelColorRGBA16(unsigned short* r, unsigned short* g, unsigned short* b, unsigned short* a, |
| 3376 | const unsigned char* in, size_t i, const LodePNGColorMode* mode) |
| 3377 | { |
| 3378 | if(mode->bitdepth != 16) return 85; /*error: this function only supports 16-bit input*/ |
| 3379 | |
| 3380 | if(mode->colortype == LCT_GREY) |
| 3381 | { |
| 3382 | *r = *g = *b = 256 * in[i * 2 + 0] + in[i * 2 + 1]; |
| 3383 | if(mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0; |
| 3384 | else *a = 65535; |
| 3385 | } |
| 3386 | else if(mode->colortype == LCT_RGB) |
| 3387 | { |
| 3388 | *r = 256 * in[i * 6 + 0] + in[i * 6 + 1]; |
| 3389 | *g = 256 * in[i * 6 + 2] + in[i * 6 + 3]; |
| 3390 | *b = 256 * in[i * 6 + 4] + in[i * 6 + 5]; |
| 3391 | if(mode->key_defined && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r |
| 3392 | && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g |
| 3393 | && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b) *a = 0; |
| 3394 | else *a = 65535; |
| 3395 | } |
| 3396 | else if(mode->colortype == LCT_GREY_ALPHA) |
| 3397 | { |
| 3398 | *r = *g = *b = 256 * in[i * 4 + 0] + in[i * 4 + 1]; |
| 3399 | *a = 256 * in[i * 4 + 2] + in[i * 4 + 3]; |
| 3400 | } |
| 3401 | else if(mode->colortype == LCT_RGBA) |
| 3402 | { |
| 3403 | *r = 256 * in[i * 8 + 0] + in[i * 8 + 1]; |
| 3404 | *g = 256 * in[i * 8 + 2] + in[i * 8 + 3]; |
| 3405 | *b = 256 * in[i * 8 + 4] + in[i * 8 + 5]; |
| 3406 | *a = 256 * in[i * 8 + 6] + in[i * 8 + 7]; |
| 3407 | } |
| 3408 | else return 85; /*error: this function only supports 16-bit input, not palettes*/ |
| 3409 | |
| 3410 | return 0; /*no error*/ |
| 3411 | } |
| 3412 | |
| 3413 | /* |
| 3414 | converts from any color type to 24-bit or 32-bit (later maybe more supported). return value = LodePNG error code |
no outgoing calls
no test coverage detected