MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / readChunk_PLTE

Function readChunk_PLTE

dependency/densecrf/examples/lodepng.cpp:4209–4231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

decodeGenericFunction · 0.85

Calls 2

lodepng_freeFunction · 0.85
lodepng_mallocFunction · 0.85

Tested by

no test coverage detected