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§
- Jpeg
Image - A decoded raster image with interleaved 8-bit samples (
channelsis 1 for grayscale or 3 for RGB, row-major,width * height * channelsbytes).
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.