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; }
55 this->
w = (colorcode >> 24) & 0xFF;
56 this->
r = (colorcode >> 16) & 0xFF;
57 this->
g = (colorcode >> 8) & 0xFF;
58 this->
b = (colorcode >> 0) & 0xFF;
61 inline uint8_t &
operator[](uint8_t x) ALWAYS_INLINE {
return this->
raw[x]; }
63 return Color(esp_scale8(this->
red, scale), esp_scale8(this->
green, scale), esp_scale8(this->
blue, scale),
64 esp_scale8(this->
white, scale));
67 this->
red = esp_scale8(this->
red, scale);
69 this->
blue = esp_scale8(this->
blue, scale);
74 return Color(esp_scale8(this->
red, scale.red), esp_scale8(this->
green, scale.green),
75 esp_scale8(this->
blue, scale.blue), esp_scale8(this->
white, scale.white));
78 this->
red = esp_scale8(this->
red, scale.red);
79 this->
green = esp_scale8(this->
green, scale.green);
80 this->
blue = esp_scale8(this->
blue, scale.blue);
81 this->
white = esp_scale8(this->
white, scale.white);
86 if (uint8_t(add.r + this->r) < this->r)
89 ret.
r = this->
r + add.r;
90 if (uint8_t(add.g + this->g) < this->g)
93 ret.
g = this->
g + add.g;
94 if (uint8_t(add.b + this->b) < this->b)
97 ret.
b = this->
b + add.b;
98 if (uint8_t(add.w + this->w) < this->w)
101 ret.
w = this->
w + add.w;
109 if (subtract.r > this->r)
112 ret.
r = this->
r - subtract.r;
113 if (subtract.g > this->g)
116 ret.
g = this->
g - subtract.g;
117 if (subtract.b > this->b)
120 ret.
b = this->
b - subtract.b;
121 if (subtract.w > this->w)
124 ret.
w = this->
w - subtract.w;
129 return (*
this) -
Color(subtract, subtract, subtract, subtract);
131 inline Color &
operator-=(uint8_t subtract) ALWAYS_INLINE {
return *
this = (*this) - subtract; }
134 uint8_t
w = rand >> 24;
135 uint8_t
r = rand >> 16;
136 uint8_t
g = rand >> 8;
137 uint8_t
b = rand >> 0;
138 const uint16_t max_rgb = std::max(r, std::max(g, b));
139 return Color(uint8_t((uint16_t(r) * 255U / max_rgb)), uint8_t((uint16_t(g) * 255U / max_rgb)),
140 uint8_t((uint16_t(b) * 255U / max_rgb)), w);
151 ESPDEPRECATED(
"Use Color::BLACK instead of COLOR_BLACK",
"v1.21")
154 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
Color lighten(uint8_t delta)
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 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