Colosseum Builders LogoColosseum Builders, Inc.


Compressed Image File Formats: JPEG, PNG, GIF, XBM, BMP

imageformats.png (46853 bytes)

John Miano's book, "Compressed Image File Formats: JPEG, PNG, GIF, XBM, BMP", is available from ACM Press/Addison Wesley Longman.

This book came about because of my own frustrations with learning about JPEG. I needed to learn the details for work. Unfortunately, everthing I read that explained the JPEG standard was overly cryptic. I figured that JPEG had to be easier to understand than the mumbo-jumbo I was reading.

I was right. I dug into the JPEG standard and wrote my own source code. I found that JPEG was not that complicated once you broke it down into the parts. So I wrote my own book to explain to others how it works.

"Compressed Image File Formats" is the first book that explains how to read and write images in the the most popular image file formats. Read this book and you will finally understand how JPEG works.

Table of Contents

  1. Introduction to Graphics File Formats

  2. Windows BMP

  3. XBM

  4. Introduction to JPEG

  5. Huffman Coding

  6. The Discrete Cosine Transform

  7. JPEG File Format

  8. Decoding Sequential JPEG Files

  9. Encoding Sequential JPEG Files

  10. Optimizing the Discrete Cosine Transform

  11. Progressive JPEG

  12. GIF

  13. PNG File Format

  14. Encoding PNG Files

  15. Decoding PNG Files

Click here to order from

Enhanced Image Source Code

The source code that accompanies the book is designed for readability. Version 4.2 of an enhanced version of this library that is intended to improve performance in exchange for slightly less understandability is available here. This ZIP archive contains ready-to-run examples for Borland C++Builder, Delphi Free Pascal and Microsoft Visual C++.

Military JPEG Standards

We were not able to distribute the JPEG standard on the CD due to copyright restrictions. This archive contains U.S. Department of Defense versions of the JPEG standard which are marked as freely distributable. These documents are significantly different from the ISO JPEG standard. However, they do contain formal descriptions of JPEG.

DCT Visualization Program

To help you better understand the material in Chapter 7 (The Discrete Cosine Transform), here is an application that graphically displays the relationship between the DCT and the IDCT approximated using various numbers of DCT coefficients. This allows you to see how the number of DCT coefficients affects the quality of the IDCT approximation to the original data.


For the 1st and 2nd printings

Page 6: The translation of the Cb and Cr coefficients should be 2Sample Precision/2   (or alternatively 2Sample Precision -1) instead of  2Sample Precision/2. In other words, for 8 bit sample precision, the Cb and Cr coefficients should be translated by 128.

Page 43: The next to last sentence should be "...method for implementing up sampling is ..."

Page 63: The frequencies in the Huffman Coding Example should be

A  L M N P
10 2 2 4 2

Page 68: In Figure 6.1, the second section should show a Huffman Code value of 0.

Page 70: Algorithm 6.1 should be:

Procedure GenerateHuffmanCodes (NUMBEROFCODES,
                                CODES [0..255])


Page 80: In Figure 7.2, the next to last line should be:

= 64.0 + 0.0 + 26.1 + 0.0 + 0.0 - 2.1 + 0.0

Page 80: In Table 7.1, the first DCT coefficient value should be 400.58.

Page 84: Equation 7.3 should have


c(i,j) = 2/N, i and j != 0

c(i,j) = 1/N, i and j = 0

c(i,j) =  sqrt (2) /N otherwise


Page 97:  In the second paragraph the huffman encoded value shoud be 02 and the magnitude value should be (2) rather than 3. The input bits should be (00).

Page 97: In Figure 8.2, Row B, the values should be

02    0    00    -1

Page 107:

In the expression for "scale factor", the parentheses are misplaced. The argument to the log function should be the constant value 2.


Page 228: The numerator of the equation below Table 14.9 should be

Image Width + Column Interval - First Column

Updates to the CD

Updated BmpDecod.cpp

This update to the source code examples on the CD fixes a problem with incorrect color counts when the number of color table entries is less than that specified by the bit count.

Updated JpegEnco.cpp

Null terminates 'JFIF' in the header.