diff --git a/esphome/components/light/__init__.py b/esphome/components/light/__init__.py index 350fb67afd..40382bbda7 100644 --- a/esphome/components/light/__init__.py +++ b/esphome/components/light/__init__.py @@ -276,6 +276,7 @@ async def setup_light_core_(light_var, output_var, config): cg.add(light_var.set_gamma_correct(gamma_correct)) fwd_arr = _get_or_create_gamma_table(gamma_correct) cg.add(light_var.set_gamma_table(fwd_arr)) + cg.add_define("USE_LIGHT_GAMMA_LUT") effects = await cg.build_registry_list( EFFECTS_REGISTRY, config.get(CONF_EFFECTS, []) ) diff --git a/esphome/components/light/addressable_light.h b/esphome/components/light/addressable_light.h index 643ec962ba..17cdb7d6f6 100644 --- a/esphome/components/light/addressable_light.h +++ b/esphome/components/light/addressable_light.h @@ -66,7 +66,9 @@ class AddressableLight : public LightOutput, public Component { Color(to_uint8_scale(red), to_uint8_scale(green), to_uint8_scale(blue), to_uint8_scale(white))); } void setup_state(LightState *state) override { +#ifdef USE_LIGHT_GAMMA_LUT this->correction_.set_gamma_table(state->get_gamma_table()); +#endif this->state_parent_ = state; } void update_state(LightState *state) override; diff --git a/esphome/components/light/light_state.cpp b/esphome/components/light/light_state.cpp index d5735b4855..175e18bcdb 100644 --- a/esphome/components/light/light_state.cpp +++ b/esphome/components/light/light_state.cpp @@ -251,6 +251,7 @@ void LightState::current_values_as_ct(float *color_temperature, float *white_bri *white_brightness = this->gamma_correct_lut(*white_brightness); } +#ifdef USE_LIGHT_GAMMA_LUT float LightState::gamma_correct_lut(float value) const { if (value <= 0.0f) return 0.0f; @@ -286,6 +287,7 @@ float LightState::gamma_uncorrect_lut(float value) const { float frac = static_cast(target - a) / static_cast(b - a); return (lo + frac) / 255.0f; } +#endif // USE_LIGHT_GAMMA_LUT bool LightState::is_transformer_active() { return this->is_transformer_active_; } diff --git a/esphome/components/light/light_state.h b/esphome/components/light/light_state.h index e2ae17460a..8ac2d36051 100644 --- a/esphome/components/light/light_state.h +++ b/esphome/components/light/light_state.h @@ -167,6 +167,7 @@ class LightState : public EntityBase, public Component { void set_gamma_correct(float gamma_correct); float get_gamma_correct() const { return this->gamma_correct_; } +#ifdef USE_LIGHT_GAMMA_LUT /// Set pre-computed gamma forward lookup table (256-entry uint16 PROGMEM array) void set_gamma_table(const uint16_t *forward) { this->gamma_table_ = forward; } @@ -177,6 +178,11 @@ class LightState : public EntityBase, public Component { float gamma_correct_lut(float value) const; /// Reverse gamma correction by binary-searching the forward LUT float gamma_uncorrect_lut(float value) const; +#else + /// No gamma LUT — passthrough + float gamma_correct_lut(float value) const { return value; } + float gamma_uncorrect_lut(float value) const { return value; } +#endif // USE_LIGHT_GAMMA_LUT /// Set the restore mode of this light void set_restore_mode(LightRestoreMode restore_mode); @@ -309,7 +315,9 @@ class LightState : public EntityBase, public Component { uint32_t flash_transition_length_{}; /// Gamma correction factor for the light. float gamma_correct_{}; +#ifdef USE_LIGHT_GAMMA_LUT const uint16_t *gamma_table_{nullptr}; +#endif // USE_LIGHT_GAMMA_LUT /// Whether the light value should be written in the next cycle. bool next_write_{true}; diff --git a/esphome/core/defines.h b/esphome/core/defines.h index c0d513d71a..59f05fc162 100644 --- a/esphome/core/defines.h +++ b/esphome/core/defines.h @@ -58,6 +58,7 @@ #define USE_IR_RF #define USE_JSON #define USE_LIGHT +#define USE_LIGHT_GAMMA_LUT #define USE_LOCK #define USE_LOGGER #define USE_LOGGER_LEVEL_LISTENERS