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

◆ scale8_video()

LIB8STATIC_ALWAYS_INLINE uint8_t scale8_video ( uint8_t i,
fract8 scale )

The "video" version of scale8() guarantees that the output will be only be zero if one or both of the inputs are zero.

If both inputs are non-zero, the output is guaranteed to be non-zero. This makes for better "video"/LED dimming, at the cost of several additional cycles.

Parameters
iinput value to scale
scalescale factor, in n/256 units
Returns
scaled value
See also
scale8()

Definition at line 127 of file scale8.h.

127 {
128#if SCALE8_C == 1 || defined(LIB8_ATTINY)
129 uint8_t j = (((int)i * (int)scale) >> 8) + ((i && scale) ? 1 : 0);
130 // uint8_t nonzeroscale = (scale != 0) ? 1 : 0;
131 // uint8_t j = (i == 0) ? 0 : (((int)i * (int)(scale) ) >> 8) +
132 // nonzeroscale;
133 return j;
134#elif SCALE8_AVRASM == 1
135 uint8_t j = 0;
136 asm volatile(" tst %[i]\n\t"
137 " breq L_%=\n\t"
138 " mul %[i], %[scale]\n\t"
139 " mov %[j], r1\n\t"
140 " clr __zero_reg__\n\t"
141 " cpse %[scale], r1\n\t"
142 " subi %[j], 0xFF\n\t"
143 "L_%=: \n\t"
144 : [j] "+d"(j) // r16-r31, restricted by subi
145 : [i] "r"(i), [scale] "r"(scale)
146 : "r0", "r1");
147 return j;
148 // uint8_t nonzeroscale = (scale != 0) ? 1 : 0;
149 // asm volatile(
150 // " tst %0 \n"
151 // " breq L_%= \n"
152 // " mul %0, %1 \n"
153 // " mov %0, r1 \n"
154 // " add %0, %2 \n"
155 // " clr __zero_reg__ \n"
156 // "L_%=: \n"
157 // : "+a" (i)
158 // : "a" (scale), "a" (nonzeroscale)
159 // : "r0", "r1");
160 // // Return the result
161 // return i;
162#else
163#error "No implementation for scale8_video available."
164#endif
165}
uint16_t scale
Definition Noise.ino:74

References LIB8STATIC_ALWAYS_INLINE, and scale.

Referenced by brighten8_video(), fl::ColorFromPalette(), fl::ColorFromPalette(), fl::ColorFromPalette(), dim8_video(), fl::HeatColor(), and hsv2rgb_rainbow().

+ Here is the caller graph for this function: