diff options
author | Daniel Garcia <danielgarcia@gmail.com> | 2019-01-20 03:42:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-20 03:42:39 +0300 |
commit | 311ed1df3f34c915aee219520dfaa44cc28762cf (patch) | |
tree | ce11894cd90c91ce8f9417d3ffafc0f6348042e7 | |
parent | fd2cbea6ebcdde85b8b813c5c331905c1d1081ab (diff) | |
parent | 09e3b3a514f8e18bb8fd01162daf2ada869d8caf (diff) |
Merge pull request #705 from K1ngjulien/master
Fixed Divide by 0 in CRGB::maximizeBrightness
-rw-r--r-- | pixeltypes.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/pixeltypes.h b/pixeltypes.h index 075c7945..ff327fd9 100644 --- a/pixeltypes.h +++ b/pixeltypes.h @@ -478,10 +478,14 @@ struct CRGB { uint8_t max = red; if( green > max) max = green; if( blue > max) max = blue; - uint16_t factor = ((uint16_t)(limit) * 256) / max; - red = (red * factor) / 256; - green = (green * factor) / 256; - blue = (blue * factor) / 256; + + // stop div/0 when color is black + if(max > 0) { + uint16_t factor = ((uint16_t)(limit) * 256) / max; + red = (red * factor) / 256; + green = (green * factor) / 256; + blue = (blue * factor) / 256; + } } /// return a new CRGB object after performing a linear interpolation between this object and the passed in object |