MCPcopy Create free account
hub / github.com/DFHack/dfhack / readChunk_tRNS

Function readChunk_tRNS

depends/lodepng/lodepng.cpp:4369–4394  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4367}
4368
4369static unsigned readChunk_tRNS(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength) {
4370 unsigned i;
4371 if(color->colortype == LCT_PALETTE) {
4372 /*error: more alpha values given than there are palette entries*/
4373 if(chunkLength > color->palettesize) return 39;
4374
4375 for(i = 0; i != chunkLength; ++i) color->palette[4 * i + 3] = data[i];
4376 } else if(color->colortype == LCT_GREY) {
4377 /*error: this chunk must be 2 bytes for grayscale image*/
4378 if(chunkLength != 2) return 30;
4379
4380 color->key_defined = 1;
4381 color->key_r = color->key_g = color->key_b = 256u * data[0] + data[1];
4382 } else if(color->colortype == LCT_RGB) {
4383 /*error: this chunk must be 6 bytes for RGB image*/
4384 if(chunkLength != 6) return 41;
4385
4386 color->key_defined = 1;
4387 color->key_r = 256u * data[0] + data[1];
4388 color->key_g = 256u * data[2] + data[3];
4389 color->key_b = 256u * data[4] + data[5];
4390 }
4391 else return 42; /*error: tRNS chunk not allowed for other color models*/
4392
4393 return 0; /* OK */
4394}
4395
4396
4397#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS

Callers 2

lodepng_inspect_chunkFunction · 0.85
decodeGenericFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected