Realcodeart.com

JPEG

The routine that turns a photograph's frequencies back into pixels.

Independent JPEG Group, Thomas G. Lane

Get it on a mug or tee →

A photograph is a grid of brightness and color. Stored that way, it is large, and the eye does not actually require every sample. JPEG compression, named for the Joint Photographic Experts Group, cuts the image into small blocks, usually eight pixels on a side, and describes each block as a sum of waves. The transform is a discrete cosine. Smooth areas become a few strong coefficients. Fine detail becomes many weak ones. A quantization table then spends bits on the coefficients a person is likely to notice and starves the rest. Chroma, the color separated from the brightness, is often stored at a coarser grain than the brightness, because the eye is pickier about edges of light than about edges of hue.

To show the picture, a decoder reverses the path. It undoes the Huffman coding that packed the coefficients, multiplies the quantization back in, and runs the inverse cosine transform so the waves become pixels again. The quality of that inverse step is the quality of the photograph on the screen. A slow, careful inverse is a closer match to the mathematics. A fast integer inverse is what a program uses when it must open a folder of pictures and not make the user wait. The trade is a little precision for a lot of speed.

The Independent JPEG Group wrote the library a generation of programs called for that job. In the early years Thomas G. Lane led the work. The first releases arrived in the early 1990s, while the ISO standard was settling, and the library became the practical meaning of JPEG for applications that did not want to implement a cosine from a journal article. Image tools, browsers, cameras' desktop software, and later a great many embedded devices linked it or reimplemented its lessons. The standard is a document. The library is the document's working shadow.

The bars are the opening of the fast integer inverse DCT. You can see the setup of a workspace, the pass down the columns, the pass across the rows. The integer method keeps the intermediate values in a range a machine can hold without a floating-point unit's full ceremony. Comments in the source label the passes. In the picture those comments are a color, not a sentence. Names are another color. The two-pass shape is the thing a person can see without being able to compile it.

The group's terms are a license with a memory. You may use, copy, modify, and distribute the software for any purpose, without a fee, provided their copyright and no-warranty notice stay unaltered when source is distributed. If you ship only executable code, the documentation has to say that the software is based in part on the work of the Independent JPEG Group. That sentence is not optional color. It is the condition. On this site it lives on the product page, with the copyright line that names Lane and the years of the early library. The shirt does not carry it. A shirt cannot keep a notice unaltered in the sense the license means. The page can.

The piece is therefore marked notice, not clear. Clear would mean the authors gave the work to the public domain and walked away. The Independent JPEG Group did not walk away. They allowed the use and kept the attribution. The bars are the inverse transform's opening, the moment frequency data becomes, again, a block of pixels. The notice is the moment the catalog admits whose work the transform was.

You can see the cost of the shortcut if you know what the colors are doing. A long run of similar operations is a pass across one axis of the block. A break is the handoff through the workspace, where columns have become numbers that rows will consume. The fast integer form scales those numbers so the arithmetic stays in integers and the final shift puts the pixels back in range. The error is small beside the error quantization already introduced on purpose. The photograph was never going to be the original samples. It was going to be the samples a person would accept.

Lane's copyright years on the notice, 1991 to 1995, mark the early library, not the end of JPEG. The format outlived the group that first coded it, and the notice outlived the machines it was compiled for. Both still apply. The page carries them. The bars carry the inverse pass, which is the only part of a photograph this catalog is willing to print.

Mug and tee of JPEG