Scrolling works!!1!
This commit is contained in:
parent
a4d24551d5
commit
c2d5c19dcc
8 changed files with 137 additions and 80 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import math
|
||||
|
||||
import numpy as np
|
||||
import click
|
||||
|
|
@ -22,26 +23,44 @@ def tb_int_to_px(val):
|
|||
return np.array([(val//0x10000)&0xff, (val//0x100)&0xff, val&0xff], dtype=np.uint8)
|
||||
|
||||
def data_encode(data, width, height):
|
||||
HEADER_W = 12
|
||||
assert width > HEADER_W
|
||||
data = struct.pack('>I', len(data)) + data
|
||||
data = np.frombuffer(data, dtype=np.uint8)
|
||||
for i in range(len(data) - 4):
|
||||
print(f'{data[i+4]:02x} ', end='')
|
||||
if i%16 == 15 and i > 0:
|
||||
print()
|
||||
|
||||
data_expanded = np.repeat(data, 2).reshape((-1, 2))
|
||||
data_expanded[:, 0] &= 0xf0
|
||||
data_expanded[:, 1] = (data_expanded[:, 1] & 0x0f) << 4
|
||||
data_expanded = data_expanded.flatten()
|
||||
|
||||
win = np.zeros([height*width*3], dtype=np.uint8)
|
||||
win[12*3:12*3+len(data_expanded)] = data_expanded
|
||||
win = win.reshape((height, width, 3))
|
||||
payload_w = width-HEADER_W
|
||||
line_capacity = payload_w*3
|
||||
print(payload_w, line_capacity, line_capacity / 2)
|
||||
block_height = math.ceil(len(data_expanded)/line_capacity)
|
||||
data_expanded = np.hstack([data_expanded, np.zeros(line_capacity*block_height - len(data_expanded), dtype=np.uint8)])
|
||||
block = np.zeros((block_height, payload_w, 3), dtype=np.uint8)
|
||||
block[:,:,:] = data_expanded.reshape((block_height, payload_w, 3))
|
||||
|
||||
win[0, :8] = WINDOW_MAGIC
|
||||
win[0, 8] = tb_int_to_px(0)
|
||||
win[0, 9] = tb_int_to_px(0)
|
||||
win[0, 10] = tb_int_to_px(width)
|
||||
win[0, 11] = tb_int_to_px(height)
|
||||
payload_area = np.vstack(
|
||||
[block] * (height // block_height) +
|
||||
[np.zeros((height % block_height, payload_w, 3), dtype=np.uint8)])
|
||||
|
||||
header = np.zeros((height, HEADER_W, 3), dtype=np.uint8)
|
||||
for y in range(height):
|
||||
header[y, :8] = WINDOW_MAGIC
|
||||
if y % block_height == 0 and y + block_height <= height:
|
||||
header[y, 8] = tb_int_to_px(0x88)
|
||||
else:
|
||||
header[y, 8] = tb_int_to_px(0)
|
||||
header[y, 9] = tb_int_to_px(y)
|
||||
header[y, 10] = tb_int_to_px(width)
|
||||
header[y, 11] = tb_int_to_px(height)
|
||||
|
||||
#print('out:', ' '.join(f'{x:02x}' for x in win.flatten()[:256]))
|
||||
return Image.fromarray(win)
|
||||
return Image.fromarray(np.hstack([header, payload_area]))
|
||||
|
||||
@click.command()
|
||||
@click.option('-w', '--width', type=int, default=400)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue