Giter Club home page Giter Club logo

Comments (2)

ThisIs0xBC avatar ThisIs0xBC commented on August 16, 2024

Just had an idea, would it be possible to just create a sinuglar frame canvas instead, and just utilize PILs "SetImage" functionality like this:

gif = Image.open(f"{self.webappRootDir}/basic-flask-app/static/gifs/{gifName}")

directory = os.fsencode(f"{self.matrixRootDir}/saved-gifs/{gifName}")
numberOfFrames = len([f for f in os.listdir(directory)if os.path.isfile(os.path.join(directory, f))])
    
canvas = self.matrix.CreateFrameCanvas()
   
for frameFileNumber in range(numberOfFrames):
    
    canvas.SetImage(Image.open(f"{self.matrixRootDir}/saved-gifs/{gifName}/frame_{frameFileNumber}.bmp"))
    canvases.append(canvas)

    self.gifFileCanvases[gifName] = [canvases, gif.info['duration']]
    
gif.close()

print(f"Loaded GIF Data from File: {gifName}")

Then when rendering the GIFS I can just iterate each frame and run:

for frame in canvases:
    matrix.SetImage(frame)

Where "frame" is a "FrameCanvas" object we created when processing the GIF before?

from rpi-rgb-led-matrix.

ThisIs0xBC avatar ThisIs0xBC commented on August 16, 2024

Ok, update. I tried the above, and it partially works.

I now create just a sinuglar canvas object with matrix.CreateFrameCanvas(), and then save the bitmap files as usual (like shown above), and then when rendering each GIF, I first load all the BMP with Image.open(), passing each BMP file (each frame of the GIF) as an argument, then saving all the results of Image.open() into a list. So I end up with a list of Image objects (each object represents a frame of the GIF)

Then, when rendering, I iterate that list of Image objects and run:

self.canvas.SetImage(listOfImages[frameNumber])
self.matrix.SwapOnVSync(self.canvas, framerate_fraction=framerateFraction)

This works, but produces noticeable flickering when the GIF restarts (as I play them 5 times each).

Any ideas? I just have the rendering code wrapped in a for i in range (5) loop for playing them 5 times.

from rpi-rgb-led-matrix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.