GCC Code Coverage Report


Directory: ./
File: channeloutput/GammaLUT.h
Date: 2026-12-01 12:27:28
Exec Total Coverage
Lines: 28 33 84.8%
Functions: 6 6 100.0%
Branches: 20 30 66.7%

Line Branch Exec Source
1 #pragma once
2 /*
3 * This file is part of the Falcon Player (FPP) and is Copyright (C)
4 * 2013-2025 by the Falcon Player Developers.
5 *
6 * The Falcon Player (FPP) is free software, and is covered under
7 * multiple Open Source licenses. Please see the included 'LICENSES'
8 * file for descriptions of what files are covered by each license.
9 *
10 * This source file is covered under the LGPL v2.1 as described in the
11 * included LICENSE.LGPL file.
12 */
13
14 #include <cmath>
15 #include <cstdlib>
16
17 #include "fpp-json.h"
18
19 // The 256 entry gamma curve every matrix output builds from its "gamma" config
20 // value. Header only so the channel output plugins, which each link their own
21 // object list, pick it up without a new object to link.
22 namespace GammaLUT {
23
24 // Outputs fall back to their own default both when gamma is unconfigured and
25 // when the configured value is outside the range they accept, so the default is
26 // a per caller parameter. Written so NaN ("gamma": "nan") is out of range too:
27 // it fails every comparison, and as a gamma it built a curve that lit every
28 // channel at full brightness.
29 197 inline float Clamp(float gamma, float def) {
30
2/4
✓ Branch 0 taken 197 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 197 times.
197 if (!(gamma >= 0.01f && gamma <= 50.0f)) {
31 ✗ return def;
32 }
33 197 return gamma;
34 }
35
36 196 inline float ParseConfig(const Json::Value& config, float def) {
37 196 float gamma = def;
38
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 141 times.
196 if (config.isMember("gamma")) {
39
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 gamma = atof(config["gamma"].asString().c_str());
40 }
41 196 return Clamp(gamma, def);
42 }
43
44 // Full scale value a panel bit depth can carry. Depths of 8 or less drive the
45 // plain 8 bit range.
46 56 inline float MaxForColorDepth(int colorDepth) {
47
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
56 if (colorDepth > 8 && colorDepth <= 16) {
48 ✗ return (float)((1 << colorDepth) - 1);
49 }
50 56 return 255.0f;
51 }
52
53 // scale trims the whole curve, for a matrix that has to make up the difference
54 // when it shares hardware set up for a brighter one. floorLowEnd keeps a value
55 // that rounds to 0, but sits more than a quarter step above it, at 1 so the
56 // bottom of the curve does not go fully black.
57 template<typename T>
58 197 inline void Build(T* curve, float gamma, float max = 255.0f, float scale = 1.0f, bool floorLowEnd = false) {
59
2/2
✓ Branch 0 taken 50432 times.
✓ Branch 1 taken 197 times.
50629 for (int x = 0; x < 256; x++) {
60 50432 float f = x;
61 50432 f = max * std::pow(f / 255.0f, gamma) * scale;
62
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50432 times.
50432 if (f > max) {
63 ✗ f = max;
64 }
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50432 times.
50432 if (f < 0.0f) {
66 ✗ f = 0.0f;
67 }
68 50432 curve[x] = std::round(f);
69
6/6
✓ Branch 0 taken 14336 times.
✓ Branch 1 taken 36096 times.
✓ Branch 2 taken 70 times.
✓ Branch 3 taken 14266 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 66 times.
50432 if (floorLowEnd && curve[x] == 0 && f > 0.25) {
70 4 curve[x] = 1;
71 }
72 }
73 197 }
74
75 template<typename T>
76 56 inline void BuildForColorDepth(T* curve, float gamma, int colorDepth, float scale = 1.0f) {
77 56 Build(curve, gamma, MaxForColorDepth(colorDepth), scale, true);
78 // The two shallowest depths have no step low enough to render these values,
79 // so they take the first step the panel can actually show.
80
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 54 times.
56 if (colorDepth == 6) {
81 2 curve[2] = curve[4];
82 2 curve[3] = curve[4];
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 } else if (colorDepth == 7) {
84 ✗ curve[1] = curve[2];
85 }
86 56 }
87
88 } // namespace GammaLUT
89