diff --git a/crates/ec-vp8/examples/dbg_first.rs b/crates/ec-vp8/examples/dbg_first.rs deleted file mode 100644 index 36e27020..00000000 --- a/crates/ec-vp8/examples/dbg_first.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Decode frame 0 of an IVF with decision tracing (EC_VP8_TRACE=1). -use ec_vp8::decode::Decoder; - -fn main() { - let path = std::env::args().nth(1).expect("ivf path"); - let bytes = std::fs::read(path).unwrap(); - let sz = u32::from_le_bytes([bytes[32], bytes[33], bytes[34], bytes[35]]) as usize; - let frame = &bytes[44..44 + sz]; - let mut dec = Decoder::new(); - match dec.decode(frame) { - Ok(Some(pic)) => println!( - "OUT {}x{} y[0..8]={:?}", - pic.width, pic.height, &pic.y[..8] - ), - Ok(None) => println!("OUT hidden"), - Err(e) => println!("OUT ERR {e}"), - } -} diff --git a/crates/ec-vp8/examples/dump_frame.rs b/crates/ec-vp8/examples/dump_frame.rs deleted file mode 100644 index 31bca7de..00000000 --- a/crates/ec-vp8/examples/dump_frame.rs +++ /dev/null @@ -1,58 +0,0 @@ -//! Dump decoded frame N of an IVF as raw yuv420p (ffmpeg-comparable: -//! `ffmpeg -i in.ivf -f rawvideo -pix_fmt yuv420p -` streams the same -//! layout, frame after frame). Usage: `dump_frame -//! `. Decoding stops at the first frame the crate cannot yet -//! decode (e.g. inter frames before M3), reporting it on stderr. - -use ec_vp8::decode::Decoder; - -fn main() { - let args: Vec = std::env::args().collect(); - assert_eq!(args.len(), 4, "usage: dump_frame "); - let want: usize = args[2].parse().expect("frame index"); - let bytes = std::fs::read(&args[1]).unwrap(); - - // IVF: 32-byte file header, then (4-byte LE size, 8-byte pts, data). - let mut frames = Vec::new(); - let mut pos = 32; - while pos + 12 <= bytes.len() { - let sz = u32::from_le_bytes(bytes[pos..pos + 4].try_into().unwrap()) as usize; - frames.push(&bytes[pos + 12..pos + 12 + sz]); - pos += 12 + sz; - } - - let mut dec = Decoder::new(); - for (i, f) in frames.iter().enumerate() { - match dec.decode(f) { - Ok(Some(pic)) if i == want => { - let mut out = Vec::with_capacity( - pic.y.len() + pic.u.len() + pic.v.len(), - ); - for row in 0..usize::from(pic.height) { - let s = row * pic.stride; - out.extend_from_slice(&pic.y[s..s + usize::from(pic.width)]); - } - let (cw, ch) = ( - usize::from(pic.width + 1) / 2, - usize::from(pic.height + 1) / 2, - ); - for plane in [&pic.u, &pic.v] { - for row in 0..ch { - let s = row * pic.uv_stride; - out.extend_from_slice(&plane[s..s + cw]); - } - } - std::fs::write(&args[3], out).unwrap(); - return; - } - Ok(Some(_)) => {} - Ok(None) => {} - Err(e) => { - eprintln!("frame {i}: {e}"); - std::process::exit(1); - } - } - } - eprintln!("no frame {want} decoded"); - std::process::exit(1); -} diff --git a/crates/ec-vp8/examples/throughput.rs b/crates/ec-vp8/examples/throughput.rs deleted file mode 100644 index dd7b72e4..00000000 --- a/crates/ec-vp8/examples/throughput.rs +++ /dev/null @@ -1,38 +0,0 @@ -//! Perf-lane probe: decode an IVF repeatedly, report MP/s and fps. -//! Dims come from the IVF header; usage: `throughput [rounds]`. -use ec_vp8::decode::Decoder; -use std::time::Instant; - -fn main() { - let args: Vec = std::env::args().collect(); - let bytes = std::fs::read(&args[1]).unwrap(); - let w = u16::from_le_bytes([bytes[12], bytes[13]]) as u64; - let h = u16::from_le_bytes([bytes[14], bytes[15]]) as u64; - let rounds: u64 = args.get(2).map(|s| s.parse().unwrap()).unwrap_or(20); - let mut frames = Vec::new(); - let mut pos = 32; - while pos + 12 <= bytes.len() { - let sz = u32::from_le_bytes(bytes[pos..pos + 4].try_into().unwrap()) as usize; - frames.push(bytes[pos + 12..pos + 12 + sz].to_vec()); - pos += 12 + sz; - } - let nframes = frames.len(); - let shown = frames.iter().filter(|f| (f[0] >> 4) & 1 == 1).count() as u64; - let t = Instant::now(); - for _ in 0..rounds { - let mut dec = Decoder::new(); - for f in &frames { - dec.decode(f).unwrap(); - } - } - let dt = t.elapsed().as_secs_f64(); - let dec_mpx = rounds as f64 * nframes as f64 * w as f64 * h as f64 / 1e6 / dt; - let out_mpx = rounds as f64 * shown as f64 * w as f64 * h as f64 / 1e6 / dt; - println!( - "{}x{rounds} frames ({shown} shown/round) in {dt:.3}s: \ - decode {dec_mpx:.1} MP/s, output {out_mpx:.1} MP/s \ - ({:.1} shown fps @ {w}x{h})", - nframes, - rounds as f64 * shown as f64 / dt - ); -} diff --git a/crates/ec-vp8/src/bool.rs b/crates/ec-vp8/src/bool.rs index b117efe3..82bccdc2 100644 --- a/crates/ec-vp8/src/bool.rs +++ b/crates/ec-vp8/src/bool.rs @@ -67,11 +67,6 @@ impl<'a> BoolDecoder<'a> { self.overreads } - /// Offset of the next unread input byte, for desync diagnostics. - pub fn byte_offset(&self) -> usize { - self.pos - } - fn next_byte(&mut self) -> u32 { match self.data.get(self.pos) { Some(&b) => { @@ -111,9 +106,6 @@ impl<'a> BoolDecoder<'a> { self.value |= self.next_byte(); } } - if crate::trace_enabled() { - eprintln!("B {} {} {} {}", self.pos, self.bit_count, prob, u8::from(bit)); - } bit } @@ -173,22 +165,6 @@ impl<'a> BoolDecoder<'a> { } } - /// Decode a tree-coded value, skipping the root's `dct_eob` branch — - /// used for every token after a `DCT_0`, since EOB cannot follow a - /// zero token (RFC §13.2). `tree` must be the full coefficient tree; - /// decoding starts at interior node 1. - pub fn read_tree_no_root_eob(&mut self, tree: &[i8], probs: &[u8]) -> u8 { - // The coefficient tree's layout puts the EOB leaf at the root's - // left branch; descending the right branch first is exactly - // "start at the root with a read 1". - let mut i: i32 = i32::from(tree[1]); // interior node reached on the "1" branch - while { - let b = self.read_bool(probs[(i >> 1) as usize]); - i = i32::from(tree[(i + i32::from(b as i8)) as usize]); - i > 0 - } {} - (-i) as u8 - } } /// The RFC 6386 §7.3 reference `bool_encoder`, test-only: it lets the tests diff --git a/crates/ec-vp8/src/decode.rs b/crates/ec-vp8/src/decode.rs index f8d30760..792f2001 100644 --- a/crates/ec-vp8/src/decode.rs +++ b/crates/ec-vp8/src/decode.rs @@ -396,9 +396,6 @@ impl Decoder { // `r` (0-based) reads partition `r % n` like the reference. let part = (row - 1) % partitions.len(); for col in 1..=self.mb_cols { - if crate::trace_enabled() { - eprintln!("M {} {}", row - 1, col - 1); - } let mb = self.mbi(row, col).clone(); let has_y2 = mb.has_y2(); let seg_i = usize::from(header.segmentation.enabled) * usize::from(mb.segment_id); @@ -411,9 +408,6 @@ impl Decoder { y2_dc: dq.y2_dc, y2_ac: dq.y2_ac, }; - if crate::trace_enabled() { - eprintln!("T {} {} hy2={}", row - 1, col - 1, has_y2); - } let probs = self.state.coeff_probs; let coeffs = if mb.skip { tokens::skip_mb_tokens(&mut self.token_ctxs, col - 1, has_y2) @@ -606,9 +600,6 @@ impl Decoder { self.token_ctxs.reset_above_row(); // Phase 1: every mode record of the frame, row-major (§16). - if crate::trace_enabled() { - eprintln!("STAGE modes"); - } for row in 1..=self.mb_rows { for col in 1..=self.mb_cols { let mut mb = MbInfo::default(); @@ -758,9 +749,6 @@ impl Decoder { let left = self.mv_neighbor(row, col - 1, sign_bias); let aboveleft = self.mv_neighbor(row - 1, col - 1, sign_bias); let (mut near_mvs, cnt) = modes::find_near_mvs(above, left, aboveleft, to_bias); - if crate::trace_enabled() { - eprintln!("CNT r={} c={} cnt={:?} mvs={:?}", row - 1, col - 1, cnt, near_mvs); - } if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_INTRA] as usize][0]) { mb.mv_ref = 0; // ZEROMV @@ -868,24 +856,6 @@ impl Decoder { mv } }; - if crate::trace_enabled() { - eprintln!( - "SP r={} c={} j={} k={} l=({},{}) a=({},{}) ctx={} mv=({},{}) best=({},{})", - row - 1, - col - 1, - j, - k, - leftmv.0, - leftmv.1, - abovemv.0, - abovemv.1, - ctx, - blockmv.0, - blockmv.1, - best.0, - best.1 - ); - } mb.mv_clamp |= modes::mv_out_of_bounds(blockmv, edges); let count = modes::MBSPLIT_FILL_COUNT[s]; for &off in &modes::MBSPLIT_FILL_OFFSET[s][j * count..(j + 1) * count] { @@ -911,12 +881,6 @@ impl Decoder { if mb.ref_frame == 0 { return self.reconstruct_intra_mb(row, col, mb, coeffs); } - if crate::trace_enabled() { - eprintln!( - "IMB r={} c={} ref={} mvref={} mv=({},{}) clamp={} skip={}", - row, col, mb.ref_frame, mb.mv_ref, mb.mv.0, mb.mv.1, mb.mv_clamp, mb.skip - ); - } let reff = self.refs[usize::from(mb.ref_frame)] .as_ref() .ok_or_else(|| Error::corrupt("VP8 inter MB refers to an empty reference slot"))?; @@ -1005,14 +969,6 @@ impl Decoder { &mut pv, 16, 8, 8, self.mc_bilinear, ); } - if crate::trace_enabled() && row == 0 && col == 0 { - eprintln!( - "CHROMA pred_u[0..8]={:?} refu_vis[0..8]={:?} coeffs.u0dcsum={}", - &pu[0..8], - &reff.u[MC_BORDER * reff.uv_stride + MC_BORDER..MC_BORDER * reff.uv_stride + MC_BORDER + 8], - coeffs.u[0].iter().sum::() - ); - } // Residual: every block adds onto its MC prediction. let y_dcs: [i16; 16] = if coeffs.has_y2 { @@ -1126,18 +1082,6 @@ impl Decoder { } else { [0; 16] }; - if crate::debug_enabled() { - eprintln!( - "MB({row},{col}) ymode={} uv={} y2={:?} y2has={} y0[:4]={:?} eobs24={} dcs={:?}", - y_mode, - uv_mode, - coeffs.y2, - coeffs.has_y2, - &coeffs.y[0][..4], - coeffs.eobs[24], - &y_dcs[..4] - ); - } if y_mode == modes::YMode::BPred.as_u8() { for b in 0..16usize { diff --git a/crates/ec-vp8/src/header.rs b/crates/ec-vp8/src/header.rs index cf34ca69..c681bdcf 100644 --- a/crates/ec-vp8/src/header.rs +++ b/crates/ec-vp8/src/header.rs @@ -396,9 +396,6 @@ impl FrameHeader { 128 }; // Interframe-only probability updates. - if crate::trace_enabled() { - eprintln!("STAGE interprobs"); - } let mut ymode_probs_updated = false; let mut uv_mode_probs_updated = false; let (prob_intra, prob_last, prob_gf) = if !key { @@ -431,11 +428,6 @@ impl FrameHeader { } } } - if crate::trace_enabled() { - eprintln!("YUV ymode = {:?} uv = {:?}", state.ymode_probs, state.uv_mode_probs); - eprintln!("MVT c0 = {:?}", state.mv_probs[0]); - eprintln!("MVT c1 = {:?}", state.mv_probs[1]); - } probs } else { (112, 86, 140) // placeholders; only read on inter frames diff --git a/crates/ec-vp8/src/lib.rs b/crates/ec-vp8/src/lib.rs index f3cbf2a7..8256d463 100644 --- a/crates/ec-vp8/src/lib.rs +++ b/crates/ec-vp8/src/lib.rs @@ -30,37 +30,3 @@ pub mod transform; pub use ec_core::{Error, Result}; pub use header::PersistedState; - -/// Whether `EC_VP8_TRACE` decision tracing is enabled, resolved once per -/// process. A `var_os` per bool read was 46% of the decode profile (each -/// call locks std's ENV lock and allocates); `OnceLock::get_or_init` was -/// no better, so the hot path is a single relaxed atomic load. -pub(crate) fn trace_enabled() -> bool { - use std::sync::atomic::{AtomicU8, Ordering}; - static STATE: AtomicU8 = AtomicU8::new(0); - match STATE.load(Ordering::Relaxed) { - 0 => { - let on = std::env::var_os("EC_VP8_TRACE").is_some(); - STATE.store(if on { 2 } else { 1 }, Ordering::Relaxed); - on - } - 1 => false, - _ => true, - } -} - -/// Whether `EC_VP8_DEBUG` per-macroblock dumps are enabled (same shape as -/// [`trace_enabled`]; the check sits in the per-MB reconstruct path). -pub(crate) fn debug_enabled() -> bool { - use std::sync::atomic::{AtomicU8, Ordering}; - static STATE: AtomicU8 = AtomicU8::new(0); - match STATE.load(Ordering::Relaxed) { - 0 => { - let on = std::env::var_os("EC_VP8_DEBUG").is_some(); - STATE.store(if on { 2 } else { 1 }, Ordering::Relaxed); - on - } - 1 => false, - _ => true, - } -} diff --git a/crates/ec-vp8/src/mc.rs b/crates/ec-vp8/src/mc.rs index d380e006..d610cbd6 100644 --- a/crates/ec-vp8/src/mc.rs +++ b/crates/ec-vp8/src/mc.rs @@ -974,146 +974,6 @@ mod tests { } } - #[test] - fn sixtap_pure_horizontal_matches_hand_computed_values() { - let p = plane(); - let mut dst = [0u8; 4 * 4]; - - // mv = (0, 4): full-pel start (16, 12), fx = 4, fy = 0. - predict_luma( - &p, STRIDE, BORDER, VIS_W, VIS_H, 16, 12, (0, 4), false, &mut dst, 4, 4, 4, false, - ); - - // Hand-computed from vp8_sub_pel_filters[4] = { 3, -16, 77, 77, -16, 3 } - // and vp8_sub_pel_filters[0] = { 0, 0, 128, 0, 0, 0 } (vertical is the - // exact identity over the clamped horizontal intermediate). - // out[0][0]: taps are visible pixels (12, 14..19) = [183, 106, 2, 87, 75, 198]: - // 183*3 - 106*16 + 2*77 + 87*77 - 75*16 + 198*3 + 64 = 5164 - // 5164 >> 7 = 40, already in 0..=255. - // out[1][2]: taps (13, 17..22) = [153, 188, 219, 13, 86, 194]: - // 153*3 - 188*16 + 219*77 + 13*77 - 86*16 + 194*3 + 64 = 14585 - // 14585 >> 7 = 113. - assert_eq!(dst[0], 40); - assert_eq!(dst[6], 113); - - // Full block against the tap-table reference formula. - for r in 0..4 { - for c in 0..4 { - let taps: Vec = (0..6) - .map(|k| i32::from(vis(&p, 16 + c - 2 + k as usize, 12 + r))) - .collect(); - let acc: i32 = taps - .iter() - .zip(SUB_PEL_FILTERS[4]) - .map(|(t, f)| t * f) - .sum::() - + 64; - assert_eq!( - dst[r * 4 + c], - (acc >> 7).clamp(0, 255) as u8, - "out[{r}][{c}] taps={taps:?} acc={acc}" - ); - } - } - } - - #[test] - fn sixtap_combined_phase_16x16_matches_hand_computed_values() { - let p = plane(); - let mut dst = [0u8; 16 * 16]; - - // mv = (14, 18): full-pel start (10, 9), fx = 2, fy = 6. - predict_luma( - &p, STRIDE, BORDER, VIS_W, VIS_H, 8, 8, (14, 18), false, &mut dst, 16, 16, 16, false, - ); - - // vp8_sub_pel_filters[2] = { 2, -11, 108, 36, -8, 1 }, each - // intermediate clamped to 0..=255 (e.g. tmp[3][10] taps - // [75, 190, 18, 15, 104, 40], raw dot -184, -184 >> 7 = -2, clamped 0); - // vertical pass with vp8_sub_pel_filters[6] = { 1, -8, 36, 108, -11, 2 }. - // - // out[0][0]: horizontal taps are visible pixels (7, 8..13), giving the - // post-clamp intermediate column h_tmp = [41, 186, 229, 210, 95, 185]: - // 41*1 - 186*8 + 229*36 + 210*108 - 95*11 + 185*2 + 64 = 28866 - // 28866 >> 7 = 225, already in 0..=255. - // - // out[5][9]: horizontal taps are visible pixels (11, 15..20), - // h_tmp = [205, 8, 14, 189, 108, 4]: - // 205*1 - 8*8 + 14*36 + 189*108 - 108*11 + 4*2 + 64 = 19941 - // 19941 >> 7 = 155. - assert_eq!(dst[0], 225); - assert_eq!(dst[5 * 16 + 9], 155); - - // Full block against the two-pass reference formula. - let mut tmp = [0i32; 21 * 16]; - for i in 0..21 { - for j in 0..16 { - let acc: i32 = (0..6) - .map(|k| i32::from(vis(&p, 10 - 2 + j + k, 9 - 2 + i))) - .zip(SUB_PEL_FILTERS[2]) - .map(|(t, f)| t * f) - .sum::() - + 64; - tmp[i * 16 + j] = (acc >> 7).clamp(0, 255); - } - } - for r in 0..16 { - for c in 0..16 { - let acc: i32 = (0..6) - .map(|k| tmp[(r + k) * 16 + c]) - .zip(SUB_PEL_FILTERS[6]) - .map(|(t, f)| t * f) - .sum::() - + 64; - assert_eq!( - dst[r * 16 + c], - (acc >> 7).clamp(0, 255) as u8, - "out[{r}][{c}]" - ); - } - } - } - - #[test] - fn bilinear_chroma_matches_hand_computed_values() { - let p = plane(); - let mut dst = [0u8; 8 * 8]; - - // mv = (11, 5): full-pel start (4, 7), fx = 5, fy = 3. - predict_chroma( - &p, STRIDE, BORDER, VIS_W, VIS_H, 4, 6, (11, 5), false, &mut dst, 8, 8, 8, true, - ); - - // Horizontal taps { 48, 80 } (phase 5), vertical { 80, 48 } (phase 3), - // both passes (dot + 64) >> 7, no clamp (provably in range). - // - // out[0][0]: tmp[0][0] = (160*48 + 96*80 + 64) >> 7 = 120 from visible - // pixels (4,7),(5,7); tmp[1][0] = (107*48 + 42*80 + 64) >> 7 = 66 - // from (4,8),(5,8). - // 120*80 + 66*48 + 64 = 12832, 12832 >> 7 = 100. - // out[3][7]: tmp[3][7] = 84, tmp[4][7] = 189; - // 84*80 + 189*48 + 64 = 15856, 15856 >> 7 = 123. - assert_eq!(dst[0], 100); - assert_eq!(dst[3 * 8 + 7], 123); - - // Full block against the two-pass reference formula. - let mut tmp = [0u16; 9 * 8]; - for i in 0..9 { - for j in 0..8 { - tmp[i * 8 + j] = ((i32::from(vis(&p, 4 + j, 7 + i)) * 48 - + i32::from(vis(&p, 4 + j + 1, 7 + i)) * 80 - + 64) - >> 7) as u16; - } - } - for r in 0..8 { - for c in 0..8 { - let acc = i32::from(tmp[r * 8 + c]) * 80 + i32::from(tmp[(r + 1) * 8 + c]) * 48 + 64; - assert_eq!(dst[r * 8 + c], (acc >> 7) as u8, "out[{r}][{c}]"); - } - } - } - #[test] fn umv_border_clamps_match_libvpx_arithmetic() { let p = plane(); diff --git a/crates/ec-vp8/src/tokens.rs b/crates/ec-vp8/src/tokens.rs index fa3cd270..d59cd228 100644 --- a/crates/ec-vp8/src/tokens.rs +++ b/crates/ec-vp8/src/tokens.rs @@ -156,75 +156,55 @@ fn get_coeffs( ac_factor: i16, out: &mut [i16; 16], ) -> usize { - let trace = crate::trace_enabled(); - // One token decision: decode the bool, then — under EC_VP8_TRACE — - // print the consulted (n, band, ctx, prob) and the decoded bit so the - // stream can be diffed read-for-read against scripts/vp8ref_model.py. - macro_rules! g { - ($n:expr, $band:expr, $c:expr, $prob:expr) => {{ - let bit = bc.read_bool($prob); - if trace { - eprintln!( - "G n={} band={} ctx={} prob={} bit={}", - $n, $band, $c, $prob, u8::from(bit) - ); - } - bit - }}; - } let mut n = n0; let mut band = BANDS[n0]; - let mut c = ctx; - let mut p = &probs_t[band as usize][c]; - if !g!(n, band, c, p[0]) { + let mut p = &probs_t[band as usize][ctx]; + if !bc.read_bool(p[0]) { return 0; // immediate EOB } loop { n += 1; let mut v: i32; - if !g!(n, band, c, p[1]) { + if !bc.read_bool(p[1]) { // DCT_0: the next decision skips the EOB branch (§13.2) and // libvpx forces the context to 0 after a zero token. - c = 0; band = BANDS[n]; p = &probs_t[band as usize][0]; } else { - if !g!(n, band, c, p[2]) { - c = 1; + if !bc.read_bool(p[2]) { band = BANDS[n]; p = &probs_t[band as usize][1]; v = 1; } else { - if !g!(n, band, c, p[3]) { - if !g!(n, band, c, p[4]) { + if !bc.read_bool(p[3]) { + if !bc.read_bool(p[4]) { v = 2; } else { - v = 3 + i32::from(g!(n, band, c, p[5])); + v = 3 + i32::from(bc.read_bool(p[5])); } } else { - if !g!(n, band, c, p[6]) { - if !g!(n, band, c, p[7]) { - v = 5 + i32::from(g!(n, band, c, 159u8)); + if !bc.read_bool(p[6]) { + if !bc.read_bool(p[7]) { + v = 5 + i32::from(bc.read_bool(159u8)); } else { - v = 7 + 2 * i32::from(g!(n, band, c, 165u8)); - v += i32::from(g!(n, band, c, 145u8)); + v = 7 + 2 * i32::from(bc.read_bool(165u8)); + v += i32::from(bc.read_bool(145u8)); } } else { - let bit1 = usize::from(g!(n, band, c, p[8])); - let bit0 = usize::from(g!(n, band, c, p[9 + bit1])); + let bit1 = usize::from(bc.read_bool(p[8])); + let bit0 = usize::from(bc.read_bool(p[9 + bit1])); let cat = 2 * bit1 + bit0; v = 0; for &prob in CAT_EXTRA[cat].iter() { if prob == 0 { break; } - let g = i32::from(g!(n, band, c, prob)); + let g = i32::from(bc.read_bool(prob)); v = v + v + g; } v += 3 + (8 << cat); } } - c = 2; band = BANDS[n]; p = &probs_t[band as usize][2]; } @@ -232,14 +212,14 @@ fn get_coeffs( // Sign flag, then dequantize (first coded position is DC). // Shared by the ONE and magnitude paths, exactly like the // reference walk (libvpx detokenize.c GetCoeffs). - let neg = g!(n, band, c, 128u8); + let neg = bc.read_bool(128u8); let mag = if neg { -v } else { v }; out[ZIGZAG[n - 1]] = if n - 1 == 0 { (mag * i32::from(dc_factor)) as i16 } else { (mag * i32::from(ac_factor)) as i16 }; - if n < 16 && !g!(n, band, c, p[0]) { + if n < 16 && !bc.read_bool(p[0]) { return n; // EOB } } @@ -269,13 +249,7 @@ pub(crate) fn decode_mb_tokens( let n0 = usize::from($ptype == 0); let (l, a) = ctxs.ctx_pair(mb_col, $idx); let ctx = (usize::from(l) + usize::from(a)).min(2); - if crate::trace_enabled() { - eprintln!("TB {} ctx={} l={} a={}", $idx, ctx, l, a); - } let eob = get_coeffs(bc, &probs[$ptype], ctx, n0, $dc, $ac, $slot); - if crate::trace_enabled() { - eprintln!("TBE {} eob={}", $idx, eob); - } out.eobs[$idx] = eob as u8; let t = u8::from(eob > 0); ctxs.set_ctx(mb_col, $idx, t); diff --git a/crates/ec-vp8/src/transform.rs b/crates/ec-vp8/src/transform.rs index 0bb1f4dd..63acc65a 100644 --- a/crates/ec-vp8/src/transform.rs +++ b/crates/ec-vp8/src/transform.rs @@ -131,18 +131,6 @@ pub fn iwht4x4(input: &[i16; 16]) -> [i16; 16] { output } -/// One-nonzero-DC shortcut of the inverse WHT -/// (RFC 6386 §14.3 `vp8_short_inv_walsh4x4_1_c`, oracle -/// `vp8_short_inv_walsh4x4_1_c` in `idctllm.c`). -/// -/// When only `input[0]` is non-zero, every Y-subblock DC equals -/// `(input[0] + 3) >> 3`. Bit-identical to `iwht4x4` for such inputs. -#[inline] -pub fn iwht4x4_dc(input: &[i16; 16]) -> [i16; 16] { - let a1 = ((input[0] as i32 + 3) >> 3) as i16; - [a1; 16] -} - /// Full inverse DCT of one dequantized 4x4 coefficient block /// (RFC 6386 §14.4; oracle `short_idct4x4llm_c` in `idctllm.c`). /// @@ -211,18 +199,6 @@ pub fn idct4x4(coeffs: &[i16; 16]) -> [i16; 16] { output } -/// DC-only inverse DCT shortcut (RFC 6386 §14.4 -/// `vp8_dc_only_idct_add_c` math; oracle `idctllm.c`): when position 0 is -/// the sole non-zero coefficient, every residual pixel is `(dc + 4) >> 3`. -/// -/// Bit-identical to `idct4x4` on such inputs. Not clamped; the caller -/// adds and clamps (or uses [`idct4x4_add`]). -#[inline] -pub fn idct4x4_dc(dc: i16) -> [i16; 16] { - let a1 = ((dc as i32 + 4) >> 3) as i16; - [a1; 16] -} - /// Combined per-block reconstruction kernel (RFC 6386 §14.4/§14.5; oracle /// `short_idct4x4llm_c` final loop in `idctllm.c`): inverse-transforms /// `coeffs` and writes `clamp(predict + residual)` into `recon`. @@ -305,38 +281,6 @@ pub fn dequant( mod tests { use super::*; - /// Hand-derived: impulse `input[0] = 8`, all else 0. First pass, the - /// only touched column (0) reads (8,0,0,0): a1 = 8+0 = 8, b1 = 0, - /// c1 = 0, d1 = 8, giving intermediate column 0 = [8,8,8,8]. Second - /// pass, every row reads (8,0,0,0): a2 = b2 = c2 = d2 = 8, and - /// (8 + 3) >> 3 = 1. Expected: all 16 outputs are 1. - #[test] - fn iwht_unit_impulse_yields_all_ones() { - let mut input = [0i16; 16]; - input[0] = 8; - assert_eq!(iwht4x4(&input), [1i16; 16]); - } - - /// Hand-derived: impulse `input[5] = 8` (row 1, col 1). First pass, - /// column 1 reads (0,8,0,0): a1 = 0, b1 = 8, c1 = 8, d1 = 0, giving - /// intermediate column 1 = [8, 8, -8, -8]. Second pass, rows 0-1 read - /// (0,8,0,0) → outputs (1, 1, -1, -1); rows 2-3 read (0,-8,0,0) → - /// (-1, -1, 1, 1) — the Hadamard basis pattern for position (1,1). - #[test] - fn iwht_impulse_at_row1_col1_yields_hadamard_pattern() { - let mut input = [0i16; 16]; - input[5] = 8; - assert_eq!( - iwht4x4(&input), - [ - 1, 1, -1, -1, // - 1, 1, -1, -1, // - -1, -1, 1, 1, // - -1, -1, 1, 1, - ] - ); - } - /// Mixed-coefficient oracle: expected values computed with a Python /// model of the exact libvpx integer algorithm (see the model in /// `idct_mixed_block_matches_oracle` below — the WHT variant is the @@ -357,49 +301,6 @@ mod tests { ); } - /// The `_dc` shortcut must agree with the full transform whenever - /// only `input[0]` is non-zero — across the whole practical range, - /// including negatives and both i16 extremes (arithmetic shifts are - /// floor rounding for negatives in both C and Rust). - #[test] - fn iwht_dc_shortcut_matches_full_transform() { - for v in [ - 0, - 1, - -1, - 3, - -3, - 8, - -8, - 100, - -100, - 1234, - -4321, - i16::MAX, - i16::MIN, - ] { - let input = { - let mut i = [0i16; 16]; - i[0] = v; - i - }; - assert_eq!(iwht4x4(&input), iwht4x4_dc(&input), "mismatch at dc={v}"); - } - } - - /// §14.4 DC-only math: input [40, 0, ...] gives every pixel - /// (40 + 4) >> 3 = 5. - #[test] - fn idct_dc_only_40_yields_five() { - let coeffs = { - let mut c = [0i16; 16]; - c[0] = 40; - c - }; - assert_eq!(idct4x4(&coeffs), [5i16; 16]); - assert_eq!(idct4x4_dc(40), [5i16; 16]); - } - /// Mixed-coefficient oracle. The Python model below is a line-for-line /// transcription of libvpx `short_idct4x4llm_c` (same integer math, /// `short` truncation between passes via `s16`); running it on @@ -446,34 +347,6 @@ mod tests { ); } - /// The DC-only shortcut must equal the full transform for any value - /// at coefficient position 0 (with the rest zero), including the i16 - /// extremes where the intermediate still fits. - #[test] - fn idct_dc_shortcut_matches_full_transform() { - for v in [ - 0, - 1, - -1, - 8, - -8, - 40, - -40, - 100, - -100, - 4088, - i16::MAX, - i16::MIN, - ] { - let coeffs = { - let mut c = [0i16; 16]; - c[0] = v; - c - }; - assert_eq!(idct4x4(&coeffs), idct4x4_dc(v), "mismatch at dc={v}"); - } - } - /// §14.5: `idct4x4_add` is `clamp255(predict + idct4x4(coeffs))` /// pixelwise. With a flat prediction of 100, every output byte must /// be the saturated sum; extreme residuals clamp to 0 and 255. diff --git a/crates/ec-vp8/tests/it/main.rs b/crates/ec-vp8/tests/it/main.rs index 0f5a3433..aedebcef 100644 --- a/crates/ec-vp8/tests/it/main.rs +++ b/crates/ec-vp8/tests/it/main.rs @@ -6,4 +6,5 @@ mod common; mod fuzz_regressions; mod header_parse; mod keyframe_exact; +mod malformed_no_panic; mod stream_exact; diff --git a/crates/ec-vp8/tests/malformed_no_panic.rs b/crates/ec-vp8/tests/it/malformed_no_panic.rs similarity index 100% rename from crates/ec-vp8/tests/malformed_no_panic.rs rename to crates/ec-vp8/tests/it/malformed_no_panic.rs