Ascii Map Compression
Just a simple RLE algorithm for a project in the works. Mainly just a silly project. Regardless this algorithm is used to compress ascii maps down to a smaller file size. It does this by using a run-length encoding algorithm.
TL;DR
Small Scale
Uncompressed map is 2kb
Compressed map is 758 bytes
Big(ger) Scale
Uncompressed map is 86kb
Compressed map is 42kb
So over half size saved.
There is still room for improvement, but I can't be too bothered right now
4 Replies
Here is an uncompressed map
Heres that compressed
My algorithm differs slightly from your typical RLE. It only compresses what makes sense to compress. This is because instead of just doing something like
#2
to repeat #
twice I do #(2)
. This is to try and make sure cases where there may just really be a #2
somewhere in the map from getting messed up.
The side effect is sometimes "shortening" doesn't actually make it shorter. Either it's the same length or longer.
This is where my algorithm differs. It won't replace anything that will either take more characters, or equal amount of characters
My poor code
This code is bad, as it's really meant for a test, not productionYou could compress it even more using the characters with the corresponding ASCII number and then decoding it
Like replace
33
with !
(if readability isn't an issue)
48
with 0
etcYes I did think about that, this was for more of a proof of concept so I didn't feel the need to push it that far.
For bigger numbers though I would likely have to split it into multiple characters
Each byte could represent up to 256
Because there isn't any need for length 0