profile must already have been inited with mode. It's ok to set some parameters of profile to done already.*/
| 3551 | /*profile must already have been inited with mode. |
| 3552 | It's ok to set some parameters of profile to done already.*/ |
| 3553 | static unsigned get_color_profile(ColorProfile* profile, |
| 3554 | const unsigned char* in, |
| 3555 | size_t numpixels /*must be full image size, for certain filesize based choices*/, |
| 3556 | const LodePNGColorMode* mode, |
| 3557 | unsigned fix_png) |
| 3558 | { |
| 3559 | unsigned error = 0; |
| 3560 | size_t i; |
| 3561 | |
| 3562 | if(mode->bitdepth == 16) |
| 3563 | { |
| 3564 | for(i = 0; i < numpixels; i++) |
| 3565 | { |
| 3566 | unsigned short r, g, b, a; |
| 3567 | error = getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode); |
| 3568 | if(error) break; |
| 3569 | |
| 3570 | /*a color is considered good for 8-bit if the first byte and the second byte are equal, |
| 3571 | (so if it's divisible through 257), NOT necessarily if the second byte is 0*/ |
| 3572 | if(!profile->sixteenbit_done |
| 3573 | && (((r & 255) != ((r >> 8) & 255)) |
| 3574 | || ((g & 255) != ((g >> 8) & 255)) |
| 3575 | || ((b & 255) != ((b >> 8) & 255)))) |
| 3576 | { |
| 3577 | profile->sixteenbit = 1; |
| 3578 | profile->sixteenbit_done = 1; |
| 3579 | profile->greybits_done = 1; /*greybits is not applicable anymore at 16-bit*/ |
| 3580 | profile->numcolors_done = 1; /*counting colors no longer useful, palette doesn't support 16-bit*/ |
| 3581 | } |
| 3582 | |
| 3583 | if(!profile->colored_done && (r != g || r != b)) |
| 3584 | { |
| 3585 | profile->colored = 1; |
| 3586 | profile->colored_done = 1; |
| 3587 | profile->greybits_done = 1; /*greybits is not applicable anymore*/ |
| 3588 | } |
| 3589 | |
| 3590 | if(!profile->alpha_done && a != 65535) |
| 3591 | { |
| 3592 | /*only use color key if numpixels large enough to justify tRNS chunk size*/ |
| 3593 | if(a == 0 && numpixels > 16 && !(profile->key && (r != profile->key_r || g != profile->key_g || b != profile->key_b))) |
| 3594 | { |
| 3595 | if(!profile->alpha && !profile->key) |
| 3596 | { |
| 3597 | profile->key = 1; |
| 3598 | profile->key_r = r; |
| 3599 | profile->key_g = g; |
| 3600 | profile->key_b = b; |
| 3601 | } |
| 3602 | } |
| 3603 | else |
| 3604 | { |
| 3605 | profile->alpha = 1; |
| 3606 | profile->alpha_done = 1; |
| 3607 | profile->greybits_done = 1; /*greybits is not applicable anymore*/ |
| 3608 | } |
| 3609 | } |
| 3610 |
no test coverage detected