(another) Animated GIF player

bitbank

Member
Long ago, in a job far far way, I wrote optimized image codecs for all standard image types. I've been slowly porting them to be compatible with Arduinos and today I got my old GIF player to run on the Teensy4. It still needs some cleanup before it can be released as an Arduino library, but today I got it running reliably.


It currently uses a lot of RAM and doesn't optimize the display writes, but I will get there in stages. Hopefully this will make it easier to use animated images on the Teensy when I finish it.
 
That looks quick!

So you’re going to build a new library to play back the GIFs, or will it be an extension library that utilizes the APIs from display driver libraries such as ILI9341_t3n?
 
That looks quick!

So you’re going to build a new library to play back the GIFs, or will it be an extension library that utilizes the APIs from display driver libraries such as ILI9341_t3n?

It's going to use my bb_spi_lcd library to draw on LCDs. It should be easy to modify it to use any other LCD library from there.
 
I maintain this AnimatedGIFs "sketch", originally written for Teensy/SmartMatrix Library/SD card, but easily adaptable to other platforms: https://github.com/pixelmatix/AnimatedGIFs

Adafruit adapted the sketch into an Adafruit Arcada specific library: https://github.com/adafruit/Adafruit_Arcada_GifDecoder

I've forked their library to make it generic again, and it's now available here: https://github.com/pixelmatix/GifDecoder

It sounds like you're coding your library from scratch, but I'm sharing anyway in case it helps. Looking forward to seeing your library!
 
I've done some cleanup and testing. Here's the status so far:

1) Written for any C compiler (no dependency on Arduino or anything else)
2) Static GIF structure uses 22k of RAM; no other buffers needed and no use of malloc/free or any dynamic structures
3) Can play files from memory (internal FLASH) or SD cards (seek and read callbacks)
4) Uses a smart buffering system that de-chunks a few blocks of GIF data and doesn't have to constantly check for needing more data at each decode step
5) Can display much quicker on systems with enough RAM to hold the destination image (transparent pixel rendering in memory versus moving the LCD write cursor)

I'll share it soon; I'm still fleshing out the parts and I need to document it and provide examples.
 
I finally got time today to work on this. I've been coding the SD card support and it basically works, but I've run into an odd problem. My code tries to read a fixed amount of data (2K) to parse the GIF header of each frame instead of calling read() tons of times with tiny buffers. The problem occurs when it reaches the end of the file. If the file position is at filesize-1k and I try to read 2K, it will correctly read 1k, but from that point on, seek() has no effect and the file is 'stuck' at the end. Has anyone seen this?

Update:
If found an ugly workaround - if I read up to, but not including the last byte of the file, seek() continues to work.

 
Last edited:
Teensy 3.1 Animated GIFs sketch not working...

I finished the code - please have a look and let me know what you think:

https://github.com/bitbank2/AnimatedGIF

I am having compile issues with AnimatedGIFs sketch for my Teensy 3.1 & SmartMatrix board. I got it all working in the middle of last year but now, using the exact same sketch and no changes, I only get errors that I don't understand. Is there an update that addresses these issues? I would like to get back my SmartMatrix screen display working properly.
Here is the verbose output while trying to compile:

/Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/arduino-builder -dump-prefs -logger=machine -hardware /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware -hardware /Users/alfredolivas/Library/Arduino15/packages -tools /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/tools-builder -tools /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware/tools/avr -tools /Users/alfredolivas/Library/Arduino15/packages -built-in-libraries /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/libraries -libraries /Users/alfredolivas/Desktop/Arduino/Sketchbook/libraries -fqbn=teensy:avr:teensy31:usb=serial,speed=96,opt=o2std,keys=en-us -ide-version=10813 -build-path /var/folders/5c/6t7s01sn4db00kncp3sf1wpr0000gn/T/arduino_build_632896 -warnings=none -build-cache /var/folders/5c/6t7s01sn4db00kncp3sf1wpr0000gn/T/arduino_cache_60728 -verbose /Users/alfredolivas/Desktop/Arduino/Sketchbook/TeensyGIFs_2022/TeensyGIFs_2022.ino
/Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/arduino-builder -compile -logger=machine -hardware /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware -hardware /Users/alfredolivas/Library/Arduino15/packages -tools /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/tools-builder -tools /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware/tools/avr -tools /Users/alfredolivas/Library/Arduino15/packages -built-in-libraries /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/libraries -libraries /Users/alfredolivas/Desktop/Arduino/Sketchbook/libraries -fqbn=teensy:avr:teensy31:usb=serial,speed=96,opt=o2std,keys=en-us -ide-version=10813 -build-path /var/folders/5c/6t7s01sn4db00kncp3sf1wpr0000gn/T/arduino_build_632896 -warnings=none -build-cache /var/folders/5c/6t7s01sn4db00kncp3sf1wpr0000gn/T/arduino_cache_60728 -verbose /Users/alfredolivas/Desktop/Arduino/Sketchbook/TeensyGIFs_2022/TeensyGIFs_2022.ino
Using board 'teensy31' from platform in folder: /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware/teensy/avr
Using core 'teensy3' from platform in folder: /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware/teensy/avr
Detecting libraries used...
"/Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -mno-unaligned-access -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -fsingle-precision-constant -D__MK20DX256__ -DTEENSYDUINO=155 -DARDUINO=10813 -DARDUINO_TEENSY32 -DF_CPU=96000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-I/Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3" /var/folders/5c/6t7s01sn4db00kncp3sf1wpr0000gn/T/arduino_build_632896/sketch/TeensyGIFs_2022.ino.cpp -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE
Alternatives for MatrixHardware_Teensy3_ShieldV1toV3.h: [SmartMatrix-4.0.3@4.0.3]
ResolveLibrary(MatrixHardware_Teensy3_ShieldV1toV3.h)
-> candidates: [SmartMatrix-4.0.3@4.0.3]
"/Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -mno-unaligned-access -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -fsingle-precision-constant -D__MK20DX256__ -DTEENSYDUINO=155 -DARDUINO=10813 -DARDUINO_TEENSY32 -DF_CPU=96000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-I/Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3" -I/Users/alfredolivas/Desktop/Arduino/Sketchbook/libraries/SmartMatrix-4.0.3/src /var/folders/5c/6t7s01sn4db00kncp3sf1wpr0000gn/T/arduino_build_632896/sketch/TeensyGIFs_2022.ino.cpp -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE
Alternatives for MatrixHardware_T4Adapter.h: []
ResolveLibrary(MatrixHardware_T4Adapter.h)
-> candidates: []
/Users/alfredolivas/Desktop/Arduino/Sketchbook/TeensyGIFs_2022/TeensyGIFs_2022.ino:76:38: fatal error: MatrixHardware_T4Adapter.h: No such file or directory
compilation terminated.
Using library SmartMatrix-4.0.3 at version 4.0.3 in folder: /Users/alfredolivas/Desktop/Arduino/Sketchbook/libraries/SmartMatrix-4.0.3
Error compiling for board Teensy 3.2 / 3.1.


