FastLED 3.10.8
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 84 of file five_bit_hd_gamma.cpp.hpp.

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

References FL_NO_EXCEPT, and GAMMA_2_8_LUT.

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

+ Here is the caller graph for this function: