A Complete Guide to Web Design

(やまだぃちぅ) #1
266 Chapter 14 – GIF Format

Eight-Bit Indexed Color


Web Design in a Nutshell, eMatter Edition

Eight-Bit Indexed Color


GIF files are indexed color images that can contain a maximum of 8-bit color
information (they can also be saved at lower bit rates). This means they can
contain up to 256 colors—the maximum number that 8 bits of information can
define (2^8 = 256). Lower bit-depths result in fewer colors and may also reduce file
size. This is discussed in “Minimizing GIF File Sizes” at the end of this chapter.
“Indexed color” means that the set of colors in the image, itspalette, is stored in a
color table. Each pixel in the image contains a reference (or “index”) to a table cell
containing the color for that pixel. In Photoshop, you can view the table for an
indexed color image by selecting ImageÝ ModeÝ Color Table.
When you convert a 24-bit (millions of colors) image to GIF, it is necessary to first
convert the image to Indexed Color mode, and as part of that process, reduce the
number of colors to a palette of 256 or fewer colors. The image editing tool does
its best to approximate the full color range by using the most appropriate colors to
approximate the image (an “adaptive“ palette). You can specify an alternate set of
colors to use in this process, such as the Web Palette.

GIF Compression


There are two main things to know about GIF compression. First, it is a “lossless”
compression, meaning no image information is lost in the compression process,
and the decompressed image will be identical to the original. (Note that some
information may be lost in the conversion process from RGB to GIF format, but
once it is converted, the compression itself is lossless.)
Second, GIF uses LZW (Lempel-Zev-Welch) compression, which takes advantage
of repetition in data streams. Translated into graphic terms, this means that LZW
compression is extremely efficient at condensing rows of pixels of identical color.
To use a simplified example, when the compression scheme hits a row of 15 iden-
tical blue pixels, it can store the information as “15 blue,” but when it encounters a
row that has a gentle gradation from blue to black, it needs to store a description
for every pixel along the way, therefore requiring more data. This is why GIFs are
efficient at storing simple graphical images; the areas of flat color take advantage
of the LZW compression.
On a historical note, Unisys, the company that holds the patent on LZW compres-
sion, caused quite a stir on the Internet in 1994 when they announced that it
would begin charging licensing fees to developers incorporating GIF compression
into their products. In the face of fees and legal hassles, the Internet population
rushed to find nonproprietary alternatives to the GIF format, leading to the devel-
opment of PNG (see Chapter 16,PNG Format). Unisys does enforce its patent and
charges software companies fees for including GIF support, but GIF shows no sign
of disappearing any time soon.

When to Use GIFs


GIF is a versatile format for condensing color images for use on the Web. It is
particularly well-suited for any image with areas of flat color, such as logos, line
Free download pdf