From 4d2403f9137f81fed77d24bc6c7f0160b79fdbb2 Mon Sep 17 00:00:00 2001 From: Jan Luebbe <jluebbe@debian.org> Date: Sun, 4 May 2014 02:44:02 +0200 Subject: [PATCH] Compare agains previous frame to save bandwidth --- python/font_client.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/python/font_client.py b/python/font_client.py index 4869f89..13f80ee 100755 --- a/python/font_client.py +++ b/python/font_client.py @@ -7,16 +7,36 @@ pygame.init() screen = pygame.Surface((client.WIDTH, client.HEIGHT), depth=8) +prev_screen = None + def send(screen): + global prev_screen w = screen.get_width() h = screen.get_height() 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 = [] - for y in range(h): - for x in range(w): + for y in range(min(ys), max(ys)+1): + for x in range(min(xs), max(xs)+1): pixels.append(pxarray[x][y]) 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 font = None -- GitLab