Created
February 18, 2020 22:58
-
-
Save Melanpan/d3b724dbeda5f1f618bd76c3092d90d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import cv2 | |
import struct | |
import numpy as np | |
import socket | |
from pyboy import PyBoy | |
pyboy = PyBoy(sys.argv[1],debugging=False,disable_input=False,hide_window="--quiet" in sys.argv) | |
pyboy.set_emulation_speed(1) | |
tick = 0 | |
pixelBuffer = [] | |
rgbMode = struct.pack("<?", 0) | |
versionBit = struct.pack("<B", 1) | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
while True: | |
screen_dimensions = pyboy.get_raw_screen_buffer_dims() | |
frame = np.frombuffer(pyboy.get_raw_screen_buffer(), dtype=np.uint8).reshape(screen_dimensions[1], screen_dimensions[0], 4) | |
frame = cv2.resize(frame, dsize=(64, 32), interpolation=cv2.INTER_CUBIC) | |
rows, cols, _ = frame.shape | |
for r in range(rows): | |
for c in range(cols): | |
pixelBuffer.append(bytes(struct.pack("<2H4B", c, r, *frame[r,c]))) | |
if len(pixelBuffer) > 256: # Update screen every 256 pixels | |
sock.sendto(versionBit + rgbMode + b"".join(pixelBuffer), ("10.208.42.159", 5004)) | |
pixelBuffer = [] | |
pyboy.tick() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment