MCPcopy Create free account
hub / github.com/creatale/node-dv / addChunk_tRNS

Function addChunk_tRNS

deps/lodepng/lodepng.cpp:4995–5038  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4993}
4994
4995static 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
5040static unsigned addChunk_IDAT(ucvector* out, const unsigned char* data, size_t datasize,
5041 LodePNGCompressSettings* zlibsettings)

Callers 1

lodepng_encodeFunction · 0.85

Calls 4

ucvector_initFunction · 0.85
ucvector_push_backFunction · 0.85
addChunkFunction · 0.85
ucvector_cleanupFunction · 0.85

Tested by

no test coverage detected