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

Function get_color_profile

samples/shared/lodepng.cpp:3507–3662  ·  view source on GitHub ↗

profile must already have been inited with mode. It's ok to set some parameters of profile to done already.*/

Source from the content-addressed store, hash-verified

3505/*profile must already have been inited with mode.
3506It's ok to set some parameters of profile to done already.*/
3507unsigned get_color_profile(LodePNGColorProfile* profile,
3508 const unsigned char* in, unsigned w, unsigned h,
3509 const LodePNGColorMode* mode)
3510{
3511 unsigned error = 0;
3512 size_t i;
3513 ColorTree tree;
3514 size_t numpixels = w * h;
3515
3516 unsigned colored_done = lodepng_is_greyscale_type(mode) ? 1 : 0;
3517 unsigned alpha_done = lodepng_can_have_alpha(mode) ? 0 : 1;
3518 unsigned numcolors_done = 0;
3519 unsigned bpp = lodepng_get_bpp(mode);
3520 unsigned bits_done = bpp == 1 ? 1 : 0;
3521 unsigned maxnumcolors = 257;
3522 unsigned sixteen = 0;
3523 if(bpp <= 8) maxnumcolors = bpp == 1 ? 2 : (bpp == 2 ? 4 : (bpp == 4 ? 16 : 256));
3524
3525 color_tree_init(&tree);
3526
3527 /*Check if the 16-bit input is truly 16-bit*/
3528 if(mode->bitdepth == 16)
3529 {
3530 unsigned short r, g, b, a;
3531 for(i = 0; i < numpixels; i++)
3532 {
3533 getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode);
3534 if(r % 257u != 0 || g % 257u != 0 || b % 257u != 0 || a % 257u != 0) /*first and second byte differ*/
3535 {
3536 sixteen = 1;
3537 break;
3538 }
3539 }
3540 }
3541
3542 if(sixteen)
3543 {
3544 unsigned short r = 0, g = 0, b = 0, a = 0;
3545 profile->bits = 16;
3546 bits_done = numcolors_done = 1; /*counting colors no longer useful, palette doesn't support 16-bit*/
3547
3548 for(i = 0; i < numpixels; i++)
3549 {
3550 getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode);
3551
3552 if(!colored_done && (r != g || r != b))
3553 {
3554 profile->colored = 1;
3555 colored_done = 1;
3556 }
3557
3558 if(!alpha_done)
3559 {
3560 unsigned matchkey = (r == profile->key_r && g == profile->key_g && b == profile->key_b);
3561 if(a != 65535 && (a != 0 || (profile->key && !matchkey)))
3562 {
3563 profile->alpha = 1;
3564 alpha_done = 1;

Callers 1

Calls 10

lodepng_can_have_alphaFunction · 0.85
lodepng_get_bppFunction · 0.85
color_tree_initFunction · 0.85
getPixelColorRGBA16Function · 0.85
getPixelColorRGBA8Function · 0.85
getValueRequiredBitsFunction · 0.85
color_tree_hasFunction · 0.85
color_tree_addFunction · 0.85
color_tree_cleanupFunction · 0.85

Tested by

no test coverage detected