background color chunk (bKGD)*/
| 4397 | #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS |
| 4398 | /*background color chunk (bKGD)*/ |
| 4399 | static unsigned readChunk_bKGD(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { |
| 4400 | if(info->color.colortype == LCT_PALETTE) { |
| 4401 | /*error: this chunk must be 1 byte for indexed color image*/ |
| 4402 | if(chunkLength != 1) return 43; |
| 4403 | |
| 4404 | /*error: invalid palette index, or maybe this chunk appeared before PLTE*/ |
| 4405 | if(data[0] >= info->color.palettesize) return 103; |
| 4406 | |
| 4407 | info->background_defined = 1; |
| 4408 | info->background_r = info->background_g = info->background_b = data[0]; |
| 4409 | } else if(info->color.colortype == LCT_GREY || info->color.colortype == LCT_GREY_ALPHA) { |
| 4410 | /*error: this chunk must be 2 bytes for grayscale image*/ |
| 4411 | if(chunkLength != 2) return 44; |
| 4412 | |
| 4413 | /*the values are truncated to bitdepth in the PNG file*/ |
| 4414 | info->background_defined = 1; |
| 4415 | info->background_r = info->background_g = info->background_b = 256u * data[0] + data[1]; |
| 4416 | } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_RGBA) { |
| 4417 | /*error: this chunk must be 6 bytes for grayscale image*/ |
| 4418 | if(chunkLength != 6) return 45; |
| 4419 | |
| 4420 | /*the values are truncated to bitdepth in the PNG file*/ |
| 4421 | info->background_defined = 1; |
| 4422 | info->background_r = 256u * data[0] + data[1]; |
| 4423 | info->background_g = 256u * data[2] + data[3]; |
| 4424 | info->background_b = 256u * data[4] + data[5]; |
| 4425 | } |
| 4426 | |
| 4427 | return 0; /* OK */ |
| 4428 | } |
| 4429 | |
| 4430 | /*text chunk (tEXt)*/ |
| 4431 | static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { |
no outgoing calls
no test coverage detected