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

Function color_tree_add

depends/lodepng/lodepng.cpp:3150–3164  ·  view source on GitHub ↗

color is not allowed to already exist. Index should be >= 0 (it's signed to be compatible with using -1 for "doesn't exist") Returns error code, or 0 if ok*/

Source from the content-addressed store, hash-verified

3148Index should be >= 0 (it's signed to be compatible with using -1 for "doesn't exist")
3149Returns error code, or 0 if ok*/
3150static unsigned color_tree_add(ColorTree* tree,
3151 unsigned char r, unsigned char g, unsigned char b, unsigned char a, unsigned index) {
3152 int bit;
3153 for(bit = 0; bit < 8; ++bit) {
3154 int i = 8 * ((r >> bit) & 1) + 4 * ((g >> bit) & 1) + 2 * ((b >> bit) & 1) + 1 * ((a >> bit) & 1);
3155 if(!tree->children[i]) {
3156 tree->children[i] = (ColorTree*)lodepng_malloc(sizeof(ColorTree));
3157 if(!tree->children[i]) return 83; /*alloc fail*/
3158 color_tree_init(tree->children[i]);
3159 }
3160 tree = tree->children[i];
3161 }
3162 tree->index = (int)index;
3163 return 0;
3164}
3165
3166/*put a pixel, given its RGBA color, into image of any color type*/
3167static unsigned rgba8ToPixel(unsigned char* out, size_t i,

Callers 2

lodepng_convertFunction · 0.85

Calls 2

lodepng_mallocFunction · 0.85
color_tree_initFunction · 0.85

Tested by

no test coverage detected