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. */
| 5475 | returns 2 if the palette is semi-translucent. |
| 5476 | */ |
| 5477 | static unsigned getPaletteTranslucency(const unsigned char* palette, size_t palettesize) |
| 5478 | { |
| 5479 | size_t i; |
| 5480 | unsigned key = 0; |
| 5481 | unsigned r = 0, g = 0, b = 0; /*the value of the color with alpha 0, so long as color keying is possible*/ |
| 5482 | for(i = 0; i < palettesize; i++) |
| 5483 | { |
| 5484 | if(!key && palette[4 * i + 3] == 0) |
| 5485 | { |
| 5486 | r = palette[4 * i + 0]; g = palette[4 * i + 1]; b = palette[4 * i + 2]; |
| 5487 | key = 1; |
| 5488 | i = (size_t)(-1); /*restart from beginning, to detect earlier opaque colors with key's value*/ |
| 5489 | } |
| 5490 | else if(palette[4 * i + 3] != 255) return 2; |
| 5491 | /*when key, no opaque RGB may have key's RGB*/ |
| 5492 | else if(key && r == palette[i * 4 + 0] && g == palette[i * 4 + 1] && b == palette[i * 4 + 2]) return 2; |
| 5493 | } |
| 5494 | return key; |
| 5495 | } |
| 5496 | |
| 5497 | #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS |
| 5498 | static unsigned addUnknownChunks(ucvector* out, unsigned char* data, size_t datasize) |