WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit ab6fad0

Browse files
authored
Merge pull request #1827 from redphx/master
Re-use CreateFrameCanvas() in samples/gif-viewer.py
2 parents 7727dc3 + f5d799e commit ab6fad0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

bindings/python/samples/gif-viewer.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@
3030
matrix = RGBMatrix(options = options)
3131

3232
# Preprocess the gifs frames into canvases to improve playback performance
33-
canvases = []
33+
frames = []
34+
canvas = matrix.CreateFrameCanvas()
3435
print("Preprocessing gif, this may take a moment depending on the size of the gif...")
3536
for frame_index in range(0, num_frames):
3637
gif.seek(frame_index)
3738
# must copy the frame out of the gif, since thumbnail() modifies the image in-place
3839
frame = gif.copy()
3940
frame.thumbnail((matrix.width, matrix.height), Image.LANCZOS)
40-
canvas = matrix.CreateFrameCanvas()
41-
canvas.SetImage(frame.convert("RGB"))
42-
canvases.append(canvas)
41+
frames.append(frame.convert("RGB"))
42+
4343
# Close the gif file to save memory now that we have copied out all of the frames
4444
gif.close()
4545

@@ -51,7 +51,8 @@
5151
# Infinitely loop through the gif
5252
cur_frame = 0
5353
while(True):
54-
matrix.SwapOnVSync(canvases[cur_frame], framerate_fraction=10)
54+
canvas.SetImage(frames[cur_frame])
55+
matrix.SwapOnVSync(canvas, framerate_fraction=10)
5556
if cur_frame == num_frames - 1:
5657
cur_frame = 0
5758
else:

0 commit comments

Comments
 (0)