Understanding image file formats

By Bryan Chamberlain

When you prepare a graphic or a document that you'll distribute to others, how much thought do you give to the file format? Do you know which file format is best for a particular application? If you send a file in the wrong format, some data loss may occur or the recipient may not be able to use the file at all.

Just a few years ago, you probably created and printed a project using only one application. Now, it's common to create an illustration in one program, add to it in another, and then print it in a third. Therefore, in order to freely exchange information between applications, you must know which file formats work in each application. This is especially true when you're working with graphic files.

Two or three years ago, a Mac user would never have heard of a PCX or BMP file, and a PC user wouldn't know a MacPaint file from a PICT file. But now that more applications are becoming cross-platform, desktop publishers need to familiarize themselves with graphic file formats that were previously platform-specific.

Keeping current on all the graphic file formats available for one platform is difficult enough-for two or more platforms, it's close to impossible. But technology marches on, and in that spirit we're presenting some of the most commonly used graphic file formats on the Mac and Windows platforms. In this article, we'll first review the basics behind image file format, and then we'll outline each of the most popular image file types.

Bit depth-in over your head?

How many colors are in the color palette of a 1-bit image? How many in an 8-bit image? Can you display a 24-bit image on an 8-bit monitor?

If these questions confuse you, you're not alone. To most designers and Sega and Nintendo players, the naming conventions of 1-, 2-, 4-, 8-, 24-, and 32-bit graphics are loosely understood-more means better. However, as Table A shows, the naming convention is easily understood and based on simple math.

Table A

Bit Depth	Math Equation	Colors Available
1-bit 		21		black and white
4-bit 		24		16 colors
8-bit		28		256 colors 
16-bit		216		thousands of colors
24-bit 		224		millions of colors

The bit depth of an image makes up the color value assigned to each pixel in the image. For instance, a 1-bit image assigns each pixel a black or white value, a 4-bit image assigns each pixel one of 16 color values, and so on. The only exception is that a 32-bit image is usually a 24-bit image with additional information encoded in the remaining 8 bits-an alpha channel, for example.

As for the answers to our introductory questions: There are two colors (black and white) in a 1-bit image and 256 colors in an 8-bit image; a 24-bit image, though dithered, will appear on an 8-bit monitor display.

Compression

Currently, there are two forms of compression schemes used to shrink the large size of graphic files-Loss Less and Lossy.

Loss Less compression is the most common compression scheme used today, and although there are several varieties of it, all Loss Less compression works in the same way. While an uncompressed image encodes the value of each pixel in an image, Loss Less compression looks for areas containing pixels of the same value and encodes the area. This allows for a moderate compression rate while still ensuring that a decompressed file will look identical to the original file.

Lossy compression, a relatively new compression scheme that's currently used only in the JPEG file format, actually loses information when saving and compressing a file. This means Lossy compression achieves compression rates ten or more times greater than that of Loss Less compression.

Furthermore, even though the compression scheme loses information, there's little or no degradation of the uncompressed image when it's retrieved. How can this be? It works on the principle that graphic images can represent many more colors than the human eye can perceive or printers can print-simply put, the information lost through compression is beyond the range of human vision. Lossy compression works well for high-quality, 24-bit or higher photographic images, but it's not intended for computer-created graphic files, where any image information loss can corrupt the file.

Vector and raster formats

When you work with several file formats, you need to be aware of the two types of graphic files-vector and raster-and how they work with each other. Vector graphics describe shapes mathematically, whereas bitmap (raster) files describe shapes as a pattern of dots or pixels. (This explanation is correct for raster files; however, technically speaking, the term bitmap actually describes a bilevel, black-and-white raster graphic. While bitmap is the commonly used term for both raster and bitmap files, to be technically accurate, we'll use raster instead.)

Vector files rely on a language (for example, PostScript) to describe how to draw a graphic. It's very simple to convert vector graphics into raster graphics-simply process the vector information as if you were going to print and save the output as a raster graphic. As a result, vector files aren't tied to a particular resolution-you can generate raster images of any size from vector files.

Unfortunately, converting a raster graphic into a vector graphic isn't as easy. To do so, the computer has to interpret the patterns of pixels in the raster image as shapes and then figure out how to write the directions to draw them. Some tracing programs can convert raster graphics to vector graphics, but the results are less than perfect.

To make things more confusing, you can embed a raster graphic in a vector graphic, but never vice versa. Because a vector graphic is a description of how to draw an image, you can embed a raster graphic by including the raster information in the vector graphic. Basically, you create a shape and give it a complicated fill-the raster graphic. For example, saving a Photoshop file as an EPS embeds a raster graphic inside a vector graphic.

However, you can never embed a vector graphic in a raster graphic because a raster graphic can't contain vector information. The only way you can combine a vector graphic with a raster graphic is to convert the vector image to raster information first and then consolidate the two.

Pick a format, any format

So how do you select a file format? That really depends on the application in which you intend to use the image. Let's review each of the image formats to see which works best for you. For simplicity, we've summarized all the information about the image file formats in Table B.

Table B

Some of the terms and labels we use in this table might warrant a little explaining-most of which you'll find in the accompanying article. The Mac and PC columns refer to what platform the file format exists on; Raster (bitmap) and Vector refer to the type of graphic file; 1- to 32-Bit refer to the bit depth an image is capable of holding (bit depth is usually applicable to only raster images so we don't include it for vector graphics); and Comp refers to compression and whether the file format supports it.
Format		Mac	PC	Raster	Vector	1-Bit	2-Bit	4-Bit	8-Bit	16-Bit	24-Bit	32-Bit	Comp
TIFF		X	X	X		X	X	X	X	X	X	X	Yes
PICT		X		X	X	X	X	X	X	X	X	X	No
Photoshop	X	X	X		X	X	X	X	X	X	X	No
PNG		X	X	X		X	X	X	X	X	X	X	Yes
JPEG		X	X	X							X	X	Yes
TARGA		X	X	X					X	X	X	X	Yes
PCX		X	X	X		X	X	X	X		X		No
BMP		X	X	X		X		X	X		X		No
Metafile		X		X								No
CGM			X		X								No
AutoCad DXF			X		X							No
GL/2			X		X								No
EPS		X	X		X								No

TIFF

Versatility and compatibility make the TIFF image format the optimum choice for almost any project. It works on both the Mac and PC platforms, supports almost any picture bit depth, and allows various forms of compression.

This flexibility also makes the TIFF format a Pandora's box. There are so many versions and types of compression for the TIFF file format that no current system can decode all of them. Furthermore, there's no way to tell how a TIFF will behave until you attempt to manipulate it. Try to use LZW compression or no compression at all for best results.

PICT

Almost any Mac expert can tell you that PICT is the default file format for any image displayed by a Macintosh. Unfortunately, many people misinterpret this fact to mean that PICT is the best file format to use-untrue! PICT images are useful in Macintosh software development, but you should avoid them in desktop publishing.

Avoid using PICT format in electronic publishing-PICT images are prone to corruption. Additionally, PageMaker always knocks out PICT images as color separations.

Photoshop

This is the native Photoshop file format created by Adobe. In this format, you can save multiple alpha channels and paths along with your primary image. You can't import this format directly into most desktop publishing applications.

PNG

Because of its high compression rate (unsurpassed among ``lossless'' formats -- lossy JPEG is better for photos) PNG is the standard file format that online services use for storing 1- to 8-bit images, succeeding GIF (which is a proprietary format and thus increasingly discarded).

JPEG

Because of its good image quality and compression, the JPEG file format is becoming increasingly popular in desktop publishing. (QuarkXPress has added a JPEG import filter in XPress 3.3.) Developed by the Joint Photographic Experts Group, the JPEG format is expected to become an international standard for encoding digitized photographs. JPEG's major difference from all other current file formats is that it uses Lossy compression.

Even though JPEG is relatively new, a second format already exists-JFIF is a new TIFF subformat that embeds a JPEG image into a TIFF file. The JFIF file format has yet to become popular because it's much more complex without offering more capability.

TARGA (TGA)

Most common in the video industry, this file format is also used by high-end paint and ray-tracing programs. The TGA format has many variations and supports several types of compression. This file format is used to display AT&T Truevision images and is sometimes supported by DOS applications.

PCX

PCX is a straightforward raster file originally available only on the PC. However, PCX is migrating to the Macintosh as more mainstream programs become cross-platform. Aldus PageMaker, Adobe Photoshop, and the newest version of QuarkXPress for the Macintosh now support the PCX file format.

BMP

The BMP file format is available in almost all Windows-based graphics applications, although it's primarily used in Windows application development.

Windows Metafile (WMF)

A Windows Metafile has its good and bad points. Metafiles-composed of a list of calls to the Microsoft Windows graphics drawing library-are both small and flexible, but unless the program that created them is running, they're difficult to display properly.

Computer Graphics Metafile (CGM)

Computer Graphics Metafile is a very flexible vector format that can also save raster information. Unfortunately, it's so flexible that very few applications can use all the types available.

AutoCAD DXF

AutoCAD DXF is an AutoCAD file format that has become a standard for exchanging CAD drawings. However, because the vector information is ASCII encoded, the files can become very large and thus require a lot of memory to read.

Hewlett-Packard GL/2

GL/2 is a HP plotter language that's often used as an exchange format for graphics.

Encapsulated PostScript (EPS)

The Encapsulated PostScript format is a vector file relying on the PostScript page description language to draw its image. This format can also contain raster information, even though it's not a raster format. EPS files generally contain a raster graphic as a screen preview-Mac EPS files use a PICT and PC EPS files use a TIFF graphic. EPS is the only format that supports transparent white in bitmap mode.

Conclusion

You spend a lot of time creating or altering your graphic files. When it comes time to save the image, it's important that you use the correct format. Otherwise, you'll lose image quality when you place the file in a desktop publishing document. In this article, we've reviewed the basics of image file formats and explained how to select the right one for each job.