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

Function readChunk_tRNS

dependency/densecrf/examples/lodepng.cpp:4233–4264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4231}
4232
4233static unsigned readChunk_tRNS(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength)
4234{
4235 unsigned i;
4236 if(color->colortype == LCT_PALETTE)
4237 {
4238 /*error: more alpha values given than there are palette entries*/
4239 if(chunkLength > color->palettesize) return 38;
4240
4241 for(i = 0; i != chunkLength; ++i) color->palette[4 * i + 3] = data[i];
4242 }
4243 else if(color->colortype == LCT_GREY)
4244 {
4245 /*error: this chunk must be 2 bytes for greyscale image*/
4246 if(chunkLength != 2) return 30;
4247
4248 color->key_defined = 1;
4249 color->key_r = color->key_g = color->key_b = 256u * data[0] + data[1];
4250 }
4251 else if(color->colortype == LCT_RGB)
4252 {
4253 /*error: this chunk must be 6 bytes for RGB image*/
4254 if(chunkLength != 6) return 41;
4255
4256 color->key_defined = 1;
4257 color->key_r = 256u * data[0] + data[1];
4258 color->key_g = 256u * data[2] + data[3];
4259 color->key_b = 256u * data[4] + data[5];
4260 }
4261 else return 42; /*error: tRNS chunk not allowed for other color models*/
4262
4263 return 0; /* OK */
4264}
4265
4266
4267#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS

Callers 1

decodeGenericFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected