Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Kandlhofer <julian.kandlhofer@gmail.com>2018-12-22 03:22:13 +0300
committerJulian Kandlhofer <julian.kandlhofer@gmail.com>2018-12-22 03:22:13 +0300
commit09e3b3a514f8e18bb8fd01162daf2ada869d8caf (patch)
tree80d4f8503fbd2a628e19260e16e04c6fb21809ec
parent8f2e86434b2bfa4d6178622ca3745a68303f8b00 (diff)
Fixed Divide by 0 in CRGB::maximizeBrightness
-rw-r--r--pixeltypes.h12
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