20.1 An Overview of File Formats

An image on a computer screen is comprised of a matrix of pixels. This holds true on all current displays: cathode-ray tube, plasma, liquid crystals, and others. This is also true for laser and inkjet printers. Even the eye breaks down images into an array of rods and cones, as described in Appendix A.

The file format is how a file is stored in memory and is independent of how an image was captured and how it will eventually be viewed. So the representation of an image as a file, whether stored on disk or downloaded online, is not necessarily a representation of the final matrix of pixels. And because pixel density varies widely among mobile phone displays, computer monitors, cheap inkjet printers, and professional laser printers, any representation needs to be converted from the internal representation to the external one. Images that you produce must also be converted—be it from a phone’s camera, a scanner, or a professional digital camera.

Raster and Vector Formats

Image formats can be divided into two main families: raster and vector.

  • In the raster formats, an image is stored as a representation of the pixels it contains. A bitmap image, which can represent black and white only (no gray levels), contains 1 bit per pixel, whereas a pixmap image, which can represent gray levels and colors, contains several bits per pixel.

  • In the vector formats, an image is stored as a geometric description of its contents.

Each format has its advantages and drawbacks. An image file in vector format is generally much smaller than a file in raster format, and a vector image will be displayed at any size with the same sharpness because the pixels are computed each time the zoom factor changes. Figure 20-1 shows a 48 × 48 icon generated as a vector graphic image. The file is 63KB in the SVG format (which is a textual format in the XML convention). It is 1.3KB in JPEG because the image is very small.

An icon

Figure 20-1. An icon

The icon enlarged as a vector image

Figure 20-2. The icon enlarged as a vector image

The icon enlarged as a raster image

Figure 20-3. The icon enlarged as a raster image

Figure 20-2 shows the same icon enlarged to 480 × 480 as a vector graphic image at 300 dpi. The SVG file is the same size as before, but the JPEG file is now 30KB. Figure 20-3 shows the same icon enlarged as a raster graphic image. The JPEG file is 19KB, but the image is badly pixelated.

A typical vector graphic image

Figure 20-4. A typical vector graphic image

Although vector graphics clearly have advantages, their main drawback is they cannot represent complicated images like photographs accurately. For example, describing the relief and shading of a human face with mathematical formulas is not feasible. Figure 20-4 is a typical example of a portrait done in vector graphics. Although tools are available for converting an image from a raster format to a vector image, the results tend to be poor.

GIMP works on the raster representation of images, so it works well for photographs and illustrations. A pixmap cannot be zoomed in indefinitely, however, so when working with a raster image, work with as large a definition as possible. You can always reduce the size before sending the file to somebody or posting it online.

Lossless and Lossy Compression

Raster images are generally large, and they keep getting larger as digital cameras improve. The data size of a single pixel also increases when the number of colors that can be represented increases. And the number of pixels increases with the size and resolution of the image. A digital camera can now create images as large as 10 (or even 12) million pixels, which generally means at least 30MB if the number of colors in each channel is 256.

A 30MB file is rather large, even for current hard disks, especially if you store a lot of photos. This file size is also large for most memory cards and would be difficult to send via email or to post online. One solution is to compress the file to decrease its size. A number of algorithms are available for compressing files, especially image files. These algorithms can be either lossless or lossy.

A photo of a rose with decreasing image quality

Figure 20-5. A photo of a rose with decreasing image quality

  • A lossless compression algorithm rebuilds the original data without losing any information. The image quality remains stable, but sometimes the original image is transformed in a lossy way. If the image isn’t transformed first, then applying lossless compression won’t reduce the file size by very much.

  • A lossy compression algorithm results in some loss of information, but the differences may be invisible to the human eye. Generally, lossy compression reduces the file size considerably, but you cannot rebuild the original image exactly as it was, and if you apply lossy compression more than once, the deterioration is cumulative. Eventually, you can see the difference.

If you want maximum image quality and don’t care about size, use only lossless compression. If you can accept some loss in image quality in exchange for significant size reduction, choose a lossy algorithm.

Sizes and quality factors of the images shown in

Figure 20-6. Sizes and quality factors of the images shown in Figure 20-5

The initial photo of the rose (left); the same image after saving and reloading several times (right)

Figure 20-7. The initial photo of the rose (left); the same image after saving and reloading several times (right)

Figure 20-5 shows the same image nine times.

Each time the image’s quality factor and size decrease, as shown in Figure 20-6.

You cannot see any obvious loss of quality down to factor 60. When the factor is 10 or less, however, the loss is very apparent.

Another problem with lossy compression is that defects accumulate if you save the image several times. Figure 20-7 (left) shows an enlarged section of the rose photo, and Figure 20-7 (right) shows the same photo after we saved and reloaded it several times with a low quality factor (less than 60). The compression artifacts are clearly visible on the edge of the middle petal.

Layout Engines and Browsers

These days many people view images through browsers like Firefox or Internet Explorer. Unfortunately, not all image formats are supported by all browsers. In fact, the three common formats discussed in the next section are the only ones that are displayed by all existing browsers, and sometimes even those formats don’t work perfectly.

Many different browsers exist, and some browsers vary depending on your operating system. Browsers use layout engines to display images on the screen. Fewer than 10 layout engines are available, and only a handful are widely used. Different browsers using the same layout engine handle images in the same way. The following table lists popular layout engines and the browsers that use them:

Layout Engine

Browsers

Gecko

all Mozilla software: Firefox, Galeon, Seamonkey, etc.

KHTML

Konqueror

Presto

Opera

Trident

Internet Explorer 4 to 9

Webkit

Safari, Epiphany, Google Chrome

Because many people still use Internet Explorer, many people use Trident. No layout engine is perfect, but unfortunately Trident is one of the worst. Its main problem, with regard to image display, is that it does not handle PNG format very well. Other free software browsers handle PNG images much better.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset