Skip to main content

oxideav_vp8/
lib.rs

1//! # oxideav-vp8
2//!
3//! **Status:** clean-room rebuild in progress (post 2026-05-20 audit).
4//!
5//! The prior implementation was retired under the workspace clean-room
6//! policy and the crate is being re-implemented from scratch against
7//! RFC 6386, using only material under `docs/` and black-box
8//! validator binaries.
9//!
10//! Currently landed:
11//!
12//! * VP8 boolean (range) entropy decoder — the foundational primitive
13//!   every higher-level decode step is built on (RFC 6386 §7); see
14//!   [`bool_decoder`].
15//! * VP8 uncompressed frame header (frame tag + key-frame start code +
16//!   width / height / scale codes) per RFC 6386 §9.1; see
17//!   [`frame_header`].
18//! * VP8 boolean-coded frame header — the complete §19.2 table per
19//!   RFC 6386; see [`coded_header`]. Covers segmentation, loop-filter
20//!   knobs, MB loop-filter adjustments, DCT partition count, quantiser
21//!   indices, the `token_prob_update()` sweep, entropy-probability
22//!   refresh, the inter-frame reference refresh / copy / sign-bias
23//!   ladder, the per-MB skip flag, the §9.10 tail of `prob_intra` /
24//!   `prob_last` / `prob_gf`, the gated Y and UV intra-mode
25//!   probability replacements, and the `mv_prob_update()` sub-block
26//!   of §17.2 (two 19-position MV_CONTEXTs, each `F? P(7)`).
27//! * VP8 key-frame macroblock mode decoding (RFC 6386 §11) — the
28//!   per-MB segment id, mb_skip_coeff, Y mode (`kf_ymode_tree`),
29//!   sixteen sub-block modes when `B_PRED` is selected
30//!   (`bmode_tree` driven by the §11.3 context predictors and the
31//!   §11.5 `kf_bmode_prob[10][10][9]` table), and the UV mode
32//!   (`uv_mode_tree`). See [`macroblock`].
33//! * VP8 intra-prediction pixel kernels (RFC 6386 §12) — the four
34//!   16×16 luma modes, the four 8×8 chroma modes, and the ten 4×4
35//!   sub-block modes. Pure pixel-shape kernels operating on small
36//!   neighbour arrays; no entropy decode, no IDCT, no loop filter.
37//!   See [`intra_predict`].
38//! * VP8 DCT-coefficient token decoding (RFC 6386 §13) — the
39//!   `coeff_tree` walker, the `DCTextra` extra-bits decode, the §13.5
40//!   default token-probability table, and a per-sub-block
41//!   `decode_block` primitive that recovers a `[i16; 16]` of
42//!   quantised coefficients. The §13.3 per-macroblock token walk
43//!   ([`decode_mb_coeffs`]) sits on top of `decode_block`: it walks the
44//!   24/25 residual blocks of one macroblock (Y2 first when present, then
45//!   16 Y, 4 U, 4 V), threads the above / left non-zero predictor context
46//!   through the §20.16 `left_context_index` / `above_context_index` slot
47//!   tables (a nine-entry [`MbEntropyCtx`]: 4 Y, 2 U, 2 V, 1 Y2), honours
48//!   the §13.1 `mb_skip_coeff` short-circuit with the §20.16
49//!   `reset_mb_context` Y2-preserving rule, selects the `YAfterY2` /
50//!   `YNoY2` plane per the macroblock's `has_y2`, and reorders each block
51//!   into raster order via the §20.16 `zigzag[16]` table — producing an
52//!   [`frame::MbCoeffs`] directly from the bitstream. The coefficients are
53//!   the raw quantized token values; the §14.1 Y2 / chroma dequant scaling
54//!   is applied by the [`dequant`] layer. See [`dct_tokens`].
55//! * VP8 §14.1 dequantization scaling and the bitstream→dequant wrapper —
56//!   [`dequant::MbDequantFactors`] computes the six §14.1 dequant factors
57//!   (Y1 DC/AC, Y2 DC/AC, chroma DC/AC) from the §9.6 quantiser indices,
58//!   applying the §20.4 `dixie.c` `dequant_init` scaling / clamping rules
59//!   (Y2 DC × 2, Y2 AC × 155/100 floored at 8, chroma DC capped at 132)
60//!   over the §14.1 `dc_qlookup` / `ac_qlookup` tables with the §20.4
61//!   `clamp_q` index saturation. [`dequant::MbDequantFactors::for_segment`]
62//!   layers the §10 per-segment quantizer override (delta or absolute) on
63//!   the frame baseline. [`dequant::MbDequantFactors::dequantize`] scales a
64//!   raw [`frame::MbCoeffs`] in place, and
65//!   [`dequant::decode_and_dequantize_mb`] is the wrapper that runs
66//!   [`dct_tokens::decode_mb_coeffs`] then dequantizes — turning the
67//!   bitstream straight into the pre-dequantized [`frame::MbCoeffs`] that
68//!   [`frame::decode_keyframe`] consumes, completing the keyframe decode
69//!   chain bitstream → dequant → reconstruct → pixels. See [`dequant`].
70//! * VP8 dequantization and inverse transforms (RFC 6386 §14) — the
71//!   §14.1 `dc_qlookup` / `ac_qlookup` tables with Y-plane factor
72//!   computation, the §14.3 inverse WHT (general + single-DC fast
73//!   path), the §14.4 inverse DCT, and the §14.5 predictor+residue
74//!   summation with `clamp255`. Per-block raster-order primitives;
75//!   the Y2/chroma dequant scaling and the zig-zag→raster reordering
76//!   are documented spec gaps left to the integration round. See
77//!   [`inverse_transform`].
78//! * VP8 loop filter per-segment primitives (RFC 6386 §15) — the §15.2
79//!   simple filter, the §15.3 normal subblock / macroblock filters, and
80//!   the §15.4 control-parameter derivation
81//!   ([`LoopFilterParams::derive`]). Pure per-edge-segment kernels
82//!   operating on a caller-supplied pixel window. See [`loop_filter`].
83//! * VP8 §15.1 loop-filter frame geometry — [`filter_frame`], the
84//!   per-frame post-pass that walks the reconstructed [`KeyframePlanes`]
85//!   in raster order and applies the §15.2 / §15.3 kernels across each
86//!   macroblock's left inter-MB edge, three internal vertical subblock
87//!   edges, top inter-MB edge, and three internal horizontal subblock
88//!   edges (chroma analogues for the normal filter; the simple filter is
89//!   luma-only), honouring the §15.1 page-86 steps-2/4 skip rule (mode
90//!   neither `B_PRED` nor `SPLITMV` *and* no coded coefficient) and the
91//!   §15 page-84 level-0 whole-MB skip. The per-MB level derivation
92//!   ([`calculate_mb_filter_level`]) implements the §20.6 `dixie.c`
93//!   `calculate_filter_parameters` body: base `loop_filter_level` + §10
94//!   per-segment override (delta or absolute, clamped `0..=63`) + §9.4
95//!   reference / mode deltas (clamped again). [`FrameFilterConfig`]
96//!   carries the resolved frame state, with
97//!   [`FrameFilterConfig::keyframe`] building it from a
98//!   [`Vp8CodedHeader`]. See [`loop_filter`].
99//! * VP8 interframe intra-predicted macroblock mode decoding (RFC 6386
100//!   §16.1) — the dynamic `ymode_prob` / `uv_mode_prob` resolution
101//!   ([`InterFrameIntraProbs::for_frame_header`]) including the §16.1
102//!   last-paragraph reset on key frames and the §9.10 per-frame
103//!   overlay, plus the `ymode_tree` / context-free `bmode_prob` /
104//!   `uv_mode_tree` walks
105//!   ([`parse_inter_frame_intra_macroblock_modes`]). Returns a
106//!   [`MacroblockModes`] for one intra-predicted MB on an interframe;
107//!   the caller forwards the `segment_id` and `mb_skip_coeff` already
108//!   read before the intra-vs-inter discriminator. See
109//!   [`macroblock`].
110//! * VP8 §14.2 per-macroblock reconstruction orchestration —
111//!   [`decode_keyframe_mb_non_bpred`] ties together token-decoded
112//!   coefficients, the §14.3 inverse WHT, the §14.4 inverse DCT, the
113//!   §12 intra-prediction kernels and the §14.5 predictor+residue
114//!   summation to produce reconstructed Y / U / V pixels for one
115//!   macroblock whose 16×16 luma mode is one of the four non-`B_PRED`
116//!   modes. Honours the §11.1 `mb_skip_coeff` short-circuit.
117//!   [`decode_keyframe_mb_bpred`] is the companion §11.3 / §12.3
118//!   `B_PRED` orchestrator: it drives the sixteen 4×4 luma sub-blocks
119//!   with per-sub-block neighbour evolution (each sub-block's
120//!   reconstructed pixels become the next sub-block's `above` / `left`),
121//!   applies the §12.3 right-edge above-right fixup for sub-blocks
122//!   7 / 11 / 15, omits the Y2 WHT seeding (a `B_PRED` MB has no Y2
123//!   block), and reconstructs the chroma planes with the same 8×8
124//!   §12.2 path. See [`reconstruct`].
125//! * VP8 per-frame keyframe raster walker (RFC 6386 §12 / §14.2) —
126//!   [`decode_keyframe`] iterates a key frame's macroblocks in
127//!   raster-scan order, assembling each MB's [`reconstruct::MbNeighbors`]
128//!   strips from the already-reconstructed full-frame plane buffers (the
129//!   bottom row of the MB above, the rightmost column of the MB to the
130//!   left, the corner pixel, and — for `B_PRED` — the four §12.3
131//!   above-and-to-the-right pixels with the rightmost-MB `(-1,15)`
132//!   clamp), selecting the non-`B_PRED` vs `B_PRED` orchestrator per the
133//!   MB's decoded luma mode, and writing reconstructed pixels into the
134//!   [`frame::KeyframePlanes`] I420 buffers. Off-frame edges are reported
135//!   as `None` so the §12.2 `DC_PRED` averaging distinguishes genuine
136//!   pixels from 127 / 129 fills. Consumes [`frame::MbCoeffs`]
137//!   (pre-dequantized) produced by the [`dequant`] layer. See [`frame`].
138//!
139//! * VP8 motion-vector component decoding (RFC 6386 §17) —
140//!   [`read_mv_component`] (§17.1 `read_mvcomponent`: the short-vs-long
141//!   range selector, the [`SMALL_MVTREE`] tree-coded `0..=7` short form,
142//!   the independent-bit long form with the implicit bit-3 rule, and the
143//!   conditional sign) and [`read_mv`] (§17.2 `read_mv`: row then column).
144//!   [`resolve_mv_contexts`] applies the round-4 §17.2 `mv_prob_update()`
145//!   overlays onto a base [`MvContexts`] (defaulting via
146//!   [`default_mv_contexts`] on key frames, carried-forward across
147//!   interframes), turning the parsed updates into the live decoding
148//!   tables. Returns the raw differential [`Mv`]; the §16.3 reference-base
149//!   addition, the §18.1 range clamp / stored-luma doubling, and the §16
150//!   `mv_ref` / SPLITMV machinery are deferred to later inter-prediction
151//!   rounds. See [`motion_vector`].
152//!
153//! * VP8 interframe motion compensation (RFC 6386 §16.2 / §18) — the
154//!   inter-prediction slice that *consumes* a decoded motion vector.
155//!   [`select_ref_frame`] reads the §16.2 `prob_last` / `prob_gf`
156//!   reference selector into a [`RefFrame`]; [`stored_luma_mv`] applies
157//!   the §18.1 stored-luma doubling, [`chroma_mv`] the §18.1 `avg()`
158//!   chroma averaging (cross-checked against the §20.14 closed form), and
159//!   [`apply_full_pixel`] the version-3 full-pel-chroma truncation.
160//!   [`fetch_block_whole_pixel`] is the §20.14 `build_mc_border`
161//!   edge-replicated 4×4 reference fetch specialised to whole-pixel
162//!   offsets; [`fetch_block_halo`] is the 9×9 support-halo fetch the
163//!   six-tap convolution needs. The §18.3 sub-pixel interpolation lands
164//!   here: [`SIXTAP_FILTERS`] / [`BILINEAR_FILTERS`] are the §18.3 tap
165//!   tables ([`filter_set_for_version`] / [`FilterSet`] pick the set by
166//!   frame-tag version), [`interp`] / [`sixtap_2d`] are the §20.14
167//!   one-dimensional convolutions, and [`filter_block_4x4`] is the
168//!   §20.14 `filter_block` per-sub-block dispatcher (whole-pixel copy or
169//!   horizontal-then-vertical six-tap synthesis). [`predict_inter_mb`]
170//!   assembles the §18.2 whole-MB prediction buffer for a non-SPLITMV
171//!   macroblock ([`ReferencePlanes`] borrows the reference frame's I420
172//!   planes), and [`reconstruct_inter_mb`] folds in the §14 dequantized
173//!   residual (Y2 WHT seeding + per-sub-block inverse DCT + §14.5
174//!   summation) to complete inter-MB reconstruction. The whole-pixel-only
175//!   [`predict_inter_mb_whole_pixel`] /
176//!   [`reconstruct_inter_mb_whole_pixel`] entry points are retained and
177//!   refuse a sub-pixel vector with
178//!   [`MotionCompError::SubPixelNotSupported`]. See [`motion_comp`].
179//!
180//! * VP8 near/nearest motion-vector census and inter-mode tree (RFC 6386
181//!   §16.2 / §16.3 / §18.1) — [`near_mv`], the slice that decides *which*
182//!   vector a whole-MB inter macroblock uses. [`find_near_mvs`] is the
183//!   §16.3 `vp8_find_near_mvs` spatial census over the above / left /
184//!   above-left [`MbInfo`] neighbours ([`MbInfo::border`] for the §16.3
185//!   1-MB off-frame border), producing the `best` / `nearest` / `near`
186//!   candidates and the weighted `cnt` census (with the §16.3 dedupe,
187//!   SPLITMV-merge, near↔nearest swap, and best:=nearest store).
188//!   [`SignBias`] carries the §9.7 sign-bias bits and drives the §16.3
189//!   `mv_bias` negation; [`mv_ref_probs`] derives the §16.2 tree
190//!   probabilities from the census via [`MV_COUNTS_TO_PROBS`]; and
191//!   [`read_inter_mode`] walks [`MV_REF_TREE`] into an [`InterMode`].
192//!   [`clamp_mv`] / [`MvClampRect`] are the §16.3 / §18.1 one-MB-border
193//!   clamp. [`resolve_inter_mb_mv`] ties census → probabilities → mode →
194//!   the single per-MB vector (ZEROMV / NEARESTMV / NEARMV / NEWMV, the
195//!   last adding the §17 differential to the clamped best per §18.1), and
196//!   [`decode_inter_mb`] drives [`reconstruct_inter_mb`] with that vector
197//!   so a whole-MB inter macroblock decodes from bitstream to
198//!   reconstructed pixels. §16.4 SPLITMV's per-sub-block walk is a
199//!   follow-up ([`ResolvedInterMode::Split`] /
200//!   [`InterMbError::SplitNotSupported`] carry the clamped best base).
201//!   See [`near_mv`].
202//!
203//! * VP8 top-level per-frame decode driver ([`decode_vp8`]) and the
204//!   [`oxideav_core::Decoder`] integration ([`decoder::Vp8Decoder`],
205//!   gated on the default-on `registry` feature). [`decode_vp8`] takes
206//!   the raw bytes of one VP8 frame, parses the §9.1 uncompressed header
207//!   and the §19.2 boolean-coded frame header, runs the §11 macroblock
208//!   prediction layer, carves the §9.5 DCT partitions (round-robin row
209//!   striping per §20.4), decodes + dequantizes each macroblock's §13
210//!   residuals, reconstructs the frame via [`decode_keyframe`], applies
211//!   the §15.1 loop-filter post-pass, and emits a visible-cropped I420
212//!   [`decoder::Vp8DecodedFrame`]. Interframes (§16) are surfaced as a
213//!   clean [`decoder::DecodeError::Unsupported`]. See [`decoder`].
214//!
215//! * VP8 multi-frame stateful decoder driver
216//!   ([`state::Vp8DecoderState`], [`state::Vp8DecoderState::decode_frame`])
217//!   owning the RFC 6386 §9 three-slot reference-frame buffer
218//!   ([`state::RefFrameSlot`] for `LAST` / `GOLDEN` / `ALTREF`), the §9.10
219//!   entropy / intra-mode / MV carry-state (with the §20 `saved_entropy`
220//!   rollback when `refresh_entropy_probs` is false), and the §9
221//!   `copy_buffer_to_*` / `refresh_*` slot rotation. The per-frame walker
222//!   dispatches each macroblock to either the §11 keyframe intra path or
223//!   the §16 inter path (intra-on-interframe via
224//!   [`parse_inter_frame_intra_macroblock_modes`], whole-MB inter via
225//!   `select_ref_frame` → §16.3 census → §16.2 inter-mode tree →
226//!   `reconstruct_inter_mb`, SPLITMV via `decode_split_mv` →
227//!   `reconstruct_split_mv_mb`), runs the §15.1 loop-filter post-pass
228//!   with the full §9.4 ref + mode delta ladder
229//!   ([`loop_filter::FrameFilterConfig::interframe`] +
230//!   [`loop_filter::filter_inter_frame`] +
231//!   [`loop_filter::calculate_mb_filter_level_inter`]), and emits a
232//!   visible-cropped I420 picture per frame.
233//!
234//! With the §13.3 per-MB token walk ([`dct_tokens::decode_mb_coeffs`]),
235//! the §14.1 dequant scaling ([`dequant::decode_and_dequantize_mb`]), the
236//! per-key-frame [`decode_vp8`] driver, the §16.4 SPLITMV walk, and now
237//! the multi-frame [`state::Vp8DecoderState`] all landed, the full
238//! key+inter decode chain is bit-exact against the reference decoder output
239//! on multi-frame fixtures (single I + P; 5-frame mid-GOP golden refresh;
240//! 10-frame `auto-alt-ref` + ARNR).
241//!
242//! * **VP8 encoder Phase 1** — the bitstream-formatting half of the
243//!   encoder ([`encoder`]). Ships the §7.3 [`encoder::BoolEncoder`] (a
244//!   Rust port of the `bool_encoder` C listing embedded in RFC 6386
245//!   §7.3), the §9.1 / §9.3 / §9.4 / §9.5 / §9.6 / §9.9 / §9.10 / §9.11
246//!   frame-header writer subroutines, and the top-level
247//!   [`encoder::encode_silent_keyframe`] driver. Every emitted MB is
248//!   coded as `mb_skip_coeff = 1` with `DC_PRED` luma + chroma, so the
249//!   §13 token / §14 transform / mode-selection logic is not exercised
250//!   yet — but the resulting bytes are a structurally-valid VP8 key
251//!   frame the crate's own [`decode_vp8`] consumes and that
252//!   `ffmpeg -c:v vp8` accepts when wrapped in an IVF container. The
253//!   §13 / §14 rate-distortion encode side is future work.
254//!
255//! * **VP8 encoder Phase 2 begin: §14 forward 4×4 DCT + WHT
256//!   primitives** ([`forward_transform`]) — [`forward_dct_4x4`],
257//!   [`forward_wht_4x4`], and [`raster_to_scan`], the encoder partners
258//!   of the §14.3 / §14.4 inverse transforms and the §20.16 zig-zag
259//!   reorder. Mechanically derived as the transpose of the §14.3 /
260//!   §14.4 inverse listings (the §14.4 preamble itself notes the
261//!   transform is *"a classical 2-D inverse discrete cosine
262//!   transform"*); both reuse the same `COSPI8_SQRT2_MINUS1 = 20091`
263//!   / `SINPI8_SQRT2 = 35468` fixed-point constants so the
264//!   forward / inverse rounding shapes match. Wired through the
265//!   existing [`encoder::TokenEncoder`] for a per-MB roundtrip proof
266//!   (FDCT → quantize → raster-to-scan → encode → decode → scan-to-
267//!   raster → dequant → IDCT) at 48.13 dB PSNR on a synthetic flat
268//!   block at `yac_qi = 32` (lossless at `yac_qi = 0`); see
269//!   `tests/encoder_transform_roundtrip.rs`. The per-MB block-set
270//!   wiring (Y2 DC seeding, 24/25-block walk, RD-driven mode +
271//!   quant-step selection) is the next encoder round.
272
273#![cfg_attr(feature = "simd", feature(portable_simd))]
274#![warn(missing_debug_implementations)]
275
276pub mod arnr;
277pub mod bool_decoder;
278pub mod coded_header;
279pub mod dct_tokens;
280pub mod decoder;
281pub mod dequant;
282pub mod encoder;
283pub mod error;
284pub mod forward_transform;
285pub mod frame;
286pub mod frame_header;
287pub mod frame_tag;
288pub mod intra_predict;
289pub mod inverse_transform;
290pub mod ivf;
291pub mod loop_filter;
292pub mod macroblock;
293pub mod motion_comp;
294pub mod motion_search;
295pub mod motion_vector;
296pub mod near_mv;
297pub mod reconstruct;
298mod rowsync;
299pub mod state;
300pub mod stream;
301
302#[cfg(feature = "registry")]
303pub mod registry;
304
305// ───────────────────── 0.1.13 module-path aliases ─────────────────────
306//
307// The crates.io `oxideav-vp8 0.1.13` release organised its public
308// modules under a slightly different naming scheme. The aliases below
309// restore the historical module paths without renaming the underlying
310// files, so downstream consumers that wrote
311// `oxideav_vp8::loopfilter::LoopFilterParams` keep building.
312
313/// 0.1.13 alias of [`crate::forward_transform`] — the §14 forward 4×4
314/// DCT / WHT primitives.
315pub mod fdct {
316    pub use crate::forward_transform::*;
317}
318
319/// 0.1.13 alias of [`crate::inverse_transform`] — the §14 inverse 4×4
320/// DCT / WHT primitives and §14.5 predictor+residue summation.
321pub mod transform {
322    pub use crate::inverse_transform::*;
323}
324
325/// 0.1.13 alias of [`crate::intra_predict`] — the §12 intra-prediction
326/// pixel kernels.
327pub mod intra {
328    pub use crate::intra_predict::*;
329}
330
331/// 0.1.13 alias of [`crate::loop_filter`] — the §15 loop-filter
332/// primitives.
333pub mod loopfilter {
334    pub use crate::loop_filter::*;
335}
336
337/// 0.1.13 alias of [`crate::motion_vector`] — the §17 motion-vector
338/// primitives.
339pub mod mv {
340    pub use crate::motion_vector::*;
341}
342
343/// 0.1.13 alias of [`crate::dct_tokens`] — the §13 DCT-token decoding /
344/// classification.
345pub mod tokens {
346    pub use crate::dct_tokens::*;
347}
348
349/// 0.1.13 grouped alias of the inter-prediction modules
350/// ([`crate::motion_comp`] + [`crate::motion_search`] +
351/// [`crate::motion_vector`] + [`crate::near_mv`]).
352pub mod inter {
353    pub use crate::motion_comp::*;
354    pub use crate::motion_search::*;
355    pub use crate::motion_vector::*;
356    pub use crate::near_mv::*;
357}
358
359/// 0.1.13 alias surface for the §7.3 bool encoder. The current
360/// [`BoolEncoder`](crate::encoder::BoolEncoder) lives in
361/// [`crate::encoder`]; this module re-exposes it (and the
362/// classification helper) under the original 0.1.13 path.
363pub mod bool_encoder {
364    pub use crate::encoder::BoolEncoder;
365    pub use crate::encoder::{
366        TokenEncodeError, TokenEncoder, classify_coeff_token, encode_coeff_block,
367    };
368}
369
370/// 0.1.13 grouping module for the in-tree default-probability / scan
371/// / dequant tables. Today these tables live next to the layer that
372/// consumes them; this module re-exports them under the original
373/// `tables` path.
374pub mod tables {
375    pub use crate::coded_header::{DEFAULT_MV_CONTEXT, MV_PROB_COUNT};
376    pub use crate::dct_tokens::{COEFF_BANDS, DEFAULT_COEFF_PROBS, MB_ENTROPY_CTX_LEN, ZIGZAG};
377    pub use crate::inverse_transform::{AC_QLOOKUP, DC_QLOOKUP, QINDEX_RANGE};
378    pub use crate::loop_filter::{MAX_MB_SEGMENTS, MAX_MODE_LF_DELTAS, MAX_REF_LF_DELTAS};
379    pub use crate::macroblock::{IF_BMODE_PROB, IF_UV_MODE_PROB_DEFAULTS, IF_YMODE_PROB_DEFAULTS};
380    pub use crate::motion_comp::{BILINEAR_FILTERS, SIXTAP_FILTERS};
381    pub use crate::near_mv::{
382        MV_COUNTS_TO_PROBS, MV_PARTITION_PROBS, MV_PARTITION_TREE, MV_PARTITIONS, MV_REF_TREE,
383        SUBMV_REF_PROBS, SUBMV_REF_TREE,
384    };
385}
386
387pub use arnr::{ArnrConfig, ArnrPicture, build_arnr_altref};
388pub use bool_decoder::{BoolDecoder, BoolDecoderError};
389pub use coded_header::{
390    CodedHeaderError, DEFAULT_MV_CONTEXT, MV_PROB_COUNT, MbLfAdjustments, MvProbUpdates,
391    QuantIndices, TokenProbUpdates, UpdateSegmentation, Vp8CodedHeader,
392};
393pub use dct_tokens::{
394    BlockType, COEFF_BANDS, CoeffProbs, DEFAULT_COEFF_PROBS, DctToken, DctTokenError,
395    MB_ENTROPY_CTX_LEN, MbCoeffError, MbEntropyCtx, ZIGZAG, decode_block, decode_mb_coeffs,
396    merge_default_token_probs,
397};
398pub use decoder::{
399    DEFAULT_MAX_PIXELS_PER_FRAME, DecodeError, Vp8DecodeOptions, Vp8DecodedFrame, decode_vp8,
400    decode_vp8_with_max_pixels, decode_vp8_with_options,
401};
402
403/// 0.1.13 alias for [`decoder::Vp8DecodedFrame`] — the per-frame
404/// reconstructed I420 picture is now named `Vp8Frame` at the crate root
405/// to match the historical `oxideav_vp8::Vp8Frame` path that downstream
406/// consumers wrote against. The underlying struct is unchanged.
407pub type Vp8Frame = decoder::Vp8DecodedFrame;
408
409/// 0.1.13 alias for the registry-gated [`decoder::Vp8Decoder`] handle.
410/// Re-exported at the crate root so `use oxideav_vp8::Vp8Decoder;`
411/// works. Standalone callers without `oxideav-core` should use
412/// [`state::Vp8DecoderState`] instead.
413#[cfg(feature = "registry")]
414pub use decoder::Vp8Decoder;
415
416/// Legacy alias of [`decode_vp8`] yielding the framework's
417/// [`oxideav_core::VideoFrame`] instead of [`Vp8Frame`]. Gated on the
418/// `registry` feature; standalone callers should use [`decode_vp8`].
419#[cfg(feature = "registry")]
420pub fn decode_frame(
421    bytes: &[u8],
422) -> core::result::Result<oxideav_core::VideoFrame, decoder::DecodeError> {
423    decode_vp8(bytes).map(Into::into)
424}
425pub use dequant::{MbDequantFactors, UV_DC_MAX, Y2_AC_MIN, decode_and_dequantize_mb};
426pub use encoder::{
427    AdaptiveQuantConfig, BoolEncoder, BranchCounts, CopyBufferSelector, EncodeEffort, EncodeError,
428    EncodedMb, I420Frame, InterCodingOptions, InterEncoded, InterSegmentationConfig,
429    KeyframeCodingOptions, KeyframeEncodeOptions, KeyframeEncoded, KeyframeParams,
430    LoopFilterDeltaSlot, LoopFilterDeltas, MbPixels, RefreshControls,
431    ScaleCode as EncoderScaleCode, SilentKeyframeEncoder, SilentKeyframeParams, TokenEncodeError,
432    TokenEncoder, TrellisStrength, UpdateSegmentationLayer, classify_coeff_token,
433    count_block_branches, count_inter_frame_branches, count_keyframe_branches, count_mb_branches,
434    empty_branch_counts, encode_coeff_block, encode_invisible_altref_update,
435    encode_invisible_altref_update_with_coding_options, encode_keyframe,
436    encode_keyframe_adaptive_quant, encode_keyframe_adaptive_quant_with_reconstruction,
437    encode_keyframe_adaptive_quant_with_reconstruction_and_trellis,
438    encode_keyframe_adaptive_quant_with_segment_lf_deltas,
439    encode_keyframe_adaptive_quant_with_segment_lf_deltas_and_trellis,
440    encode_keyframe_adaptive_quant_with_trellis, encode_keyframe_auto_loop_filter,
441    encode_keyframe_auto_loop_filter_with_reconstruction, encode_keyframe_detailed,
442    encode_keyframe_with_fitted_token_prob_updates, encode_keyframe_with_options,
443    encode_keyframe_with_reconstruction, encode_keyframe_with_reconstruction_and_coding_options,
444    encode_keyframe_with_reconstruction_and_fitted_token_prob_updates,
445    encode_keyframe_with_reconstruction_and_options,
446    encode_keyframe_with_reconstruction_and_token_updates, encode_keyframe_with_token_prob_updates,
447    encode_mb_block_set, encode_mb_block_set_with_neighbors,
448    encode_mb_block_set_with_neighbors_strength, encode_p_frame_detailed, encode_p_frame_multi_ref,
449    encode_p_frame_multi_ref_adaptive_quant, encode_p_frame_multi_ref_auto_loop_filter,
450    encode_p_frame_multi_ref_with_fitted_token_prob_updates,
451    encode_p_frame_multi_ref_with_intra_pick, encode_p_frame_multi_ref_with_refresh,
452    encode_p_frame_multi_ref_with_refresh_and_coding_options,
453    encode_p_frame_multi_ref_with_refresh_and_intra_pick,
454    encode_p_frame_multi_ref_with_refresh_and_lf_deltas,
455    encode_p_frame_multi_ref_with_refresh_and_lf_deltas_and_fitted_token_prob_updates,
456    encode_p_frame_multi_ref_with_refresh_and_lf_deltas_and_intra_pick,
457    encode_p_frame_multi_ref_with_refresh_and_lf_deltas_and_intra_pick_and_fitted_token_prob_updates,
458    encode_p_frame_multi_ref_with_refresh_and_lf_deltas_and_token_updates,
459    encode_p_frame_multi_ref_with_token_updates, encode_p_frame_zero_mv, encode_silent_keyframe,
460    fit_token_prob_updates, make_silent_keyframe_encoder, patch_first_partition_size,
461    quality_to_qindex, quality_to_trellis_strength, write_frame_tag, write_loop_filter,
462    write_loop_filter_with_deltas, write_mb_no_skip_coeff, write_no_token_prob_updates,
463    write_quant_indices, write_segment_update_flags, write_token_partition_count,
464    write_token_prob_updates, write_update_segmentation,
465};
466
467/// Framework `make_encoder` / `make_encoder_with_qindex` /
468/// `make_encoder_with_quality` re-exports (registry-gated; require
469/// `oxideav-core`). These mirror the `encoder::` module path so
470/// `use oxideav_vp8::make_encoder;` works for binding-compatible
471/// downstream code (notably `oxideav-webp`'s lossy VP8 path).
472#[cfg(feature = "registry")]
473pub use encoder::{
474    Vp8EncoderOptions, make_encoder, make_encoder_from_param_options, make_encoder_with_options,
475    make_encoder_with_qindex, make_encoder_with_quality,
476};
477pub use forward_transform::{forward_dct_4x4, forward_wht_4x4, raster_to_scan};
478pub use frame::{FrameError, KeyframePlanes, MbCoeffs, decode_keyframe};
479pub use frame_header::{
480    FrameHeaderError, KEY_FRAME_START_CODE, LoopFilterPolicy, ReconstructionFilter, ScaleCode,
481    Vp8FrameHeader,
482};
483pub use intra_predict::{
484    DEFAULT_ABOVE_PIXEL, DEFAULT_LEFT_PIXEL, DEFAULT_TOPLEFT_DC, predict_b4x4, predict_uv8x8,
485    predict_uv8x8_dc, predict_uv8x8_h, predict_uv8x8_tm, predict_uv8x8_v, predict_y16x16,
486    predict_y16x16_dc, predict_y16x16_h, predict_y16x16_tm, predict_y16x16_v,
487};
488pub use inverse_transform::{
489    AC_QLOOKUP, DC_QLOOKUP, QINDEX_RANGE, Y1DequantFactors, add_residue, add_residue_4x4,
490    clamp_qindex, clamp255, dequant_block, inverse_dct_4x4, inverse_dct_4x4_add_into,
491    inverse_wht_4x4, inverse_wht_4x4_dc_only,
492};
493pub use loop_filter::{
494    FrameFilterConfig, LoopFilterParams, MAX_MB_SEGMENTS, MAX_MODE_LF_DELTAS, MAX_REF_LF_DELTAS,
495    calculate_mb_filter_level, clamp_s8, common_adjust, filter_frame, mb_filter, s2u,
496    simple_segment, subblock_filter, u2s,
497};
498pub use macroblock::{
499    IF_BMODE_PROB, IF_UV_MODE_PROB_DEFAULTS, IF_YMODE_PROB_DEFAULTS, InterFrameIntraProbs,
500    IntraBmode, IntraUvMode, IntraYMode, MacroblockError, MacroblockModes,
501    parse_inter_frame_intra_macroblock_modes, parse_key_frame_macroblock_modes,
502};
503pub use motion_comp::{
504    BILINEAR_FILTERS, FilterSet, MotionCompError, RefFrame, ReferencePlanes, SIXTAP_FILTERS,
505    apply_full_pixel, chroma_idx_for_luma_subblock, chroma_mv, fetch_block_halo,
506    fetch_block_whole_pixel, filter_block_4x4, filter_set_for_version, interp, predict_inter_mb,
507    predict_inter_mb_whole_pixel, predict_split_mv, reconstruct_inter_mb,
508    reconstruct_inter_mb_whole_pixel, reconstruct_split_mv_mb, select_ref_frame, sixtap_2d,
509    split_chroma_mvs, stored_luma_mv, whole_pixel_fraction_is_zero,
510};
511pub use motion_search::{
512    HALF_PIXEL_STEP, LumaRef, MV_MAX, MV_MIN, QUARTER_PIXEL_STEP, SearchResult, WHOLE_PIXEL_STEP,
513    block_sad_16x16, half_pixel_refine_luma, mb_luma_sad_at_mv, mb_luma_sad_at_whole_mv,
514    quarter_pixel_refine_luma, small_diamond_search_luma,
515};
516pub use motion_vector::{
517    Mv, MvContext, MvContexts, SMALL_MVTREE, default_mv_contexts, mv_bits, mv_component_bits,
518    read_mv, read_mv_component, resolve_mv_contexts, write_mv, write_mv_component,
519};
520pub use near_mv::{
521    InterMbError, InterMode, MV_COUNTS_TO_PROBS, MV_PARTITION_PROBS, MV_PARTITION_TREE,
522    MV_PARTITIONS, MV_REF_TREE, MbInfo, MvClampRect, MvPartition, NearMvs, ResolvedInterMode,
523    SUBMV_REF_PROBS, SUBMV_REF_TREE, SignBias, SplitMvResult, SubMvRefMode, above_block_mv,
524    clamp_mv, decode_inter_mb, decode_split_mv, decode_split_mv_mb, find_near_mvs, left_block_mv,
525    mv_ref_probs, partition_id, read_inter_mode, read_mv_partition, resolve_inter_mb_mv, submv_ref,
526    submv_ref_context,
527};
528pub use reconstruct::{
529    MbNeighbors, ReconstructError, ReconstructedMb, decode_keyframe_mb_bpred,
530    decode_keyframe_mb_non_bpred,
531};
532pub use state::{RefFrameSlot, Vp8DecoderState, bench_rotate_reference_slots};
533pub use stream::{
534    AltrefPacketKind, AltrefStreamConfig, AltrefStreamPacket, EncodedStreamFrame, FrameKind,
535    StreamEncodeError, Vp8AltrefStreamEncoder, Vp8InterStreamEncoder, Vp8KeyframeStreamEncoder,
536};
537
538/// Crate-local error type for the not-yet-implemented surfaces.
539///
540/// The decoder path (`decode_vp8`) has its own richer
541/// [`decoder::DecodeError`]; this type now only backs the encoder stub,
542/// which is still scaffolded pending the §13 / §14 encode round.
543#[derive(Debug, Clone, Copy, PartialEq, Eq)]
544#[non_exhaustive]
545pub enum Error {
546    /// The requested operation is not wired up yet (currently: the
547    /// encoder). The decode path is implemented for key frames — see
548    /// [`decode_vp8`] / [`decoder::DecodeError`].
549    NotImplemented,
550}
551
552impl core::fmt::Display for Error {
553    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
554        write!(f, "oxideav-vp8: requested operation not implemented")
555    }
556}
557
558impl std::error::Error for Error {}
559
560/// Unified top-level error surface for the crate — re-exported here
561/// from [`error::Vp8Error`] so downstream consumers can write
562/// `use oxideav_vp8::Vp8Error;` without naming the submodule.
563///
564/// See the [`error`] module for the variant shape, conversion adapters,
565/// and the rationale behind the flat-four design.
566pub use error::Vp8Error;
567
568/// Crate-wide [`Result`](core::result::Result) alias — every fallible
569/// entry point that surfaces a [`Vp8Error`] uses this.
570pub use error::Result;
571
572// ── 0.1.13 frame_header / frame_tag re-exports ──
573pub use frame_tag::{
574    FrameTag, FrameType, KeyframeHeader, ParsedHeader, parse_header, parse_keyframe_header,
575};
576
577/// 0.1.13 alias of [`frame_header::Vp8FrameHeader`] under the historical
578/// name `FrameHeader`. The struct is unchanged.
579pub type FrameHeader = frame_header::Vp8FrameHeader;
580
581// ── 0.1.13 encoder surface re-exports ──
582pub use encoder::{
583    AQ_QINDEX_RANGE_MAX, DEFAULT_ADAPTIVE_SEGMENT_THRESHOLDS, DEFAULT_ALT_REF_INTERVAL,
584    DEFAULT_AQ_QINDEX_RANGE, DEFAULT_CHROMA_AWARE_SPATIAL_CHROMA_WEIGHT_X256,
585    DEFAULT_CHROMA_AWARE_SPATIAL_LUMA_WEIGHT_X256, DEFAULT_GOLDEN_INTERVAL,
586    DEFAULT_JOINT_R44R49_PICKER_MAX_ITERS, DEFAULT_KMEANS_CONVERGENCE_THRESHOLD,
587    DEFAULT_KMEANS_SPATIAL_ALPHA_X256, DEFAULT_LAMBDA_LONG_REF_SCALE_X256,
588    DEFAULT_LOOKAHEAD_WINDOW, DEFAULT_NLM_H2, DEFAULT_PSY_RD_STRENGTH, DEFAULT_QINDEX,
589    DEFAULT_SCENE_CUT_BOOST_FRAMES, DEFAULT_SCENE_CUT_QUANT_BOOST, DEFAULT_SCENE_CUT_THRESHOLD,
590    DEFAULT_SEGMENT_LF_DELTAS, DEFAULT_SEGMENT_QUANT_DELTAS, DEFAULT_SIMPLE_LF_MAX_LEVEL,
591    DEFAULT_SPATIAL_LF_N_COL_BANDS, DEFAULT_SPATIAL_LF_N_ROW_BANDS,
592    DEFAULT_SPLIT_MV_JOINT_REFINE_PASSES, FrameComplexity, INTRA_IN_P_BPRED_VARIANCE_THRESHOLD,
593    JOINT_R44R49_PICKER_MAX_ITERS_MAX, KMEANS_SPATIAL_MAX_ITERS, LAMBDA_SCALE_DEFAULT,
594    LoopFilterMode, QP_SENSITIVITY_X8, SCENE_CUT_ABS_FLOOR, SEGMENT_VARIANCE_THRESHOLDS,
595    SPLIT_MV_JOINT_REFINE_PASSES_MAX, Vp8Encoder, Vp8EncoderConfig, Vp8EncoderStats,
596    Vp8TwoPassConfig, Vp8TwoPassEncoder, first_pass_analyze, make_encoder_typed_with_config,
597    make_two_pass_encoder, two_pass_qindex_for_frame, two_pass_qindices,
598};
599
600#[cfg(feature = "registry")]
601pub use encoder::make_encoder_with_config;
602
603/// Crate-root codec id string. Matches the registry id installed by
604/// the `oxideav_core::register!` hook below and the
605/// `oxideav-vp8 0.1.13` constant of the same name.
606pub const CODEC_ID_STR: &str = "vp8";
607
608// ── 0.1.13 registry surface re-exports ──
609#[cfg(feature = "registry")]
610pub use registry::{register_codecs, register_containers};
611
612/// Encode a VP8 keyframe.
613///
614/// Phase 1 of the encoder is implemented: this routes to
615/// [`encode_silent_keyframe`], which emits a structurally-valid
616/// all-zero-quantization key frame for the supplied dimensions
617/// (`_pixels` is currently ignored — the §13 / §14 encode round will
618/// wire in actual pixel-driven residual coding).
619///
620/// Errors are surfaced as the legacy crate-level [`Error`] (currently
621/// only [`Error::NotImplemented`]) for backwards compatibility with
622/// callers that already pattern-match against it. To consume the
623/// richer [`EncodeError`] surface directly, call
624/// [`encode_silent_keyframe`] instead.
625pub fn encode_vp8_keyframe(
626    _pixels: &[u8],
627    width: u32,
628    height: u32,
629) -> core::result::Result<Vec<u8>, Error> {
630    encode_silent_keyframe(SilentKeyframeParams::new(width, height))
631        .map_err(|_| Error::NotImplemented)
632}
633
634/// Install the VP8 codec (decoder) into a runtime context. Delegates to
635/// [`decoder::register`].
636#[cfg(feature = "registry")]
637pub use decoder::register;
638
639#[cfg(feature = "registry")]
640oxideav_core::register!("vp8", register);