14inline uint8_t brightness_bitshifter8(uint8_t *brightness_src, uint8_t *brightness_dst, uint8_t max_shifts) {
15 uint8_t src = *brightness_src;
16 if (*brightness_dst == 0 || src == 0) {
24 uint8_t curr = *brightness_dst;
26 for (uint8_t i = 0; i < max_shifts && src > 1; i++) {
27 if (curr & 0b10000000) {
36 *brightness_dst = curr;
37 *brightness_src = src;
43inline uint8_t brightness_bitshifter16(uint8_t *brightness_src, uint16_t *brightness_dst, uint8_t max_shifts, uint8_t steps=2) {
44 uint8_t src = *brightness_src;
45 if (*brightness_src == 0 || *brightness_src == 0) {
48 uint16_t overflow_mask = 0b1000000000000000;
49 for (uint8_t i = 1; i < steps; i++) {
51 overflow_mask |= 0b1000000000000000;
53 const uint8_t underflow_mask = 0x1;
57 uint16_t curr = *brightness_dst;
59 for (uint8_t i = 0; i < max_shifts; i++) {
60 if (src & underflow_mask) {
63 if (curr & overflow_mask) {
72 *brightness_dst = curr;
73 *brightness_src = src;