ESPHome 2026.3.0
Loading...
Searching...
No Matches
light_color_values.cpp
Go to the documentation of this file.
2
3namespace esphome::light {
4
5// Lightweight lerp: a + t * (b - a).
6// Avoids std::lerp's NaN/infinity handling which Clang doesn't optimize out,
7// adding ~200 bytes per call. Safe because all values are finite floats.
8static float __attribute__((noinline)) lerp_fast(float a, float b, float t) { return a + t * (b - a); }
9
11 // Directly interpolate the raw values to avoid getter/setter overhead.
12 // This is safe because:
13 // - All LightColorValues except color_temperature_ have their values clamped when set via the setters
14 // - lerp_fast output stays in range when inputs are in range and 0 <= completion <= 1
15 // - Therefore the output doesn't need clamping, so we can skip the setters
17 v.color_mode_ = end.color_mode_;
18 v.state_ = lerp_fast(start.state_, end.state_, completion);
19 v.brightness_ = lerp_fast(start.brightness_, end.brightness_, completion);
20 v.color_brightness_ = lerp_fast(start.color_brightness_, end.color_brightness_, completion);
21 v.red_ = lerp_fast(start.red_, end.red_, completion);
22 v.green_ = lerp_fast(start.green_, end.green_, completion);
23 v.blue_ = lerp_fast(start.blue_, end.blue_, completion);
24 v.white_ = lerp_fast(start.white_, end.white_, completion);
25 v.color_temperature_ = lerp_fast(start.color_temperature_, end.color_temperature_, completion);
26 v.cold_white_ = lerp_fast(start.cold_white_, end.cold_white_, completion);
27 v.warm_white_ = lerp_fast(start.warm_white_, end.warm_white_, completion);
28 return v;
29}
30
31} // namespace esphome::light
This class represents the color state for a light object.
float state_
ON / OFF, float for transition.
static LightColorValues lerp(const LightColorValues &start, const LightColorValues &end, float completion)
Linearly interpolate between the values in start to the values in end.
float color_temperature_
Color Temperature in Mired.
struct @65::@66 __attribute__
static float float float t
static float float b
uint8_t end[39]
Definition sun_gtil2.cpp:17