Permalink
Browse files

Fixed Divide by 0 in CRGB::maximizeBrightness

  • Loading branch information...
K1ngjulien committed Dec 22, 2018
1 parent 8f2e864 commit 09e3b3a514f8e18bb8fd01162daf2ada869d8caf
Showing with 8 additions and 4 deletions.
  1. +8 −4 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

0 comments on commit 09e3b3a

Please sign in to comment.