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

Function lodepng_convert

samples/shared/lodepng.cpp:3409–3469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3407}
3408
3409unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
3410 LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in,
3411 unsigned w, unsigned h)
3412{
3413 size_t i;
3414 ColorTree tree;
3415 size_t numpixels = w * h;
3416
3417 if(lodepng_color_mode_equal(mode_out, mode_in))
3418 {
3419 size_t numbytes = lodepng_get_raw_size(w, h, mode_in);
3420 for(i = 0; i < numbytes; i++) out[i] = in[i];
3421 return 0;
3422 }
3423
3424 if(mode_out->colortype == LCT_PALETTE)
3425 {
3426 size_t palsize = (unsigned int)(1u << mode_out->bitdepth);
3427 if(mode_out->palettesize < palsize) palsize = mode_out->palettesize;
3428 color_tree_init(&tree);
3429 for(i = 0; i < palsize; i++)
3430 {
3431 unsigned char* p = &mode_out->palette[i * 4];
3432 color_tree_add(&tree, p[0], p[1], p[2], p[3], (unsigned int)i);
3433 }
3434 }
3435
3436 if(mode_in->bitdepth == 16 && mode_out->bitdepth == 16)
3437 {
3438 for(i = 0; i < numpixels; i++)
3439 {
3440 unsigned short r = 0, g = 0, b = 0, a = 0;
3441 getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in);
3442 rgba16ToPixel(out, i, mode_out, r, g, b, a);
3443 }
3444 }
3445 else if(mode_out->bitdepth == 8 && mode_out->colortype == LCT_RGBA)
3446 {
3447 getPixelColorsRGBA8(out, numpixels, 1, in, mode_in);
3448 }
3449 else if(mode_out->bitdepth == 8 && mode_out->colortype == LCT_RGB)
3450 {
3451 getPixelColorsRGBA8(out, numpixels, 0, in, mode_in);
3452 }
3453 else
3454 {
3455 unsigned char r = 0, g = 0, b = 0, a = 0;
3456 for(i = 0; i < numpixels; i++)
3457 {
3458 getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in);
3459 rgba8ToPixel(out, i, mode_out, &tree, r, g, b, a);
3460 }
3461 }
3462
3463 if(mode_out->colortype == LCT_PALETTE)
3464 {
3465 color_tree_cleanup(&tree);
3466 }

Callers 2

lodepng_decodeFunction · 0.85
lodepng_encodeFunction · 0.85

Calls 10

lodepng_color_mode_equalFunction · 0.85
lodepng_get_raw_sizeFunction · 0.85
color_tree_initFunction · 0.85
color_tree_addFunction · 0.85
getPixelColorRGBA16Function · 0.85
rgba16ToPixelFunction · 0.85
getPixelColorsRGBA8Function · 0.85
getPixelColorRGBA8Function · 0.85
rgba8ToPixelFunction · 0.85
color_tree_cleanupFunction · 0.85

Tested by

no test coverage detected