LZW (short for Lempel-Ziv-Welch) is a lossless compression technique that is an optional part of the GIF and TIFF image file formats.
The Lempel-Ziv algorithm looks for repeated pixel combinations and builds a lookup table (on-the-fly) of compression codes to represent the combinations. The codes are Huffman-encoded for further compression efficiency.
LZW compression is commonly used for 1- through 8-bit palette color images and less often for 24-bit RGB images. Typically an LZW-compressed palette color image is 60 to 80% of the original size. But for some images LZW can create a larger file than the original uncompressed image requires. Compression efficiency varies based on image complexity.
Table 1. Comparison of Compression Efficiencies for a 24-bit Image Compression Image bits/pixel File Format Size (kb) (% of original) none 24 TIFF 223,646 100 LZW 24 TIFF 243,829 109 run length 24 TGA 224,055 101 JPEG quality=75 24 JPEG 14,572 7 JPEG quality=50 24 JPEG 9,413 4Notice that for the 24-bit image LZW (or run length encoding) is not really compressing but actually increasing the space requirements. This demonstrates why LZW compression is seldom used for 24-bit images. (Be sure to see the JPEG Application Note.)
Using color reduction (with optimized palette and diffusion scatter) the original image is converted to 8 bits per pixel. Color reduction cuts the image size by 2/3. Now examine the resulting file sizes when the image is saved in 8-bit formats.
Table 2. Comparison of Compression Efficiencies for an 8-bit Image Compression Image bits/pixel File Format Size (kb) (% of original) none 8 TIFF 77,810 100 run length 8 PCX 79,028 102 LZW 8 GIF 59,582 77Table 2 shows typical LZW compression efficiency for palette color images. Now take a look at the 8-bit LZW image. You can compare the quality and speed of transmission to that of the 24-bit JPEG.
The Victor Library includes complete support for LZW compression and decompression within the GIF and TIFF-LZW image file formats. LZW functionality is fully enabled.
The Unisys US patent on lzw compression/decompression expired June 20, 2003. The European and Canadian patents expired July 7, 2004.
The Victor Library includes complete support for optional LZW compression and decompression within the GIF and TIFF image file formats.
The GIF and TIFF file load and save functions all perform normally for non-LZW compressed images, that is, no unlocking is necessary.
int load_a_gif(char *fname, imgdes *image)
{
GifData gdat;
int rcode;
// Get info on the GIF file we're to load
gifinfo(fname, &gdat);
// Allocate space for the image based on the data in the GIF file
allocimage(image, gdat.width, gdat.length, gdat.vbitcount);
rcode = loadgif(fname, image);
return(rcode);
}
As soon as the image is loaded it is eligible for use with any of the
Victor functions for processing, printing, saving, or display. See the
list of Victor functions.
int save_a_gif(char *fname, imgdes *image)
{
int rcode;
int savemode = GIFTRANSPARENT | GIFNOCOMP; // Transparent, no compression
int transcolor = 43;
rcode = savegifex(fname, image, savemode, transcolor);
return(rcode);
}