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 123 of file scale8.h.

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

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: