-
Notifications
You must be signed in to change notification settings - Fork 1
/
display_png.py
47 lines (35 loc) · 1.21 KB
/
display_png.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import logging
from PIL import Image
logger = logging.getLogger(__name__)
class Display:
def __init__(self, cfg):
self.logger = logging.getLogger(__name__)
self.filename = 'display.png'
self.height = cfg.getint('main', 'height', fallback=600)
self.width = cfg.getint('main', 'width', fallback=800)
self.frame_buf = Image.new('L', (self.width, self.height), 0xFF)
def clear(self):
self.clearBuf()
self.draw_full()
def clearBuf(self):
self.frame_buf.paste(0xFF, box=(0, 0, self.width, self.height))
def getBuf(self):
return self.frame_buf.copy()
def updateBuf(self, buf):
self.frame_buf.paste(buf)
def refresh(self, partial=False, greyscale=True, flash=True):
if not greyscale:
if flash:
# Go to white image first
tmpBuf = self.getBuf()
self.clearBuf()
self.draw_full()
self.updateBuf(tmpBuf)
if partial:
self.draw_partial()
else:
self.draw_full()
def draw_partial(self):
self.frame_buf.save(self.filename)
def draw_full(self):
self.frame_buf.save(self.filename)