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