I’m Kayla. I build little tools, small games, and odd prints for work. I like simple stuff that just works. RLE is one of those “count the repeats” tricks that feels old-school but still handy. I used it for tiny sprites, a home label printer, and even a PDF form with a lot of white space. Let me tell you what happened.
If you'd like the blow-by-blow numbers from my lab notebook, you can skim through the full experiment write-up.
A quick story: why I reached for RLE
I had a small OLED screen on an Arduino, 128×64, black and white. My icons took too much flash. I didn’t need fancy math. I just needed smaller files. RLE said, “Got a bunch of repeats? I can count them.” That’s it. No fuss.
And you know what? It worked.
What RLE feels like (the sock drawer trick)
Think of a drawer full of socks. If you see: white, white, white, white, then one black, you don’t list every sock. You say, “4 white, 1 black.” That’s RLE. It turns long runs into a simple count.
Text example:
- Input: AAAAAABBCC
- RLE form: 6A 2B 2C
Not magic. Just counting. For a deeper dive into RLE and dozens of other lightweight algorithms, the encyclopedic site DataCompression.info is a great starting point. Students and teachers might also enjoy the hands-on walkthrough provided by the CS Field Guide on run-length encoding.
Real tests I ran
1) Plain text with lots of repeats
I had a log line that looked like this (it was a sensor that didn’t change much):
WWWWWWWWWWWWWWWWWWWWBBBBWWWWWWWWWW
- Raw length: 30 chars
- RLE form: 20W 4B 6W
- RLE length if stored as count+char pairs: 6 bytes (if count and char are single bytes)
That’s a big drop. Why? Long runs.
But wait. I tried a messy line too:
WBWBWBWBWBWBWBWBWBWBWBW
- Raw length: 24
- RLE form: 1W 1B 1W 1B … (24 pairs)
- RLE length: 48 bytes if stored as (count, char)
It got bigger. Ouch. That’s the flip side.
2) Pixel art on a tiny screen
I had a 16×16 sprite, 1-bit pixels. Lots of solid rows. A typical row looked like:
- 12 white, 4 black
- Next row: 16 white
- Next: 10 white, 6 black
…and so on.
Stored raw, that’s 32 bytes per sprite (16 rows x 2 bytes). With RLE, my average sprite dropped to about 10–14 bytes. I packed a whole set of UI icons that way: battery, wifi, play, pause. It felt like finding extra pockets in a jacket I already wore.
3) A document with wide margins
I exported a monochrome page to a simple bitmap and tried RLE. It had large white margins and small black text. Raw was big. RLE shaved it down a lot, since each line started with a long streak of white. I then pushed it through a PDF with RunLengthDecode (yes, PDF has that filter), and it stayed small. Not as tiny as fancy image codecs, but it loaded fast and was easy to process on a cheap printer.
Tiny code I used (super simple)
I tested with a quick Python helper. Nothing fancy.
def rle_encode(data):
if not data:
return []
out = []
count = 1
prev = data[0]
for c in data[1:]:
if c == prev and count < 255:
count += 1
else:
out.append((count, prev))
count = 1
prev = c
out.append((count, prev))
return out
def rle_decode(pairs):
out = []
for count, val in pairs:
out.extend([val] * count)
return out
I used this for strings and raw bytes from bitmaps. It took me minutes to hook it up to my sprite packer.
Where RLE shines for me
- Long runs. Big simple blocks: empty space, flat colors, repeated values.
- Old or small hardware. I used it on an Arduino and a thermal label printer. It’s fast and light.
- Simple file formats. RLE in TIFF (PackBits), PCX, BMP (some variants), and PDFs with RunLengthDecode. Easy to parse.
Spending a whole week living inside bloated archival scans taught me a lot—here’s exactly what worked for squeezing TIFF files when RLE alone wasn’t enough.
Bonus: it’s easy to debug. You can read the pairs and “see” the picture in your head.
Where it flops
- Noisy data. Photos, grain, or text with mixed pixels. It can even get bigger.
- Many color changes. Pixel art with lots of dithering? Meh.
- Already compressed data. Don’t stack RLE on PNG or ZIP. It won’t help.
For truly aggressive targets—like trying to squash photographs down to just 15 KB—this field report shows the hoops you have to jump through.
I made this mistake with a sprite that had a checkerboard shadow. It looked cool. It compressed badly. I tweaked the art to use bigger flat areas. Then it flew.
Little tricks I learned
- Cap the count at 255 if you store counts in a byte. Simple, safe.
- Group by rows. For images, reset runs at each row so you can seek fast.
- Add a tiny header. I store width, height, and 1 bit for color depth so I don’t forget later.
- For black-and-white sprites, pack 8 pixels per byte before RLE. That combo saves a lot.
My verdict: old-school, but still handy
I still use it for:
- Monochrome icons and HUDs
- Printer jobs with long white gaps
- Simple logs that repeat the same flag
Would I use it for photos? No. For photos, I pick PNG or JPEG.
Speaking of sharing, sometimes the challenge isn’t slimming down a bitmap but finding someone to swap those finished creations with; if your project breaks involve looking to meet new, open-minded adults nearby, you can hop over to FuckLocal’s Adult Finder for a fast, location-based matchmaking tool that gets you chatting and trading ideas (and maybe compressed images) in minutes. If you’re coding from south Orange County and want a more tailored late-night meet-up, their sister directory for Rancho Santa Margarita escorts lists verified companions, rates, and contact options, letting you line up post-hack-session relaxation without endless scrolling.
But if your only assignment is to drag a regular vacation snap under a 4 MB upload limit, you might dig into this real-world 4 MB compression walk-through.
But for clean, blocky stuff, RLE is my little pocket knife. Not fancy. Very useful. And yeah, it saved my project more than once.