working multitasking
This commit is contained in:
77
pixelflut.py
77
pixelflut.py
@@ -31,10 +31,12 @@ args = parser.parse_args()
|
||||
|
||||
class DrawThread(threading.Thread):
|
||||
def run(self):
|
||||
xfrom = self.args["xfrom"]
|
||||
yfrom = self.args["yfrom"]
|
||||
xto = self.args["xto"]
|
||||
yto = self.args["yto"]
|
||||
xfrom = self._kwargs["xfrom"]
|
||||
yfrom = self._kwargs["yfrom"]
|
||||
xto = self._kwargs["xto"]
|
||||
yto = self._kwargs["yto"]
|
||||
|
||||
print(xfrom, xto, yfrom, yto)
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((args.host, args.port))
|
||||
@@ -52,50 +54,43 @@ class DrawThread(threading.Thread):
|
||||
|
||||
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():
|
||||
buf = bytearray()
|
||||
global framebuffer, old_framebuffer
|
||||
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
|
||||
|
||||
chunkxsize = effectivex//XSPLIT
|
||||
chunkysize = effectivey//YSPLIT
|
||||
|
||||
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:
|
||||
framebuffer.paste(ImageColor.getrgb(args.color), (0,0,sizex,sizey))
|
||||
if args.dumb:
|
||||
draw_dumb()
|
||||
else:
|
||||
draw()
|
||||
draw()
|
||||
|
||||
elif args.image:
|
||||
image = Image.open(str(args.image))
|
||||
framebuffer.paste(image)
|
||||
effectivex = min(image.size[0], sizex)
|
||||
effectivey = min(image.size[1], sizey)
|
||||
if args.dumb:
|
||||
draw_dumb()
|
||||
else:
|
||||
draw()
|
||||
|
||||
wf.close()
|
||||
s.close()
|
||||
draw()
|
||||
|
||||
Reference in New Issue
Block a user