127 {
128
129
130
131
132
133
134
135
136 static uint32_t bright_scale[32] = {
137 0, 2023680, 1011840, 674560, 505920, 404736, 337280, 289097,
138 252960, 224853, 202368, 183971, 168640, 155668, 144549, 134912,
139 126480, 119040, 112427, 106509, 101184, 96366, 91985, 87986,
140 84320, 80947, 77834, 74951, 72274, 69782, 67456, 65280};
141
142 auto max3 = [](u16 a, u16 b, u16 c) {
return fl_max(
fl_max(a, b), c); };
143
144
146 *out = CRGB(0, 0, 0);
147 *out_power_5bit = 0;
148 return;
149 }
150 if (r16 == 0 && g16 == 0 && b16 == 0) {
151 *out = CRGB(0, 0, 0);
153 return;
154 }
155
156 uint8_t r8 = 0, g8 = 0, b8 = 0;
157
158
163 }
164
165
166 uint16_t
scale = max3(r16, g16, b16);
167
169 *out = CRGB(0, 0, 0);
170 *out_power_5bit = 0;
171 return;
172 } else {
173 uint32_t scalef;
174
175
177
178
179
180 scalef = bright_scale[
scale];
181 r8 = (r16 * scalef + 0x808000) >> 24;
182 g8 = (g16 * scalef + 0x808000) >> 24;
183 b8 = (b16 * scalef + 0x808000) >> 24;
184
185 *out = CRGB(r8, g8, b8);
186 *out_power_5bit =
static_cast<uint8_t
>(
scale);
187 return;
188 }
189}
UISlider brightness("Brightness", 128, 0, 255, 1)
LIB8STATIC_ALWAYS_INLINE uint16_t scale16by8(uint16_t i, fract8 scale)
Scale a 16-bit unsigned value by an 8-bit value, which is treated as the numerator of a fraction whos...
common_type_t< T, U > fl_max(T a, U b)