MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / getPixelColorsRGBA8

Function getPixelColorsRGBA8

src/lodepng.cpp:3213–3346  ·  view source on GitHub ↗

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.*/

Source from the content-addressed store, hash-verified

3211enough memory, if has_alpha is true the output is RGBA. mode has the color mode
3212of the input buffer.*/
3213static unsigned getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels,
3214 unsigned has_alpha, const unsigned char* in,
3215 const LodePNGColorMode* mode,
3216 unsigned fix_png)
3217{
3218 unsigned num_channels = has_alpha ? 4 : 3;
3219 size_t i;
3220 if(mode->colortype == LCT_GREY)
3221 {
3222 if(mode->bitdepth == 8)
3223 {
3224 for(i = 0; i < numpixels; i++, buffer += num_channels)
3225 {
3226 buffer[0] = buffer[1] = buffer[2] = in[i];
3227 if(has_alpha) buffer[3] = mode->key_defined && in[i] == mode->key_r ? 0 : 255;
3228 }
3229 }
3230 else if(mode->bitdepth == 16)
3231 {
3232 for(i = 0; i < numpixels; i++, buffer += num_channels)
3233 {
3234 buffer[0] = buffer[1] = buffer[2] = in[i * 2];
3235 if(has_alpha) buffer[3] = mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r ? 0 : 255;
3236 }
3237 }
3238 else
3239 {
3240 unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/
3241 size_t j = 0;
3242 for(i = 0; i < numpixels; i++, buffer += num_channels)
3243 {
3244 unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth);
3245 buffer[0] = buffer[1] = buffer[2] = (value * 255) / highest;
3246 if(has_alpha) buffer[3] = mode->key_defined && value == mode->key_r ? 0 : 255;
3247 }
3248 }
3249 }
3250 else if(mode->colortype == LCT_RGB)
3251 {
3252 if(mode->bitdepth == 8)
3253 {
3254 for(i = 0; i < numpixels; i++, buffer += num_channels)
3255 {
3256 buffer[0] = in[i * 3 + 0];
3257 buffer[1] = in[i * 3 + 1];
3258 buffer[2] = in[i * 3 + 2];
3259 if(has_alpha) buffer[3] = mode->key_defined && buffer[0] == mode->key_r
3260 && buffer[1]== mode->key_g && buffer[2] == mode->key_b ? 0 : 255;
3261 }
3262 }
3263 else
3264 {
3265 for(i = 0; i < numpixels; i++, buffer += num_channels)
3266 {
3267 buffer[0] = in[i * 6 + 0];
3268 buffer[1] = in[i * 6 + 2];
3269 buffer[2] = in[i * 6 + 4];
3270 if(has_alpha) buffer[3] = mode->key_defined

Callers 1

lodepng_convertFunction · 0.85

Calls 1

Tested by

no test coverage detected