Browse Source

Added gamma correction to HD output

master
klonfish 7 years ago
parent
commit
22787835b2
  1. 14
      blup/output.py

14
blup/output.py

@ -331,13 +331,14 @@ class BLPOutput(Output):
# #
class BlinkenbuntHDOutput(Output): class BlinkenbuntHDOutput(Output):
moduleRegexDesc = 'bbunthd[:BRIGHTNESS]' moduleRegexDesc = 'bbunthd:BRIGHTNESS[:GAMMA]'
moduleRegex = '^bbunthd(:(?P<brightness>\d+))?$' moduleRegex = '^bbunthd:(?P<brightness>\d+)(:(?P<gamma>\d+(\.\d+)?))?$'
def __init__(self, brightness): def __init__(self, brightness, gamma=1):
import neopixel import neopixel
self.w = 22 self.w = 22
self.h = 16 self.h = 16
self.gamma = gamma
LED_COUNT = self.w * self.h LED_COUNT = self.w * self.h
LED_PIN = 13 LED_PIN = 13
LED_FREQ_HZ = 800000 LED_FREQ_HZ = 800000
@ -354,8 +355,9 @@ class BlinkenbuntHDOutput(Output):
@classmethod @classmethod
def fromRegexMatch(cls, regexMatch): def fromRegexMatch(cls, regexMatch):
b = int(regexMatch.groupdict().get('brightness', 50)) b = int(regexMatch.group('brightness'))
return cls(brightness=b) g = float(regexMatch.group('gamma') or 1)
return cls(brightness=b, gamma=g)
def sendFrame(self, frame): def sendFrame(self, frame):
for y in range(self.h): for y in range(self.h):
@ -365,7 +367,7 @@ class BlinkenbuntHDOutput(Output):
else: else:
lednum = x*self.h - y + 15 lednum = x*self.h - y + 15
pix = frame.getPixel(self.w - x - 1, self.h - y - 1) 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.setPixelColor(lednum, self._color_cls(g, r, b))
self.strip.show() self.strip.show()

Loading…
Cancel
Save