Imagine transmitting a fax. Most of the page is white. A typical line might be 300 white pixels, then 20 black pixels, then 280 more white. Sending each pixel as a single bit costs 600 bits. But why not just say "300 white, 20 black, 280 white"? That takes fewer than 20 characters â a 10Ă saving for that line alone.
That idea is Run-Length Encoding (RLE): scan the input left to right, group consecutive identical symbols into runs, and replace each run with a (symbol, count) pair. The output can be far shorter whenever the data contains long flat stretches.
RLE was formalized in the early days of digital communication and is provably optimal for a specific class of source models â geometric distributions over run lengths â which is exactly what you get with bilevel (black-and-white) images. It is also the simplest possible lossless scheme: encoding and decoding are both a single linear scan, requiring no lookups, no trees and no arithmetic. The complexity of Huffman coding grows from here.
Comments
Loading comments...