img_av1#
AV1 intra coding -- crate root lib/img_av1/lib.rs
img_av1 -- AV1 intra decoder and encoder for AVIF still images (AV1 bitstream specification; model:
tools/av1_ref.py, bit-exact) [src/img/av1*.s]
Av1Dec::new() -> decoder av1_new (av1_free = drop)
dec.set_cancel(flag) av1_set_cancel: polled per superblock
dec.set_stage(stage) av1_set_stage: test hook, AVS_* (output after that step)
dec.set_nograin(flag) av1_set_nograin: 1 = do not apply film grain
dec.obus(data) -> Ok / Err(ERR_*) av1_obus: OBUs in the low-overhead format: sequence
header, frame header / frame / tile groups of the
first shown frame (decoded when its last tile
arrives); temporal delimiters, metadata, padding and
everything after the first frame are ignored
dec.finish() -> Pic / Err(ERR_*) av1_finish: the decoded frame (film grain applied)
dec.qindex(seg, curq) -> qindex av1_qindex: get_qindex( curq < 0, seg )
Supported: profiles 0..2 (8 / 10 / 12 bits, 4:0:0 / 4:2:0 / 4:2:2 / 4:4:4), key frames and
intra-only frames with every intra tool, operating point 0. ERR_UNSUPPORTED: inter / switch
frames, show_existing_frame, frames that are not shown, intra block copy, large scale tile.
Modules: dec (av1.s: OBUs, headers, frame buffers, tile groups, the post filter chain), sym
(av1_sym.s), blk (av1_blk.s: tile / block syntax), coef (av1_coef.s), ipred (av1_ipred.s), itx
(av1_itx.s), txfn (av1_txfn.s, generated), lf (av1_lf.s), cdef (av1_cdef.s), lr (av1_lr.s:
superres, loop restoration), fg (av1_fg.s), tab (av1_tab.s, generated by tools/gen_av1.py).
The deblocking filter, CDEF and loop restoration run on the worker pool (plat::parallel_for)
like the assembly's; every item writes its own rows (or columns), so the bytes never depend
on the thread count.
img_av1 API#
test stages (av1_set_stage): output after that step [av1.inc AVS_*]
AVS_FINAL: u32 = 0
AVS_RECON: u32 = 1 // reconstruction, no in-loop filter
AVS_LF: u32 = 2 // after the deblocking filter
AVS_CDEF: u32 = 3
AVS_SR: u32 = 4 // after superres (of the CDEF output)
AVS_LR: u32 = 5 // after loop restoration (film grain not applied)
struct Pic<'a>the decoded frame (A1P of av1.inc): u16 sample planes owned by the decoderw: u32-- output size (UpscaledWidth x FrameHeight)h: u32bd: u32-- BitDepthsubx: u32-- subsampling (1 / 1 for monochrome)suby: u32mono: u32cdp: u32-- color_description_present_flagprim: u32trc: u32mc: u32full: u32-- color_rangecsp: u32-- chroma_sample_positionplanes: [&'a [u16]; 3]-- (empty for the chroma of a monochrome frame)strides: [u32; 3]-- in samplesrw: u32-- render sizerh: u32
From lib/img_av1/dec.rs:
struct Av1Dec<'a>the AV1 intra decoder (AV)
impl<'a> Av1Dec<'a>
fn new() -> Av1Dec<'a>av1_newfn set_cancel(&mut self, c: Option<&'a AtomicU32>)av1_set_cancel: a flag polled per superblock (!= 0 cancels)fn set_stage(&mut self, stage: u32)av1_set_stage: test hook, AVS_* (output after that step)fn set_nograin(&mut self, flag: u32)av1_set_nograin: 1 = do not apply film grainfn qindex(&self, seg: u32, curq: i32) -> u32av1_qindex: get_qindex( curq < 0, seg ) with CurrentQIndex = curqfn obus(&mut self, data: &[u8]) -> Result<(), i32>av1_obus: OBUs in the low-overhead formatfn finish(&mut self) -> Result<Pic<'_>, i32>av1_finish: the decoded frame
From lib/img_av1/enc.rs (img_av1::enc):
struct EncIn<'a>av1_encode's input (A1E)w: u32-- frame size (1 .. 65536)h: u32bd: u32-- bit depth: 8 / 10chroma: u32-- 0 (4:0:0) / 1 (4:2:0) / 3 (4:4:4)qidx: u32-- base_q_idx 0 .. 255 (0 = lossless)cicp: u32-- primaries | transfer << 8 | matrix << 16 | full range << 24tile_sb: u32-- smallest tile side in superblocks (0: 4)flags: u32-- (reserved, 0)cancel: Option<&'a AtomicU32>planes: [&'a [u16]; 3]-- u16 samples; chroma (w + subX) >> subX widestrides: [u32; 3]-- in samples
struct EncOutav1_encode's output (A1O)data: Vec<u8>-- OBUs: sequence header OBU, frame OBUseqlen: u32-- bytes of the sequence header OBU (the av1C configOBUs)profile: u32-- seq_profilelevel: u32-- seq_level_idx
fn encode(cfg: &EncIn) -> Result<EncOut, i32>av1_encode
img_av1 modules#
The codec's building blocks (public for the codec test app codectest; see their source headers):
| Module | Content |
|---|---|
img_av1::eec | AV1 encoder: range encoder (libaom's od_ec_enc, the inverse of the specification's symbol decoder) and symbol output / cost estimation of the tile encoder |
img_av1::enc | AV1 intra encoder: one key frame with a reduced still picture header (AVIF items) |
img_av1::ftx | forward DCT4 .. DCT64, ADST8 and ADST16 butterflies of the AV1 encoder as straight-line code, and the encoder's tables |