FastLED 3.9.15
Loading...
Searching...
No Matches
crgb.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include "fl/stl/stdint.h"
7#include "chsv.h"
8#include "crgb.h"
9#include "lib8tion.h"
11#include "fl/math/scale8.h"
12
13
14// Define namespace-aware scale8 macro
15#define FUNCTION_SCALE8(a,b) fl::scale8(a,b)
16
23
24
26{
27 r = fl::qadd8( r, d);
28 g = fl::qadd8( g, d);
29 b = fl::qadd8( b, d);
30 return *this;
31}
32
34{
35 r = fl::qsub8( r, rhs.r);
36 g = fl::qsub8( g, rhs.g);
37 b = fl::qsub8( b, rhs.b);
38 return *this;
39}
40
47
50{
51 CRGB retval(*this);
52 ++(*this);
53 return retval;
54}
55
57{
58 r = fl::qsub8( r, d);
59 g = fl::qsub8( g, d);
60 b = fl::qsub8( b, d);
61 return *this;
62}
63
65{
66 r = fl::qmul8( r, d);
67 g = fl::qmul8( g, d);
68 b = fl::qmul8( b, d);
69 return *this;
70}
71
73{
74 nscale8x3_video( r, g, b, scaledown);
75 return *this;
76}
77
79{
80 nscale8x3_video( r, g, b, scaledown);
81 return *this;
82}
83
85{
86 nscale8x3_video( r, g, b, 255 - fadefactor);
87 return *this;
88}
89
96
99{
100 CRGB retval(*this);
101 --(*this);
102 return retval;
103}
104
105
106constexpr CRGB CRGB::nscale8_constexpr(const CRGB scaledown) const FL_NOEXCEPT
107{
108 return CRGB(
109 (((fl::u16)r) * (1 + (fl::u16)(scaledown.r))) >> 8,
110 (((fl::u16)g) * (1 + (fl::u16)(scaledown.g))) >> 8,
111 (((fl::u16)b) * (1 + (fl::u16)(scaledown.b))) >> 8
112 );
113}
114
115
117{
118 r = FUNCTION_SCALE8(r, scaledown.r);
119 g = FUNCTION_SCALE8(g, scaledown.g);
120 b = FUNCTION_SCALE8(b, scaledown.b);
121 return *this;
122}
123
125{
126 CRGB out = *this;
127 fl::nscale8x3( out.r, out.g, out.b, scaledown);
128 return out;
129}
130
132{
133 CRGB out;
134 out.r = FUNCTION_SCALE8(r, scaledown.r);
135 out.g = FUNCTION_SCALE8(g, scaledown.g);
136 out.b = FUNCTION_SCALE8(b, scaledown.b);
137 return out;
138}
139
140
142 //Y' = 0.2126 R' + 0.7152 G' + 0.0722 B'
143 // 54 183 18 (!)
144
145 fl::u8 luma = scale8_LEAVING_R1_DIRTY( r, 54) + \
146 scale8_LEAVING_R1_DIRTY( g, 183) + \
147 scale8_LEAVING_R1_DIRTY( b, 18);
148 cleanup_R1();
149 return luma;
150}
151
153#if FASTLED_SCALE8_FIXED == 1
154 const fl::u8 eightyfive = 85;
155#else
156 const fl::u8 eightyfive = 86;
157#endif
158 fl::u8 avg = scale8_LEAVING_R1_DIRTY( r, eightyfive) + \
159 scale8_LEAVING_R1_DIRTY( g, eightyfive) + \
160 scale8_LEAVING_R1_DIRTY( b, eightyfive);
161 cleanup_R1();
162 return avg;
163}
164
165
166
168{
169 CRGB ret;
170
171 ret.r = lerp16by16(r<<8,other.r<<8,frac)>>8;
172 ret.g = lerp16by16(g<<8,other.g<<8,frac)>>8;
173 ret.b = lerp16by16(b<<8,other.b<<8,frac)>>8;
174
175 return ret;
176}
177
178
179namespace fl {
180
183{
184 return CRGB( fl::qadd8( p1.r, p2.r),
185 fl::qadd8( p1.g, p2.g),
186 fl::qadd8( p1.b, p2.b));
187}
188
191{
192 return CRGB( fl::qsub8( p1.r, p2.r),
193 fl::qsub8( p1.g, p2.g),
194 fl::qsub8( p1.b, p2.b));
195}
196
199{
200 return CRGB( qmul8( p1.r, d),
201 qmul8( p1.g, d),
202 qmul8( p1.b, d));
203}
204
207{
208 CRGB retval( p1);
209 retval.nscale8_video( d);
210 return retval;
211}
212
213} // namespace fl
214
215
216#undef FUNCTION_SCALE8
217
Defines the hue, saturation, and value (HSV) pixel struct.
Legacy header.
#define FUNCTION_SCALE8(a, b)
Definition crgb.hpp:15
Legacy compatibility header for 8-bit scaling functions.
LIB8STATIC fl::u16 lerp16by16(fl::u16 a, fl::u16 b, fract16 frac)
Linear interpolation between two unsigned 16-bit values, with 16-bit fraction.
Definition lib8tion.h:380
Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.
u16 fract16
ANSI: unsigned _Fract.
Definition s16x16x4.h:171
unsigned char u8
Definition s16x16x4.h:132
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:15
FASTLED_FORCE_INLINE CRGB operator*(const CRGB &p1, u8 d) FL_NOEXCEPT
Multiply each of the channels by a constant, saturating each channel at 0xFF.
Definition crgb.hpp:198
FASTLED_FORCE_INLINE CRGB operator+(const CRGB &p1, const CRGB &p2) FL_NOEXCEPT
Add one CRGB to another, saturating at 0xFF for each channel.
Definition crgb.hpp:182
FASTLED_FORCE_INLINE CRGB operator-(const CRGB &p1, const CRGB &p2) FL_NOEXCEPT
Subtract one CRGB from another, saturating at 0x00 for each channel.
Definition crgb.hpp:190
FASTLED_FORCE_INLINE CRGB operator%(const CRGB &p1, u8 d) FL_NOEXCEPT
Scale using CRGB::nscale8_video()
Definition crgb.hpp:206
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_DISABLE_WARNING_RETURN_TYPE
#define FL_DISABLE_WARNING_IMPLICIT_INT_CONVERSION
#define FASTLED_FORCE_INLINE
#define FL_DISABLE_WARNING_PUSH
#define FL_DISABLE_WARNING_SIGN_CONVERSION
#define FL_DISABLE_WARNING_POP
#define FL_DISABLE_WARNING_UNUSED_PARAMETER
#define FL_DISABLE_WARNING_FLOAT_CONVERSION
#define FL_NOEXCEPT
constexpr CRGB nscale8_constexpr(const CRGB scaledown) const FL_NOEXCEPT
Definition crgb.hpp:106
FASTLED_FORCE_INLINE CRGB & operator-=(const CRGB &rhs) FL_NOEXCEPT
Subtract one CRGB from another, saturating at 0x00 for each channel.
Definition crgb.hpp:33
FASTLED_FORCE_INLINE CRGB scale8(u8 scaledown) const FL_NOEXCEPT
Return a CRGB object that is a scaled down version of this object.
Definition crgb.hpp:124
FASTLED_FORCE_INLINE CRGB & addToRGB(u8 d) FL_NOEXCEPT
Add a constant to each channel, saturating at 0xFF.
Definition crgb.hpp:25
FASTLED_FORCE_INLINE CRGB & operator--() FL_NOEXCEPT
Subtract a constant of '1' from each channel, saturating at 0x00.
Definition crgb.hpp:91
u8 getLuma() const FL_NOEXCEPT
Get the "luma" of a CRGB object.
Definition crgb.hpp:141
FASTLED_FORCE_INLINE CRGB & fadeLightBy(u8 fadefactor) FL_NOEXCEPT
fadeLightBy is a synonym for nscale8_video(), as a fade instead of a scale
Definition crgb.hpp:84
FASTLED_FORCE_INLINE CRGB & operator*=(u8 d) FL_NOEXCEPT
Multiply each of the channels by a constant, saturating each channel at 0xFF.
Definition crgb.hpp:64
FASTLED_FORCE_INLINE CRGB & operator++() FL_NOEXCEPT
Add a constant of '1' from each channel, saturating at 0xFF.
Definition crgb.hpp:42
FASTLED_FORCE_INLINE u8 getAverageLight() const FL_NOEXCEPT
Get the average of the R, G, and B values.
Definition crgb.hpp:152
FASTLED_FORCE_INLINE CRGB lerp16(const CRGB &other, fract16 frac) const FL_NOEXCEPT
Return a new CRGB object after performing a linear interpolation between this object and the passed i...
Definition crgb.hpp:167
FASTLED_FORCE_INLINE CRGB & operator%=(u8 scaledown) FL_NOEXCEPT
%= is a synonym for nscale8_video().
Definition crgb.hpp:78
CRGB & nscale8(u8 scaledown) FL_NOEXCEPT
Scale down a RGB to N/256ths of its current brightness, using "plain math" dimming rules.
Definition crgb.cpp.hpp:88
FASTLED_FORCE_INLINE CRGB() FL_NOEXCEPT
Default constructor.
Definition crgb.h:111
FASTLED_FORCE_INLINE CRGB & nscale8_video(u8 scaledown) FL_NOEXCEPT
Scale down a RGB to N/256ths of it's current brightness using "video" dimming rules.
Definition crgb.hpp:72
FASTLED_FORCE_INLINE CRGB & subtractFromRGB(u8 d) FL_NOEXCEPT
Subtract a constant from each channel, saturating at 0x00.
Definition crgb.hpp:56
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38