From 22787835b2bd3aa6405002b22cf1f8d0721ca435 Mon Sep 17 00:00:00 2001 From: klonfish Date: Thu, 21 Dec 2017 21:03:22 +0100 Subject: [PATCH] Added gamma correction to HD output --- blup/output.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/blup/output.py b/blup/output.py index 88bc780..af7a4ee 100644 --- a/blup/output.py +++ b/blup/output.py @@ -331,13 +331,14 @@ class BLPOutput(Output): # class BlinkenbuntHDOutput(Output): - moduleRegexDesc = 'bbunthd[:BRIGHTNESS]' - moduleRegex = '^bbunthd(:(?P\d+))?$' + moduleRegexDesc = 'bbunthd:BRIGHTNESS[:GAMMA]' + moduleRegex = '^bbunthd:(?P\d+)(:(?P\d+(\.\d+)?))?$' - def __init__(self, brightness): + def __init__(self, brightness, gamma=1): import neopixel self.w = 22 self.h = 16 + self.gamma = gamma LED_COUNT = self.w * self.h LED_PIN = 13 LED_FREQ_HZ = 800000 @@ -354,8 +355,9 @@ class BlinkenbuntHDOutput(Output): @classmethod def fromRegexMatch(cls, regexMatch): - b = int(regexMatch.groupdict().get('brightness', 50)) - return cls(brightness=b) + b = int(regexMatch.group('brightness')) + g = float(regexMatch.group('gamma') or 1) + return cls(brightness=b, gamma=g) def sendFrame(self, frame): for y in range(self.h): @@ -365,7 +367,7 @@ class BlinkenbuntHDOutput(Output): else: lednum = x*self.h - y + 15 pix = frame.getPixel(self.w - x - 1, self.h - y - 1) - r, g, b = pix + r, g, b = map(lambda c: round(((c/255)**self.gamma)*255), pix) self.strip.setPixelColor(lednum, self._color_cls(g, r, b)) self.strip.show()