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

◆ five_bit_hd_gamma_bitshift() [1/2]

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

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

85 {
86
87 u16 n = static_cast<u16>(colors.size());
88 if (out_colors.size() < n) n = static_cast<u16>(out_colors.size());
89 if (out_power_5bit.size() < n) n = static_cast<u16>(out_power_5bit.size());
90
91 // Brightness==0: zero everything and return immediately.
92 if (global_brightness == 0) {
93 for (u16 i = 0; i < n; ++i) {
94 out_colors[i] = CRGB(0, 0, 0);
95 out_power_5bit[i] = 0;
96 }
97 return;
98 }
99
101
102 // Precompute color-scale multipliers once (avoid per-pixel branches).
103 const bool apply_r_scale = (colors_scale.r != 0xff);
104 const bool apply_g_scale = (colors_scale.g != 0xff);
105 const bool apply_b_scale = (colors_scale.b != 0xff);
106 const u16 rscale_p1 = 1u + static_cast<u16>(colors_scale.r);
107 const u16 gscale_p1 = 1u + static_cast<u16>(colors_scale.g);
108 const u16 bscale_p1 = 1u + static_cast<u16>(colors_scale.b);
109
110 // Precompute brightness multiplier once.
111 const bool apply_brightness = (global_brightness != 0xff);
112 const u16 bright_p1 = 1u + static_cast<u16>(global_brightness);
113
114 for (u16 i = 0; i < n; ++i) {
115 const CRGB &c = colors[i];
116
117 u16 r16 = five_bit_impl::gamma_lut_read(glut, c.r);
118 u16 g16 = five_bit_impl::gamma_lut_read(glut, c.g);
119 u16 b16 = five_bit_impl::gamma_lut_read(glut, c.b);
120
121 // Color-scale: branchless multiply, guarded by precomputed bools.
122 if (apply_r_scale) r16 = five_bit_impl::scale16by8_nozero(r16, rscale_p1);
123 if (apply_g_scale) g16 = five_bit_impl::scale16by8_nozero(g16, gscale_p1);
124 if (apply_b_scale) b16 = five_bit_impl::scale16by8_nozero(b16, bscale_p1);
125
126 five_bit_impl::five_bit_pixel(r16, g16, b16, global_brightness,
127 bright_p1, apply_brightness,
128 &out_colors[i], &out_power_5bit[i]);
129 }
130}
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().

Referenced by APA102Controller< DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED, GAMMA_CORRECTION_MODE, START_FRAME, END_FRAME >::showPixelsGammaBitShift().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: