mirror of
https://github.com/esphome/esphome.git
synced 2026-03-03 19:28:20 -07:00
Merge remote-tracking branch 'origin/light-gamma-lut' into integration
This commit is contained in:
@@ -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, [])
|
||||
)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<float>(target - a) / static_cast<float>(b - a);
|
||||
return (lo + frac) / 255.0f;
|
||||
}
|
||||
#endif // USE_LIGHT_GAMMA_LUT
|
||||
|
||||
bool LightState::is_transformer_active() { return this->is_transformer_active_; }
|
||||
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user