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

◆ applyGamma_video() [3/3]

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

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

1290 {
1291 // Fixed-point path (s16x16) avoids pulling `__ieee754_pow` (libm,
1292 // ~2.7 KB) into release builds — see #2886 / #2910. Matches the
1293 // gamma8 LUT generator's approach in src/fl/math/ease.cpp.hpp.
1294 if (brightness == 0) {
1295 return 0;
1296 }
1297 constexpr fl::s16x16 inv_255_fp(1.0f / 255.0f);
1298 const fl::s16x16 gamma_fp(gamma);
1299 const fl::s16x16 x = static_cast<i32>(brightness) * inv_255_fp; // [0, 1]
1300 const fl::s16x16 r = fl::s16x16::pow(x, gamma_fp); // (0, 1]
1301 // Scale to u8 [0, 255] with round-half-up:
1302 // result = ((u32)raw * 255 + 0x8000) >> 16
1303 const fl::u32 scaled =
1304 (static_cast<fl::u32>(r.raw()) * 255u + 0x8000u) >> 16;
1305 fl::u8 result = static_cast<fl::u8>(scaled > 255u ? 255u : scaled);
1306 if (result == 0) {
1307 result = 1; // never gamma-adjust a positive number down to zero
1308 }
1309 return result;
1310}
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
int x
Definition simple.h:92
constexpr i32 raw() const FL_NOEXCEPT
Definition s16x16.h:60
static FASTLED_FORCE_INLINE s16x16 pow(s16x16 base, s16x16 exp) FL_NOEXCEPT
Definition s16x16.h:235
unsigned char u8
Definition stdint.h:131
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
constexpr u32 gamma(float g) FL_NOEXCEPT
Definition gamma_lut.h:36

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: