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

◆ brightness_bitshifter8()

uint8_t brightness_bitshifter8 ( uint8_t * brightness_src,
uint8_t * brightness_dst,
uint8_t max_shifts )
inline

Definition at line 14 of file brightness_bitshifter.h.

14 {
15 uint8_t src = *brightness_src;
16 if (*brightness_dst == 0 || src == 0) {
17 return 0;
18 }
19 // Steal brightness from brightness_src and give it to brightness_dst.
20 // After this function concludes the multiplication of brightness_dst and brightness_src will remain
21 // constant.
22 // This algorithm is a little difficult to follow and I don't understand why it works that well,
23 // however I did work it out manually and has something to do with how numbers respond to bitshifts.
24 uint8_t curr = *brightness_dst;
25 uint8_t shifts = 0;
26 for (uint8_t i = 0; i < max_shifts && src > 1; i++) {
27 if (curr & 0b10000000) {
28 // next shift will overflow
29 break;
30 }
31 curr <<= 1;
32 src >>= 1;
33 shifts++;
34 }
35 // write out the output values.
36 *brightness_dst = curr;
37 *brightness_src = src;
38 return shifts;
39}

Referenced by fl::five_bit_bitshift().

+ Here is the caller graph for this function: