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

◆ scale8()

LIB8STATIC_ALWAYS_INLINE uint8_t scale8 ( uint8_t i,
fract8 scale )

Scale one byte by a second one, which is treated as the numerator of a fraction whose denominator is 256.

In other words, it computes i * (scale / 256)

Parameters
iinput value to scale
scalescale factor, in n/256 units
Returns
scaled value
Note
Takes 4 clocks on AVR with MUL, 2 clocks on ARM
Examples
Fire2012WithPalette.ino, NoisePlusPalette.ino, Pacifica.ino, and XYMatrix.ino.

Definition at line 34 of file scale8.h.

34 {
35#if SCALE8_C == 1
36#if (FASTLED_SCALE8_FIXED == 1)
37 return (((uint16_t)i) * (1 + (uint16_t)(scale))) >> 8;
38#else
39 return ((uint16_t)i * (uint16_t)(scale)) >> 8;
40#endif
41#elif SCALE8_AVRASM == 1
42#if defined(LIB8_ATTINY)
43#if (FASTLED_SCALE8_FIXED == 1)
44 uint8_t work = i;
45#else
46 uint8_t work = 0;
47#endif
48 uint8_t cnt = 0x80;
49 asm volatile(
50#if (FASTLED_SCALE8_FIXED == 1)
51 " inc %[scale] \n\t"
52 " breq DONE_%= \n\t"
53 " clr %[work] \n\t"
54#endif
55 "LOOP_%=: \n\t"
56 /*" sbrc %[scale], 0 \n\t"
57 " add %[work], %[i] \n\t"
58 " ror %[work] \n\t"
59 " lsr %[scale] \n\t"
60 " clc \n\t"*/
61 " sbrc %[scale], 0 \n\t"
62 " add %[work], %[i] \n\t"
63 " ror %[work] \n\t"
64 " lsr %[scale] \n\t"
65 " lsr %[cnt] \n\t"
66 "brcc LOOP_%= \n\t"
67 "DONE_%=: \n\t"
68 : [work] "+r"(work), [cnt] "+r"(cnt)
69 : [scale] "r"(scale), [i] "r"(i)
70 :);
71 return work;
72#else
73 asm volatile(
74#if (FASTLED_SCALE8_FIXED == 1)
75 // Multiply 8-bit i * 8-bit scale, giving 16-bit r1,r0
76 "mul %0, %1 \n\t"
77 // Add i to r0, possibly setting the carry flag
78 "add r0, %0 \n\t"
79 // load the immediate 0 into i (note, this does _not_ touch any flags)
80 "ldi %0, 0x00 \n\t"
81 // walk and chew gum at the same time
82 "adc %0, r1 \n\t"
83#else
84 /* Multiply 8-bit i * 8-bit scale, giving 16-bit r1,r0 */
85 "mul %0, %1 \n\t"
86 /* Move the high 8-bits of the product (r1) back to i */
87 "mov %0, r1 \n\t"
88 /* Restore r1 to "0"; it's expected to always be that */
89#endif
90 "clr __zero_reg__ \n\t"
91
92 : "+d"(i) /* writes to i; r16-r31, restricted by ldi */
93 : "r"(scale) /* uses scale */
94 : "r0", "r1" /* clobbers r0, r1 */
95 );
96 /* Return the result */
97 return i;
98#endif
99#else
100#error "No implementation for scale8 available."
101#endif
102}
UISlider scale("Scale", 4,.1, 4,.1)

References LIB8STATIC_ALWAYS_INLINE, and scale.

Referenced by DATA_NOP::adjust(), beatsin8(), brighten8_lin(), brighten8_raw(), ColorFromPalette(), ColorFromPalette(), dim8_lin(), dim8_raw(), fl::Fire2012::draw(), ease8InOutQuad(), fadeUsingColor(), fill_raw_2dnoise16into8(), fill_raw_2dnoise8(), fillnoise8(), fl::NoisePalette::fillnoise8(), Fire2012WithPalette(), Fire2023(), hsv2rgb_rainbow(), hsv2rgb_spectrum(), PixelController< RGB_ORDER, LANES, MASK >::init_binary_dithering(), lerp7by8(), lerp8by8(), PixelController< RGB_ORDER, LANES, MASK >::loadAndScale(), PixelController< RGB_ORDER, LANES, MASK >::loadAndScale(), loop(), map8(), nblend(), fl::Pacifica::pacifica_add_whitecaps(), pacifica_add_whitecaps(), fl::Pacifica::pacifica_deepen_colors(), pacifica_deepen_colors(), rgb2hsv_approximate(), rgb_2_rgbw_exact(), rgb_2_rgbw_max_brightness(), rgb_2_rgbw_null_white_pixel(), rgb_2_rgbw_white_boosted(), PixelController< RGB_ORDER, LANES, MASK >::scale(), and PixelController< RGB_ORDER, LANES, MASK >::scale().

+ Here is the caller graph for this function: