File compression and Data Loss
 
The most important thing to remember about the winzip format is that the method of compression makes a pixel perfect copy of the original file. All compression formats that work on program files must not lose data in compression.
 
All of the file formats we have looked at to this point compress with no data loss. Some file formats archive a higher level of compression by simply dis guarding less significant data. An example of this would be converting a 30,000 color BMP file to a 256 color GIF file. If you start with an BMP image that has 256 colors or less, the GIF file will be an exact copy of your BMP. If on the other hand, you started with a BMP image with 30,000 colors you would have to reduce the number of colors to less than 256 before you could save the image as a GIF. Some programs will do this color reduction in the background making it confusing as to what is really happening. If you save a 30,000 color image in Adobe Photoshop as a GIF, with the "File Save As" method you get a very non intuitive dialog box asking you which method of color reduction you would like to use. When saving GIF images in Photoshop use the "Save for Web" option. This method will let you see the exact options that are being used for color reduction.
 
 
"Lossy" and "Lossless" Compression
 
Lossy compression is Compression WITH data loss.
Lossless compression is Compression WITHOUT data loss
 
The BMP, GIF, TIFF and ZIP formats are all Lossless formats. The JPG Format uses the idea of Lossy compression to archive an extremely high amount of file compression.
 

 
Color Reduction
 
As stated above, if you start with a 30,000 color image file and wish to save it in the GIF format, you will need to reduce the number of colors to 256 or less. Look at the Random Examples page again. Notice that in each case there was data loss between the original JPG image and the GIF image.
 
Lets take another look at the black and white church picture example, with histograms.
 

JPG
256 Colors

GIF
32 Colors


 
You can plainly see that the original image had much finer shades of gray. One method to do this is to average colors that are similar. This is called "Quantizing" and is used in the JPG format.
 
There are many different methods for choosing the "best" colors to keep. Some photoshop methods include Perceptual, Selective, Adaptive, and Web. Each is different and have different uses.
 
 

 
Quality Reduction
 
The second method is probably the most commonly used. Simply shrink the picture, save it, and enlarge the picture when you wish to view it. The results are less than satisfactory as can be seen below.
 

Normal Zoom
JPG
60 K

2x Zoom (1/4 number of pixels)
JPG
21 K
 
Notice that even though the picture on the right is 1/4 the pixel size as the picture on the right (before being enlarged for viewing), the file size is only 1/3. This due to the JPG file format which has some special methods of file compression. If these pictures were saved in the BMP Format the size would be a nice 1/4 file size for 1/4 quality.
 

Normal Zoom
BMP
266 K

2x Zoom (1/4 number of pixels)
BMP
67 K
 
67 K / 266 K = 1/4 (see, it really works!).  
All of this information will be used in discussing the JPG format next.  

 
Next -----> 9. The JPEG File Format