cleanup, honest palette

This commit is contained in:
Peter D. Gray 2023-06-12 11:32:26 -04:00 committed by scgbckbone
parent 70c189b56a
commit 657097029c

View File

@ -11,28 +11,9 @@ class ST7788:
# for framebuf.FrameBuffer
self.width = 320
self.height = 240
#self.buffer = bytearray(320*240)
self.pipe = open(int(sys.argv[1]), 'wb')
#super().__init__(self.buffer, self.width, self.height, framebuf.GS8)
def show_partial(self, y, h):
# update just a few rows of the display
assert h >= 1
assert h < 120 # sim limitation
rows = memoryview(self.buffer)[320*y:320*(y+h)]
hdr = struct.pack('<s5H', 'p', 0, y, 320, h, len(rows))
self.pipe.write(hdr + rows)
def show(self):
# send entire frame buffer, but two packets
hdr = struct.pack('<s5H', 'p', 0, 0, 320, 120, 320*120)
self.pipe.write(hdr + self.buffer[0:320*120])
hdr = struct.pack('<s5H', 'p', 0, 120, 320, 120, 320*120)
self.pipe.write(hdr + self.buffer[320*120:])
def show_zpixels(self, x, y, w, h, zpixels):
# display compressed pixel data
hdr = struct.pack('<s5H', 'z', x, y, w, h, len(zpixels))
@ -51,23 +32,8 @@ class ST7788:
assert len(palette) == 2 * 16
assert len(pixels) == w * h // 2
if 0:
# do palette lookup now
tmp = bytearray(2 * w * h)
pos = 0
for px in pixels:
col = (px >> 4)
tmp[pos:pos+2] = palette[col:col+2]
col = px & 0xf
tmp[pos+2:pos+4] = palette[col:col+2]
pos += 4
hdr = struct.pack('<s5H', 'r', x, y, w, h, len(tmp))
self.pipe.write(hdr + tmp)
else:
# assumes simulator has same palette
hdr = struct.pack('<s5H', 't' if palette[0] == 0 else 'i', x, y, w, h, len(pixels))
self.pipe.write(hdr + pixels)
hdr = struct.pack('<s5H', 't', x, y, w, h, len(pixels)+len(palette))
self.pipe.write(hdr + palette + pixels)
def show_qr_data(self, x, y, w, expand, scan_w, packed_data):
# 8-bit packed QR data, and where to draw it, expanded