MCPcopy Create free account
hub / github.com/FastLED/FastLED / applyGamma_video

Function applyGamma_video

src/fl/gfx/colorutils.cpp.hpp:1290–1310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1288}
1289
1290fl::u8 applyGamma_video(fl::u8 brightness, float gamma) {
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}
1311
1312CRGB applyGamma_video(const CRGB &orig, float gamma) {
1313 CRGB adj;

Callers 2

colorutils.cpp.hppFile · 0.85
napplyGamma_videoFunction · 0.85

Calls 2

powFunction · 0.50
rawMethod · 0.45

Tested by

no test coverage detected