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

Function readChunk_PLTE

samples/cgpu/cgpu-basic/mandelbrot/lodepng.c:4216–4238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4214}
4215
4216static unsigned readChunk_PLTE(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength)
4217{
4218 unsigned pos = 0, i;
4219 if(color->palette) lodepng_free(color->palette);
4220 color->palettesize = chunkLength / 3;
4221 color->palette = (unsigned char*)lodepng_malloc(4 * color->palettesize);
4222 if(!color->palette && color->palettesize)
4223 {
4224 color->palettesize = 0;
4225 return 83; /*alloc fail*/
4226 }
4227 if(color->palettesize > 256) return 38; /*error: palette too big*/
4228
4229 for(i = 0; i != color->palettesize; ++i)
4230 {
4231 color->palette[4 * i + 0] = data[pos++]; /*R*/
4232 color->palette[4 * i + 1] = data[pos++]; /*G*/
4233 color->palette[4 * i + 2] = data[pos++]; /*B*/
4234 color->palette[4 * i + 3] = 255; /*alpha*/
4235 }
4236
4237 return 0; /* OK */
4238}
4239
4240static unsigned readChunk_tRNS(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength)
4241{

Callers 1

decodeGenericFunction · 0.85

Calls 2

lodepng_freeFunction · 0.85
lodepng_mallocFunction · 0.85

Tested by

no test coverage detected