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, Pacifica.ino, and XYMatrix.ino.

Definition at line 44 of file scale8.h.

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

References LIB8STATIC_ALWAYS_INLINE, and scale.

Referenced by DATA_NOP::adjust(), beatsin8(), brighten8_lin(), brighten8_raw(), fl::ColorFromPalette(), fl::ColorFromPalette(), dim8_lin(), dim8_raw(), fl::Fire2012::draw(), ease8InOutQuad(), fl::easeInQuad8(), fl::fadeUsingColor(), fill_raw_2dnoise16into8(), fill_raw_2dnoise8(), fillFrameBufferNoise(), 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(), fl::nblend(), fl::Pacifica::pacifica_add_whitecaps(), pacifica_add_whitecaps(), fl::Pacifica::pacifica_deepen_colors(), pacifica_deepen_colors(), fl::Luminova::plotDot(), plotDot(), rgb2hsv_approximate(), fl::rgb_2_rgbw_exact(), fl::rgb_2_rgbw_max_brightness(), fl::rgb_2_rgbw_null_white_pixel(), fl::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: