13inline static constexpr uint8_t esp_scale8(uint8_t i, uint8_t scale) {
14 return (uint16_t(i) * (1 + uint16_t(scale))) / 256;
22inline static constexpr uint8_t esp_scale8_twice(uint8_t i, uint8_t scale1, uint8_t scale2) {
52 operator lv_color_t()
const {
return lv_color_make(this->
r, this->
g, this->
b); }
65 inline explicit constexpr Color(uint32_t colorcode) ESPHOME_ALWAYS_INLINE :
r((colorcode >> 16) & 0xFF),
66 g((colorcode >> 8) & 0xFF),
67 b((colorcode >> 0) & 0xFF),
68 w((colorcode >> 24) & 0xFF) {}
70 inline bool is_on() ESPHOME_ALWAYS_INLINE {
return this->
raw_32 != 0; }
76 return this->
raw_32 == colorcode;
82 return this->
raw_32 != colorcode;
84 inline uint8_t &
operator[](uint8_t
x) ESPHOME_ALWAYS_INLINE {
return this->
raw[
x]; }
86 return Color(esp_scale8(this->
red, scale), esp_scale8(this->
green, scale), esp_scale8(this->
blue, scale),
87 esp_scale8(this->
white, scale));
93 this->
red = esp_scale8(this->
red, scale);
95 this->
blue = esp_scale8(this->
blue, scale);
100 return Color(esp_scale8(this->
red, scale.red), esp_scale8(this->
green, scale.green),
101 esp_scale8(this->
blue, scale.blue), esp_scale8(this->
white, scale.white));
104 this->
red = esp_scale8(this->
red, scale.red);
105 this->
green = esp_scale8(this->
green, scale.green);
106 this->
blue = esp_scale8(this->
blue, scale.blue);
107 this->
white = esp_scale8(this->
white, scale.white);
112 if (uint8_t(add.r + this->r) < this->r) {
115 ret.
r = this->
r + add.r;
117 if (uint8_t(add.g + this->g) < this->g) {
120 ret.
g = this->
g + add.g;
122 if (uint8_t(add.b + this->b) < this->b) {
125 ret.
b = this->
b + add.b;
127 if (uint8_t(add.w + this->w) < this->w) {
130 ret.
w = this->
w + add.w;
135 inline Color operator+(uint8_t add)
const ESPHOME_ALWAYS_INLINE {
return (*
this) +
Color(add, add, add, add); }
136 inline Color &
operator+=(uint8_t add) ESPHOME_ALWAYS_INLINE {
return *
this = (*this) + add; }
139 if (subtract.r > this->r) {
142 ret.
r = this->
r - subtract.r;
144 if (subtract.g > this->g) {
147 ret.
g = this->
g - subtract.g;
149 if (subtract.b > this->b) {
152 ret.
b = this->
b - subtract.b;
154 if (subtract.w > this->w) {
157 ret.
w = this->
w - subtract.w;
163 return (*
this) -
Color(subtract, subtract, subtract, subtract);
165 inline Color &
operator-=(uint8_t subtract) ESPHOME_ALWAYS_INLINE {
return *
this = (*this) - subtract; }
168 uint8_t
w = rand >> 24;
169 uint8_t
r = rand >> 16;
170 uint8_t
g = rand >> 8;
171 uint8_t
b = rand >> 0;
172 const uint16_t max_rgb = std::max(
r, std::max(
g,
b));
173 return Color(uint8_t((uint16_t(
r) * 255U / max_rgb)), uint8_t((uint16_t(
g) * 255U / max_rgb)),
174 uint8_t((uint16_t(
b) * 255U / max_rgb)),
w);
179 float amnt_f = float(amnt) / 255.0f;
180 new_color.
r = amnt_f * (to_color.
r - (*this).r) + (*this).r;
181 new_color.
g = amnt_f * (to_color.
g - (*this).g) + (*this).g;
182 new_color.
b = amnt_f * (to_color.
b - (*this).b) + (*this).b;
183 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