oxideav-mjpeg 0.1.8

Pure-Rust JPEG / Motion-JPEG codec for oxideav — baseline, extended-sequential, and progressive decode; baseline and progressive encode
Documentation
//! JPEG marker byte constants (ITU T.81 Annex B).
//!
//! Each marker is a two-byte sequence `0xFF, 0x??`. Only the second byte
//! is declared here. The first byte is always `0xFF`; a run of `0xFF`
//! bytes before the payload byte is legal as fill.

/// Start of Image.
pub const SOI: u8 = 0xD8;
/// End of Image.
pub const EOI: u8 = 0xD9;
/// Start of Scan.
pub const SOS: u8 = 0xDA;
/// Define Quantization Table(s).
pub const DQT: u8 = 0xDB;
/// Define Huffman Table(s).
pub const DHT: u8 = 0xC4;
/// Define Arithmetic Coding conditioning table(s) — used by SOF9..SOF15
/// arithmetic JPEGs to override the default `(L=0, U=1, Kx=5)` parameters.
pub const DAC: u8 = 0xCC;
/// Define Restart Interval.
pub const DRI: u8 = 0xDD;
/// Define Number of Lines (T.81 §B.2.5). Carries the frame's `NL`
/// (number of lines) when the SOF `Y` field was coded as 0; the segment
/// appears immediately after the first scan's entropy-coded data and is
/// mandatory in that case.
pub const DNL: u8 = 0xDC;
/// COMment segment.
pub const COM: u8 = 0xFE;

/// Baseline DCT sequential.
pub const SOF0: u8 = 0xC0;
/// Extended sequential DCT (same scan structure as SOF0 for 8-bit).
pub const SOF1: u8 = 0xC1;
/// Progressive DCT.
pub const SOF2: u8 = 0xC2;
/// Lossless sequential, Huffman-coded (T.81 Annex H — predictor-based, no DCT).
pub const SOF3: u8 = 0xC3;
/// Extended sequential DCT, arithmetic-coded (T.81 §F.1.4).
pub const SOF9: u8 = 0xC9;
/// Progressive DCT, arithmetic-coded (T.81 §G.1.3 — the SOF2 scan
/// structure entropy-coded by the Annex D Q-coder).
pub const SOF10: u8 = 0xCA;
/// Lossless sequential, arithmetic-coded (T.81 §H.1.2.3 two-dimensional
/// statistical model over the Annex D Q-coder).
pub const SOF11: u8 = 0xCB;

/// Application-specific markers APP0..APP15 (0xE0..0xEF).
pub const APP0: u8 = 0xE0;
/// APP2 — conventionally carries the embedded ICC colour profile.
/// Payload begins with the 12-byte ASCII identifier `"ICC_PROFILE\0"`
/// followed by a one-byte chunk-sequence number, a one-byte total-chunk
/// count, and then the next slice of the ICC profile bytes (T.872 / Annex
/// L of T.871 — see docs/image/jpeg/jpeg-fixtures-and-traces.md §3.11).
pub const APP2: u8 = 0xE2;
/// APP14 — conventionally carries the Adobe colour-transform tag.
pub const APP14: u8 = 0xEE;
pub const APP15: u8 = 0xEF;

/// Restart markers RST0..RST7 (0xD0..0xD7).
pub const RST0: u8 = 0xD0;
pub const RST7: u8 = 0xD7;

/// Returns true if `b` is an `APPn` marker byte.
pub fn is_app(b: u8) -> bool {
    (APP0..=APP15).contains(&b)
}

/// Returns true if `b` is a restart (RSTn) marker byte.
pub fn is_rst(b: u8) -> bool {
    (RST0..=RST7).contains(&b)
}

/// Returns true if `b` is any SOFn (Start Of Frame) marker.
/// Excludes DHT (0xC4) and JPG (0xC8).
pub fn is_sof(b: u8) -> bool {
    matches!(
        b,
        0xC0..=0xC3 | 0xC5..=0xC7 | 0xC9..=0xCB | 0xCD..=0xCF
    )
}