FastLED 3.10.8
Loading...
Searching...
No Matches

◆ applyGamma_video()

fl::u8 fl::applyGamma_video ( fl::u8 brightness,
float gamma )

Definition at line 1376 of file colorutils.cpp.hpp.

1376 {
1377 // Fixed-point path (s16x16) avoids pulling `__ieee754_pow` (libm,
1378 // ~2.7 KB) into release builds — see #2886 / #2910. Matches the
1379 // gamma8 LUT generator's approach in src/fl/math/ease.cpp.hpp.
1380 if (brightness == 0) {
1381 return 0;
1382 }
1383 constexpr fl::s16x16 inv_255_fp(1.0f / 255.0f);
1384 const fl::s16x16 gamma_fp(gamma);
1385 const fl::s16x16 x = static_cast<i32>(brightness) * inv_255_fp; // [0, 1]
1386 const fl::s16x16 r = fl::s16x16::pow(x, gamma_fp); // (0, 1]
1387 // Scale to u8 [0, 255] with round-half-up:
1388 // result = ((u32)raw * 255 + 0x8000) >> 16
1389 const fl::u32 scaled =
1390 (static_cast<fl::u32>(r.raw()) * 255u + 0x8000u) >> 16;
1391 fl::u8 result = static_cast<fl::u8>(scaled > 255u ? 255u : scaled);
1392 if (result == 0) {
1393 result = 1; // never gamma-adjust a positive number down to zero
1394 }
1395 return result;
1396}
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
int x
Definition simple.h:92
constexpr i32 raw() const FL_NO_EXCEPT
Definition s16x16.h:62
static FASTLED_FORCE_INLINE s16x16 pow(s16x16 base, s16x16 exp) FL_NO_EXCEPT
Definition s16x16.h:279
unsigned char u8
Definition stdint.h:131
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31