9#include "lib8tion/types.h"
10#include "force_inline.h"
11#include "template_magic.h"
14FASTLED_NAMESPACE_BEGIN
17#ifndef FASTLED_HD_COLOR_MIXING
20#define FASTLED_HD_COLOR_MIXING 0
22#define FASTLED_HD_COLOR_MIXING 1
76 FASTLED_FORCE_INLINE
const uint8_t&
operator[] (uint8_t x)
const
83 FASTLED_FORCE_INLINE
CRGB() =
default;
89 constexpr CRGB(uint8_t ir, uint8_t ig, uint8_t ib) noexcept
96 constexpr CRGB(uint32_t colorcode) noexcept
97 :
r((colorcode >> 16) & 0xFF),
g((colorcode >> 8) & 0xFF),
b((colorcode >> 0) & 0xFF)
101 constexpr uint32_t as_uint32_t() const noexcept {
102 return uint32_t(0xff000000) |
103 (uint32_t{
r} << 16) |
111 :
r((colorcode >> 16) & 0xFF),
g((colorcode >> 8) & 0xFF),
b((colorcode >> 0) & 0xFF)
118 :
r((colorcode >> 16) & 0xFF),
g((colorcode >> 8) & 0xFF),
b((colorcode >> 0) & 0xFF)
123 FASTLED_FORCE_INLINE
CRGB(
const CRGB& rhs) =
default;
138 r = (colorcode >> 16) & 0xFF;
139 g = (colorcode >> 8) & 0xFF;
140 b = (colorcode >> 0) & 0xFF;
148 FASTLED_FORCE_INLINE
CRGB&
setRGB (uint8_t nr, uint8_t ng, uint8_t nb)
160 FASTLED_FORCE_INLINE
CRGB&
setHSV (uint8_t hue, uint8_t sat, uint8_t val)
186 r = (colorcode >> 16) & 0xFF;
187 g = (colorcode >> 8) & 0xFF;
188 b = (colorcode >> 0) & 0xFF;
265 FASTLED_FORCE_INLINE
CRGB&
nscale8 (uint8_t scaledown );
273 constexpr CRGB nscale8_constexpr (
const CRGB scaledown )
const;
277 FASTLED_FORCE_INLINE
CRGB scale8 (uint8_t scaledown )
const;
289 if( rhs.
r >
r)
r = rhs.
r;
290 if( rhs.
g >
g)
g = rhs.
g;
291 if( rhs.
b >
b)
b = rhs.
b;
307 if( rhs.
r <
r)
r = rhs.
r;
308 if( rhs.
g <
g)
g = rhs.
g;
309 if( rhs.
b <
b)
b = rhs.
b;
323 constexpr explicit operator bool()
const
329 constexpr explicit operator uint32_t()
const
331 return uint32_t(0xff000000) |
332 (uint32_t{
r} << 16) |
340 return CRGB(255 -
r, 255 -
g, 255 -
b);
343#if (defined SmartMatrix_h || defined SmartMatrix3_h)
346 operator rgb24()
const {
357 FASTLED_FORCE_INLINE uint8_t
getLuma()
const;
374 uint16_t factor = ((uint16_t)(limit) * 256) / max;
375 red = (
red * factor) / 256;
396 uint8_t sum =
r +
g +
b;
426 if( parity == curparity)
return;
430 if( (
b > 0) && (
b < 255)) {
431 if(
r ==
g &&
g ==
b) {
436 }
else if( (
r > 0) && (
r < 255)) {
438 }
else if( (
g > 0) && (
g < 255)) {
441 if(
r ==
g &&
g ==
b) {
450 if(
r ==
g &&
g ==
b) {
460 if(
r ==
g &&
g ==
b) {
636 return (lhs.
r == rhs.
r) && (lhs.
g == rhs.
g) && (lhs.
b == rhs.
b);
642 return !(lhs == rhs);
648 return (lhs.
h == rhs.
h) && (lhs.
s == rhs.
s) && (lhs.
v == rhs.
v);
654 return !(lhs == rhs);
661 sl = lhs.
r + lhs.
g + lhs.
b;
662 sr = rhs.
r + rhs.
g + rhs.
b;
670 sl = lhs.
r + lhs.
g + lhs.
b;
671 sr = rhs.
r + rhs.
g + rhs.
b;
679 sl = lhs.
r + lhs.
g + lhs.
b;
680 sr = rhs.
r + rhs.
g + rhs.
b;
688 sl = lhs.
r + lhs.
g + lhs.
b;
689 sr = rhs.
r + rhs.
g + rhs.
b;
698 return CRGB( p1.
r/d, p1.
g/d, p1.
b/d);
705 return CRGB( p1.
r < p2.
r ? p1.
r : p2.
r,
706 p1.
g < p2.
g ? p1.
g : p2.
g,
707 p1.
b < p2.
b ? p1.
b : p2.
b);
713 return CRGB( p1.
r > p2.
r ? p1.
r : p2.
r,
714 p1.
g > p2.
g ? p1.
g : p2.
g,
715 p1.
b > p2.
b ? p1.
b : p2.
b);
733FASTLED_DEFINE_OUTPUT_OPERATOR(
CRGB) {
735 os <<(static_cast<int>(obj.r));
737 os <<(static_cast<int>(obj.g));
739 os <<(static_cast<int>(obj.b));
Contains definitions for color correction and temperature.
ColorTemperature
Color temperature values.
LEDColorCorrection
Color correction starting points.
uint8_t fract8
ANSI: unsigned short _Fract.
uint16_t fract16
ANSI: unsigned _Fract.
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.
void hsv2rgb_rainbow(const CHSV &hsv, CRGB &rgb)
Forward declaration of hsv2rgb_rainbow here, to avoid circular dependencies.
FASTLED_FORCE_INLINE CRGB()=default
Default constructor.
FASTLED_FORCE_INLINE uint8_t getLuma() const
Get the "luma" of a CRGB object.
FASTLED_FORCE_INLINE bool operator!=(const CRGB &lhs, const CRGB &rhs)
Check if two CRGB objects do not have the same color data.
FASTLED_FORCE_INLINE bool operator<=(const CRGB &lhs, const CRGB &rhs)
Check if the sum of the color channels in one CRGB object is less than or equal to another.
FASTLED_FORCE_INLINE bool operator==(const CRGB &lhs, const CRGB &rhs)
Check if two CRGB objects have the same color data.
FASTLED_FORCE_INLINE CRGB operator/(const CRGB &p1, uint8_t d)
Divide each of the channels by a constant.
uint8_t raw[3]
Access the red, green, and blue data as an array.
uint8_t r
Red channel value.
FASTLED_FORCE_INLINE uint8_t getParity()
Returns 0 or 1, depending on the lowest bit of the sum of the color components.
FASTLED_FORCE_INLINE CRGB & operator/=(uint8_t d)
Divide each of the channels by a constant.
FASTLED_FORCE_INLINE CRGB & fadeLightBy(uint8_t fadefactor)
fadeLightBy is a synonym for nscale8_video(), as a fade instead of a scale
constexpr CRGB(ColorTemperature colorcode) noexcept
Allow construction from a ColorTemperature enum.
FASTLED_FORCE_INLINE CRGB operator%(const CRGB &p1, uint8_t d)
Scale using CRGB::nscale8_video()
FASTLED_FORCE_INLINE CRGB(const CRGB &rhs)=default
Allow copy construction.
FASTLED_FORCE_INLINE CRGB & operator++()
Add a constant of '1' from each channel, saturating at 0xFF.
FASTLED_FORCE_INLINE CRGB & nscale8(uint8_t scaledown)
Scale down a RGB to N/256ths of its current brightness, using "plain math" dimming rules.
constexpr CRGB(uint32_t colorcode) noexcept
Allow construction from 32-bit (really 24-bit) bit 0xRRGGBB color code.
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...
FASTLED_FORCE_INLINE CRGB & operator-=(const CRGB &rhs)
Subtract one CRGB from another, saturating at 0x00 for each channel.
FASTLED_FORCE_INLINE CRGB & setRGB(uint8_t nr, uint8_t ng, uint8_t nb)
Allow assignment from red, green, and blue.
FASTLED_FORCE_INLINE CRGB & setColorCode(uint32_t colorcode)
Allow assignment from 32-bit (really 24-bit) 0xRRGGBB color code.
FASTLED_FORCE_INLINE CRGB & operator=(const CRGB &rhs)=default
Allow assignment from one RGB struct to another.
FASTLED_FORCE_INLINE void setParity(uint8_t parity)
Adjusts the color in the smallest way possible so that the parity of the coloris now the desired valu...
static CRGB computeAdjustment(uint8_t scale, const CRGB &colorCorrection, const CRGB &colorTemperature)
Calculates the combined color adjustment to the LEDs at a given scale, color correction,...
FASTLED_FORCE_INLINE CRGB(const CHSV &rhs)
Allow construction from a CHSV color.
FASTLED_FORCE_INLINE CRGB & setHSV(uint8_t hue, uint8_t sat, uint8_t val)
Allow assignment from hue, saturation, and value.
FASTLED_FORCE_INLINE CRGB & operator--()
Subtract a constant of '1' from each channel, saturating at 0x00.
FASTLED_FORCE_INLINE CRGB operator-(const CRGB &p1, const CRGB &p2)
Subtract one CRGB from another, saturating at 0x00 for each channel.
FASTLED_FORCE_INLINE bool operator<(const CRGB &lhs, const CRGB &rhs)
Check if the sum of the color channels in one CRGB object is less than another.
FASTLED_FORCE_INLINE CRGB lerp8(const CRGB &other, fract8 frac) const
Return a new CRGB object after performing a linear interpolation between this object and the passed i...
uint8_t g
Green channel value.
uint8_t red
Red channel value.
FASTLED_FORCE_INLINE CRGB operator|(const CRGB &p1, const CRGB &p2)
Combine two CRGB objects, taking the largest value of each channel.
FASTLED_FORCE_INLINE CRGB operator&(const CRGB &p1, const CRGB &p2)
Combine two CRGB objects, taking the smallest value of each channel.
FASTLED_FORCE_INLINE CRGB & operator>>=(uint8_t d)
Right shift each of the channels by a constant.
constexpr CRGB operator-() const
Invert each channel.
FASTLED_FORCE_INLINE CRGB & operator+=(const CRGB &rhs)
Add one CRGB to another, saturating at 0xFF for each channel.
FASTLED_FORCE_INLINE uint8_t & operator[](uint8_t x)
Array access operator to index into the CRGB object.
uint8_t blue
Blue channel value.
FASTLED_FORCE_INLINE CRGB & operator&=(const CRGB &rhs)
"and" operator brings each channel down to the lower of the two values
FASTLED_FORCE_INLINE uint8_t getAverageLight() const
Get the average of the R, G, and B values.
FASTLED_FORCE_INLINE CRGB & addToRGB(uint8_t d)
Add a constant to each channel, saturating at 0xFF.
FASTLED_FORCE_INLINE CRGB & subtractFromRGB(uint8_t d)
Subtract a constant from each channel, saturating at 0x00.
constexpr CRGB(uint8_t ir, uint8_t ig, uint8_t ib) noexcept
Allow construction from red, green, and blue.
FASTLED_FORCE_INLINE bool operator>(const CRGB &lhs, const CRGB &rhs)
Check if the sum of the color channels in one CRGB object is greater than another.
uint8_t b
Blue channel value.
FASTLED_FORCE_INLINE CRGB scale8(uint8_t scaledown) const
Return a CRGB object that is a scaled down version of this object.
uint8_t green
Green channel value.
FASTLED_FORCE_INLINE CRGB & operator*=(uint8_t d)
Multiply each of the channels by a constant, saturating each channel at 0xFF.
FASTLED_FORCE_INLINE CRGB & setHue(uint8_t hue)
Allow assignment from just a hue.
FASTLED_FORCE_INLINE CRGB & operator%=(uint8_t scaledown)
%= is a synonym for nscale8_video().
FASTLED_FORCE_INLINE bool operator>=(const CRGB &lhs, const CRGB &rhs)
Check if the sum of the color channels in one CRGB object is greater than or equal to another.
FASTLED_FORCE_INLINE void maximizeBrightness(uint8_t limit=255)
Maximize the brightness of this CRGB object.
constexpr CRGB(LEDColorCorrection colorcode) noexcept
Allow construction from a LEDColorCorrection enum.
HTMLColorCode
Predefined RGB colors.
FASTLED_FORCE_INLINE CRGB & fadeToBlackBy(uint8_t fadefactor)
fadeToBlackBy is a synonym for nscale8(), as a fade instead of a scale
FASTLED_FORCE_INLINE CRGB operator*(const CRGB &p1, uint8_t d)
Multiply each of the channels by a constant, saturating each channel at 0xFF.
FASTLED_FORCE_INLINE CRGB operator+(const CRGB &p1, const CRGB &p2)
Add one CRGB to another, saturating at 0xFF for each channel.
FASTLED_FORCE_INLINE CRGB & operator|=(const CRGB &rhs)
"or" operator brings each channel up to the higher of the two values
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
uint8_t v
Color value (brightness).
uint8_t s
Color saturation.
Representation of an RGB pixel (Red, Green, Blue)