Thanks in advance.
 
Last edited:
I am having compile issues with AnimatedGIFs sketch for my Teensy 3.1 & SmartMatrix board. I got it all working in the middle of last year but now, using the exact same sketch and no changes, I only get errors that I don't understand. Is there an update that addresses these issues? I would like to get back my SmartMatrix screen display working properly.
Thanks in advance.

Please post the error msgs; AnimatedGIF is working on my setups; I can't fix what I can't reproduce.
 
The error is here (and unrelated to the AnimatedGIF)

Code:
/Users/alfredolivas/Desktop/Arduino/Sketchbook/TeensyGIFs_2022/TeensyGIFs_2022.ino:76:38: fatal error: MatrixHardware_T4Adapter.h: No such file or directory

The file is now named `MatrixHardware_Teensy4_ShieldV4Adapter.h`. It was renamed as part of the SmartMatrix Library 4.0 release, you must have been using an older version.
 
The error is here (and unrelated to the AnimatedGIF)

Code:
/Users/alfredolivas/Desktop/Arduino/Sketchbook/TeensyGIFs_2022/TeensyGIFs_2022.ino:76:38: fatal error: MatrixHardware_T4Adapter.h: No such file or directory

The file is now named `MatrixHardware_Teensy4_ShieldV4Adapter.h`. It was renamed as part of the SmartMatrix Library 4.0 release, you must have been using an older version.

NOPE - Tried the changes here as suggested and still get the same error.

Arduino: 1.8.13 (Mac OS X), TD: 1.55, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz (overclock), Faster, US English"











/Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/arduino-builder -dump-prefs -logger=machine -hardware /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware -hardware /Users/alfredolivas/Library/Arduino15/packages -tools /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/tools-builder -tools /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware/tools/avr -tools /Users/alfredolivas/Library/Arduino15/packages -built-in-libraries /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/libraries -libraries /Users/alfredolivas/Desktop/Arduino/Sketchbook/libraries -fqbn=teensy:avr:teensy31:usb=serial,speed=96,opt=o2std,keys=en-us -ide-version=10813 -build-path /var/folders/5c/6t7s01sn4db00kncp3sf1wpr0000gn/T/arduino_build_411163 -warnings=none -build-cache /var/folders/5c/6t7s01sn4db00kncp3sf1wpr0000gn/T/arduino_cache_339882 -verbose /Users/alfredolivas/Desktop/Arduino/Sketchbook/TeensyGIFs_2022/TeensyGIFs_2022.ino
/Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/arduino-builder -compile -logger=machine -hardware /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware -hardware /Users/alfredolivas/Library/Arduino15/packages -tools /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/tools-builder -tools /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware/tools/avr -tools /Users/alfredolivas/Library/Arduino15/packages -built-in-libraries /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/libraries -libraries /Users/alfredolivas/Desktop/Arduino/Sketchbook/libraries -fqbn=teensy:avr:teensy31:usb=serial,speed=96,opt=o2std,keys=en-us -ide-version=10813 -build-path /var/folders/5c/6t7s01sn4db00kncp3sf1wpr0000gn/T/arduino_build_411163 -warnings=none -build-cache /var/folders/5c/6t7s01sn4db00kncp3sf1wpr0000gn/T/arduino_cache_339882 -verbose /Users/alfredolivas/Desktop/Arduino/Sketchbook/TeensyGIFs_2022/TeensyGIFs_2022.ino
Using board 'teensy31' from platform in folder: /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware/teensy/avr
Using core 'teensy3' from platform in folder: /Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware/teensy/avr
Detecting libraries used...
"/Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -mno-unaligned-access -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -fsingle-precision-constant -D__MK20DX256__ -DTEENSYDUINO=155 -DARDUINO=10813 -DARDUINO_TEENSY32 -DF_CPU=96000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-I/Users/alfredolivas/Desktop/Desktop - Alfred’s iMac - 1/Arduino/Arduino.app/Contents/Java/hardware/teens
 
Please post the full (not truncated) compilation log and your full sketch. Use gist.github.com or another text sharing service if it doesn't fit within a post

Also, MatrixHardware_T4Adapter.h and MatrixHardware_Teensy4_ShieldV4Adapter.h are meant for use with a Teensy 4 (with an adapter to connect to a SmartLED Shield for Teensy 3). You're compiling for a Teensy 3. Something's wrong there.
 
Back
Top