Expand description
Baseline JPEG codec for otf-pixels, implemented from scratch.
“Baseline” here means what the format means by it: 8-bit samples, sequential
DCT, Huffman entropy coding. Progressive JPEG is a different enough decoder
that ADR-0004 puts it behind a wrapped codec instead; this crate reports it
as PixelsError::Unsupported rather than half-decoding it.
§Memory
Decode is streaming, at one MCU row. A JPEG’s entropy stream is a single
run of bits with no per-row structure, but it is ordered: every block of
MCU row n precedes every block of row n + 1. So the decoder keeps one
band of component planes — 8 or 16 pixel rows — converts it to interleaved
output, serves those rows, and reuses the band. Nothing scales with image
height, which is what makes a thumbnail of a 24 MP photograph affordable.
§Safety
Every parser here reads attacker-controlled bytes. Malformed input is a
value, never a panic: unsafe_code = "forbid" and the workspace’s ban on
unwrap/expect/panic! mean the classic decoder failures — a Huffman
table indexing past its symbols, an MCU count overflowing, a block written
outside its plane — are unrepresentable rather than merely avoided.
Structs§
- Component
- One component of a frame.
- Frame
- A parsed start-of-frame header.
- Jpeg
Codec - The JPEG entry in a sniffing registry.
- Jpeg
Decoder - Decodes a JPEG stream.
- Jpeg
Encoder - Encodes a baseline JPEG stream.
- Scan
- A parsed start-of-scan header.
- Scan
Component - One component of a scan, naming the entropy tables it is coded with.
Enums§
- Scale
- How much of an image a decode produces, as eighths of full size.
- Subsampling
- How much the chroma channels are subsampled relative to luma.
Constants§
- SIGNATURE
- The two-byte prefix every JPEG stream starts with, plus the marker that must follow it.
Functions§
- probe
- Whether
prefixstarts with a JPEG signature.