def sendgifs(target): thost, tport = target.split(':') crapthing = crap.CRAPClient(thost, int(tport)) last_gif = None while True: with gif_cond: gif_cond.wait_for(lambda: last_gif != gif) last_gif = gif img = Image.open(last_gif) palette = img.getpalette() last_frame = Image.new("RGBA", img.size) sleepiness = min(img.info.get('duration', 100) / 1000.0, 10.0) for frame in ImageSequence.Iterator(img): #This works around a known bug in Pillow #See also: http://stackoverflow.com/questions/4904940/python-converting-gif-frames-to-png frame.putpalette(palette) c = frame.convert("RGBA") if 'background' in img.info and 'transparency' in img.info: last_frame.paste(c, c) else: last_frame = c im = last_frame.copy() im = ImageOps.fit(im, (config.display_width, config.display_height), Image.NEAREST, centering=(0.5, 0.5)) crapthing.sendframe(im.tobytes()) time.sleep(sleepiness) if last_gif != gif: break
for l in f.readlines())) if __name__ == '__main__': try: ml = matelight.Matelight(config.ml_usb_serial_match) except ValueError as e: print(e, 'Starting in headless mode.', file=sys.stderr) ml = None loop = asyncio.get_event_loop() tcp_server = MatelightTCPServer(config.tcp_addr, config.tcp_port, loop) udp_server = crap.CRAPServer(config.udp_addr, config.udp_port) forwarder = crap.CRAPClient( config.crap_fw_addr, config.crap_fw_port) if config.crap_fw_addr is not None else None async_thr = threading.Thread(target=loop.run_forever) async_thr.daemon = True async_thr.start() with suppress(KeyboardInterrupt): while True: for title, frame in _fallbackiter( udp_server, _fallbackiter(tcp_server, defaulttexts())): if ml: if ml.sendframe(frame) == 1: try: ml = matelight.Matelight( config.ml_usb_serial_match)
def opc_to_crap(dhost, dport, lhost, lport): while True: cc = crap.CRAPClient(dhost, dport) for frame in OPCServer(lhost, lport): cc.sendframe(frame)