MCPcopy Create free account
hub / github.com/DFHack/dfhack / getPixelColorsRGB8

Function getPixelColorsRGB8

depends/lodepng/lodepng.cpp:3424–3494  ·  view source on GitHub ↗

Similar to getPixelColorsRGBA8, but with 3-channel RGB output.*/

Source from the content-addressed store, hash-verified

3422
3423/*Similar to getPixelColorsRGBA8, but with 3-channel RGB output.*/
3424static void getPixelColorsRGB8(unsigned char* LODEPNG_RESTRICT buffer, size_t numpixels,
3425 const unsigned char* LODEPNG_RESTRICT in,
3426 const LodePNGColorMode* mode) {
3427 const unsigned num_channels = 3;
3428 size_t i;
3429 if(mode->colortype == LCT_GREY) {
3430 if(mode->bitdepth == 8) {
3431 for(i = 0; i != numpixels; ++i, buffer += num_channels) {
3432 buffer[0] = buffer[1] = buffer[2] = in[i];
3433 }
3434 } else if(mode->bitdepth == 16) {
3435 for(i = 0; i != numpixels; ++i, buffer += num_channels) {
3436 buffer[0] = buffer[1] = buffer[2] = in[i * 2];
3437 }
3438 } else {
3439 unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/
3440 size_t j = 0;
3441 for(i = 0; i != numpixels; ++i, buffer += num_channels) {
3442 unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth);
3443 buffer[0] = buffer[1] = buffer[2] = (value * 255) / highest;
3444 }
3445 }
3446 } else if(mode->colortype == LCT_RGB) {
3447 if(mode->bitdepth == 8) {
3448 lodepng_memcpy(buffer, in, numpixels * 3);
3449 } else {
3450 for(i = 0; i != numpixels; ++i, buffer += num_channels) {
3451 buffer[0] = in[i * 6 + 0];
3452 buffer[1] = in[i * 6 + 2];
3453 buffer[2] = in[i * 6 + 4];
3454 }
3455 }
3456 } else if(mode->colortype == LCT_PALETTE) {
3457 if(mode->bitdepth == 8) {
3458 for(i = 0; i != numpixels; ++i, buffer += num_channels) {
3459 unsigned index = in[i];
3460 /*out of bounds of palette not checked: see lodepng_color_mode_alloc_palette.*/
3461 lodepng_memcpy(buffer, &mode->palette[index * 4], 3);
3462 }
3463 } else {
3464 size_t j = 0;
3465 for(i = 0; i != numpixels; ++i, buffer += num_channels) {
3466 unsigned index = readBitsFromReversedStream(&j, in, mode->bitdepth);
3467 /*out of bounds of palette not checked: see lodepng_color_mode_alloc_palette.*/
3468 lodepng_memcpy(buffer, &mode->palette[index * 4], 3);
3469 }
3470 }
3471 } else if(mode->colortype == LCT_GREY_ALPHA) {
3472 if(mode->bitdepth == 8) {
3473 for(i = 0; i != numpixels; ++i, buffer += num_channels) {
3474 buffer[0] = buffer[1] = buffer[2] = in[i * 2 + 0];
3475 }
3476 } else {
3477 for(i = 0; i != numpixels; ++i, buffer += num_channels) {
3478 buffer[0] = buffer[1] = buffer[2] = in[i * 4 + 0];
3479 }
3480 }
3481 } else if(mode->colortype == LCT_RGBA) {

Callers 1

lodepng_convertFunction · 0.85

Calls 2

lodepng_memcpyFunction · 0.85

Tested by

no test coverage detected