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

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

References LIB8STATIC_ALWAYS_INLINE, and scale.

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

+ Here is the caller graph for this function: