Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-use CreateFrameCanvas() in samples/gif-viewer.py #1556

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions bindings/python/samples/gif-viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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:
Expand Down