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 <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
21
23{
24 r = qadd8( r, d);
25 g = qadd8( g, d);
26 b = qadd8( b, d);
27 return *this;
28}
29
31{
32 r = qsub8( r, rhs.r);
33 g = qsub8( g, rhs.g);
34 b = qsub8( b, rhs.b);
35 return *this;
36}
37
40{
41 addToRGB(1);
42 return *this;
43}
44
47{
48 CRGB retval(*this);
49 ++(*this);
50 return retval;
51}
52
54{
55 r = qsub8( r, d);
56 g = qsub8( g, d);
57 b = qsub8( b, d);
58 return *this;
59}
60
62{
63 r = qmul8( r, d);
64 g = qmul8( g, d);
65 b = qmul8( b, d);
66 return *this;
67}
68
70{
71 nscale8x3_video( r, g, b, scaledown);
72 return *this;
73}
74
76{
77 nscale8x3_video( r, g, b, scaledown);
78 return *this;
79}
80
82{
83 nscale8x3_video( r, g, b, 255 - fadefactor);
84 return *this;
85}
86
93
96{
97 CRGB retval(*this);
98 --(*this);
99 return retval;
100}
101
102
103constexpr 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
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
121FASTLED_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
128FASTLED_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
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
150#if FASTLED_SCALE8_FIXED == 1
151 const uint8_t eightyfive = 85;
152#else
153 const uint8_t eightyfive = 86;
154#endif
155 uint8_t avg = scale8_LEAVING_R1_DIRTY( r, eightyfive) + \
156 scale8_LEAVING_R1_DIRTY( g, eightyfive) + \
157 scale8_LEAVING_R1_DIRTY( b, eightyfive);
158 cleanup_R1();
159 return avg;
160}
161
162
163
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
178{
179 return CRGB( qadd8( p1.r, p2.r),
180 qadd8( p1.g, p2.g),
181 qadd8( p1.b, p2.b));
182}
183
186{
187 return CRGB( qsub8( p1.r, p2.r),
188 qsub8( p1.g, p2.g),
189 qsub8( p1.b, p2.b));
190}
191
194{
195 return CRGB( qmul8( p1.r, d),
196 qmul8( p1.g, d),
197 qmul8( p1.b, d));
198}
199
202{
203 CRGB retval( p1);
204 retval.nscale8_video( d);
205 return retval;
206}
207
209
210#undef FUNCTION_SCALE8
Defines the hue, saturation, and value (HSV) pixel struct.
Defines the red, green, and blue (RGB) pixel struct.
#define FUNCTION_SCALE8(a, b)
Definition crgb.hpp:17
#define FASTLED_FORCE_INLINE
Definition force_inline.h:6
uint16_t fract16
ANSI: unsigned _Fract.
Definition types.h:46
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:454
LIB8STATIC_ALWAYS_INLINE uint8_t qadd8(uint8_t i, uint8_t j)
Add one byte to another, saturating at 0xFF.
Definition math8.h:31
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:470
LIB8STATIC_ALWAYS_INLINE uint8_t qsub8(uint8_t i, uint8_t j)
Subtract one byte from another, saturating at 0x00.
Definition math8.h:103
FASTLED_FORCE_INLINE CRGB operator%(const CRGB &p1, uint8_t d)
Scale using CRGB::nscale8_video()
Definition crgb.hpp:201
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:185
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:193
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:177
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
Definition scale8.h:339
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:176
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:363
constexpr uint8_t scale8_constexpr(uint8_t i, fract8 scale)
Definition scale8.h:110
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:397
Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.
#define FASTLED_NAMESPACE_END
Definition namespace.h:23
Implements the FastLED namespace macros.
FASTLED_FORCE_INLINE CRGB & nscale8_video(uint8_t scaledown)
Scale down a RGB to N/256ths of it's current brightness using "video" dimming rules.
Definition crgb.hpp:69
FASTLED_FORCE_INLINE CRGB & addToRGB(uint8_t d)
Add a constant to each channel, saturating at 0xFF.
Definition crgb.hpp:22
FASTLED_FORCE_INLINE CRGB()=default
Default constructor.
uint8_t getLuma() const
Get the "luma" of a CRGB object.
Definition crgb.hpp:138
FASTLED_FORCE_INLINE CRGB & fadeLightBy(uint8_t fadefactor)
fadeLightBy is a synonym for nscale8_video(), as a fade instead of a scale
Definition crgb.hpp:81
FASTLED_FORCE_INLINE CRGB & operator++()
Add a constant of '1' from each channel, saturating at 0xFF.
Definition crgb.hpp:39
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:164
FASTLED_FORCE_INLINE CRGB & operator-=(const CRGB &rhs)
Subtract one CRGB from another, saturating at 0x00 for each channel.
Definition crgb.hpp:30
CRGB & nscale8(uint8_t scaledown)
Scale down a RGB to N/256ths of its current brightness, using "plain math" dimming rules.
Definition crgb.cpp:88
FASTLED_FORCE_INLINE CRGB & operator--()
Subtract a constant of '1' from each channel, saturating at 0x00.
Definition crgb.hpp:88
FASTLED_FORCE_INLINE uint8_t getAverageLight() const
Get the average of the R, G, and B values.
Definition crgb.hpp:149
FASTLED_FORCE_INLINE CRGB & subtractFromRGB(uint8_t d)
Subtract a constant from each channel, saturating at 0x00.
Definition crgb.hpp:53
FASTLED_FORCE_INLINE CRGB scale8(uint8_t scaledown) const
Return a CRGB object that is a scaled down version of this object.
Definition crgb.hpp:121
FASTLED_FORCE_INLINE CRGB & operator*=(uint8_t d)
Multiply each of the channels by a constant, saturating each channel at 0xFF.
Definition crgb.hpp:61
FASTLED_FORCE_INLINE CRGB & operator%=(uint8_t scaledown)
%= is a synonym for nscale8_video().
Definition crgb.hpp:75
constexpr CRGB nscale8_constexpr(const CRGB scaledown) const
Definition crgb.hpp:103
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55