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): @@ -331,13 +331,14 @@ class BLPOutput(Output):
#
class BlinkenbuntHDOutput(Output):
moduleRegexDesc = 'bbunthd[:BRIGHTNESS]'
moduleRegex = '^bbunthd(:(?P<brightness>\d+))?$'
moduleRegexDesc = 'bbunthd:BRIGHTNESS[:GAMMA]'
moduleRegex = '^bbunthd:(?P<brightness>\d+)(:(?P<gamma>\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): @@ -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): @@ -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()

Loading…
Cancel
Save