GCC Code Coverage Report


Directory: ./
File: overlays/wled/crgb.hpp
Date: 2026-10-29 08:11:58
Exec Total Coverage
Lines: 10 10 100.0%
Functions: 0 0 -%
Branches: 3 8 37.5%

Line Branch Exec Source
1 /// @file crgb.hpp
2 /// Defines utility functions for the red, green, and blue (RGB) pixel struct
3
4 #pragma once
5
6 #include <stdint.h>
7 #include "chsv.h"
8 #include "crgb.h"
9 #include "lib8tion.h"
10 #include "fl/namespace.h"
11 #include "fl/force_inline.h"
12 //#include "fl/str.h"
13
14 #if FASTLED_IS_USING_NAMESPACE
15 #define FUNCTION_SCALE8(a,b) FASTLED_NAMESPACE::scale8(a,b)
16 #else
17 #define FUNCTION_SCALE8(a,b) ::scale8(a,b)
18 #endif
19
20 FASTLED_NAMESPACE_BEGIN
21
22 FASTLED_FORCE_INLINE CRGB& CRGB::addToRGB (uint8_t d )
23 {
24 r = qadd8( r, d);
25 g = qadd8( g, d);
26 b = qadd8( b, d);
27 return *this;
28 }
29
30 FASTLED_FORCE_INLINE CRGB& CRGB::operator-= (const CRGB& rhs )
31 {
32 r = qsub8( r, rhs.r);
33 g = qsub8( g, rhs.g);
34 b = qsub8( b, rhs.b);
35 return *this;
36 }
37
38 /// Add a constant of '1' from each channel, saturating at 0xFF
39 FASTLED_FORCE_INLINE CRGB& CRGB::operator++ ()
40 {
41 addToRGB(1);
42 return *this;
43 }
44
45 /// @copydoc operator++
46 FASTLED_FORCE_INLINE CRGB CRGB::operator++ (int )
47 {
48 CRGB retval(*this);
49 ++(*this);
50 return retval;
51 }
52
53 FASTLED_FORCE_INLINE CRGB& CRGB::subtractFromRGB(uint8_t d)
54 {
55 r = qsub8( r, d);
56 g = qsub8( g, d);
57 b = qsub8( b, d);
58 return *this;
59 }
60
61 FASTLED_FORCE_INLINE CRGB& CRGB::operator*= (uint8_t d )
62 {
63 r = qmul8( r, d);
64 g = qmul8( g, d);
65 b = qmul8( b, d);
66 return *this;
67 }
68
69 FASTLED_FORCE_INLINE CRGB& CRGB::nscale8_video(uint8_t scaledown )
70 {
71 46 nscale8x3_video( r, g, b, scaledown);
72 46 return *this;
73 }
74
75 FASTLED_FORCE_INLINE CRGB& CRGB::operator%= (uint8_t scaledown )
76 {
77 nscale8x3_video( r, g, b, scaledown);
78 return *this;
79 }
80
81 FASTLED_FORCE_INLINE CRGB& CRGB::fadeLightBy (uint8_t fadefactor )
82 {
83 nscale8x3_video( r, g, b, 255 - fadefactor);
84 return *this;
85 }
86
87 /// Subtract a constant of '1' from each channel, saturating at 0x00
88 FASTLED_FORCE_INLINE CRGB& CRGB::operator-- ()
89 {
90 subtractFromRGB(1);
91 return *this;
92 }
93
94 /// @copydoc operator--
95 FASTLED_FORCE_INLINE CRGB CRGB::operator-- (int )
96 {
97 CRGB retval(*this);
98 --(*this);
99 return retval;
100 }
101
102
103 constexpr CRGB CRGB::nscale8_constexpr(const CRGB scaledown) const
104 {
105 return CRGB(
106 scale8_constexpr(r, scaledown.r),
107 scale8_constexpr(g, scaledown.g),
108 scale8_constexpr(b, scaledown.b)
109 );
110 }
111
112
113 FASTLED_FORCE_INLINE CRGB& CRGB::nscale8 (const CRGB & scaledown )
114 {
115 r = FUNCTION_SCALE8(r, scaledown.r);
116 g = FUNCTION_SCALE8(g, scaledown.g);
117 b = FUNCTION_SCALE8(b, scaledown.b);
118 return *this;
119 }
120
121 FASTLED_FORCE_INLINE CRGB CRGB::scale8 (uint8_t scaledown ) const
122 {
123 CRGB out = *this;
124 nscale8x3( out.r, out.g, out.b, scaledown);
125 return out;
126 }
127
128 FASTLED_FORCE_INLINE CRGB CRGB::scale8 (const CRGB & scaledown ) const
129 {
130 CRGB out;
131 out.r = FUNCTION_SCALE8(r, scaledown.r);
132 out.g = FUNCTION_SCALE8(g, scaledown.g);
133 out.b = FUNCTION_SCALE8(b, scaledown.b);
134 return out;
135 }
136
137
138 FASTLED_FORCE_INLINE uint8_t CRGB::getLuma( ) const {
139 //Y' = 0.2126 R' + 0.7152 G' + 0.0722 B'
140 // 54 183 18 (!)
141
142 uint8_t luma = scale8_LEAVING_R1_DIRTY( r, 54) + \
143 scale8_LEAVING_R1_DIRTY( g, 183) + \
144 scale8_LEAVING_R1_DIRTY( b, 18);
145 cleanup_R1();
146 return luma;
147 }
148
149 FASTLED_FORCE_INLINE uint8_t CRGB::getAverageLight( ) const {
150 #if FASTLED_SCALE8_FIXED == 1
151 const uint8_t eightyfive = 85;
152 #else
153 22625 const uint8_t eightyfive = 86;
154 #endif
155 22625 uint8_t avg = scale8_LEAVING_R1_DIRTY( r, eightyfive) + \
156 22625 scale8_LEAVING_R1_DIRTY( g, eightyfive) + \
157 45250 scale8_LEAVING_R1_DIRTY( b, eightyfive);
158 cleanup_R1();
159 22625 return avg;
160 }
161
162
163
164 FASTLED_FORCE_INLINE CRGB CRGB::lerp16( const CRGB& other, fract16 frac) const
165 {
166 CRGB ret;
167
168 ret.r = lerp16by16(r<<8,other.r<<8,frac)>>8;
169 ret.g = lerp16by16(g<<8,other.g<<8,frac)>>8;
170 ret.b = lerp16by16(b<<8,other.b<<8,frac)>>8;
171
172 return ret;
173 }
174
175
176 /// @copydoc CRGB::operator+=
177 FASTLED_FORCE_INLINE CRGB operator+( const CRGB& p1, const CRGB& p2)
178 {
179
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
13522 return CRGB( qadd8( p1.r, p2.r),
180 27044 qadd8( p1.g, p2.g),
181
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 13522 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13522 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 13522 times.
54088 qadd8( p1.b, p2.b));
182 }
183
184 /// @copydoc CRGB::operator-=
185 FASTLED_FORCE_INLINE CRGB operator-( const CRGB& p1, const CRGB& p2)
186 {
187 return CRGB( qsub8( p1.r, p2.r),
188 qsub8( p1.g, p2.g),
189 qsub8( p1.b, p2.b));
190 }
191
192 /// @copydoc CRGB::operator*=
193 FASTLED_FORCE_INLINE CRGB operator*( const CRGB& p1, uint8_t d)
194 {
195 return CRGB( qmul8( p1.r, d),
196 qmul8( p1.g, d),
197 qmul8( p1.b, d));
198 }
199
200 /// Scale using CRGB::nscale8_video()
201 FASTLED_FORCE_INLINE CRGB operator%( const CRGB& p1, uint8_t d)
202 {
203 CRGB retval( p1);
204 retval.nscale8_video( d);
205 return retval;
206 }
207
208 FASTLED_NAMESPACE_END
209
210 #undef FUNCTION_SCALE8
211