From 490adb51638be160b87d0351aa63c290d4b51db9 Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Mon, 19 Jun 2023 09:48:17 +0700 Subject: [PATCH] Reuse CreateFrameCanvas() in samples/gif-viewer.py --- bindings/python/samples/gif-viewer.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bindings/python/samples/gif-viewer.py b/bindings/python/samples/gif-viewer.py index 3bc2950f1..a886aae18 100644 --- a/bindings/python/samples/gif-viewer.py +++ b/bindings/python/samples/gif-viewer.py @@ -30,16 +30,16 @@ matrix = RGBMatrix(options = options) # Preprocess the gifs frames into canvases to improve playback performance -canvases = [] +frames = [] +canvas = matrix.CreateFrameCanvas() print("Preprocessing gif, this may take a moment depending on the size of the gif...") for frame_index in range(0, num_frames): gif.seek(frame_index) # must copy the frame out of the gif, since thumbnail() modifies the image in-place frame = gif.copy() frame.thumbnail((matrix.width, matrix.height), Image.ANTIALIAS) - canvas = matrix.CreateFrameCanvas() - canvas.SetImage(frame.convert("RGB")) - canvases.append(canvas) + + frames.append(frame.convert("RGB")) # Close the gif file to save memory now that we have copied out all of the frames gif.close() @@ -51,7 +51,8 @@ # Infinitely loop through the gif cur_frame = 0 while(True): - matrix.SwapOnVSync(canvases[cur_frame], framerate_fraction=10) + canvas.SetImage(frames[cur_frame]) + matrix.SwapOnVSync(canvas, framerate_fraction=10) if cur_frame == num_frames - 1: cur_frame = 0 else: