ESPHome 2025.12.1
Loading...
Searching...
No Matches
esp_color_correction.cpp
Go to the documentation of this file.
3#include "esphome/core/log.h"
4
5namespace esphome::light {
6
8 for (uint16_t i = 0; i < 256; i++) {
9 // corrected = val ^ gamma
10 auto corrected = to_uint8_scale(gamma_correct(i / 255.0f, gamma));
11 this->gamma_table_[i] = corrected;
12 }
13 if (gamma == 0.0f) {
14 for (uint16_t i = 0; i < 256; i++)
15 this->gamma_reverse_table_[i] = i;
16 return;
17 }
18 for (uint16_t i = 0; i < 256; i++) {
19 // val = corrected ^ (1/gamma)
20 auto uncorrected = to_uint8_scale(powf(i / 255.0f, 1.0f / gamma));
21 this->gamma_reverse_table_[i] = uncorrected;
22 }
23}
24
25} // namespace esphome::light
float gamma_correct(float value, float gamma)
Applies gamma correction of gamma to value.
Definition helpers.cpp:554