TIFF 6.0 Specification
Final—June 3, 1992
The function StringFromCode() gets the string associated with a particular code
from the string table.
The function AddStringToTable() adds a string to the string table. The “+” sign
joining the two parts of the argument to AddStringToTable indicates string con-
catenation.
StringFromCode() looks up the string associated with a given code.
WriteString() adds a string to the output stream.
When SamplesPerPixel Is Greater Than 1
So far, we have described the compression scheme as if SamplesPerPixel were
always 1, as is the case with palette-color and grayscale images. But what do we
do with RGB image data?
Tests on our sample images indicate that the LZW compression ratio is nearly
identical whether PlanarConfiguration=1 or PlanarConfiguration=2, for RGB
images. So, use whichever configuration you prefer and simply compress the
bytes in the strip.
Note: Compression ratios on our test RGB images were disappointingly low:
between 1.1 to 1 and 1.5 to 1, depending on the image. Vendors are urged to do
what they can to remove as much noise as possible from their images. Preliminary
tests indicate that significantly better compression ratios are possible with less-
noisy images. Even something as simple as zeroing-out one or two least-signifi-
cant bitplanes can be effective, producing little or no perceptible image
degradation.
Implementation
The exact structure of the string table and the method used to determine if a string
is already in the table are probably the most significant design decisions in the
implementation of a LZW compressor and decompressor. Hashing has been sug-
gested as a useful technique for the compressor. We have chosen a tree-based
approach, with good results. The decompressor is more straightforward and faster
because no search is involved—strings can be accessed directly by code value.
LZW Extensions
Some images compress better using LZW coding if they are first subjected to a
process wherein each pixel value is replaced by the difference between the pixel
and the preceding pixel. See the following Section.
62