chidea / FBpyGIF

Pure Python implemented Frame Buffer memory mapping library with GIF animation playing support on SBC(Raspberry pi)
MIT License
34 stars 5 forks source link

Pre-load GIF images? #13

Open alexylem opened 7 years ago

alexylem commented 7 years ago

I was planning to use FBpyGIF in my project to show GIF looping animations based on events. Thanks to #12 it now perfectly works, however the load time is quite long for some GIFs: (on a Raspberry Pi 3)

I can't wait so long as GIF are illustrating the events in real time.

I see in the README.md you have planned to:

  • [ ] Background loading of next animation file to reduce loading delay between them

Would you consider the possibility to load/prepare the whole playlist in memory and allow showing the right one based on events/signals/other? I've looked into main.py and have the feeling that fb.ready_fb() could be what I'm looking for. I'm ready to write some Python code if you would provide such library.

Many thanks in advance for your help.

ozett commented 7 years ago

👍 like to see a "net-socket" or the like, to have external control while running.

my usecase would be somehow: i could show certain images on external events (from my homeautomation) for certain time, than come back to random loop again ..

like once described here: https://github.com/chidea/FBpyGIF/issues/6

alexylem commented 7 years ago

@ozett fyi I run a similar project (voice assistant for home automation) and I ended up using gifview from gifsicle in X. I'm waiting this enhancement to go back to the framebuffer world.

chidea commented 7 years ago

Sorry for late reply. I was away from my home. Loading uncompressed frames onto memory requires huge size of it. You can simply calculate the size of it by bpp*width*height*frames/8 = x (bytes).

That 4 seconds are simply because CPU needs long I/O time to load up image from SD card into memory, frame by frame with uncompressing calculations. After playing of each image, it just removes image from memory to gather free memory for next image. The thing here is that Raspberry has too small RAM, weak CPU and deadly slow I/O time than real PC. Furthermore, I don't have time to invent another faster algorithm.

If you need to use it even though with this obstacles, what you can consider is these two options.

  1. Preview flag shows uncompressed frame before uncompressing next frame. This'll slowly draw first iteration of loop and normally after. This is almost the same as how every modern web browsers does internally.
  2. Manual use of ready_gif function. This function loads up frames onto memory, into a single python list to be returned. You can put this list later into gif_loop function with an event to control the loop of gif play. ready_fb function is for setting up framebuffer in first load up your program. Calling this can cause kernel to reset display and framebuffer driver.