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

◆ five_bit_hd_gamma_bitshift() [2/2]

void fl::five_bit_hd_gamma_bitshift ( fl::span< const CRGB > colors,
CRGB colors_scale,
u8 global_brightness,
fl::span< CRGBA5 > out )

Definition at line 133 of file five_bit_hd_gamma.cpp.hpp.

135 {
136
137 u16 n = static_cast<u16>(colors.size());
138 if (out.size() < n) n = static_cast<u16>(out.size());
139
140 // Brightness==0: zero everything and return immediately.
141 if (global_brightness == 0) {
142 for (u16 i = 0; i < n; ++i) {
143 out[i].color = CRGB(0, 0, 0);
144 out[i].brightness_5bit = 0;
145 }
146 return;
147 }
148
150
151 // Precompute color-scale multipliers once (avoid per-pixel branches).
152 const bool apply_r_scale = (colors_scale.r != 0xff);
153 const bool apply_g_scale = (colors_scale.g != 0xff);
154 const bool apply_b_scale = (colors_scale.b != 0xff);
155 const u16 rscale_p1 = 1u + static_cast<u16>(colors_scale.r);
156 const u16 gscale_p1 = 1u + static_cast<u16>(colors_scale.g);
157 const u16 bscale_p1 = 1u + static_cast<u16>(colors_scale.b);
158
159 // Precompute brightness multiplier once.
160 const bool apply_brightness = (global_brightness != 0xff);
161 const u16 bright_p1 = 1u + static_cast<u16>(global_brightness);
162
163 for (u16 i = 0; i < n; ++i) {
164 const CRGB &c = colors[i];
165
166 u16 r16 = five_bit_impl::gamma_lut_read(glut, c.r);
167 u16 g16 = five_bit_impl::gamma_lut_read(glut, c.g);
168 u16 b16 = five_bit_impl::gamma_lut_read(glut, c.b);
169
170 // Color-scale: branchless multiply, guarded by precomputed bools.
171 if (apply_r_scale) r16 = five_bit_impl::scale16by8_nozero(r16, rscale_p1);
172 if (apply_g_scale) g16 = five_bit_impl::scale16by8_nozero(g16, gscale_p1);
173 if (apply_b_scale) b16 = five_bit_impl::scale16by8_nozero(b16, bscale_p1);
174
175 five_bit_impl::five_bit_pixel(r16, g16, b16, global_brightness,
176 bright_p1, apply_brightness,
177 &out[i].color, &out[i].brightness_5bit);
178 }
179}
constexpr fl::size size() const FL_NOEXCEPT
Definition span.h:458
fl::CRGB CRGB
Definition video.h:15
const u16 GAMMA_2_8_LUT[256]
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38

References GAMMA_2_8_LUT, and fl::span< T, Extent >::size().

+ Here is the call graph for this function: