This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
sci4me's profile picture

RLE Encoding: rle.lua

Started by sci4me, 21 March 2016 - 08:12 PM
sci4me #1
Posted 21 March 2016 - 09:12 PM
rle.lua is a simple RLE encoding and decoding library I wrote. It's basically a DIY compression and decompression library I wrote. It's very simple and naive so it likely doesn't even compare to the standard compression algorithms that are out there.

To load rle.lua:

local rle = dofile("rle.lua")

To compress some data:

local encoded = rle.compress(myData)

and to decompress some compressed data:

local decoded = rle.decompress(myEncodedData)

Both the compress and decompress functions expect arrays of bytes. I haven't really added any error checking to the library so if you give it invalid data, it will probably blow up.

The code and documentation as well as a detailed explanation of how it works is available on the github repository (https://github.com/SciOS-CC/rle.lua).

The project is fully open source and licensed under MIT.

Let me know what ya'll think! Thanks!
Edited on 24 March 2016 - 05:56 PM
CrazedProgrammer #2
Posted 22 March 2016 - 10:21 AM
rle.lua is a simple RLE encoding and decoding library I wrote. It's basically a DIY compression and decompression library I wrote. It's very simple and naive so it likely doesn't even compare to the standard compression algorithms that are out there.

To load rle.lua:

local rle = dofile("rle.lua")

To compress some data:

local encoded = rle.compress(myData)

and to decompress some compressed data:

local decoded = rle.decompress(myEncodedData)

Both the compress and decompress functions expect arrays of bytes. I haven't really added any error checking to the library so if you give it invalid data, it will probably blow up.

The code and documentation as well as a detailed explanation of how it works is available on the github repository (https://github.com/sci4me/rle.lua).

The project is fully open source and licensed under MIT.

Let me know what ya'll think! Thanks!
Very cool!
I think the best use for it would be in an image format, where there are many repeating pixels.
For any other format, I'd use LZW :P/>
Bomb Bloke #3
Posted 22 March 2016 - 11:32 AM
If you're interested, you might consider looking into a Burrows-Wheeler transform as a next step - the technique allows you re-arrange a byte stream into something more suitable for RLE compression, which can then be reverted later down the track. Clever stuff, but still fairly simple to implement.
H4X0RZ #4
Posted 23 March 2016 - 09:41 AM
Here is a simple BWT implementaion I wrote some time ago. http://pastebin.com/u6dXUFrV it's only downside is that you need a character which isn't in the string you want to compress.