FastLED 3.10.6
Loading...
Searching...
No Matches

◆ applyGamma_video() [3/3]

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

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

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

References brightness, gamma(), fl::s16x16::pow(), fl::s16x16::raw(), and x.

Referenced by applyGamma_video(), applyGamma_video(), FL_DISABLE_WARNING(), napplyGamma_video(), napplyGamma_video(), napplyGamma_video(), and napplyGamma_video().

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