LZW compression.
In the upper line we represent a string of red and blue pixels
by a string of characters, R and B,
which are the root characters.
In the lower line we construct its LZW code representation.
The numbers in the code refer to places in the table,
whereas the code table is constructed depending on what is found in
the input string.
The elements of the code-table sequence are strings of root characters.
Let us denote here the i-th element by t(i).
Then 7R stands for t(7)R = 2BR = t(2)BR = BBR.
See also how decompression works.
Further Reading
- Ziv, J. and Lempel, A., A Universal Algorithm for Sequential Data
Compression, IEEE Transactions on Information Theory, (May 1977).
- Welch, T., A Technique for High-Performance Data Compression,
Computer, (June 1984).
- Nelson, M.R., LZW Data Compression, Dr. Dobb's Journal,
(October 1989).