background color chunk (bKGD)*/
| 4267 | #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS |
| 4268 | /*background color chunk (bKGD)*/ |
| 4269 | static unsigned readChunk_bKGD(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) |
| 4270 | { |
| 4271 | if(info->color.colortype == LCT_PALETTE) |
| 4272 | { |
| 4273 | /*error: this chunk must be 1 byte for indexed color image*/ |
| 4274 | if(chunkLength != 1) return 43; |
| 4275 | |
| 4276 | info->background_defined = 1; |
| 4277 | info->background_r = info->background_g = info->background_b = data[0]; |
| 4278 | } |
| 4279 | else if(info->color.colortype == LCT_GREY || info->color.colortype == LCT_GREY_ALPHA) |
| 4280 | { |
| 4281 | /*error: this chunk must be 2 bytes for greyscale image*/ |
| 4282 | if(chunkLength != 2) return 44; |
| 4283 | |
| 4284 | info->background_defined = 1; |
| 4285 | info->background_r = info->background_g = info->background_b = 256u * data[0] + data[1]; |
| 4286 | } |
| 4287 | else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_RGBA) |
| 4288 | { |
| 4289 | /*error: this chunk must be 6 bytes for greyscale image*/ |
| 4290 | if(chunkLength != 6) return 45; |
| 4291 | |
| 4292 | info->background_defined = 1; |
| 4293 | info->background_r = 256u * data[0] + data[1]; |
| 4294 | info->background_g = 256u * data[2] + data[3]; |
| 4295 | info->background_b = 256u * data[4] + data[5]; |
| 4296 | } |
| 4297 | |
| 4298 | return 0; /* OK */ |
| 4299 | } |
| 4300 | |
| 4301 | /*text chunk (tEXt)*/ |
| 4302 | static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) |