8inline static constexpr uint8_t esp_scale8(uint8_t i, uint8_t scale) {
9 return (uint16_t(i) * (1 + uint16_t(scale))) / 256;
46 inline explicit constexpr Color(uint32_t colorcode) ESPHOME_ALWAYS_INLINE :
r((colorcode >> 16) & 0xFF),
47 g((colorcode >> 8) & 0xFF),
48 b((colorcode >> 0) & 0xFF),
49 w((colorcode >> 24) & 0xFF) {}
51 inline bool is_on() ESPHOME_ALWAYS_INLINE {
return this->
raw_32 != 0; }
57 return this->
raw_32 == colorcode;
63 return this->
raw_32 != colorcode;
65 inline uint8_t &
operator[](uint8_t
x) ESPHOME_ALWAYS_INLINE {
return this->
raw[
x]; }
67 return Color(esp_scale8(this->
red, scale), esp_scale8(this->
green, scale), esp_scale8(this->
blue, scale),
68 esp_scale8(this->
white, scale));
74 this->
red = esp_scale8(this->
red, scale);
76 this->
blue = esp_scale8(this->
blue, scale);
81 return Color(esp_scale8(this->
red, scale.red), esp_scale8(this->
green, scale.green),
82 esp_scale8(this->
blue, scale.blue), esp_scale8(this->
white, scale.white));
85 this->
red = esp_scale8(this->
red, scale.red);
86 this->
green = esp_scale8(this->
green, scale.green);
87 this->
blue = esp_scale8(this->
blue, scale.blue);
88 this->
white = esp_scale8(this->
white, scale.white);
93 if (uint8_t(add.r + this->r) < this->r) {
96 ret.
r = this->
r + add.r;
98 if (uint8_t(add.g + this->g) < this->g) {
101 ret.
g = this->
g + add.g;
103 if (uint8_t(add.b + this->b) < this->b) {
106 ret.
b = this->
b + add.b;
108 if (uint8_t(add.w + this->w) < this->w) {
111 ret.
w = this->
w + add.w;
116 inline Color operator+(uint8_t add)
const ESPHOME_ALWAYS_INLINE {
return (*
this) +
Color(add, add, add, add); }
117 inline Color &
operator+=(uint8_t add) ESPHOME_ALWAYS_INLINE {
return *
this = (*this) + add; }
120 if (subtract.r > this->r) {
123 ret.
r = this->
r - subtract.r;
125 if (subtract.g > this->g) {
128 ret.
g = this->
g - subtract.g;
130 if (subtract.b > this->b) {
133 ret.
b = this->
b - subtract.b;
135 if (subtract.w > this->w) {
138 ret.
w = this->
w - subtract.w;
144 return (*
this) -
Color(subtract, subtract, subtract, subtract);
146 inline Color &
operator-=(uint8_t subtract) ESPHOME_ALWAYS_INLINE {
return *
this = (*this) - subtract; }
149 uint8_t
w = rand >> 24;
150 uint8_t
r = rand >> 16;
151 uint8_t
g = rand >> 8;
152 uint8_t
b = rand >> 0;
153 const uint16_t max_rgb = std::max(
r, std::max(
g,
b));
154 return Color(uint8_t((uint16_t(
r) * 255U / max_rgb)), uint8_t((uint16_t(
g) * 255U / max_rgb)),
155 uint8_t((uint16_t(
b) * 255U / max_rgb)),
w);
160 float amnt_f = float(amnt) / 255.0f;
161 new_color.
r = amnt_f * (to_color.
r - (*this).r) + (*this).r;
162 new_color.
g = amnt_f * (to_color.
g - (*this).g) + (*this).g;
163 new_color.
b = amnt_f * (to_color.
b - (*this).b) + (*this).b;
164 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