GCC Code Coverage Report


Directory: ./
File: overlays/wled/crgb.cpp
Date: 2026-10-29 08:11:58
Exec Total Coverage
Lines: 11 39 28.2%
Functions: 3 7 42.9%
Branches: 4 18 22.2%

Line Branch Exec Source
1 /// @file crgb.cpp
2 /// Utility functions for the red, green, and blue (RGB) pixel struct
3
4 #define FASTLED_INTERNAL
5 #include "crgb.h"
6 #include "FastLED.h"
7
8 #include "lib8tion/math8.h"
9
10 #include "fl/namespace.h"
11
12 FASTLED_NAMESPACE_BEGIN
13
14
15 ✗ CRGB CRGB::computeAdjustment(uint8_t scale, const CRGB &colorCorrection,
16 const CRGB &colorTemperature) {
17 #if defined(NO_CORRECTION) && (NO_CORRECTION == 1)
18 return CRGB(scale, scale, scale);
19 #else
20 ✗ CRGB adj(0, 0, 0);
21 ✗ if (scale > 0) {
22 ✗ for (uint8_t i = 0; i < 3; ++i) {
23 ✗ uint8_t cc = colorCorrection.raw[i];
24 ✗ uint8_t ct = colorTemperature.raw[i];
25 ✗ if (cc > 0 && ct > 0) {
26 // Optimized for AVR size. This function is only called very
27 // infrequently so size matters more than speed.
28 ✗ uint32_t work = (((uint16_t)cc) + 1);
29 ✗ work *= (((uint16_t)ct) + 1);
30 ✗ work *= scale;
31 ✗ work /= 0x10000L;
32 ✗ adj.raw[i] = work & 0xFF;
33 }
34 }
35 }
36 ✗ return adj;
37 #endif
38 }
39
40 ✗ CRGB CRGB::blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2) {
41 ✗ return CRGB(blend8(p1.r, p2.r, amountOfP2), blend8(p1.g, p2.g, amountOfP2),
42 ✗ blend8(p1.b, p2.b, amountOfP2));
43 }
44
45 ✗ CRGB CRGB::blendAlphaMaxChannel(const CRGB &upper, const CRGB &lower) {
46 // Use luma of upper pixel as alpha (0..255)
47 ✗ uint8_t max_component = 0;
48 ✗ for (int i = 0; i < 3; ++i) {
49 ✗ if (upper.raw[i] > max_component) {
50 ✗ max_component = upper.raw[i];
51 }
52 }
53 // uint8_t alpha = upper.getLuma();
54 // blend(lower, upper, alpha) → (lower * (255−alpha) + upper * alpha) / 256
55 ✗ uint8_t amountOf2 = 255 - max_component;
56 ✗ return CRGB::blend(upper, lower, amountOf2);
57 }
58
59 27044 CRGB &CRGB::nscale8(uint8_t scaledown) {
60 27044 nscale8x3(r, g, b, scaledown);
61 27044 return *this;
62 }
63
64 /// Add one CRGB to another, saturating at 0xFF for each channel
65 35737 CRGB &CRGB::operator+=(const CRGB &rhs) {
66
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35737 times.
35737 r = qadd8(r, rhs.r);
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35737 times.
35737 g = qadd8(g, rhs.g);
68
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 35725 times.
35737 b = qadd8(b, rhs.b);
69 35737 return *this;
70 }
71
72 ✗ CRGB CRGB::lerp8(const CRGB &other, fract8 amountOf2) const {
73 CRGB ret;
74
75 ✗ ret.r = lerp8by8(r, other.r, amountOf2);
76 ✗ ret.g = lerp8by8(g, other.g, amountOf2);
77 ✗ ret.b = lerp8by8(b, other.b, amountOf2);
78
79 ✗ return ret;
80 }
81
82 19 CRGB& CRGB::fadeToBlackBy (uint8_t fadefactor )
83 {
84 19 nscale8x3( r, g, b, 255 - fadefactor);
85 19 return *this;
86 }
87
88
89 FASTLED_NAMESPACE_END
90