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;
62 return Color(esp_scale8(this->
red, scale), esp_scale8(this->
green, scale), esp_scale8(this->
blue, scale),
63 esp_scale8(this->
white, scale));
66 this->
red = esp_scale8(this->
red, scale);
68 this->
blue = esp_scale8(this->
blue, scale);
73 return Color(esp_scale8(this->
red, scale.red), esp_scale8(this->
green, scale.green),
74 esp_scale8(this->
blue, scale.blue), esp_scale8(this->
white, scale.white));
77 this->
red = esp_scale8(this->
red, scale.red);
78 this->
green = esp_scale8(this->
green, scale.green);
79 this->
blue = esp_scale8(this->
blue, scale.blue);
80 this->
white = esp_scale8(this->
white, scale.white);
85 if (uint8_t(add.r + this->r) < this->r)
88 ret.
r = this->
r + add.r;
89 if (uint8_t(add.g + this->g) < this->g)
92 ret.
g = this->
g + add.g;
93 if (uint8_t(add.b + this->b) < this->b)
96 ret.
b = this->
b + add.b;
97 if (uint8_t(add.w + this->w) < this->w)
100 ret.
w = this->
w + add.w;
108 if (subtract.r > this->r)
111 ret.
r = this->
r - subtract.r;
112 if (subtract.g > this->g)
115 ret.
g = this->
g - subtract.g;
116 if (subtract.b > this->b)
119 ret.
b = this->
b - subtract.b;
120 if (subtract.w > this->w)
123 ret.
w = this->
w - subtract.w;
128 return (*
this) -
Color(subtract, subtract, subtract, subtract);
130 inline Color &
operator-=(uint8_t subtract) ALWAYS_INLINE {
return *
this = (*this) - subtract; }
133 uint8_t
w = rand >> 24;
134 uint8_t
r = rand >> 16;
135 uint8_t
g = rand >> 8;
136 uint8_t
b = rand >> 0;
137 const uint16_t max_rgb = std::max(r, std::max(g, b));
138 return Color(uint8_t((uint16_t(r) * 255U / max_rgb)), uint8_t((uint16_t(g) * 255U / max_rgb)),
139 uint8_t((uint16_t(b) * 255U / max_rgb)), w);
144 float amnt_f = float(amnt) / 255.0f;
145 new_color.
r = amnt_f * (to_color.
r - (*this).r) + (*this).r;
146 new_color.
g = amnt_f * (to_color.
g - (*this).g) + (*this).g;
147 new_color.
b = amnt_f * (to_color.
b - (*this).b) + (*this).b;
148 new_color.
w = amnt_f * (to_color.
w - (*this).w) + (*this).w;
161 ESPDEPRECATED(
"Use Color::BLACK instead of COLOR_BLACK",
"v1.21")
164 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 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
bool is_on() ALWAYS_INLINE