Basic implementation of RGB to Epd display. Still needs some fine tuning.

This commit is contained in:
Maximilian Giller 2019-02-28 22:38:06 +01:00
parent b28341ada5
commit c58ebcbe33

View file

@ -39,22 +39,20 @@ class Epd7in5bAdapter (EpdAdapter):
def get_frame_buffer (self, image): def get_frame_buffer (self, image):
buf = [ 0x00 ] * int(self.height * self.width / 4) buf = [ 0x00 ] * int(self.height * self.width / 4)
# Set buffer to value of Python Imaging Library image. image_rgb = image
# Image must be in mode L. imwidth, imheight = image_rgb.size
image_grayscale = image.convert('L', dither=None)
imwidth, imheight = image_grayscale.size
if imwidth != self.height or imheight != self.width: if imwidth != self.height or imheight != self.width:
raise ValueError('Image must be same dimensions as display \ raise ValueError('Image must be same dimensions as display \
({0}x{1}).' .format(self.height, self.width)) ({0}x{1}).' .format(self.height, self.width))
pixels = image_grayscale.load()
for y in range(self.width): for y in range(self.width):
for x in range(self.height): for x in range(self.height):
# Set the bits for the column of pixels at the current # Set the bits for the column of pixels at the current
# position. # position.
if pixels[x, y] < 75: #was 64 # black pixel = image_rgb.getpixel((x, y))
if self.__brightness__(pixel) < 75: #was 64 # black
buf[int((x + y * self.height) / 4)] &= ~(0xC0 >> (x % 4 * 2)) buf[int((x + y * self.height) / 4)] &= ~(0xC0 >> (x % 4 * 2))
elif pixels[x, y] < 110: #was 192 # convert gray to red elif pixel[0] > 150 and (pixel[2] + pixel[1]) < 50: #was 192
buf[int((x + y * self.height) / 4)] &= ~(0xC0 >> (x % 4 * 2)) buf[int((x + y * self.height) / 4)] &= ~(0xC0 >> (x % 4 * 2))
buf[int((x + y * self.height) / 4)] |= 0x40 >> (x % 4 * 2) buf[int((x + y * self.height) / 4)] |= 0x40 >> (x % 4 * 2)
else: # white else: # white
@ -62,6 +60,9 @@ class Epd7in5bAdapter (EpdAdapter):
return buf #due to python2 -> python3, int had to be added in 'get_frame return buf #due to python2 -> python3, int had to be added in 'get_frame
#_buffer #_buffer
def __brightness__ (self, pixel):
return (pixel[0] + pixel[1] + pixel[2]) / 3
def calibrate (self): def calibrate (self):
for _ in range(2): for _ in range(2):
self.init_render() self.init_render()