Compressed Image File Formats: JPEG, PNG, GIF, XBM, BMP
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 mumbojumbo 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

Introduction to Graphics File Formats

Windows BMP

XBM

Introduction to JPEG

Huffman Coding

The Discrete Cosine Transform

JPEG File Format

Decoding Sequential JPEG Files

Encoding Sequential JPEG Files

Optimizing the Discrete Cosine Transform

Progressive JPEG

GIF

PNG File Format

Encoding PNG Files

Decoding PNG Files
Click here to order from Amazon.com.
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 readytorun 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.
Errata
For the 1st and 2nd printings
Page 6: The translation of the Cb and Cr coefficients should be 2^{Sample Precision}/2 (or alternatively 2^{Sample Precision 1}) instead of 2^{Sample 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,
CODELENGTHS[0..NUMBEROFCODES1],
CODES [0..255])
Begin
HUFFMANCODECOUNTER = 0
CODELENGTHCOUNTER = 1
For INDEX = 0 TO NUMBEROFCODES  1 Do
Begin
While CODELENGTHS [INDEX] > CODELENGTHCOUNTER Do
Begin
HUFFMANCODECOUNTER = HUFFMANCODECOUNTER LeftShift 1
CODELENGTHCOUNTER = CODELENGTHCOUNTER + 1
End
CODES [INDEX] = HUFFMANCODECOUNTER
HUFFMANCODECOUNTER = HUFFMANCODECOUNTER + 1
End
End
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
where
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.