Skip to content
Snippets Groups Projects
Commit 4d2403f9 authored by Jan Luebbe's avatar Jan Luebbe
Browse files

Compare agains previous frame to save bandwidth

parent c0479b40
No related branches found
No related tags found
No related merge requests found
...@@ -7,16 +7,36 @@ pygame.init() ...@@ -7,16 +7,36 @@ pygame.init()
screen = pygame.Surface((client.WIDTH, client.HEIGHT), depth=8) screen = pygame.Surface((client.WIDTH, client.HEIGHT), depth=8)
prev_screen = None
def send(screen): def send(screen):
global prev_screen
w = screen.get_width() w = screen.get_width()
h = screen.get_height() h = screen.get_height()
pxarray = pygame.PixelArray(screen) pxarray = pygame.PixelArray(screen)
if prev_screen:
prev_pxarray = pygame.PixelArray(prev_screen)
xs = set()
ys = set()
for y in range(h):
for x in range(w):
if not pxarray[x][y] == prev_pxarray[x][y]:
xs.add(x)
ys.add(y)
else:
xs = set((0, client.WIDTH-1))
ys = set((0, client.HEIGHT-1))
if not xs:
return
prev_screen = screen.copy()
pixels = [] pixels = []
for y in range(h): for y in range(min(ys), max(ys)+1):
for x in range(w): for x in range(min(xs), max(xs)+1):
pixels.append(pxarray[x][y]) pixels.append(pxarray[x][y])
del pxarray del pxarray
client.blit(0, 0, w, h, pixels) client.blit(min(xs), min(ys), max(xs)-min(xs)+1, max(ys)-min(ys)+1, pixels)
prev_mx = None prev_mx = None
font = None font = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment