| 4993 | } |
| 4994 | |
| 4995 | static unsigned addChunk_tRNS(ucvector* out, const LodePNGColorMode* info) |
| 4996 | { |
| 4997 | unsigned error = 0; |
| 4998 | size_t i; |
| 4999 | ucvector tRNS; |
| 5000 | ucvector_init(&tRNS); |
| 5001 | if(info->colortype == LCT_PALETTE) |
| 5002 | { |
| 5003 | size_t amount = info->palettesize; |
| 5004 | /*the tail of palette values that all have 255 as alpha, does not have to be encoded*/ |
| 5005 | for(i = info->palettesize; i != 0; --i) |
| 5006 | { |
| 5007 | if(info->palette[4 * (i - 1) + 3] == 255) --amount; |
| 5008 | else break; |
| 5009 | } |
| 5010 | /*add only alpha channel*/ |
| 5011 | for(i = 0; i != amount; ++i) ucvector_push_back(&tRNS, info->palette[4 * i + 3]); |
| 5012 | } |
| 5013 | else if(info->colortype == LCT_GREY) |
| 5014 | { |
| 5015 | if(info->key_defined) |
| 5016 | { |
| 5017 | ucvector_push_back(&tRNS, (unsigned char)(info->key_r >> 8)); |
| 5018 | ucvector_push_back(&tRNS, (unsigned char)(info->key_r & 255)); |
| 5019 | } |
| 5020 | } |
| 5021 | else if(info->colortype == LCT_RGB) |
| 5022 | { |
| 5023 | if(info->key_defined) |
| 5024 | { |
| 5025 | ucvector_push_back(&tRNS, (unsigned char)(info->key_r >> 8)); |
| 5026 | ucvector_push_back(&tRNS, (unsigned char)(info->key_r & 255)); |
| 5027 | ucvector_push_back(&tRNS, (unsigned char)(info->key_g >> 8)); |
| 5028 | ucvector_push_back(&tRNS, (unsigned char)(info->key_g & 255)); |
| 5029 | ucvector_push_back(&tRNS, (unsigned char)(info->key_b >> 8)); |
| 5030 | ucvector_push_back(&tRNS, (unsigned char)(info->key_b & 255)); |
| 5031 | } |
| 5032 | } |
| 5033 | |
| 5034 | error = addChunk(out, "tRNS", tRNS.data, tRNS.size); |
| 5035 | ucvector_cleanup(&tRNS); |
| 5036 | |
| 5037 | return error; |
| 5038 | } |
| 5039 | |
| 5040 | static unsigned addChunk_IDAT(ucvector* out, const unsigned char* data, size_t datasize, |
| 5041 | LodePNGCompressSettings* zlibsettings) |
no test coverage detected