background color chunk (bKGD)*/
| 4312 | #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS |
| 4313 | /*background color chunk (bKGD)*/ |
| 4314 | static unsigned readChunk_bKGD(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) |
| 4315 | { |
| 4316 | if(info->color.colortype == LCT_PALETTE) |
| 4317 | { |
| 4318 | /*error: this chunk must be 1 byte for indexed color image*/ |
| 4319 | if(chunkLength != 1) return 43; |
| 4320 | |
| 4321 | info->background_defined = 1; |
| 4322 | info->background_r = info->background_g = info->background_b = data[0]; |
| 4323 | } |
| 4324 | else if(info->color.colortype == LCT_GREY || info->color.colortype == LCT_GREY_ALPHA) |
| 4325 | { |
| 4326 | /*error: this chunk must be 2 bytes for greyscale image*/ |
| 4327 | if(chunkLength != 2) return 44; |
| 4328 | |
| 4329 | info->background_defined = 1; |
| 4330 | info->background_r = info->background_g = info->background_b |
| 4331 | = 256 * data[0] + data[1]; |
| 4332 | } |
| 4333 | else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_RGBA) |
| 4334 | { |
| 4335 | /*error: this chunk must be 6 bytes for greyscale image*/ |
| 4336 | if(chunkLength != 6) return 45; |
| 4337 | |
| 4338 | info->background_defined = 1; |
| 4339 | info->background_r = 256 * data[0] + data[1]; |
| 4340 | info->background_g = 256 * data[2] + data[3]; |
| 4341 | info->background_b = 256 * data[4] + data[5]; |
| 4342 | } |
| 4343 | |
| 4344 | return 0; /* OK */ |
| 4345 | } |
| 4346 | |
| 4347 | /*text chunk (tEXt)*/ |
| 4348 | static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) |