Previous Table of Contents Next


PCX Image Compression and Decompression

The PCX file format uses a simple lossless compression scheme. To decompress PCX scan-line data, first read a single byte. If the two high-order bits are both set to binary one values, then the low-order six bits indicate a replication count for the next byte which ranges from 1 to 63. Otherwise, the value is a pixel value. A replication value of 0x0A indicates the next byte should be repeated ten times—hence the name run length encoding. The DecodePcxScanLine() present in many of this book’s programs demonstrates how to decode entire image scan lines for palette or direct color images. For direct color images, the color plane scan lines are individually compressed in the following order:

Scan Line 0: RRRRRRR... (Red color component)
GGGGGG... (Green color component)
BBBBBBB... (Blue color component)
Scan Line 1: RRRRRRR... (Red color component)
GGGGGG... (Green color component)
BBBBBBB... (Blue color component)

etc.

In summary, the PCX file format is a simple file format that illustrates many of the principles involved in recovering images from their compressed form within files. While it is becoming less popular, to its credit it provides a lossless compression scheme which does not require a license. Thank you, ZSoft.

Image File Size and Transmission Bandwidth

When scanning a photo to create an image file for local or LAN-connected system viewing, transmission bandwidth is often not an issue. So, it’s tempting, and not unrealistic, to scan photos in millions of colors (24 bits per pixel) or thousands of colors (15 or 16 bits per pixel) at high scanning rates such as 300 dots per inch (dpi). This approach visually produces continuous-tone, photographic-quality images on monitors. Such high detail and color quality scanning also produces large images— 1 MByte images are not unusual. A 10 MBytes/sec SCSI channel would transport this image in about a tenth of a second and a Pentium processor would move the image into video memory in a heartbeat, using a 132 MBytes/sec PCI system bus.

However, downloading such an image from the World Wide Web using a cocktail-straw 28.8 KBits/sec modem significantly shifts the landscape, usually resulting in frantic quality versus size tradeoffs to drastically reduce download time. Moreover, consider that typical home modems only provide users less than 80 percent data throughput at any transmission speed because they add a start and stop bit to each eight data bits. TCP/IP protocol adds even more overhead and delay. Recall that transmission weight is what counts with international postal correspondence, resulting in tissue paper envelopes that double as stationery on the inside. Similarly, WWW images presently should be approximately 20 Kbytes if at all possible. That’s 1/50th the size of a 1 MByte file and introduces us to the necessity of image compression and image file types, not to mention visual quality tradeoffs.

Image Files and Their Image Compression Algorithms

There are two primary image file types used on the WWW. They have radically different image compression approaches and formats, each with its own advantages. As luck would have it, these two types of file formats complement each other nicely for WWW use.

An image file with a jpg extension is a Joint Photographic Experts Group (JPEG) File Interchange Format (JFIF) file and uses JPEG compression. Alternately, an image file with a gif extension is a Graphics Interchange Format (GIF) file developed in 1987 and copyrighted by CompuServe Corp. GIF files use Lempel-Ziv & Welsh (LZW) compression, now patented by Unisys Corp. Hence, developers who distribute GIF creation applications must obtain a license from Unisys. A third image file type which is becoming popular is the Portable Network Graphics (PNG) file format. PNG files have a png extension and use a compression called Lempel-Ziv (LZ77). In contrast to LZW, while LZ77 is similar to LZW, LZ77 is an open, royalty free standard and promises to allow PNG to replace GIF eventually.

Here’s the second rub. Images are considered the digital world’s Styrofoam—bulky and tough to compress. There are two types of general compression approaches: lossy and lossless. Lossless compression approaches, such as LZW, preserve all image detail. Lossy compression approaches, such as JPEG, first facilitate subsequent compression operations by discarding (hopefully) visually insignificant image detail. This limits the number of times you can edit an image since, like audiotape recordings, the image degrades slightly with each new copy made from a previous copy.


Previous Table of Contents Next