working multitasking

This commit is contained in:
Yannik Enss
2020-02-04 19:40:28 +01:00
parent d4b935c60f
commit 8ff465aa04

View File

@@ -31,10 +31,12 @@ args = parser.parse_args()
class DrawThread(threading.Thread): class DrawThread(threading.Thread):
def run(self): def run(self):
xfrom = self.args["xfrom"] xfrom = self._kwargs["xfrom"]
yfrom = self.args["yfrom"] yfrom = self._kwargs["yfrom"]
xto = self.args["xto"] xto = self._kwargs["xto"]
yto = self.args["yto"] yto = self._kwargs["yto"]
print(xfrom, xto, yfrom, yto)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((args.host, args.port)) s.connect((args.host, args.port))
@@ -52,39 +54,38 @@ class DrawThread(threading.Thread):
s.close() s.close()
def draw_dumb():
for x in range(sizex):
for y in range(sizey):
value = "%02X%02X%02X%02X"%framebuffer.getpixel((x,y))
wf.write("PX {} {} {}\n".format(x,y+args.yoffset,value))
while args.repeat:
for x in range(sizex):
for y in range(sizey):
value = "%02X%02X%02X%02X"%framebuffer.getpixel((x,y))
wf.write("PX {} {} {}\n".format(x,y+args.yoffset,value))
def draw(): def draw():
buf = bytearray() chunkxsize = effectivex//XSPLIT
global framebuffer, old_framebuffer chunkysize = effectivey//YSPLIT
if framebuffer == old_framebuffer:
# nothing to draw
return
for x in range(effectivex):
for y in range(effectivey):
# if framebuffer.getpixel((x,y))[3] != 0 and framebuffer.getpixel((x,y)) != old_framebuffer.getpixel((x,y)):
value = b"%02X%02X%02X%02X"%framebuffer.getpixel((x,y))
buf += b"PX %b %b %b\n"%(bytes(str(x), "ascii"),bytes(str(y+args.yoffset), "ascii"),value)
s.send(buf)
while args.repeat:
s.send(buf)
old_framebuffer = framebuffer
remainderx = effectivex % XSPLIT
remaindery = effectivey % YSPLIT
xchunks = []
ychunks = []
remainingx = effectivex
remainingy = effectivey
while remainingx > remainderx:
start = effectivex - remainingx
remainingx -= chunkxsize
stop = effectivex - remainingx
xchunks.append((start, stop))
xchunks.append((remainingx-effectivex, effectivex))
while remainingy > remaindery:
start = effectivey - remainingy
remainingy -= chunkysize
stop = effectivey - remainingy
ychunks.append((start, stop))
ychunks.append((remainingy-effectivey, effectivey))
for xchunk in xchunks:
for ychunk in ychunks:
DrawThread(kwargs={"xfrom":xchunk[0], "xto":xchunk[1], "yfrom":ychunk[0], "yto":ychunk[1]}).start()
if args.color: if args.color:
framebuffer.paste(ImageColor.getrgb(args.color), (0,0,sizex,sizey)) framebuffer.paste(ImageColor.getrgb(args.color), (0,0,sizex,sizey))
if args.dumb:
draw_dumb()
else:
draw() draw()
elif args.image: elif args.image:
@@ -92,10 +93,4 @@ elif args.image:
framebuffer.paste(image) framebuffer.paste(image)
effectivex = min(image.size[0], sizex) effectivex = min(image.size[0], sizex)
effectivey = min(image.size[1], sizey) effectivey = min(image.size[1], sizey)
if args.dumb:
draw_dumb()
else:
draw() draw()
wf.close()
s.close()