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/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#include "fl/compiler_control.h"
15
22
23#if FASTLED_IS_USING_NAMESPACE
24#define FUNCTION_SCALE8(a,b) FASTLED_NAMESPACE::scale8(a,b)
25#else
26#define FUNCTION_SCALE8(a,b) ::scale8(a,b)
27#endif
28
30
32{
33 r = qadd8( r, d);
34 g = qadd8( g, d);
35 b = qadd8( b, d);
36 return *this;
37}
38
40{
41 r = qsub8( r, rhs.r);
42 g = qsub8( g, rhs.g);
43 b = qsub8( b, rhs.b);
44 return *this;
45}
46
49{
50 addToRGB(1);
51 return *this;
52}
53
56{
57 CRGB retval(*this);
58 ++(*this);
59 return retval;
60}
61
63{
64 r = qsub8( r, d);
65 g = qsub8( g, d);
66 b = qsub8( b, d);
67 return *this;
68}
69
71{
72 r = qmul8( r, d);
73 g = qmul8( g, d);
74 b = qmul8( b, d);
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, scaledown);
87 return *this;
88}
89
90FASTLED_FORCE_INLINE CRGB& CRGB::fadeLightBy (uint8_t fadefactor )
91{
92 nscale8x3_video( r, g, b, 255 - fadefactor);
93 return *this;
94}
95
98{
100 return *this;
101}
102
105{
106 CRGB retval(*this);
107 --(*this);
108 return retval;
109}
110
111
112constexpr CRGB CRGB::nscale8_constexpr(const CRGB scaledown) const
113{
114 return CRGB(
115 scale8_constexpr(r, scaledown.r),
116 scale8_constexpr(g, scaledown.g),
117 scale8_constexpr(b, scaledown.b)
118 );
119}
120
121
123{
124 r = FUNCTION_SCALE8(r, scaledown.r);
125 g = FUNCTION_SCALE8(g, scaledown.g);
126 b = FUNCTION_SCALE8(b, scaledown.b);
127 return *this;
128}
129
130FASTLED_FORCE_INLINE CRGB CRGB::scale8 (uint8_t scaledown ) const
131{
132 CRGB out = *this;
133 nscale8x3( out.r, out.g, out.b, scaledown);
134 return out;
135}
136
137FASTLED_FORCE_INLINE CRGB CRGB::scale8 (const CRGB & scaledown ) const
138{
139 CRGB out;
140 out.r = FUNCTION_SCALE8(r, scaledown.r);
141 out.g = FUNCTION_SCALE8(g, scaledown.g);
142 out.b = FUNCTION_SCALE8(b, scaledown.b);
143 return out;
144}
145
146
148 //Y' = 0.2126 R' + 0.7152 G' + 0.0722 B'
149 // 54 183 18 (!)
150
151 uint8_t luma = scale8_LEAVING_R1_DIRTY( r, 54) + \
152 scale8_LEAVING_R1_DIRTY( g, 183) + \
153 scale8_LEAVING_R1_DIRTY( b, 18);
154 cleanup_R1();
155 return luma;
156}
157
159#if FASTLED_SCALE8_FIXED == 1
160 const uint8_t eightyfive = 85;
161#else
162 const uint8_t eightyfive = 86;
163#endif
164 uint8_t avg = scale8_LEAVING_R1_DIRTY( r, eightyfive) + \
165 scale8_LEAVING_R1_DIRTY( g, eightyfive) + \
166 scale8_LEAVING_R1_DIRTY( b, eightyfive);
167 cleanup_R1();
168 return avg;
169}
170
171
172
174{
175 CRGB ret;
176
177 ret.r = lerp16by16(r<<8,other.r<<8,frac)>>8;
178 ret.g = lerp16by16(g<<8,other.g<<8,frac)>>8;
179 ret.b = lerp16by16(b<<8,other.b<<8,frac)>>8;
180
181 return ret;
182}
183
184
187{
188 return CRGB( qadd8( p1.r, p2.r),
189 qadd8( p1.g, p2.g),
190 qadd8( p1.b, p2.b));
191}
192
195{
196 return CRGB( qsub8( p1.r, p2.r),
197 qsub8( p1.g, p2.g),
198 qsub8( p1.b, p2.b));
199}
200
203{
204 return CRGB( qmul8( p1.r, d),
205 qmul8( p1.g, d),
206 qmul8( p1.b, d));
207}
208
211{
212 CRGB retval( p1);
213 retval.nscale8_video( d);
214 return retval;
215}
216
218
219#undef FUNCTION_SCALE8
220
Defines the hue, saturation, and value (HSV) pixel struct.
#define FL_DISABLE_WARNING_RETURN_TYPE
#define FL_DISABLE_WARNING_IMPLICIT_INT_CONVERSION
#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
Defines the red, green, and blue (RGB) pixel struct.
FASTLED_FORCE_INLINE CRGB operator%(const CRGB &p1, uint8_t d)
Scale using CRGB::nscale8_video()
Definition crgb.hpp:210
FASTLED_FORCE_INLINE CRGB operator-(const CRGB &p1, const CRGB &p2)
Subtract one CRGB from another, saturating at 0x00 for each channel.
Definition crgb.hpp:194
#define FUNCTION_SCALE8(a, b)
Definition crgb.hpp:26
FASTLED_FORCE_INLINE CRGB operator*(const CRGB &p1, uint8_t d)
Multiply each of the channels by a constant, saturating each channel at 0xFF.
Definition crgb.hpp:202
FASTLED_FORCE_INLINE CRGB operator+(const CRGB &p1, const CRGB &p2)
Add one CRGB to another, saturating at 0xFF for each channel.
Definition crgb.hpp:186
#define FASTLED_FORCE_INLINE
Definition force_inline.h:6
LIB8STATIC uint16_t lerp16by16(uint16_t a, uint16_t b, fract16 frac)
Linear interpolation between two unsigned 16-bit values, with 16-bit fraction.
Definition lib8tion.h:310
LIB8STATIC_ALWAYS_INLINE uint8_t qadd8(uint8_t i, uint8_t j)
Add one byte to another, saturating at 0xFF.
Definition math8.h:40
LIB8STATIC_ALWAYS_INLINE uint8_t qmul8(uint8_t i, uint8_t j)
8x8 bit multiplication with 8-bit result, saturating at 0xFF.
Definition math8.h:486
LIB8STATIC_ALWAYS_INLINE uint8_t qsub8(uint8_t i, uint8_t j)
Subtract one byte from another, saturating at 0x00.
Definition math8.h:112
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
Definition scale8.h:343
LIB8STATIC_ALWAYS_INLINE uint8_t scale8_LEAVING_R1_DIRTY(uint8_t i, fract8 scale)
This version of scale8() does not clean up the R1 register on AVR.
Definition scale8.h:180
LIB8STATIC void nscale8x3(uint8_t &r, uint8_t &g, uint8_t &b, fract8 scale)
Scale three one-byte values by a fourth one, which is treated as the numerator of a fraction whose de...
Definition scale8.h:367
constexpr uint8_t scale8_constexpr(uint8_t i, fract8 scale)
Definition scale8.h:114
LIB8STATIC void nscale8x3_video(uint8_t &r, uint8_t &g, uint8_t &b, fract8 scale)
Scale three one-byte values by a fourth one, which is treated as the numerator of a fraction whose de...
Definition scale8.h:401
Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.
#define FASTLED_NAMESPACE_END
Definition namespace.h:23
#define FASTLED_NAMESPACE_BEGIN
Definition namespace.h:22
Implements the FastLED namespace macros.
u16 fract16
ANSI: unsigned _Fract.
Definition int.h:59
fl::u8 getLuma() const
Get the "luma" of a CRGB object.
Definition crgb.hpp:147
FASTLED_FORCE_INLINE CRGB & operator%=(fl::u8 scaledown)
%= is a synonym for nscale8_video().
FASTLED_FORCE_INLINE CRGB & subtractFromRGB(fl::u8 d)
Subtract a constant from each channel, saturating at 0x00.
CRGB & nscale8(fl::u8 scaledown)
Scale down a RGB to N/256ths of its current brightness, using "plain math" dimming rules.
FASTLED_FORCE_INLINE CRGB & operator*=(fl::u8 d)
Multiply each of the channels by a constant, saturating each channel at 0xFF.
FASTLED_FORCE_INLINE CRGB & operator++()
Add a constant of '1' from each channel, saturating at 0xFF.
Definition crgb.hpp:48
FASTLED_FORCE_INLINE CRGB()
Default constructor.
Definition crgb.h:158
FASTLED_FORCE_INLINE CRGB & fadeLightBy(fl::u8 fadefactor)
fadeLightBy is a synonym for nscale8_video(), as a fade instead of a scale
FASTLED_FORCE_INLINE CRGB lerp16(const CRGB &other, fract16 frac) const
Return a new CRGB object after performing a linear interpolation between this object and the passed i...
Definition crgb.hpp:173
FASTLED_FORCE_INLINE CRGB & operator-=(const CRGB &rhs)
Subtract one CRGB from another, saturating at 0x00 for each channel.
Definition crgb.hpp:39
FASTLED_FORCE_INLINE CRGB & operator--()
Subtract a constant of '1' from each channel, saturating at 0x00.
Definition crgb.hpp:97
FASTLED_FORCE_INLINE CRGB scale8(fl::u8 scaledown) const
Return a CRGB object that is a scaled down version of this object.
FASTLED_FORCE_INLINE fl::u8 getAverageLight() const
Get the average of the R, G, and B values.
Definition crgb.hpp:158
FASTLED_FORCE_INLINE CRGB & addToRGB(fl::u8 d)
Add a constant to each channel, saturating at 0xFF.
FASTLED_FORCE_INLINE CRGB & nscale8_video(fl::u8 scaledown)
Scale down a RGB to N/256ths of it's current brightness using "video" dimming rules.
constexpr CRGB nscale8_constexpr(const CRGB scaledown) const
Definition crgb.hpp:112
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86