MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / getPaletteTranslucency

Function getPaletteTranslucency

src/lodepng.cpp:5628–5645  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

5626returns 2 if the palette is semi-translucent.
5627*/
5628static unsigned getPaletteTranslucency(const unsigned char* palette, size_t palettesize)
5629{
5630 size_t i, key = 0;
5631 unsigned r = 0, g = 0, b = 0; /*the value of the color with alpha 0, so long as color keying is possible*/
5632 for(i = 0; i < palettesize; i++)
5633 {
5634 if(!key && palette[4 * i + 3] == 0)
5635 {
5636 r = palette[4 * i + 0]; g = palette[4 * i + 1]; b = palette[4 * i + 2];
5637 key = 1;
5638 i = (size_t)(-1); /*restart from beginning, to detect earlier opaque colors with key's value*/
5639 }
5640 else if(palette[4 * i + 3] != 255) return 2;
5641 /*when key, no opaque RGB may have key's RGB*/
5642 else if(key && r == palette[i * 4 + 0] && g == palette[i * 4 + 1] && b == palette[i * 4 + 2]) return 2;
5643 }
5644 return key;
5645}
5646
5647#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
5648static unsigned addUnknownChunks(ucvector* out, unsigned char* data, size_t datasize)

Callers 1

lodepng_encodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected