To compress an image, each pixel is considered. The color of each pixel, represented
as an index into a color palette, is compared with the color of the pixel's upper
and left neighbors and encoded to an entry in the color palette. A probability
distribution is updated based on the colors of the pixel and its left and upper
neighbors. Once all pixels are encoded, the color palette is optimized using the
probability distribution, and the indices into the color palette for the pixels
are compressed. In the preferred embodiment, the compression is achieved using
a single pass over the pixels in the image, and the probability distribution is
updated dynamically as each pixel is compressed.