8 inline static uint8_t esp_scale8(uint8_t i, uint8_t scale) {
return (uint16_t(i) * (1 + uint16_t(scale))) / 256; }
34 inline Color() ALWAYS_INLINE :
r(0),
g(0),
b(0),
w(0) {}
41 inline explicit Color(uint32_t colorcode) ALWAYS_INLINE :
r((colorcode >> 16) & 0xFF),
42 g((colorcode >> 8) & 0xFF),
43 b((colorcode >> 0) & 0xFF),
44 w((colorcode >> 24) & 0xFF) {}
46 inline bool is_on() ALWAYS_INLINE {
return this->
raw_32 != 0; }
52 return this->
raw_32 == colorcode;
58 return this->
raw_32 != colorcode;
69 this->
w = (colorcode >> 24) & 0xFF;
70 this->
r = (colorcode >> 16) & 0xFF;
71 this->
g = (colorcode >> 8) & 0xFF;
72 this->
b = (colorcode >> 0) & 0xFF;
75 inline uint8_t &
operator[](uint8_t x) ALWAYS_INLINE {
return this->
raw[x]; }
77 return Color(esp_scale8(this->
red, scale), esp_scale8(this->
green, scale), esp_scale8(this->
blue, scale),
78 esp_scale8(this->
white, scale));
81 this->
red = esp_scale8(this->
red, scale);
83 this->
blue = esp_scale8(this->
blue, scale);
88 return Color(esp_scale8(this->
red, scale.red), esp_scale8(this->
green, scale.green),
89 esp_scale8(this->
blue, scale.blue), esp_scale8(this->
white, scale.white));
92 this->
red = esp_scale8(this->
red, scale.red);
93 this->
green = esp_scale8(this->
green, scale.green);
94 this->
blue = esp_scale8(this->
blue, scale.blue);
95 this->
white = esp_scale8(this->
white, scale.white);
100 if (uint8_t(add.r + this->r) < this->r)
103 ret.
r = this->
r + add.r;
104 if (uint8_t(add.g + this->g) < this->g)
107 ret.
g = this->
g + add.g;
108 if (uint8_t(add.b + this->b) < this->b)
111 ret.
b = this->
b + add.b;
112 if (uint8_t(add.w + this->w) < this->w)
115 ret.
w = this->
w + add.w;
123 if (subtract.r > this->r)
126 ret.
r = this->
r - subtract.r;
127 if (subtract.g > this->g)
130 ret.
g = this->
g - subtract.g;
131 if (subtract.b > this->b)
134 ret.
b = this->
b - subtract.b;
135 if (subtract.w > this->w)
138 ret.
w = this->
w - subtract.w;
143 return (*
this) -
Color(subtract, subtract, subtract, subtract);
145 inline Color &
operator-=(uint8_t subtract) ALWAYS_INLINE {
return *
this = (*this) - subtract; }
148 uint8_t
w = rand >> 24;
149 uint8_t
r = rand >> 16;
150 uint8_t
g = rand >> 8;
151 uint8_t
b = rand >> 0;
152 const uint16_t max_rgb = std::max(r, std::max(g, b));
153 return Color(uint8_t((uint16_t(r) * 255U / max_rgb)), uint8_t((uint16_t(g) * 255U / max_rgb)),
154 uint8_t((uint16_t(b) * 255U / max_rgb)), w);
159 float amnt_f = float(amnt) / 255.0f;
160 new_color.
r = amnt_f * (to_color.
r - (*this).r) + (*this).r;
161 new_color.
g = amnt_f * (to_color.
g - (*this).g) + (*this).g;
162 new_color.
b = amnt_f * (to_color.
b - (*this).b) + (*this).b;
163 new_color.
w = amnt_f * (to_color.
w - (*this).w) + (*this).w;
176 ESPDEPRECATED(
"Use Color::BLACK instead of COLOR_BLACK",
"v1.21")
179 extern const
Color COLOR_WHITE;
Color operator-(const Color &subtract) const ALWAYS_INLINE
const Color COLOR_BLACK(0, 0, 0, 0)
Color(uint32_t colorcode) ALWAYS_INLINE
uint32_t random_uint32()
Return a random 32-bit unsigned integer.
Color & operator-=(uint8_t subtract) ALWAYS_INLINE
Color & operator=(const Color &rhs) ALWAYS_INLINE
Color fade_to_black(uint8_t amnt)
Color & operator+=(uint8_t add) ALWAYS_INLINE
Color fade_to_white(uint8_t amnt)
Color(uint8_t red, uint8_t green, uint8_t blue) ALWAYS_INLINE
Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) ALWAYS_INLINE
bool operator==(uint32_t colorcode)
bool operator!=(uint32_t colorcode)
bool operator==(const Color &rhs)
Color lighten(uint8_t delta)
bool operator!=(const Color &rhs)
static Color random_color()
ESPDEPRECATED("Use Color::BLACK instead of COLOR_BLACK", "v1.21") extern const Color COLOR_BLACK
Color & operator*=(uint8_t scale) ALWAYS_INLINE
Color operator+(const Color &add) const ALWAYS_INLINE
Color operator+(uint8_t add) const ALWAYS_INLINE
Color & operator+=(const Color &add) ALWAYS_INLINE
const Color COLOR_WHITE(255, 255, 255, 255)
Color operator*(const Color &scale) const ALWAYS_INLINE
Color operator-(uint8_t subtract) const ALWAYS_INLINE
Color gradient(const Color &to_color, uint8_t amnt)
Color darken(uint8_t delta)
uint8_t & operator[](uint8_t x) ALWAYS_INLINE
Color operator*(uint8_t scale) const ALWAYS_INLINE
Color & operator-=(const Color &subtract) ALWAYS_INLINE
Color & operator*=(const Color &scale) ALWAYS_INLINE
Color & operator=(uint32_t colorcode) ALWAYS_INLINE
bool is_on() ALWAYS_INLINE