Expand description
JPEG / Motion-JPEG codec, pure Rust.
Each video packet is a standalone JPEG (one full SOI..EOI). The decoder
recognises baseline (SOF0), extended-sequential (SOF1), progressive
(SOF2), and lossless (SOF3) JPEGs with 4:2:0 / 4:2:2 / 4:4:4 chroma
subsampling (DCT variants) and outputs MjpegFrames in the matching
Yuv*P pixel format or Gray8 for 1-component streams. SOF0 and
SOF1 share the same Huffman sequential scan structure at 8-bit
precision; both are handled by the same scan decoder, and
non-interleaved sequential scans (one SOS per component) fall back
to the same coefficient-accumulator path used by the progressive
decoder. Progressive scans accumulate DCT coefficients across
multiple SOS segments using both spectral selection and successive
approximation; the inverse DCT runs once after EOI. Restart markers
(RSTn) and DRI segments are honoured on both paths. APP0..APP15
segments (JFIF, EXIF, ICC, XMP, …) are skipped without parsing. The
encoder accepts the same pixel formats and produces a standalone
baseline JPEG using the Annex K “typical” Huffman tables, so its
output is interoperable with any compliant JPEG decoder. A
progressive (SOF2) output mode is available via
encoder::MjpegEncoder::set_progressive or
encoder::encode_jpeg_progressive; it emits a DC-first scan
followed by two per-component AC band scans (spectral selection
only, Ah = Al = 0). A lossless (SOF3) grayscale output mode is
available via encoder::encode_lossless_jpeg_grayscale (or
MjpegEncoder::set_lossless(true) on the trait-API encoder):
every precision P ∈ 2..=16 and every Annex H Table H.1 spatial
predictor 1..=7 are supported, and the bitstream round-trips
bit-exact through the matching SOF3 decoder.
4-component (CMYK / Adobe YCCK) JPEGs decode to packed Cmyk — the
decoder inspects the APP14 Adobe transform flag to choose among plain
CMYK, Adobe-inverted CMYK, and Adobe YCCK (which is colour-converted
back to CMYK via BT.601 full-range YCbCr→RGB→CMY plus K inversion).
The 4-component path covers both the sequential (SOF0 / SOF1) and the
progressive (SOF2) scan decompositions at P = 8. 12-bit precision
sequential JPEGs (SOF0/SOF1 with P=12) decode to Gray12Le /
Yuv444P12Le / Yuv422P12Le / Yuv420P12Le; sample buffers stay
16-bit throughout the inverse DCT and the level shift uses 2048.
Lossless JPEGs (SOF3) decode at every precision P ∈ 2..=16 via
Annex H predictor reconstruction (bit-exact, no DCT). Single-component
grayscale output: Gray8 at P = 8, Gray10Le / Gray12Le at
P = 10/12, Gray16Le everywhere else. Three-component (RGB-class,
H_i = V_i = 1) output: packed Rgb24 at P = 8, planar
Gbrp10Le / Gbrp12Le / Gbrp14Le at P = 10/12/14, packed
Rgb48Le at every other precision in the valid range.
Extended-sequential arithmetic (SOF9) is decoded via the Q-coder /
arithmetic entropy decoder from T.81 Annex D + F.2.4. The DAC marker
(Define Arithmetic Conditioning) is parsed when present; if absent the
decoder uses the spec defaults (L=0, U=1) for DC / lossless
conditioning and Kx=5 for AC. Progressive arithmetic (SOF10) is
decoded via the same Q-coder under the T.81 §G.1.3 procedures: DC
first scans reuse the §F.1.4.1 model on the point-transformed
values, DC refinement bits use the fixed 0.5 estimate, AC first
scans run the §F.1.4 procedure per band (Kmin = Ss, EOB =
end-of-band), and AC refinement scans follow the §G.1.3.3 model
(Figures G.10 / G.11, Table G.2) — at P = 8 and P = 12 with
the same output shaping as the Huffman progressive (SOF2) path,
4-component CMYK / YCCK included at P = 8. Lossless arithmetic
(SOF11) is decoded via the same Q-coder under the two-dimensional
statistical model of §H.1.2.3 (binary decisions conditioned on the
left / above difference classifications through the Figure H.2
array), covering the full Annex H surface the SOF3 path handles:
every precision, every predictor, point transform and restart
intervals.
Not supported (will return Error::Unsupported):
- Hierarchical (SOF5..SOF7, SOF13..SOF15) JPEGs
- 12-bit progressive 4-component JPEGs (the workspace
PixelFormatenum has no 12-bit CMYK variant;P=84-component CMYK / YCCK is supported on both the sequential and progressive scan decompositions).
Motion-JPEG carried over RTP (RFC 2435) is supported on the decode
path via rtp::JpegDepacketizer, which reassembles fragmented
RTP/JPEG payloads and reconstructs the absent SOI / DQT / SOF0 / DHT /
SOS / EOI marker segments (from the §3.1 main header’s Q field or an
in-band §3.1.8 quantization-table header) so the result is a complete
JPEG interchange stream the decoder consumes directly.
§Standalone vs registry-integrated
The crate’s default registry Cargo feature pulls in oxideav-core
and exposes the Decoder / Encoder trait surface, the JPEG-still
container, and the registry::register / registry::register_codecs
/ registry::register_containers entry points. Disable the feature (default-features = false) for
an oxideav-core-free build that still exposes the standalone
[decoder::decode_jpeg] API plus crate-local MjpegFrame /
MjpegPlane / MjpegPixelFormat / MjpegError types built
only on std.
Re-exports§
pub use error::MjpegError;pub use error::Result;pub use image::MjpegFrame;pub use image::MjpegPixelFormat;pub use image::MjpegPlane;pub use jpeg::inspect::inspect_jpeg;pub use jpeg::inspect::parse_adobe_app14;pub use jpeg::inspect::parse_icc_profile_app2;pub use jpeg::inspect::parse_jfif_app0;pub use jpeg::inspect::parse_jfxx_app0;pub use jpeg::inspect::AdobeApp14;pub use jpeg::inspect::AdobeColorTransform;pub use jpeg::inspect::ChromaSubsampling;pub use jpeg::inspect::ColorHint;pub use jpeg::inspect::IccProfileApp2Chunk;pub use jpeg::inspect::IccProfileChunks;pub use jpeg::inspect::InspectedComponent;pub use jpeg::inspect::JfifApp0;pub use jpeg::inspect::JfifUnits;pub use jpeg::inspect::JfxxApp0;pub use jpeg::inspect::JfxxThumbnail;pub use jpeg::inspect::JpegInfo;pub use jpeg::inspect::SofKind;pub use registry::register;pub use registry::register_codecs;pub use registry::register_containers;
Modules§
- container
- Still-image JPEG container (
.jpg/.jpeg). - decoder
- JPEG packet decoder — baseline (SOF0) and progressive (SOF2).
- encoder
- Baseline / progressive JPEG encoder.
- error
- Crate-local error type used by
oxideav-mjpeg’s standalone (nooxideav-core) public API. - image
- Crate-local frame and pixel-format types used by
oxideav-mjpeg. - jpeg
- Baseline JPEG bitstream primitives.
- mjpeg_
container - Raw Motion-JPEG container (
.mjpeg/.mjpg). - registry
oxideav-coreintegration layer foroxideav-mjpeg.- rtp
- RTP/JPEG depacketization (RFC 2435).