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

Function FL_TEST_FILE

tests/fl/gfx/gamma_lut.cpp:9–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#include <cstdio> // ok include - for printf()
8
9FL_TEST_FILE(FL_FILEPATH) {
10
11using namespace fl;
12
13FL_TEST_CASE("gamma_lut - constexpr gamma helper") {
14 // gamma<u8x24>(2.2f) should return the raw fixed-point value
15 constexpr u32 raw = gamma<u8x24>(2.2f);
16 // 2.2 * 2^24 = 2.2 * 16777216 = 36909875.2
17 FL_CHECK_EQ(raw, u8x24(2.2f).raw());
18 FL_CHECK_GT(raw, 0u);
19}
20
21FL_TEST_CASE("gamma_lut - GammaEval boundaries") {
22 constexpr u32 g22 = gamma<u8x24>(2.2f);
23 GammaEval<g22> eval;
24
25 // x=0 must always map to 0
26 FL_CHECK_EQ(eval(0), 0);
27 // x=255 must always map to 255
28 FL_CHECK_EQ(eval(255), 255);
29}
30
31FL_TEST_CASE("gamma_lut - GammaEval monotonicity") {
32 constexpr u32 g22 = gamma<u8x24>(2.2f);
33 GammaEval<g22> eval;
34
35 // Gamma-corrected output must be monotonically non-decreasing
36 u8 prev = 0;
37 for (int i = 0; i < 256; ++i) {
38 u8 val = eval(static_cast<u8>(i));
39 FL_CHECK_GE(val, prev);
40 prev = val;
41 }
42}
43
44FL_TEST_CASE("gamma_lut - GammaEval accuracy vs float pow") {
45 constexpr u32 g22 = gamma<u8x24>(2.2f);
46 GammaEval<g22> eval;
47
48 // Check accuracy against floating-point reference for a few values.
49 // Allow +-2 tolerance for fixed-point approximation error.
50 for (int i = 1; i < 255; ++i) {
51 double expected = ::pow(i / 255.0, 2.2) * 255.0;
52 u8 actual = eval(static_cast<u8>(i));
53 int diff = static_cast<int>(actual) - static_cast<int>(expected + 0.5);
54 if (diff < 0) diff = -diff;
55 FL_CHECK_LE(diff, 2);
56 }
57}
58
59FL_TEST_CASE("gamma_lut - ProgmemLUT read") {
60 // Instantiate a 256-entry gamma 2.2 table and verify it can be read.
61 typedef ProgmemLUT<GammaEval<gamma<u8x24>(2.2f)>, 256> G22;
62
63 FL_CHECK_EQ(G22::read(0), 0);
64 FL_CHECK_EQ(G22::read(255), 255);
65
66 // Midpoint should be less than linear (gamma > 1 darkens midtones)

Callers

nothing calls this directly

Calls 6

u8x24Class · 0.85
evalFunction · 0.85
printfFunction · 0.85
powFunction · 0.50
readFunction · 0.50
rawMethod · 0.45

Tested by

no test coverage detected