TIFF 6.0 Specification
Final—June 3, 1992
you can write it as a 9-bit code after the ClearCode . Decompression gives the
same result in either case.
To make things a little simpler for the decompressor, we will require that each
strip begins with a ClearCode and ends with an EndOfInformation code. Every
LZW-compressed strip must begin on a byte boundary. It need not begin on a
word boundary. LZW compression codes are stored into bytes in high-to-low-
order fashion, i.e., FillOrder is assumed to be 1. The compressed codes are written
as bytes (not words) so that the compressed data will be identical whether it is an
‘II’ or ‘MM’ file.
Note that the LZW string table is a continuously updated history of the strings that
have been encountered in the data. Thus, it reflects the characteristics of the data,
providing a high degree of adaptability.
LZW Decoding
The procedure for decompression is a little more complicated:
while ((Code = GetNextCode()) != EoiCode) {
if (Code == ClearCode) {
InitializeTable();
Code = GetNextCode();
if (Code == EoiCode)
break;
WriteString(StringFromCode(Code));
OldCode = Code;
} /* end of ClearCode case */
else {
if (IsInTable(Code)) {
WriteString(StringFromCode(Code));
AddStringToTable(StringFromCode(OldCode
)+FirstChar(StringFromCode(Code)));
OldCode = Code;
} else {
OutString = StringFromCode(OldCode) +
FirstChar(StringFromCode(OldCode));
WriteString(OutString);
AddStringToTable(OutString);
OldCode = Code;
}
} /* end of not-ClearCode case */
} /* end of while loop */
The function GetNextCode() retrieves the next code from the LZW-coded data. It
must keep track of bit boundaries. It knows that the first code that it gets will be a
9-bit code. We add a table entry each time we get a code. So, GetNextCode() must
switch over to 10-bit codes as soon as string #510 is stored into the table.
Simi-
larly, the switch is made to 11-bit codes after #1022 and to 12-bit codes after
#2046.
61
Index Bookmark Pages Text
Previous Next
Pages: Index All Pages
This HTML file was created by VeryPDF PDF to HTML Converter product.