| 80 | } // anonymous namespace |
| 81 | |
| 82 | FL_OPTIMIZE_FUNCTION |
| 83 | void five_bit_hd_gamma_bitshift( |
| 84 | fl::span<const CRGB> colors, CRGB colors_scale, u8 global_brightness, |
| 85 | fl::span<CRGB> out_colors, fl::span<u8> out_power_5bit) { |
| 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 | |
| 100 | const aligned_ptr<const u16, 64> glut(GAMMA_2_8_LUT); |
| 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 | } |
| 131 | |
| 132 | FL_OPTIMIZE_FUNCTION |
| 133 | void five_bit_hd_gamma_bitshift( |
no test coverage detected