background color chunk (bKGD)*/
| 4166 | #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS |
| 4167 | /*background color chunk (bKGD)*/ |
| 4168 | static unsigned readChunk_bKGD(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) |
| 4169 | { |
| 4170 | if(info->color.colortype == LCT_PALETTE) |
| 4171 | { |
| 4172 | /*error: this chunk must be 1 byte for indexed color image*/ |
| 4173 | if(chunkLength != 1) return 43; |
| 4174 | |
| 4175 | info->background_defined = 1; |
| 4176 | info->background_r = info->background_g = info->background_b = data[0]; |
| 4177 | } |
| 4178 | else if(info->color.colortype == LCT_GREY || info->color.colortype == LCT_GREY_ALPHA) |
| 4179 | { |
| 4180 | /*error: this chunk must be 2 bytes for greyscale image*/ |
| 4181 | if(chunkLength != 2) return 44; |
| 4182 | |
| 4183 | info->background_defined = 1; |
| 4184 | info->background_r = info->background_g = info->background_b = 256u * data[0] + data[1]; |
| 4185 | } |
| 4186 | else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_RGBA) |
| 4187 | { |
| 4188 | /*error: this chunk must be 6 bytes for greyscale image*/ |
| 4189 | if(chunkLength != 6) return 45; |
| 4190 | |
| 4191 | info->background_defined = 1; |
| 4192 | info->background_r = 256u * data[0] + data[1]; |
| 4193 | info->background_g = 256u * data[2] + data[3]; |
| 4194 | info->background_b = 256u * data[4] + data[5]; |
| 4195 | } |
| 4196 | |
| 4197 | return 0; /* OK */ |
| 4198 | } |
| 4199 | |
| 4200 | /*text chunk (tEXt)*/ |
| 4201 | static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) |