| 4276 | } |
| 4277 | |
| 4278 | static unsigned readChunk_tRNS(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength) |
| 4279 | { |
| 4280 | unsigned i; |
| 4281 | if(color->colortype == LCT_PALETTE) |
| 4282 | { |
| 4283 | /*error: more alpha values given than there are palette entries*/ |
| 4284 | if(chunkLength > color->palettesize) return 38; |
| 4285 | |
| 4286 | for(i = 0; i < chunkLength; i++) color->palette[4 * i + 3] = data[i]; |
| 4287 | } |
| 4288 | else if(color->colortype == LCT_GREY) |
| 4289 | { |
| 4290 | /*error: this chunk must be 2 bytes for greyscale image*/ |
| 4291 | if(chunkLength != 2) return 30; |
| 4292 | |
| 4293 | color->key_defined = 1; |
| 4294 | color->key_r = color->key_g = color->key_b = 256 * data[0] + data[1]; |
| 4295 | } |
| 4296 | else if(color->colortype == LCT_RGB) |
| 4297 | { |
| 4298 | /*error: this chunk must be 6 bytes for RGB image*/ |
| 4299 | if(chunkLength != 6) return 41; |
| 4300 | |
| 4301 | color->key_defined = 1; |
| 4302 | color->key_r = 256 * data[0] + data[1]; |
| 4303 | color->key_g = 256 * data[2] + data[3]; |
| 4304 | color->key_b = 256 * data[4] + data[5]; |
| 4305 | } |
| 4306 | else return 42; /*error: tRNS chunk not allowed for other color models*/ |
| 4307 | |
| 4308 | return 0; /* OK */ |
| 4309 | } |
| 4310 | |
| 4311 | |
| 4312 | #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS |