Previous Table of Contents Next


To create an image file, users usually first create direct color (24-, 16-, or 15-bit color) image data either using a graphics program, a scanner, or both. When the image is suitable for saving, users can usually select the file format type as a menu option during the save operation. The content usually favors one format or the other but here are some guidelines.

JPEG

JPEG exploits the fact that human vision is more sensitive to slow intensity and color transitions than to rapid changes over short distances. Consequently, JPEG does not work well on lettering, line drawings, or art containing sharp edges or flat colors. Rather, JPEG best compresses photographs, natural artwork, and images of otherwise natural scenes.

JPEG compression first divides images into 8x8 pixel groups and compresses each group individually, independent of the others, by decomposing the R, G, and B spatial image data into waves of different frequencies—think of different size egg cartons. Depending on the compression amount (quality setting) higher frequency information is then selectively discarded—much like sanding rough wood. Most importantly, when decompressed, JPEG images always produce slightly degraded 24-bit images.

GIF

There are two popular GIF file versions:

GIF only supports indexed color images, and users can usually specify less than 8 bits per pixel. This naturally helps reduce file size but limits images to 2 (bilevel), 4, 8, 16, 32, 64, 128, or 256 colors maximum. Table 10-2 summarizes how this affected one image (sizes rounded to nearest 100 bytes).

Bit Depth Number of Colors Dithered File Size Nondithered File Size
8 256 9,500 9,500
7 128 8,000 7,600
6 64 6,100 5,500
5 32 4,400 3,800
4 16 3,900 1,900

Table 10-2: Effect of dithering on file size

After specifying the number of colors allowed in an image, selecting the correct colors is the second step. With leading image processing applications such as Adobe’s PhotoShop or JASC’s PaintShop Pro (a.k.a. PSP) shareware, users can specify a predefined palette or have the image program determine the best colors on an image by image basis. This uses a color selection algorithm that produces image palettes called custom or adaptive palettes.

Regardless, the resulting palette is eventually saved in the image file along with the compressed image data in order to recover the image information later. The program then uses the palette to determine the best color representation for each pixel and optionally aerosols any error to nearby pixels that have not yet been indexed. This optional error diffusion process, also called dithering, often tricks the human visual system into believing there are more colors in an image than there actually are. However, these fuller-gamut images often have a grainy or otherwise pointillist appearance some folks consider undesirable.

After converting image data to index image data, LZW compresses the indexed image row by row, byte by byte, by remembering the previously encountered input data and incrementally extending its memory (that old stuff plus this new byte). This row-oriented behavior best compresses horizontal patterns. In addition to saving scan lines consecutively from top to bottom, GIF file images can be saved as interlaced (every eighth row, then every fourth row, etc.) This allows WWW browsers to display an interlaced image as a blocky, low-resolution image which gradually resolves, called a progressive display, often at the expense of a 10 percent additional file size increase. Because LZW compression is tricky, getting the smallest possible file size is difficult. The most impressive GIF wizard allows users to vary the number of allowed colors and applies several different algorithms to minimize file size. Table 10-3 summarizes the file formats.

Format Typical Compression Ratio Description
GIF 4:1 - 10:1 Lossless only when images have 256 or fewer colors. Best for images with flat color and sharp edges. Horizontal patterns compress better than vertical patterns.
PNG 10 to 30 percent smaller than GIFs Similar to GIFs only often better. Best with flat color art and sharp edges. Compresses horizontally and vertically but solid color blocks often compress best.
JFIF (JPEG) 10:1 - 20:1 (High quality) Has little or no image quality loss with continuous tone images. Bilevel images and flat color art with sharp edges degrade. Degradation loss can be cumulative with subsequent image edits.
  30:1 - 50:1 (Moderate quality) Often the best WWW choice.
  60:1 - 100:1 (Poorest quality) Usually suitable only for previews and thumbnails.

Table 10-3: Summary of file formats


Previous Table of Contents Next