Overflow in color_uncorrect_red(), color_uncorrect_green(), color_uncorrect_blue() and color_uncorrect_white() methods of ESPColorCorrection object #5725
There are some brightness values at which "it" lambda parameter returns wrong values.
This issue is occured by the color_uncorrect_red(), color_uncorrect_green(), color_uncorrect_blue() and color_uncorrect_white() methods of ESPColorCorrection object. In some cases there are overflow in calculations.
This is an examle:
If red = 255, brightness = 104 and gamma = 2.8, then then value of the pixel will be 21 (this is correct).
If i read this value with it[1].get().red() the color_uncorrect_red() method of ESPColorCorrection object calclutates the following (in esp_color_correction.h):
The gamma_reversetable[21] returns value 105 (instead of 104), because 104 and 105 have the same gamma value (21).
The calculation is the following: 105 (reverse gamma) 255 (const) / 255 (maxbrightness.red) 255 (const) / 104 (localbrightness) = 257.45. --> The res variable overflows and returns value 1 instead of 255.
The problem
There are some brightness values at which "it" lambda parameter returns wrong values.
This issue is occured by the color_uncorrect_red(), color_uncorrect_green(), color_uncorrect_blue() and color_uncorrect_white() methods of ESPColorCorrection object. In some cases there are overflow in calculations. This is an examle: If red = 255, brightness = 104 and gamma = 2.8, then then value of the pixel will be 21 (this is correct). If i read this value with it[1].get().red() the color_uncorrect_red() method of ESPColorCorrection object calclutates the following (in esp_color_correction.h):
The gamma_reversetable[21] returns value 105 (instead of 104), because 104 and 105 have the same gamma value (21). The calculation is the following: 105 (reverse gamma) 255 (const) / 255 (maxbrightness.red) 255 (const) / 104 (localbrightness) = 257.45. --> The res variable overflows and returns value 1 instead of 255.
Test yaml:
Teszt case 1: Service call in HomeAssistant (brightness = 103):
After starting "Test" effect, returns good values:
Teszt case 2: Service call in HomeAssistant (brightness = 102):
After starting "Test" effect, returns wrong values:
Which version of ESPHome has the issue?
2024.4.0
What type of installation are you using?
pip
Which version of Home Assistant has the issue?
2024.4.3
What platform are you using?
ESP32
Board
nodemcu
Component causing the issue
Light
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response