Skip to main content

Crate otf_pixels_codec_jpeg

Crate otf_pixels_codec_jpeg 

Source
Expand description

JPEG codec for otf-pixels, implemented from scratch.

Baseline JPEG — 8-bit samples, sequential DCT, Huffman coding — is decoded and encoded. Progressive JPEG is decoded too (ADR-0018): its scans fill a coefficient buffer that is then turned into pixels by the same path. Arithmetic coding, lossless, 12-bit and CMYK report PixelsError::Unsupported.

§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.
JpegCodec
The JPEG entry in a sniffing registry.
JpegDecoder
Decodes a JPEG stream.
JpegEncoder
Encodes a baseline JPEG stream.
Scan
A parsed start-of-scan header.
ScanComponent
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 prefix starts with a JPEG signature.