[SDL] RLE Compression

Donny Viszneki donny.viszneki at gmail.com
Fri Apr 10 10:05:32 PDT 2009

On Fri, Apr 10, 2009 at 4:57 AM, Rudolf Janz <rudolf.janz at gmx.net> wrote:
> I have implemented RLE compression for per-pixel alpha surfaces (could be adapted for color key as well). The new implementation compresses horizontal lines of the same color (translucent and opaque). It does this using signed run length (negative means repeat next color). The current RLE acceleration only removes transparent pixels and groups opaque/translucent pixels for faster blitting.


> Additionally this implementation uses a two pass RLE conversion. First the size of the resulting RLE compressed data is computed (by running the same algorithm on a dummy buffer).
> THen the surface is actually compressed into a memory block of the right size. The RLE implementation in the current SDL allocates a worst case buffer (which in most cases is much too large) and reallocs that at the end, after the size is known. At least on Windows CE with the limited Virtual Memory (max. 32 MB, around 24 M usable) that leads to serious memory fragmentation.

That's a shame. shrinking the most recently allocated chunk of memory
should not cause memory fragmentation!

> On a normal PC memory is normally not much of a problem. But on a memory limited device like the NDS this might be useful.

A good libc allocator should not have a hard time with either approach.


More information about the SDL mailing list