index: bitgroup index, bits: bitgroup size(1, 2 or 4), in: bitgroup value, out: octet array to add bits to*/
| 2895 | |
| 2896 | /*index: bitgroup index, bits: bitgroup size(1, 2 or 4), in: bitgroup value, out: octet array to add bits to*/ |
| 2897 | static void addColorBits(unsigned char* out, size_t index, unsigned bits, unsigned in) |
| 2898 | { |
| 2899 | unsigned m = bits == 1 ? 7 : bits == 2 ? 3 : 1; /*8 / bits - 1*/ |
| 2900 | /*p = the partial index in the byte, e.g. with 4 palettebits it is 0 for first half or 1 for second half*/ |
| 2901 | unsigned p = index & m; |
| 2902 | in &= (1 << bits) - 1; /*filter out any other bits of the input value*/ |
| 2903 | in = in << (bits * (m - p)); |
| 2904 | if(p == 0) out[index * bits / 8] = in; |
| 2905 | else out[index * bits / 8] |= in; |
| 2906 | } |
| 2907 | |
| 2908 | typedef struct ColorTree ColorTree; |
| 2909 |