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

How to limit Height ou reduce memory usage on ESP32? #8

Closed
FrenchLab47 opened this issue Aug 19, 2020 · 6 comments
Closed

How to limit Height ou reduce memory usage on ESP32? #8

FrenchLab47 opened this issue Aug 19, 2020 · 6 comments

Comments

@FrenchLab47
Copy link

Hello,

Your library displays GIFs perfectly on a double RGB Led matrix (128 x 32) controlled by an ESP32
But as I load a large code and many libraries (server, clock, audio spectrum, etc.), my memory space is very limited.

My problem :
With #define MAX_WIDTH 320, I cannot compile my code (overflowed by XXXX bytes)
With #define MAX_WIDTH 128 instead of 320, it's better, but a few bytes of memory are still missing to compile.

If I halve #define MAX_WIDTH 64, the code compiles fine and the images display fine. Even the 128px wide one (I understand that it doesn't cut out the images).

As I read your comment: Designed to decode images up to 480x320
I would like to know how to adjust these two values WIDTH an HEIGHT (480x320) to the actual size of my matrix (128x32 or 128x64)?
Or limit the memory for these values?

Thank you so much.

@bitbank2
Copy link
Owner

The height doesn't affect the amount of memory used since each line is emitted one at a time. If you're running out of memory on the ESP32, then re-use the GIF structure for other purposes. It needs about 22.5K of RAM, but only while decoding. You can use that memory for something else when not using the GIF decoder. Another way of describing this is a "memory pool". For example:

static uint8_t my_memory_pool[24000];

AnimatedGIF *pGIF = static_cast<AnimatedGIF *>(my_memory_pool);

Then use the memory for something else that doesn't need to run at the same time as the GIF decoder.

Hope this helps.
L.B.

@FrenchLab47
Copy link
Author

This is a very good idea, I will try this.
Thanks for your help.

@marcmerlin
Copy link

@bitbank2
Copy link
Owner

Instead of changing the library code, why not allocate the whole GIF structure with malloc? That's why I wrote it the way I did. You can define it as a static or allocate the whole structure in one shot.

@marcmerlin
Copy link

marcmerlin commented Nov 29, 2020

note that those patches are to an old version of the library. With the current one, using one malloc makes sense.
however, because memory is fragmented on ESP32, it's better to malloc each structure you need than malloc a big contiguous pool (which might not exist as one contiguous block).
In case you're curious, I maintain an old fork along with SmartMatrix and memory is tight on ESP32 when you reach resolutions of 128x64
http://marc.merlins.org/perso/arduino/post_2018-07-13_AnimatedGIFs-for-SmartMatrix-or-NeoMatrix-_Neopixel-WS2812B_-from-SDcard-or-SPIFFS_-on-Teensy-3_x_-ESP8266_-or-ESP32.html

I am now running the same (old) gif decoding library code on rPi to decode just about any resolution since rPi has so much RAM (and can drive bigger rgbpanels). It's super cool that this library was written in a way (with callbacks) that porting it to ESP32 SPIFFS/FatFS, and then straight linux (rPI) was very little work. Here's the result:
https://youtu.be/bQc7sh-a6hQ?t=163

Ideally in my "copious spare time", I should sync up my old fork against this one, but given that the old one is working fine for me, it's not been pressing on my list of priorities ;)
https://github.com/marcmerlin/AnimatedGIFs
most of my relevant code is here
https://github.com/marcmerlin/AnimatedGIFs/blob/master/GifAnim_Impl.h

That said, I see that this lib has changed "a lot" since the fork I made, so it'll likely be a new port as opposed to a resync

@tsctrl tsctrl mentioned this issue Jun 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants