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 the common case of RGBA with 8 bit per channel. buffer must be RGBA with enough memory.*/
| 3326 | to the common case of RGBA with 8 bit per channel. buffer must be RGBA with |
| 3327 | enough memory.*/ |
| 3328 | static void getPixelColorsRGBA8(unsigned char* LODEPNG_RESTRICT buffer, size_t numpixels, |
| 3329 | const unsigned char* LODEPNG_RESTRICT in, |
| 3330 | const LodePNGColorMode* mode) { |
| 3331 | unsigned num_channels = 4; |
| 3332 | size_t i; |
| 3333 | if(mode->colortype == LCT_GREY) { |
| 3334 | if(mode->bitdepth == 8) { |
| 3335 | for(i = 0; i != numpixels; ++i, buffer += num_channels) { |
| 3336 | buffer[0] = buffer[1] = buffer[2] = in[i]; |
| 3337 | buffer[3] = 255; |
| 3338 | } |
| 3339 | if(mode->key_defined) { |
| 3340 | buffer -= numpixels * num_channels; |
| 3341 | for(i = 0; i != numpixels; ++i, buffer += num_channels) { |
| 3342 | if(buffer[0] == mode->key_r) buffer[3] = 0; |
| 3343 | } |
| 3344 | } |
| 3345 | } else if(mode->bitdepth == 16) { |
| 3346 | for(i = 0; i != numpixels; ++i, buffer += num_channels) { |
| 3347 | buffer[0] = buffer[1] = buffer[2] = in[i * 2]; |
| 3348 | buffer[3] = mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r ? 0 : 255; |
| 3349 | } |
| 3350 | } else { |
| 3351 | unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/ |
| 3352 | size_t j = 0; |
| 3353 | for(i = 0; i != numpixels; ++i, buffer += num_channels) { |
| 3354 | unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); |
| 3355 | buffer[0] = buffer[1] = buffer[2] = (value * 255) / highest; |
| 3356 | buffer[3] = mode->key_defined && value == mode->key_r ? 0 : 255; |
| 3357 | } |
| 3358 | } |
| 3359 | } else if(mode->colortype == LCT_RGB) { |
| 3360 | if(mode->bitdepth == 8) { |
| 3361 | for(i = 0; i != numpixels; ++i, buffer += num_channels) { |
| 3362 | lodepng_memcpy(buffer, &in[i * 3], 3); |
| 3363 | buffer[3] = 255; |
| 3364 | } |
| 3365 | if(mode->key_defined) { |
| 3366 | buffer -= numpixels * num_channels; |
| 3367 | for(i = 0; i != numpixels; ++i, buffer += num_channels) { |
| 3368 | if(buffer[0] == mode->key_r && buffer[1]== mode->key_g && buffer[2] == mode->key_b) buffer[3] = 0; |
| 3369 | } |
| 3370 | } |
| 3371 | } else { |
| 3372 | for(i = 0; i != numpixels; ++i, buffer += num_channels) { |
| 3373 | buffer[0] = in[i * 6 + 0]; |
| 3374 | buffer[1] = in[i * 6 + 2]; |
| 3375 | buffer[2] = in[i * 6 + 4]; |
| 3376 | buffer[3] = mode->key_defined |
| 3377 | && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r |
| 3378 | && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g |
| 3379 | && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b ? 0 : 255; |
| 3380 | } |
| 3381 | } |
| 3382 | } else if(mode->colortype == LCT_PALETTE) { |
| 3383 | if(mode->bitdepth == 8) { |
| 3384 | for(i = 0; i != numpixels; ++i, buffer += num_channels) { |
| 3385 | unsigned index = in[i]; |
no test coverage detected