From 7a4ef7f3b3c8d3f43a467140f492c1824c989f7f Mon Sep 17 00:00:00 2001 From: George Waters Date: Fri, 3 Jul 2020 21:19:54 -0400 Subject: [PATCH 1/2] Only override white pixel when not given --- adafruit_pypixelbuf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_pypixelbuf.py b/adafruit_pypixelbuf.py index f36aded..b567457 100644 --- a/adafruit_pypixelbuf.py +++ b/adafruit_pypixelbuf.py @@ -253,9 +253,9 @@ def _parse_color(self, value): # same as math.ceil(brightness * 31) & 0b00011111 # Idea from https://www.codeproject.com/Tips/700780/Fast-floor-ceiling-functions w = (32 - int(32 - w * 31) & 0b00011111) | DOTSTAR_LED_START - elif self._has_white and r == g and g == b: + elif self._has_white and (isinstance(value, int) or len(value) == 3) and r == g and g == b: # If all components are the same and we have a white pixel then use it - # instead of the individual components. + # instead of the individual components when all 4 values aren't explicitly given. w = r r = 0 g = 0 From 7a39dd01e1dc3579f848bdc82604efb5406fbdf6 Mon Sep 17 00:00:00 2001 From: George Waters Date: Fri, 3 Jul 2020 21:25:28 -0400 Subject: [PATCH 2/2] Format changes for black --- adafruit_pypixelbuf.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adafruit_pypixelbuf.py b/adafruit_pypixelbuf.py index b567457..d9f3592 100644 --- a/adafruit_pypixelbuf.py +++ b/adafruit_pypixelbuf.py @@ -253,7 +253,12 @@ def _parse_color(self, value): # same as math.ceil(brightness * 31) & 0b00011111 # Idea from https://www.codeproject.com/Tips/700780/Fast-floor-ceiling-functions w = (32 - int(32 - w * 31) & 0b00011111) | DOTSTAR_LED_START - elif self._has_white and (isinstance(value, int) or len(value) == 3) and r == g and g == b: + elif ( + self._has_white + and (isinstance(value, int) or len(value) == 3) + and r == g + and g == b + ): # If all components are the same and we have a white pixel then use it # instead of the individual components when all 4 values aren't explicitly given. w = r