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!
1
u/DCorboy Dec 25 '23
Are you sure they’re the correct resolution? If so, another approach you can use is (pre) converting all your data to 565 color encoding (2 bytes/pixel) saving 1/3 over 24-bit color.
RLE will be beneficial if you have a lot of contiguous color, like a black background.
1
u/thork_the_stork Dec 26 '23
The images I'm using are black and white, and its a byte per pixel.
I'm trying RLE, but i don't know where to begin...
1
u/EmielDeBil Dec 26 '23
You can also add an SD card reader or ROM chips to the arduino and control them to expand your memory.
Note that unpacking compressed data will result in more data in memory again, unless you procees it and immeduatejly get rid of it again.
The Arduino is not really made for projects that need more than :2kb. The Arduino mega doubles the RAM, and newer stuff like the esp32 are limitless in comparison to the duino. I would start here.
1
u/thork_the_stork Dec 26 '23
I wish I realised this before hand, but my PCB's already been made/soldered.
But I'll note removing data once used, thank you!
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.