MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / getPixelColorsRGBA8

Function getPixelColorsRGBA8

samples/shared/lodepng.cpp:3242–3372  ·  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

3240enough memory, if has_alpha is true the output is RGBA. mode has the color mode
3241of the input buffer.*/
3242static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels,
3243 unsigned has_alpha, const unsigned char* in,
3244 const LodePNGColorMode* mode)
3245{
3246 unsigned num_channels = has_alpha ? 4 : 3;
3247 size_t i;
3248 if(mode->colortype == LCT_GREY)
3249 {
3250 if(mode->bitdepth == 8)
3251 {
3252 for(i = 0; i < numpixels; i++, buffer += num_channels)
3253 {
3254 buffer[0] = buffer[1] = buffer[2] = in[i];
3255 if(has_alpha) buffer[3] = mode->key_defined && in[i] == mode->key_r ? 0 : 255;
3256 }
3257 }
3258 else if(mode->bitdepth == 16)
3259 {
3260 for(i = 0; i < numpixels; i++, buffer += num_channels)
3261 {
3262 buffer[0] = buffer[1] = buffer[2] = in[i * 2];
3263 if(has_alpha) buffer[3] = mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r ? 0 : 255;
3264 }
3265 }
3266 else
3267 {
3268 unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/
3269 size_t j = 0;
3270 for(i = 0; i < numpixels; i++, buffer += num_channels)
3271 {
3272 unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth);
3273 buffer[0] = buffer[1] = buffer[2] = (value * 255) / highest;
3274 if(has_alpha) buffer[3] = mode->key_defined && value == mode->key_r ? 0 : 255;
3275 }
3276 }
3277 }
3278 else if(mode->colortype == LCT_RGB)
3279 {
3280 if(mode->bitdepth == 8)
3281 {
3282 for(i = 0; i < numpixels; i++, buffer += num_channels)
3283 {
3284 buffer[0] = in[i * 3 + 0];
3285 buffer[1] = in[i * 3 + 1];
3286 buffer[2] = in[i * 3 + 2];
3287 if(has_alpha) buffer[3] = mode->key_defined && buffer[0] == mode->key_r
3288 && buffer[1]== mode->key_g && buffer[2] == mode->key_b ? 0 : 255;
3289 }
3290 }
3291 else
3292 {
3293 for(i = 0; i < numpixels; i++, buffer += num_channels)
3294 {
3295 buffer[0] = in[i * 6 + 0];
3296 buffer[1] = in[i * 6 + 2];
3297 buffer[2] = in[i * 6 + 4];
3298 if(has_alpha) buffer[3] = mode->key_defined
3299 && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r

Callers 1

lodepng_convertFunction · 0.85

Calls 1

Tested by

no test coverage detected