mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 21:44:55 +01:00
Fix overflow in ESPColorCorrection object (#7268)
This commit is contained in:
parent
e17c7124f4
commit
033ab55206
1 changed files with 8 additions and 8 deletions
|
@ -41,29 +41,29 @@ class ESPColorCorrection {
|
||||||
if (this->max_brightness_.red == 0 || this->local_brightness_ == 0)
|
if (this->max_brightness_.red == 0 || this->local_brightness_ == 0)
|
||||||
return 0;
|
return 0;
|
||||||
uint16_t uncorrected = this->gamma_reverse_table_[red] * 255UL;
|
uint16_t uncorrected = this->gamma_reverse_table_[red] * 255UL;
|
||||||
uint8_t res = ((uncorrected / this->max_brightness_.red) * 255UL) / this->local_brightness_;
|
uint16_t res = ((uncorrected / this->max_brightness_.red) * 255UL) / this->local_brightness_;
|
||||||
return res;
|
return (uint8_t) std::min(res, uint16_t(255));
|
||||||
}
|
}
|
||||||
inline uint8_t color_uncorrect_green(uint8_t green) const ESPHOME_ALWAYS_INLINE {
|
inline uint8_t color_uncorrect_green(uint8_t green) const ESPHOME_ALWAYS_INLINE {
|
||||||
if (this->max_brightness_.green == 0 || this->local_brightness_ == 0)
|
if (this->max_brightness_.green == 0 || this->local_brightness_ == 0)
|
||||||
return 0;
|
return 0;
|
||||||
uint16_t uncorrected = this->gamma_reverse_table_[green] * 255UL;
|
uint16_t uncorrected = this->gamma_reverse_table_[green] * 255UL;
|
||||||
uint8_t res = ((uncorrected / this->max_brightness_.green) * 255UL) / this->local_brightness_;
|
uint16_t res = ((uncorrected / this->max_brightness_.green) * 255UL) / this->local_brightness_;
|
||||||
return res;
|
return (uint8_t) std::min(res, uint16_t(255));
|
||||||
}
|
}
|
||||||
inline uint8_t color_uncorrect_blue(uint8_t blue) const ESPHOME_ALWAYS_INLINE {
|
inline uint8_t color_uncorrect_blue(uint8_t blue) const ESPHOME_ALWAYS_INLINE {
|
||||||
if (this->max_brightness_.blue == 0 || this->local_brightness_ == 0)
|
if (this->max_brightness_.blue == 0 || this->local_brightness_ == 0)
|
||||||
return 0;
|
return 0;
|
||||||
uint16_t uncorrected = this->gamma_reverse_table_[blue] * 255UL;
|
uint16_t uncorrected = this->gamma_reverse_table_[blue] * 255UL;
|
||||||
uint8_t res = ((uncorrected / this->max_brightness_.blue) * 255UL) / this->local_brightness_;
|
uint16_t res = ((uncorrected / this->max_brightness_.blue) * 255UL) / this->local_brightness_;
|
||||||
return res;
|
return (uint8_t) std::min(res, uint16_t(255));
|
||||||
}
|
}
|
||||||
inline uint8_t color_uncorrect_white(uint8_t white) const ESPHOME_ALWAYS_INLINE {
|
inline uint8_t color_uncorrect_white(uint8_t white) const ESPHOME_ALWAYS_INLINE {
|
||||||
if (this->max_brightness_.white == 0 || this->local_brightness_ == 0)
|
if (this->max_brightness_.white == 0 || this->local_brightness_ == 0)
|
||||||
return 0;
|
return 0;
|
||||||
uint16_t uncorrected = this->gamma_reverse_table_[white] * 255UL;
|
uint16_t uncorrected = this->gamma_reverse_table_[white] * 255UL;
|
||||||
uint8_t res = ((uncorrected / this->max_brightness_.white) * 255UL) / this->local_brightness_;
|
uint16_t res = ((uncorrected / this->max_brightness_.white) * 255UL) / this->local_brightness_;
|
||||||
return res;
|
return (uint8_t) std::min(res, uint16_t(255));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in a new issue