Run-length encoding

From WikiTech, the free technology encyclopedia

Simple lossless compression of repeated data

4 sources from MIT OpenCourseWare, Princeton University, Microsoft and 1 more. Checked by ByteExplained editors on 5 December 2026. How we check facts

Run-length encoding (RLE) is a simple form of lossless data compression that replaces a long run of the same symbol with the symbol and the number of times it repeats.[1] For example, the sequence "a B B B B B a a a" can be written as "a 1 B 5 a 3".[1] Because nothing is thrown away, the original data can be recovered exactly.[1]

Contents
  1. How it works
  2. Applications
  3. See also
  4. References

How it works

RLE exploits one kind of redundancy: long runs of repeated values.[2] When the data has only two possible values, as in a string of bits, the symbol need not be stored at all; the encoder simply records the lengths of alternating runs of 0s and 1s.[2] Practical schemes use counts of a fixed size, often 8 bits, and must deal with runs longer than the largest count, for example by inserting a run of length zero.[2] The method gives good results for drawings and black-and-white scanned pages, but little or no saving for data without repeated symbols, such as photographs, where shading changes from pixel to pixel.[1]

Applications

Fax machines were a natural fit: long stretches of white or black pixels on a page are sent as counts rather than pixel by pixel.[1] The Group 3 fax standard combines run lengths with Huffman coding, assigning a code word to each run of all-white or all-black pixels.[4] Run-length coding is also listed among the techniques used in JPEG.[2]

In Microsoft Windows, bitmaps can be stored with RLE using the BI_RLE8 and BI_RLE4 formats, for 8 and 4 bits per pixel. In "encoded mode" a pair of bytes gives a pixel count and a colour index, while an "absolute mode" stores runs of differing pixels directly.[3] The TIFF 6.0 image format, published by Aldus in 1992, adopted Apple's PackBits scheme from the Macintosh as its simple byte-oriented run-length option, noting that in the worst case it adds at most one byte for every 128 input bytes.[4]

See also

References

  1. ^ Information and Entropy, Chapter 3: Compression. MIT OpenCourseWare. 2008. ocw.mit.edu
  2. ^ Data Compression (COS 226 lecture). Princeton University. 2019. cs.princeton.edu
  3. ^ Bitmap Compression. Microsoft. learn.microsoft.com
  4. ^ TIFF Revision 6.0. Aldus Corporation (hosted by ITU). 1992-06-03. itu.int
Technologies on WikiTech
Data compression
Algorithms
All technologies