MCPcopy Create free account
hub / github.com/DFHack/dfhack / addColorBits

Function addColorBits

depends/lodepng/lodepng.cpp:3092–3100  ·  view source on GitHub ↗

index: bitgroup index, bits: bitgroup size(1, 2 or 4), in: bitgroup value, out: octet array to add bits to*/

Source from the content-addressed store, hash-verified

3090
3091/*index: bitgroup index, bits: bitgroup size(1, 2 or 4), in: bitgroup value, out: octet array to add bits to*/
3092static void addColorBits(unsigned char* out, size_t index, unsigned bits, unsigned in) {
3093 unsigned m = bits == 1 ? 7 : bits == 2 ? 3 : 1; /*8 / bits - 1*/
3094 /*p = the partial index in the byte, e.g. with 4 palettebits it is 0 for first half or 1 for second half*/
3095 unsigned p = index & m;
3096 in &= (1u << bits) - 1u; /*filter out any other bits of the input value*/
3097 in = in << (bits * (m - p));
3098 if(p == 0) out[index * bits / 8u] = in;
3099 else out[index * bits / 8u] |= in;
3100}
3101
3102typedef struct ColorTree ColorTree;
3103

Callers 1

rgba8ToPixelFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected