FastLED 3.9.15
Loading...
Searching...
No Matches

◆ brightness_bitshifter16()

uint8_t brightness_bitshifter16 ( uint8_t * brightness_src,
uint16_t * brightness_dst,
uint8_t max_shifts,
uint8_t steps = 2 )
inline

Definition at line 43 of file brightness_bitshifter.h.

43 {
44 uint8_t src = *brightness_src;
45 if (*brightness_dst == 0 || src == 0) {
46 return 0;
47 }
48 uint16_t overflow_mask = 0b1000000000000000;
49 for (uint8_t i = 1; i < steps; i++) {
50 overflow_mask >>= 1;
51 overflow_mask |= 0b1000000000000000;
52 }
53 const uint8_t underflow_mask = 0x1;
54 // Steal brightness from brightness_src and give it to brightness_dst.
55 // After this function concludes the multiplication of brightness_dst and brightness_src will remain
56 // constant.
57 uint16_t curr = *brightness_dst;
58 uint8_t shifts = 0;
59 for (uint8_t i = 0; i < max_shifts; i++) {
60 if (src & underflow_mask) {
61 break;
62 }
63 if (curr & overflow_mask) {
64 // next shift will overflow
65 break;
66 }
67 curr <<= steps;
68 src >>= 1;
69 shifts++;
70 }
71 // write out the output values.
72 *brightness_dst = curr;
73 *brightness_src = src;
74 return shifts;
75}

Referenced by fl::five_bit_bitshift().

+ Here is the caller graph for this function: