PackBits
From Wikipedia, the free encyclopedia
PackBits is a fast, simple compression scheme for run-length encoding of data.
Apple introduced the PackBits format with the release of MacPaint on the Macintosh computer. This compression scheme is one of the types of compression that can be used in TIFF-files.
A PackBits data stream consists of packets of one byte of header followed by data. The header is a signed byte; the data can be signed, unsigned, or packed (such as MacPaint pixels).
In the following table, let n be the value of the header byte as a signed integer.
Header byte | Data following the header byte |
0 to 127 | (1 + n) literal bytes of data |
0 to -127 | One byte of data, repeated (1 – n) times in the decompressed output |
Note that interpreting 0 as positive or negative makes no difference in the output. Runs of two bytes adjacent to non-runs are typically written as literal data. It should also be noted that there is no way based on the PackBits data to determine the end of the data stream; that is to say, one must already know the size of the uncompressed data before reading a PackBits data stream to know where it ends.