ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
esp_color_correction.cpp
Go to the documentation of this file.
2
3namespace esphome::light {
4
5uint8_t ESPColorCorrection::gamma_correct_(uint8_t value) const {
6 if (this->gamma_table_ == nullptr)
7 return value;
8 return static_cast<uint8_t>((progmem_read_uint16(&this->gamma_table_[value]) + 128) / 257);
9}
10
11uint8_t ESPColorCorrection::gamma_uncorrect_(uint8_t value) const {
12 if (this->gamma_table_ == nullptr)
13 return value;
14 if (value == 0)
15 return 0;
16 uint16_t target = value * 257; // Scale 0-255 to 0-65535
17 uint8_t lo = gamma_table_reverse_search(this->gamma_table_, target);
18 if (lo >= 255)
19 return 255;
20 uint16_t a = progmem_read_uint16(&this->gamma_table_[lo]);
21 uint16_t b = progmem_read_uint16(&this->gamma_table_[lo + 1]);
22 return (target - a <= b - target) ? lo : lo + 1;
23}
24
25} // namespace esphome::light
uint8_t gamma_correct_(uint8_t value) const
Forward gamma: read uint16 PROGMEM table, convert to uint8.
uint8_t gamma_uncorrect_(uint8_t value) const
Reverse gamma: binary search the forward PROGMEM table.
uint8_t gamma_table_reverse_search(const uint16_t *table, uint16_t target)
Binary search a monotonically increasing uint16[256] PROGMEM table.
static float float b
uint16_t progmem_read_uint16(const uint16_t *addr)
Definition core.cpp:51