r/ArduinoProjects • u/thork_the_stork • Dec 25 '23
Compressing Bitmaps
Hi everyone!
First time here so I'm not sure how exactly to use this subreddit.
I've been programming on a Nano, soldered onto my PCB for a project. I have a loading screen animation for the project, but the bitmaps for the OLED screen take up the majority of the Arduino's space. They are set in the PROGMEM, but this added with the main code is 117% of its memory. Is there any way I can compress the bitmaps down and use those? I've heard the term RLE thrown around in forums but I have no clue how to use it, so there has to be another way.
Any help would be greatly appreciated. Have a great day!
0
Upvotes
1
u/totorodad Dec 25 '23
If you’re willing to learn some on programming then Run Length Encoding isn’t hard. Prescan your images/frames for runs of a single color and encode that. An example storage data type might be: (Color, length). Where color is a char and length is 1 or 2 bytes.
So if you’re storing every raw color of your frames then you can then you can use RLE to scan ahead of time (compress) your frames and store the frames as data which represents whole single color swathes.
So frames that are mostly one color for instance are candidates for RLE compression. Frames that “cost” more to encode as RLE you should have a header which tells your run time decompressor to interpret the frame as is and that the data is “raw”. This isn’t always a win.
There is also a way in Arduino to put your data in non-volatile flash memory. Google F(). Which means the data for your images/frames are stored in memory not used by your program in SRAM.
Depending on your Arduino you may also look at pulling data for your frames from a larger storage media like an sd card or nvram.