Skip to main content

Module jpeg

Module jpeg 

Source
Expand description

A simple baseline JPEG codec.

This is a small, readable implementation intended as a worked example rather than a production codec. It supports:

  • Encoding 8-bit grayscale or RGB images as baseline sequential JPEG (JFIF), using the standard Annex K quantization and Huffman tables, a quality factor in 1..=100, and 4:4:4 chroma (no subsampling).
  • Decoding baseline sequential (SOF0) JPEG files with one or three components, 8-bit precision, any chroma subsampling (upsampled by linear interpolation, like libjpeg’s “fancy” upsampling), custom Huffman and quantization tables, and restart intervals.

Progressive, arithmetic-coded, 12-bit, CMYK and multi-scan files are rejected with an error.

The pipeline is the classic one: colour conversion, 8x8 forward DCT, quantization, zig-zag ordering, differential DC coding and run-length AC coding, then Huffman coding; the decoder runs it in reverse.

See the book entry Image files.

Structs§

JpegImage
A decoded raster image with interleaved 8-bit samples (channels is 1 for grayscale or 3 for RGB, row-major, width * height * channels bytes).

Functions§

jpeg_decode
Decodes a baseline JPEG byte stream into an interleaved 8-bit image (grayscale stays 1 channel; three-component YCbCr files become RGB).
jpeg_encode
Encodes an 8-bit image as a baseline JPEG (JFIF) byte stream.