Home

PackBits

PackBits is a simple, lossless run-length encoding scheme used for compressing 8-bit data streams, notably in image formats such as TIFF and various Apple-era formats. It encodes data as a sequence of a single control byte followed by either literal data or a replicated byte, depending on the control value.

The encoding rules are defined by a signed interpretation of the control byte. If the control byte

PackBits is designed for simplicity and speed rather than maximum compression. It performs well on data with

Historically, PackBits has been associated with Apple and Macintosh software and became one of the standard

is
in
the
range
0
to
127,
the
next
control
value
plus
one
bytes
are
copied
literally
to
the
output.
If
the
control
byte
is
in
the
range
129
to
255,
the
next
byte
is
repeated
(257
minus
the
control
value)
times
in
the
output.
A
control
byte
of
128
is
a
no-op
and
produces
no
output.
Therefore,
literal
runs
can
be
1
to
128
bytes
long,
while
repeated
runs
are
2
to
128
bytes.
long
runs
of
identical
bytes
but
less
so
on
highly
varied
data,
where
overhead
from
control
bytes
can
reduce
efficiency.
The
algorithm
is
lossless
and
preserves
all
original
data
when
decoded
correctly.
compression
options
in
TIFF
6.0.
It
remains
a
widely
supported
but
not
universally
preferred
method
for
certain
image
pipelines,
particularly
where
compatibility
with
older
software
is
important.
Implementations
typically
read
the
stream
until
the
container
format
signals
end-of-data,
handling
the
128
no-op
tokens
accordingly.