palette must have 4 * palettesize bytes allocated, and given in format RGBARGBARGBARGBA... returns 0 if the palette is opaque, returns 1 if the palette has a single color with alpha 0 ==> color key returns 2 if the palette is semi-translucent. */
| 5598 | returns 2 if the palette is semi-translucent. |
| 5599 | */ |
| 5600 | static unsigned getPaletteTranslucency(const unsigned char* palette, size_t palettesize) |
| 5601 | { |
| 5602 | size_t i; |
| 5603 | unsigned key = 0; |
| 5604 | unsigned r = 0, g = 0, b = 0; /*the value of the color with alpha 0, so long as color keying is possible*/ |
| 5605 | for(i = 0; i != palettesize; ++i) |
| 5606 | { |
| 5607 | if(!key && palette[4 * i + 3] == 0) |
| 5608 | { |
| 5609 | r = palette[4 * i + 0]; g = palette[4 * i + 1]; b = palette[4 * i + 2]; |
| 5610 | key = 1; |
| 5611 | i = (size_t)(-1); /*restart from beginning, to detect earlier opaque colors with key's value*/ |
| 5612 | } |
| 5613 | else if(palette[4 * i + 3] != 255) return 2; |
| 5614 | /*when key, no opaque RGB may have key's RGB*/ |
| 5615 | else if(key && r == palette[i * 4 + 0] && g == palette[i * 4 + 1] && b == palette[i * 4 + 2]) return 2; |
| 5616 | } |
| 5617 | return key; |
| 5618 | } |
| 5619 | |
| 5620 | #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS |
| 5621 | static unsigned addUnknownChunks(ucvector* out, unsigned char* data, size_t datasize) |