13inline static constexpr uint8_t esp_scale8(uint8_t i, uint8_t scale) {
14 return (uint16_t(i) * (1 + uint16_t(scale))) / 256;
43 operator lv_color_t()
const {
return lv_color_make(this->
r, this->
g, this->
b); }
56 inline explicit constexpr Color(uint32_t colorcode) ESPHOME_ALWAYS_INLINE :
r((colorcode >> 16) & 0xFF),
57 g((colorcode >> 8) & 0xFF),
58 b((colorcode >> 0) & 0xFF),
59 w((colorcode >> 24) & 0xFF) {}
61 inline bool is_on() ESPHOME_ALWAYS_INLINE {
return this->
raw_32 != 0; }
67 return this->
raw_32 == colorcode;
73 return this->
raw_32 != colorcode;
75 inline uint8_t &
operator[](uint8_t
x) ESPHOME_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));
84 this->
red = esp_scale8(this->
red, scale);
86 this->
blue = esp_scale8(this->
blue, scale);
91 return Color(esp_scale8(this->
red, scale.red), esp_scale8(this->
green, scale.green),
92 esp_scale8(this->
blue, scale.blue), esp_scale8(this->
white, scale.white));
95 this->
red = esp_scale8(this->
red, scale.red);
96 this->
green = esp_scale8(this->
green, scale.green);
97 this->
blue = esp_scale8(this->
blue, scale.blue);
98 this->
white = esp_scale8(this->
white, scale.white);
103 if (uint8_t(add.r + this->r) < this->r) {
106 ret.
r = this->
r + add.r;
108 if (uint8_t(add.g + this->g) < this->g) {
111 ret.
g = this->
g + add.g;
113 if (uint8_t(add.b + this->b) < this->b) {
116 ret.
b = this->
b + add.b;
118 if (uint8_t(add.w + this->w) < this->w) {
121 ret.
w = this->
w + add.w;
126 inline Color operator+(uint8_t add)
const ESPHOME_ALWAYS_INLINE {
return (*
this) +
Color(add, add, add, add); }
127 inline Color &
operator+=(uint8_t add) ESPHOME_ALWAYS_INLINE {
return *
this = (*this) + add; }
130 if (subtract.r > this->r) {
133 ret.
r = this->
r - subtract.r;
135 if (subtract.g > this->g) {
138 ret.
g = this->
g - subtract.g;
140 if (subtract.b > this->b) {
143 ret.
b = this->
b - subtract.b;
145 if (subtract.w > this->w) {
148 ret.
w = this->
w - subtract.w;
154 return (*
this) -
Color(subtract, subtract, subtract, subtract);
156 inline Color &
operator-=(uint8_t subtract) ESPHOME_ALWAYS_INLINE {
return *
this = (*this) - subtract; }
159 uint8_t
w = rand >> 24;
160 uint8_t
r = rand >> 16;
161 uint8_t
g = rand >> 8;
162 uint8_t
b = rand >> 0;
163 const uint16_t max_rgb = std::max(
r, std::max(
g,
b));
164 return Color(uint8_t((uint16_t(
r) * 255U / max_rgb)), uint8_t((uint16_t(
g) * 255U / max_rgb)),
165 uint8_t((uint16_t(
b) * 255U / max_rgb)),
w);
170 float amnt_f = float(amnt) / 255.0f;
171 new_color.
r = amnt_f * (to_color.
r - (*this).r) + (*this).r;
172 new_color.
g = amnt_f * (to_color.
g - (*this).g) + (*this).g;
173 new_color.
b = amnt_f * (to_color.
b - (*this).b) + (*this).b;
174 new_color.
w = amnt_f * (to_color.
w - (*this).w) + (*this).w;
Providing packet encoding functions for exchanging data with a remote host.
uint32_t random_uint32()
Return a random 32-bit unsigned integer.
Color operator+(uint8_t add) const ESPHOME_ALWAYS_INLINE
Color & operator+=(uint8_t add) ESPHOME_ALWAYS_INLINE
bool operator!=(const Color &rhs)
Color operator-(const Color &subtract) const ESPHOME_ALWAYS_INLINE
constexpr Color(uint32_t colorcode) ESPHOME_ALWAYS_INLINE
Color fade_to_white(uint8_t amnt)
Color lighten(uint8_t delta)
Color operator*(uint8_t scale) const ESPHOME_ALWAYS_INLINE
Color & operator*=(uint8_t scale) ESPHOME_ALWAYS_INLINE
static Color random_color()
Color & operator-=(uint8_t subtract) ESPHOME_ALWAYS_INLINE
Color operator*(const Color &scale) const ESPHOME_ALWAYS_INLINE
Color operator+(const Color &add) const ESPHOME_ALWAYS_INLINE
Color operator-(uint8_t subtract) const ESPHOME_ALWAYS_INLINE
constexpr Color(uint8_t red, uint8_t green, uint8_t blue) ESPHOME_ALWAYS_INLINE
uint8_t & operator[](uint8_t x) ESPHOME_ALWAYS_INLINE
bool operator!=(uint32_t colorcode)
bool operator==(uint32_t colorcode)
Color darken(uint8_t delta)
Color fade_to_black(uint8_t amnt)
Color & operator-=(const Color &subtract) ESPHOME_ALWAYS_INLINE
Color gradient(const Color &to_color, uint8_t amnt)
constexpr Color() ESPHOME_ALWAYS_INLINE
Color & operator*=(const Color &scale) ESPHOME_ALWAYS_INLINE
Color operator~() const ESPHOME_ALWAYS_INLINE
bool is_on() ESPHOME_ALWAYS_INLINE
constexpr Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) ESPHOME_ALWAYS_INLINE
bool operator==(const Color &rhs)
Color & operator+=(const Color &add) ESPHOME_ALWAYS_INLINE