Apply color brightness to addressable light effects (#2321)

This commit is contained in:
Oxan van Leeuwen 2021-09-19 18:46:26 +02:00 committed by GitHub
parent 30eca885c9
commit 50da630811
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 8 deletions

View File

@ -27,7 +27,7 @@ std::unique_ptr<LightTransformer> AddressableLight::create_default_transition()
return make_unique<AddressableLightTransformer>(*this);
}
Color esp_color_from_light_color_values(LightColorValues val) {
Color color_from_light_color_values(LightColorValues val) {
auto r = to_uint8_scale(val.get_color_brightness() * val.get_red());
auto g = to_uint8_scale(val.get_color_brightness() * val.get_green());
auto b = to_uint8_scale(val.get_color_brightness() * val.get_blue());
@ -44,7 +44,7 @@ void AddressableLight::update_state(LightState *state) {
return;
// don't use LightState helper, gamma correction+brightness is handled by ESPColorView
this->all() = esp_color_from_light_color_values(val);
this->all() = color_from_light_color_values(val);
this->schedule_show();
}
@ -54,7 +54,7 @@ void AddressableLightTransformer::start() {
return;
auto end_values = this->target_values_;
this->target_color_ = esp_color_from_light_color_values(end_values);
this->target_color_ = color_from_light_color_values(end_values);
// our transition will handle brightness, disable brightness in correction.
this->light_.correction_.set_local_brightness(255);

View File

@ -19,6 +19,9 @@ namespace light {
using ESPColor ESPDEPRECATED("esphome::light::ESPColor is deprecated, use esphome::Color instead.", "v1.21") = Color;
/// Convert the color information from a `LightColorValues` object to a `Color` object (does not apply brightness).
Color color_from_light_color_values(LightColorValues val);
class AddressableLight : public LightOutput, public Component {
public:
virtual int32_t size() const = 0;

View File

@ -38,11 +38,8 @@ class AddressableLightEffect : public LightEffect {
void stop() override { this->get_addressable_()->set_effect_active(false); }
virtual void apply(AddressableLight &it, const Color &current_color) = 0;
void apply() override {
LightColorValues color = this->state_->remote_values;
// not using any color correction etc. that will be handled by the addressable layer
Color current_color =
Color(static_cast<uint8_t>(color.get_red() * 255), static_cast<uint8_t>(color.get_green() * 255),
static_cast<uint8_t>(color.get_blue() * 255), static_cast<uint8_t>(color.get_white() * 255));
// not using any color correction etc. that will be handled by the addressable layer through ESPColorCorrection
Color current_color = color_from_light_color_values(this->state_->remote_values);
this->apply(*this->get_addressable_(), current_color);
}