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

Function readChunk_PLTE

src/lodepng.cpp:4254–4276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4252}
4253
4254static unsigned readChunk_PLTE(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength)
4255{
4256 unsigned pos = 0, i;
4257 if(color->palette) lodepng_free(color->palette);
4258 color->palettesize = chunkLength / 3;
4259 color->palette = (unsigned char*)lodepng_malloc(4 * color->palettesize);
4260 if(!color->palette && color->palettesize)
4261 {
4262 color->palettesize = 0;
4263 return 83; /*alloc fail*/
4264 }
4265 if(color->palettesize > 256) return 38; /*error: palette too big*/
4266
4267 for(i = 0; i < color->palettesize; i++)
4268 {
4269 color->palette[4 * i + 0] = data[pos++]; /*R*/
4270 color->palette[4 * i + 1] = data[pos++]; /*G*/
4271 color->palette[4 * i + 2] = data[pos++]; /*B*/
4272 color->palette[4 * i + 3] = 255; /*alpha*/
4273 }
4274
4275 return 0; /* OK */
4276}
4277
4278static unsigned readChunk_tRNS(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength)
4279{

Callers 1

decodeGenericFunction · 0.85

Calls 2

lodepng_freeFunction · 0.85
lodepng_mallocFunction · 0.85

Tested by

no test coverage detected