Similar to getPixelColorRGBA8, but with all the for loops inside of the color mode test cases, optimized to convert the colors much faster, when converting to RGBA or RGB with 8 bit per cannel. buffer must be RGBA or RGB output with enough memory, if has_alpha is true the output is RGBA. mode has the color mode of the input buffer.*/
| 3289 | enough memory, if has_alpha is true the output is RGBA. mode has the color mode |
| 3290 | of the input buffer.*/ |
| 3291 | static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels, |
| 3292 | unsigned has_alpha, const unsigned char* in, |
| 3293 | const LodePNGColorMode* mode) |
| 3294 | { |
| 3295 | unsigned num_channels = has_alpha ? 4 : 3; |
| 3296 | size_t i; |
| 3297 | if(mode->colortype == LCT_GREY) |
| 3298 | { |
| 3299 | if(mode->bitdepth == 8) |
| 3300 | { |
| 3301 | for(i = 0; i != numpixels; ++i, buffer += num_channels) |
| 3302 | { |
| 3303 | buffer[0] = buffer[1] = buffer[2] = in[i]; |
| 3304 | if(has_alpha) buffer[3] = mode->key_defined && in[i] == mode->key_r ? 0 : 255; |
| 3305 | } |
| 3306 | } |
| 3307 | else if(mode->bitdepth == 16) |
| 3308 | { |
| 3309 | for(i = 0; i != numpixels; ++i, buffer += num_channels) |
| 3310 | { |
| 3311 | buffer[0] = buffer[1] = buffer[2] = in[i * 2]; |
| 3312 | if(has_alpha) buffer[3] = mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r ? 0 : 255; |
| 3313 | } |
| 3314 | } |
| 3315 | else |
| 3316 | { |
| 3317 | unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/ |
| 3318 | size_t j = 0; |
| 3319 | for(i = 0; i != numpixels; ++i, buffer += num_channels) |
| 3320 | { |
| 3321 | unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); |
| 3322 | buffer[0] = buffer[1] = buffer[2] = (value * 255) / highest; |
| 3323 | if(has_alpha) buffer[3] = mode->key_defined && value == mode->key_r ? 0 : 255; |
| 3324 | } |
| 3325 | } |
| 3326 | } |
| 3327 | else if(mode->colortype == LCT_RGB) |
| 3328 | { |
| 3329 | if(mode->bitdepth == 8) |
| 3330 | { |
| 3331 | for(i = 0; i != numpixels; ++i, buffer += num_channels) |
| 3332 | { |
| 3333 | buffer[0] = in[i * 3 + 0]; |
| 3334 | buffer[1] = in[i * 3 + 1]; |
| 3335 | buffer[2] = in[i * 3 + 2]; |
| 3336 | if(has_alpha) buffer[3] = mode->key_defined && buffer[0] == mode->key_r |
| 3337 | && buffer[1]== mode->key_g && buffer[2] == mode->key_b ? 0 : 255; |
| 3338 | } |
| 3339 | } |
| 3340 | else |
| 3341 | { |
| 3342 | for(i = 0; i != numpixels; ++i, buffer += num_channels) |
| 3343 | { |
| 3344 | buffer[0] = in[i * 6 + 0]; |
| 3345 | buffer[1] = in[i * 6 + 2]; |
| 3346 | buffer[2] = in[i * 6 + 4]; |
| 3347 | if(has_alpha) buffer[3] = mode->key_defined |
| 3348 | && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r |
no test coverage detected