Merge branch 'simplify/u5' into simplify/w1b
Browse files at this commit12 changed files +18 -546
- crates/ec-vp8/examples/dbg_first.rs +0 -18
- crates/ec-vp8/examples/dump_frame.rs +0 -58
- crates/ec-vp8/examples/throughput.rs +0 -38
- crates/ec-vp8/src/bool.rs +0 -24
- crates/ec-vp8/src/decode.rs +0 -56
- crates/ec-vp8/src/header.rs +0 -8
- crates/ec-vp8/src/lib.rs +0 -34
- crates/ec-vp8/src/mc.rs +0 -140
- crates/ec-vp8/src/tokens.rs +17 -43
- crates/ec-vp8/src/transform.rs +0 -127
- crates/ec-vp8/tests/it/main.rs +1 -0
- crates/ec-vp8/tests/malformed_no_panic.rs → crates/ec-vp8/tests/it/malformed_no_panic.rs +0 -0
crates/ec-vp8/examples/dbg_first.rsdeleted+0 -18
| @@ -1,18 +0,0 @@ | |||
| 1 | -// Decode frame 0 of an IVF with decision tracing (EC_VP8_TRACE=1). | ||
| 2 | -use ec_vp8::decode::Decoder; | ||
| 3 | - | ||
| 4 | -fn main() { | ||
| 5 | - let path = std::env::args().nth(1).expect("ivf path"); | ||
| 6 | - let bytes = std::fs::read(path).unwrap(); | ||
| 7 | - let sz = u32::from_le_bytes([bytes[32], bytes[33], bytes[34], bytes[35]]) as usize; | ||
| 8 | - let frame = &bytes[44..44 + sz]; | ||
| 9 | - let mut dec = Decoder::new(); | ||
| 10 | - match dec.decode(frame) { | ||
| 11 | - Ok(Some(pic)) => println!( | ||
| 12 | - "OUT {}x{} y[0..8]={:?}", | ||
| 13 | - pic.width, pic.height, &pic.y[..8] | ||
| 14 | - ), | ||
| 15 | - Ok(None) => println!("OUT hidden"), | ||
| 16 | - Err(e) => println!("OUT ERR {e}"), | ||
| 17 | - } | ||
| 18 | -} | ||
crates/ec-vp8/examples/dump_frame.rsdeleted+0 -58
| @@ -1,58 +0,0 @@ | |||
| 1 | -//! Dump decoded frame N of an IVF as raw yuv420p (ffmpeg-comparable: | ||
| 2 | -//! `ffmpeg -i in.ivf -f rawvideo -pix_fmt yuv420p -` streams the same | ||
| 3 | -//! layout, frame after frame). Usage: `dump_frame <ivf> <frame-index> | ||
| 4 | -//! <out.yuv>`. Decoding stops at the first frame the crate cannot yet | ||
| 5 | -//! decode (e.g. inter frames before M3), reporting it on stderr. | ||
| 6 | - | ||
| 7 | -use ec_vp8::decode::Decoder; | ||
| 8 | - | ||
| 9 | -fn main() { | ||
| 10 | - let args: Vec<String> = std::env::args().collect(); | ||
| 11 | - assert_eq!(args.len(), 4, "usage: dump_frame <ivf> <frame-index> <out.yuv>"); | ||
| 12 | - let want: usize = args[2].parse().expect("frame index"); | ||
| 13 | - let bytes = std::fs::read(&args[1]).unwrap(); | ||
| 14 | - | ||
| 15 | - // IVF: 32-byte file header, then (4-byte LE size, 8-byte pts, data). | ||
| 16 | - let mut frames = Vec::new(); | ||
| 17 | - let mut pos = 32; | ||
| 18 | - while pos + 12 <= bytes.len() { | ||
| 19 | - let sz = u32::from_le_bytes(bytes[pos..pos + 4].try_into().unwrap()) as usize; | ||
| 20 | - frames.push(&bytes[pos + 12..pos + 12 + sz]); | ||
| 21 | - pos += 12 + sz; | ||
| 22 | - } | ||
| 23 | - | ||
| 24 | - let mut dec = Decoder::new(); | ||
| 25 | - for (i, f) in frames.iter().enumerate() { | ||
| 26 | - match dec.decode(f) { | ||
| 27 | - Ok(Some(pic)) if i == want => { | ||
| 28 | - let mut out = Vec::with_capacity( | ||
| 29 | - pic.y.len() + pic.u.len() + pic.v.len(), | ||
| 30 | - ); | ||
| 31 | - for row in 0..usize::from(pic.height) { | ||
| 32 | - let s = row * pic.stride; | ||
| 33 | - out.extend_from_slice(&pic.y[s..s + usize::from(pic.width)]); | ||
| 34 | - } | ||
| 35 | - let (cw, ch) = ( | ||
| 36 | - usize::from(pic.width + 1) / 2, | ||
| 37 | - usize::from(pic.height + 1) / 2, | ||
| 38 | - ); | ||
| 39 | - for plane in [&pic.u, &pic.v] { | ||
| 40 | - for row in 0..ch { | ||
| 41 | - let s = row * pic.uv_stride; | ||
| 42 | - out.extend_from_slice(&plane[s..s + cw]); | ||
| 43 | - } | ||
| 44 | - } | ||
| 45 | - std::fs::write(&args[3], out).unwrap(); | ||
| 46 | - return; | ||
| 47 | - } | ||
| 48 | - Ok(Some(_)) => {} | ||
| 49 | - Ok(None) => {} | ||
| 50 | - Err(e) => { | ||
| 51 | - eprintln!("frame {i}: {e}"); | ||
| 52 | - std::process::exit(1); | ||
| 53 | - } | ||
| 54 | - } | ||
| 55 | - } | ||
| 56 | - eprintln!("no frame {want} decoded"); | ||
| 57 | - std::process::exit(1); | ||
| 58 | -} | ||
crates/ec-vp8/examples/throughput.rsdeleted+0 -38
| @@ -1,38 +0,0 @@ | |||
| 1 | -//! Perf-lane probe: decode an IVF repeatedly, report MP/s and fps. | ||
| 2 | -//! Dims come from the IVF header; usage: `throughput <ivf> [rounds]`. | ||
| 3 | -use ec_vp8::decode::Decoder; | ||
| 4 | -use std::time::Instant; | ||
| 5 | - | ||
| 6 | -fn main() { | ||
| 7 | - let args: Vec<String> = std::env::args().collect(); | ||
| 8 | - let bytes = std::fs::read(&args[1]).unwrap(); | ||
| 9 | - let w = u16::from_le_bytes([bytes[12], bytes[13]]) as u64; | ||
| 10 | - let h = u16::from_le_bytes([bytes[14], bytes[15]]) as u64; | ||
| 11 | - let rounds: u64 = args.get(2).map(|s| s.parse().unwrap()).unwrap_or(20); | ||
| 12 | - let mut frames = Vec::new(); | ||
| 13 | - let mut pos = 32; | ||
| 14 | - while pos + 12 <= bytes.len() { | ||
| 15 | - let sz = u32::from_le_bytes(bytes[pos..pos + 4].try_into().unwrap()) as usize; | ||
| 16 | - frames.push(bytes[pos + 12..pos + 12 + sz].to_vec()); | ||
| 17 | - pos += 12 + sz; | ||
| 18 | - } | ||
| 19 | - let nframes = frames.len(); | ||
| 20 | - let shown = frames.iter().filter(|f| (f[0] >> 4) & 1 == 1).count() as u64; | ||
| 21 | - let t = Instant::now(); | ||
| 22 | - for _ in 0..rounds { | ||
| 23 | - let mut dec = Decoder::new(); | ||
| 24 | - for f in &frames { | ||
| 25 | - dec.decode(f).unwrap(); | ||
| 26 | - } | ||
| 27 | - } | ||
| 28 | - let dt = t.elapsed().as_secs_f64(); | ||
| 29 | - let dec_mpx = rounds as f64 * nframes as f64 * w as f64 * h as f64 / 1e6 / dt; | ||
| 30 | - let out_mpx = rounds as f64 * shown as f64 * w as f64 * h as f64 / 1e6 / dt; | ||
| 31 | - println!( | ||
| 32 | - "{}x{rounds} frames ({shown} shown/round) in {dt:.3}s: \ | ||
| 33 | - decode {dec_mpx:.1} MP/s, output {out_mpx:.1} MP/s \ | ||
| 34 | - ({:.1} shown fps @ {w}x{h})", | ||
| 35 | - nframes, | ||
| 36 | - rounds as f64 * shown as f64 / dt | ||
| 37 | - ); | ||
| 38 | -} | ||
crates/ec-vp8/src/bool.rsmodified+0 -24
| @@ -67,11 +67,6 @@ impl<'a> BoolDecoder<'a> { | |||
| 67 | self.overreads | 67 | self.overreads |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | - /// Offset of the next unread input byte, for desync diagnostics. | ||
| 71 | - pub fn byte_offset(&self) -> usize { | ||
| 72 | - self.pos | ||
| 73 | - } | ||
| 74 | - | ||
| 75 | fn next_byte(&mut self) -> u32 { | 70 | fn next_byte(&mut self) -> u32 { |
| 76 | match self.data.get(self.pos) { | 71 | match self.data.get(self.pos) { |
| 77 | Some(&b) => { | 72 | Some(&b) => { |
| @@ -111,9 +106,6 @@ impl<'a> BoolDecoder<'a> { | |||
| 111 | self.value |= self.next_byte(); | 106 | self.value |= self.next_byte(); |
| 112 | } | 107 | } |
| 113 | } | 108 | } |
| 114 | - if crate::trace_enabled() { | ||
| 115 | - eprintln!("B {} {} {} {}", self.pos, self.bit_count, prob, u8::from(bit)); | ||
| 116 | - } | ||
| 117 | bit | 109 | bit |
| 118 | } | 110 | } |
| 119 | 111 | ||
| @@ -173,22 +165,6 @@ impl<'a> BoolDecoder<'a> { | |||
| 173 | } | 165 | } |
| 174 | } | 166 | } |
| 175 | 167 | ||
| 176 | - /// Decode a tree-coded value, skipping the root's `dct_eob` branch — | ||
| 177 | - /// used for every token after a `DCT_0`, since EOB cannot follow a | ||
| 178 | - /// zero token (RFC §13.2). `tree` must be the full coefficient tree; | ||
| 179 | - /// decoding starts at interior node 1. | ||
| 180 | - pub fn read_tree_no_root_eob(&mut self, tree: &[i8], probs: &[u8]) -> u8 { | ||
| 181 | - // The coefficient tree's layout puts the EOB leaf at the root's | ||
| 182 | - // left branch; descending the right branch first is exactly | ||
| 183 | - // "start at the root with a read 1". | ||
| 184 | - let mut i: i32 = i32::from(tree[1]); // interior node reached on the "1" branch | ||
| 185 | - while { | ||
| 186 | - let b = self.read_bool(probs[(i >> 1) as usize]); | ||
| 187 | - i = i32::from(tree[(i + i32::from(b as i8)) as usize]); | ||
| 188 | - i > 0 | ||
| 189 | - } {} | ||
| 190 | - (-i) as u8 | ||
| 191 | - } | ||
| 192 | } | 168 | } |
| 193 | 169 | ||
| 194 | /// The RFC 6386 §7.3 reference `bool_encoder`, test-only: it lets the tests | 170 | /// The RFC 6386 §7.3 reference `bool_encoder`, test-only: it lets the tests |
crates/ec-vp8/src/decode.rsmodified+0 -56
| @@ -396,9 +396,6 @@ impl Decoder { | |||
| 396 | // `r` (0-based) reads partition `r % n` like the reference. | 396 | // `r` (0-based) reads partition `r % n` like the reference. |
| 397 | let part = (row - 1) % partitions.len(); | 397 | let part = (row - 1) % partitions.len(); |
| 398 | for col in 1..=self.mb_cols { | 398 | for col in 1..=self.mb_cols { |
| 399 | - if crate::trace_enabled() { | ||
| 400 | - eprintln!("M {} {}", row - 1, col - 1); | ||
| 401 | - } | ||
| 402 | let mb = self.mbi(row, col).clone(); | 399 | let mb = self.mbi(row, col).clone(); |
| 403 | let has_y2 = mb.has_y2(); | 400 | let has_y2 = mb.has_y2(); |
| 404 | let seg_i = usize::from(header.segmentation.enabled) * usize::from(mb.segment_id); | 401 | let seg_i = usize::from(header.segmentation.enabled) * usize::from(mb.segment_id); |
| @@ -411,9 +408,6 @@ impl Decoder { | |||
| 411 | y2_dc: dq.y2_dc, | 408 | y2_dc: dq.y2_dc, |
| 412 | y2_ac: dq.y2_ac, | 409 | y2_ac: dq.y2_ac, |
| 413 | }; | 410 | }; |
| 414 | - if crate::trace_enabled() { | ||
| 415 | - eprintln!("T {} {} hy2={}", row - 1, col - 1, has_y2); | ||
| 416 | - } | ||
| 417 | let probs = self.state.coeff_probs; | 411 | let probs = self.state.coeff_probs; |
| 418 | let coeffs = if mb.skip { | 412 | let coeffs = if mb.skip { |
| 419 | tokens::skip_mb_tokens(&mut self.token_ctxs, col - 1, has_y2) | 413 | tokens::skip_mb_tokens(&mut self.token_ctxs, col - 1, has_y2) |
| @@ -606,9 +600,6 @@ impl Decoder { | |||
| 606 | self.token_ctxs.reset_above_row(); | 600 | self.token_ctxs.reset_above_row(); |
| 607 | 601 | ||
| 608 | // Phase 1: every mode record of the frame, row-major (§16). | 602 | // Phase 1: every mode record of the frame, row-major (§16). |
| 609 | - if crate::trace_enabled() { | ||
| 610 | - eprintln!("STAGE modes"); | ||
| 611 | - } | ||
| 612 | for row in 1..=self.mb_rows { | 603 | for row in 1..=self.mb_rows { |
| 613 | for col in 1..=self.mb_cols { | 604 | for col in 1..=self.mb_cols { |
| 614 | let mut mb = MbInfo::default(); | 605 | let mut mb = MbInfo::default(); |
| @@ -758,9 +749,6 @@ impl Decoder { | |||
| 758 | let left = self.mv_neighbor(row, col - 1, sign_bias); | 749 | let left = self.mv_neighbor(row, col - 1, sign_bias); |
| 759 | let aboveleft = self.mv_neighbor(row - 1, col - 1, sign_bias); | 750 | let aboveleft = self.mv_neighbor(row - 1, col - 1, sign_bias); |
| 760 | let (mut near_mvs, cnt) = modes::find_near_mvs(above, left, aboveleft, to_bias); | 751 | let (mut near_mvs, cnt) = modes::find_near_mvs(above, left, aboveleft, to_bias); |
| 761 | - if crate::trace_enabled() { | ||
| 762 | - eprintln!("CNT r={} c={} cnt={:?} mvs={:?}", row - 1, col - 1, cnt, near_mvs); | ||
| 763 | - } | ||
| 764 | 752 | ||
| 765 | if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_INTRA] as usize][0]) { | 753 | if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_INTRA] as usize][0]) { |
| 766 | mb.mv_ref = 0; // ZEROMV | 754 | mb.mv_ref = 0; // ZEROMV |
| @@ -868,24 +856,6 @@ impl Decoder { | |||
| 868 | mv | 856 | mv |
| 869 | } | 857 | } |
| 870 | }; | 858 | }; |
| 871 | - if crate::trace_enabled() { | ||
| 872 | - eprintln!( | ||
| 873 | - "SP r={} c={} j={} k={} l=({},{}) a=({},{}) ctx={} mv=({},{}) best=({},{})", | ||
| 874 | - row - 1, | ||
| 875 | - col - 1, | ||
| 876 | - j, | ||
| 877 | - k, | ||
| 878 | - leftmv.0, | ||
| 879 | - leftmv.1, | ||
| 880 | - abovemv.0, | ||
| 881 | - abovemv.1, | ||
| 882 | - ctx, | ||
| 883 | - blockmv.0, | ||
| 884 | - blockmv.1, | ||
| 885 | - best.0, | ||
| 886 | - best.1 | ||
| 887 | - ); | ||
| 888 | - } | ||
| 889 | mb.mv_clamp |= modes::mv_out_of_bounds(blockmv, edges); | 859 | mb.mv_clamp |= modes::mv_out_of_bounds(blockmv, edges); |
| 890 | let count = modes::MBSPLIT_FILL_COUNT[s]; | 860 | let count = modes::MBSPLIT_FILL_COUNT[s]; |
| 891 | for &off in &modes::MBSPLIT_FILL_OFFSET[s][j * count..(j + 1) * count] { | 861 | for &off in &modes::MBSPLIT_FILL_OFFSET[s][j * count..(j + 1) * count] { |
| @@ -911,12 +881,6 @@ impl Decoder { | |||
| 911 | if mb.ref_frame == 0 { | 881 | if mb.ref_frame == 0 { |
| 912 | return self.reconstruct_intra_mb(row, col, mb, coeffs); | 882 | return self.reconstruct_intra_mb(row, col, mb, coeffs); |
| 913 | } | 883 | } |
| 914 | - if crate::trace_enabled() { | ||
| 915 | - eprintln!( | ||
| 916 | - "IMB r={} c={} ref={} mvref={} mv=({},{}) clamp={} skip={}", | ||
| 917 | - row, col, mb.ref_frame, mb.mv_ref, mb.mv.0, mb.mv.1, mb.mv_clamp, mb.skip | ||
| 918 | - ); | ||
| 919 | - } | ||
| 920 | let reff = self.refs[usize::from(mb.ref_frame)] | 884 | let reff = self.refs[usize::from(mb.ref_frame)] |
| 921 | .as_ref() | 885 | .as_ref() |
| 922 | .ok_or_else(|| Error::corrupt("VP8 inter MB refers to an empty reference slot"))?; | 886 | .ok_or_else(|| Error::corrupt("VP8 inter MB refers to an empty reference slot"))?; |
| @@ -1005,14 +969,6 @@ impl Decoder { | |||
| 1005 | &mut pv, 16, 8, 8, self.mc_bilinear, | 969 | &mut pv, 16, 8, 8, self.mc_bilinear, |
| 1006 | ); | 970 | ); |
| 1007 | } | 971 | } |
| 1008 | - if crate::trace_enabled() && row == 0 && col == 0 { | ||
| 1009 | - eprintln!( | ||
| 1010 | - "CHROMA pred_u[0..8]={:?} refu_vis[0..8]={:?} coeffs.u0dcsum={}", | ||
| 1011 | - &pu[0..8], | ||
| 1012 | - &reff.u[MC_BORDER * reff.uv_stride + MC_BORDER..MC_BORDER * reff.uv_stride + MC_BORDER + 8], | ||
| 1013 | - coeffs.u[0].iter().sum::<i16>() | ||
| 1014 | - ); | ||
| 1015 | - } | ||
| 1016 | 972 | ||
| 1017 | // Residual: every block adds onto its MC prediction. | 973 | // Residual: every block adds onto its MC prediction. |
| 1018 | let y_dcs: [i16; 16] = if coeffs.has_y2 { | 974 | let y_dcs: [i16; 16] = if coeffs.has_y2 { |
| @@ -1126,18 +1082,6 @@ impl Decoder { | |||
| 1126 | } else { | 1082 | } else { |
| 1127 | [0; 16] | 1083 | [0; 16] |
| 1128 | }; | 1084 | }; |
| 1129 | - if crate::debug_enabled() { | ||
| 1130 | - eprintln!( | ||
| 1131 | - "MB({row},{col}) ymode={} uv={} y2={:?} y2has={} y0[:4]={:?} eobs24={} dcs={:?}", | ||
| 1132 | - y_mode, | ||
| 1133 | - uv_mode, | ||
| 1134 | - coeffs.y2, | ||
| 1135 | - coeffs.has_y2, | ||
| 1136 | - &coeffs.y[0][..4], | ||
| 1137 | - coeffs.eobs[24], | ||
| 1138 | - &y_dcs[..4] | ||
| 1139 | - ); | ||
| 1140 | - } | ||
| 1141 | 1085 | ||
| 1142 | if y_mode == modes::YMode::BPred.as_u8() { | 1086 | if y_mode == modes::YMode::BPred.as_u8() { |
| 1143 | for b in 0..16usize { | 1087 | for b in 0..16usize { |
crates/ec-vp8/src/header.rsmodified+0 -8
| @@ -396,9 +396,6 @@ impl FrameHeader { | |||
| 396 | 128 | 396 | 128 |
| 397 | }; | 397 | }; |
| 398 | // Interframe-only probability updates. | 398 | // Interframe-only probability updates. |
| 399 | - if crate::trace_enabled() { | ||
| 400 | - eprintln!("STAGE interprobs"); | ||
| 401 | - } | ||
| 402 | let mut ymode_probs_updated = false; | 399 | let mut ymode_probs_updated = false; |
| 403 | let mut uv_mode_probs_updated = false; | 400 | let mut uv_mode_probs_updated = false; |
| 404 | let (prob_intra, prob_last, prob_gf) = if !key { | 401 | let (prob_intra, prob_last, prob_gf) = if !key { |
| @@ -431,11 +428,6 @@ impl FrameHeader { | |||
| 431 | } | 428 | } |
| 432 | } | 429 | } |
| 433 | } | 430 | } |
| 434 | - if crate::trace_enabled() { | ||
| 435 | - eprintln!("YUV ymode = {:?} uv = {:?}", state.ymode_probs, state.uv_mode_probs); | ||
| 436 | - eprintln!("MVT c0 = {:?}", state.mv_probs[0]); | ||
| 437 | - eprintln!("MVT c1 = {:?}", state.mv_probs[1]); | ||
| 438 | - } | ||
| 439 | probs | 431 | probs |
| 440 | } else { | 432 | } else { |
| 441 | (112, 86, 140) // placeholders; only read on inter frames | 433 | (112, 86, 140) // placeholders; only read on inter frames |
crates/ec-vp8/src/lib.rsmodified+0 -34
| @@ -30,37 +30,3 @@ pub mod transform; | |||
| 30 | 30 | ||
| 31 | pub use ec_core::{Error, Result}; | 31 | pub use ec_core::{Error, Result}; |
| 32 | pub use header::PersistedState; | 32 | pub use header::PersistedState; |
| 33 | - | ||
| 34 | -/// Whether `EC_VP8_TRACE` decision tracing is enabled, resolved once per | ||
| 35 | -/// process. A `var_os` per bool read was 46% of the decode profile (each | ||
| 36 | -/// call locks std's ENV lock and allocates); `OnceLock::get_or_init` was | ||
| 37 | -/// no better, so the hot path is a single relaxed atomic load. | ||
| 38 | -pub(crate) fn trace_enabled() -> bool { | ||
| 39 | - use std::sync::atomic::{AtomicU8, Ordering}; | ||
| 40 | - static STATE: AtomicU8 = AtomicU8::new(0); | ||
| 41 | - match STATE.load(Ordering::Relaxed) { | ||
| 42 | - 0 => { | ||
| 43 | - let on = std::env::var_os("EC_VP8_TRACE").is_some(); | ||
| 44 | - STATE.store(if on { 2 } else { 1 }, Ordering::Relaxed); | ||
| 45 | - on | ||
| 46 | - } | ||
| 47 | - 1 => false, | ||
| 48 | - _ => true, | ||
| 49 | - } | ||
| 50 | -} | ||
| 51 | - | ||
| 52 | -/// Whether `EC_VP8_DEBUG` per-macroblock dumps are enabled (same shape as | ||
| 53 | -/// [`trace_enabled`]; the check sits in the per-MB reconstruct path). | ||
| 54 | -pub(crate) fn debug_enabled() -> bool { | ||
| 55 | - use std::sync::atomic::{AtomicU8, Ordering}; | ||
| 56 | - static STATE: AtomicU8 = AtomicU8::new(0); | ||
| 57 | - match STATE.load(Ordering::Relaxed) { | ||
| 58 | - 0 => { | ||
| 59 | - let on = std::env::var_os("EC_VP8_DEBUG").is_some(); | ||
| 60 | - STATE.store(if on { 2 } else { 1 }, Ordering::Relaxed); | ||
| 61 | - on | ||
| 62 | - } | ||
| 63 | - 1 => false, | ||
| 64 | - _ => true, | ||
| 65 | - } | ||
| 66 | -} | ||
crates/ec-vp8/src/mc.rsmodified+0 -140
| @@ -974,146 +974,6 @@ mod tests { | |||
| 974 | } | 974 | } |
| 975 | } | 975 | } |
| 976 | 976 | ||
| 977 | - #[test] | ||
| 978 | - fn sixtap_pure_horizontal_matches_hand_computed_values() { | ||
| 979 | - let p = plane(); | ||
| 980 | - let mut dst = [0u8; 4 * 4]; | ||
| 981 | - | ||
| 982 | - // mv = (0, 4): full-pel start (16, 12), fx = 4, fy = 0. | ||
| 983 | - predict_luma( | ||
| 984 | - &p, STRIDE, BORDER, VIS_W, VIS_H, 16, 12, (0, 4), false, &mut dst, 4, 4, 4, false, | ||
| 985 | - ); | ||
| 986 | - | ||
| 987 | - // Hand-computed from vp8_sub_pel_filters[4] = { 3, -16, 77, 77, -16, 3 } | ||
| 988 | - // and vp8_sub_pel_filters[0] = { 0, 0, 128, 0, 0, 0 } (vertical is the | ||
| 989 | - // exact identity over the clamped horizontal intermediate). | ||
| 990 | - // out[0][0]: taps are visible pixels (12, 14..19) = [183, 106, 2, 87, 75, 198]: | ||
| 991 | - // 183*3 - 106*16 + 2*77 + 87*77 - 75*16 + 198*3 + 64 = 5164 | ||
| 992 | - // 5164 >> 7 = 40, already in 0..=255. | ||
| 993 | - // out[1][2]: taps (13, 17..22) = [153, 188, 219, 13, 86, 194]: | ||
| 994 | - // 153*3 - 188*16 + 219*77 + 13*77 - 86*16 + 194*3 + 64 = 14585 | ||
| 995 | - // 14585 >> 7 = 113. | ||
| 996 | - assert_eq!(dst[0], 40); | ||
| 997 | - assert_eq!(dst[6], 113); | ||
| 998 | - | ||
| 999 | - // Full block against the tap-table reference formula. | ||
| 1000 | - for r in 0..4 { | ||
| 1001 | - for c in 0..4 { | ||
| 1002 | - let taps: Vec<i32> = (0..6) | ||
| 1003 | - .map(|k| i32::from(vis(&p, 16 + c - 2 + k as usize, 12 + r))) | ||
| 1004 | - .collect(); | ||
| 1005 | - let acc: i32 = taps | ||
| 1006 | - .iter() | ||
| 1007 | - .zip(SUB_PEL_FILTERS[4]) | ||
| 1008 | - .map(|(t, f)| t * f) | ||
| 1009 | - .sum::<i32>() | ||
| 1010 | - + 64; | ||
| 1011 | - assert_eq!( | ||
| 1012 | - dst[r * 4 + c], | ||
| 1013 | - (acc >> 7).clamp(0, 255) as u8, | ||
| 1014 | - "out[{r}][{c}] taps={taps:?} acc={acc}" | ||
| 1015 | - ); | ||
| 1016 | - } | ||
| 1017 | - } | ||
| 1018 | - } | ||
| 1019 | - | ||
| 1020 | - #[test] | ||
| 1021 | - fn sixtap_combined_phase_16x16_matches_hand_computed_values() { | ||
| 1022 | - let p = plane(); | ||
| 1023 | - let mut dst = [0u8; 16 * 16]; | ||
| 1024 | - | ||
| 1025 | - // mv = (14, 18): full-pel start (10, 9), fx = 2, fy = 6. | ||
| 1026 | - predict_luma( | ||
| 1027 | - &p, STRIDE, BORDER, VIS_W, VIS_H, 8, 8, (14, 18), false, &mut dst, 16, 16, 16, false, | ||
| 1028 | - ); | ||
| 1029 | - | ||
| 1030 | - // vp8_sub_pel_filters[2] = { 2, -11, 108, 36, -8, 1 }, each | ||
| 1031 | - // intermediate clamped to 0..=255 (e.g. tmp[3][10] taps | ||
| 1032 | - // [75, 190, 18, 15, 104, 40], raw dot -184, -184 >> 7 = -2, clamped 0); | ||
| 1033 | - // vertical pass with vp8_sub_pel_filters[6] = { 1, -8, 36, 108, -11, 2 }. | ||
| 1034 | - // | ||
| 1035 | - // out[0][0]: horizontal taps are visible pixels (7, 8..13), giving the | ||
| 1036 | - // post-clamp intermediate column h_tmp = [41, 186, 229, 210, 95, 185]: | ||
| 1037 | - // 41*1 - 186*8 + 229*36 + 210*108 - 95*11 + 185*2 + 64 = 28866 | ||
| 1038 | - // 28866 >> 7 = 225, already in 0..=255. | ||
| 1039 | - // | ||
| 1040 | - // out[5][9]: horizontal taps are visible pixels (11, 15..20), | ||
| 1041 | - // h_tmp = [205, 8, 14, 189, 108, 4]: | ||
| 1042 | - // 205*1 - 8*8 + 14*36 + 189*108 - 108*11 + 4*2 + 64 = 19941 | ||
| 1043 | - // 19941 >> 7 = 155. | ||
| 1044 | - assert_eq!(dst[0], 225); | ||
| 1045 | - assert_eq!(dst[5 * 16 + 9], 155); | ||
| 1046 | - | ||
| 1047 | - // Full block against the two-pass reference formula. | ||
| 1048 | - let mut tmp = [0i32; 21 * 16]; | ||
| 1049 | - for i in 0..21 { | ||
| 1050 | - for j in 0..16 { | ||
| 1051 | - let acc: i32 = (0..6) | ||
| 1052 | - .map(|k| i32::from(vis(&p, 10 - 2 + j + k, 9 - 2 + i))) | ||
| 1053 | - .zip(SUB_PEL_FILTERS[2]) | ||
| 1054 | - .map(|(t, f)| t * f) | ||
| 1055 | - .sum::<i32>() | ||
| 1056 | - + 64; | ||
| 1057 | - tmp[i * 16 + j] = (acc >> 7).clamp(0, 255); | ||
| 1058 | - } | ||
| 1059 | - } | ||
| 1060 | - for r in 0..16 { | ||
| 1061 | - for c in 0..16 { | ||
| 1062 | - let acc: i32 = (0..6) | ||
| 1063 | - .map(|k| tmp[(r + k) * 16 + c]) | ||
| 1064 | - .zip(SUB_PEL_FILTERS[6]) | ||
| 1065 | - .map(|(t, f)| t * f) | ||
| 1066 | - .sum::<i32>() | ||
| 1067 | - + 64; | ||
| 1068 | - assert_eq!( | ||
| 1069 | - dst[r * 16 + c], | ||
| 1070 | - (acc >> 7).clamp(0, 255) as u8, | ||
| 1071 | - "out[{r}][{c}]" | ||
| 1072 | - ); | ||
| 1073 | - } | ||
| 1074 | - } | ||
| 1075 | - } | ||
| 1076 | - | ||
| 1077 | - #[test] | ||
| 1078 | - fn bilinear_chroma_matches_hand_computed_values() { | ||
| 1079 | - let p = plane(); | ||
| 1080 | - let mut dst = [0u8; 8 * 8]; | ||
| 1081 | - | ||
| 1082 | - // mv = (11, 5): full-pel start (4, 7), fx = 5, fy = 3. | ||
| 1083 | - predict_chroma( | ||
| 1084 | - &p, STRIDE, BORDER, VIS_W, VIS_H, 4, 6, (11, 5), false, &mut dst, 8, 8, 8, true, | ||
| 1085 | - ); | ||
| 1086 | - | ||
| 1087 | - // Horizontal taps { 48, 80 } (phase 5), vertical { 80, 48 } (phase 3), | ||
| 1088 | - // both passes (dot + 64) >> 7, no clamp (provably in range). | ||
| 1089 | - // | ||
| 1090 | - // out[0][0]: tmp[0][0] = (160*48 + 96*80 + 64) >> 7 = 120 from visible | ||
| 1091 | - // pixels (4,7),(5,7); tmp[1][0] = (107*48 + 42*80 + 64) >> 7 = 66 | ||
| 1092 | - // from (4,8),(5,8). | ||
| 1093 | - // 120*80 + 66*48 + 64 = 12832, 12832 >> 7 = 100. | ||
| 1094 | - // out[3][7]: tmp[3][7] = 84, tmp[4][7] = 189; | ||
| 1095 | - // 84*80 + 189*48 + 64 = 15856, 15856 >> 7 = 123. | ||
| 1096 | - assert_eq!(dst[0], 100); | ||
| 1097 | - assert_eq!(dst[3 * 8 + 7], 123); | ||
| 1098 | - | ||
| 1099 | - // Full block against the two-pass reference formula. | ||
| 1100 | - let mut tmp = [0u16; 9 * 8]; | ||
| 1101 | - for i in 0..9 { | ||
| 1102 | - for j in 0..8 { | ||
| 1103 | - tmp[i * 8 + j] = ((i32::from(vis(&p, 4 + j, 7 + i)) * 48 | ||
| 1104 | - + i32::from(vis(&p, 4 + j + 1, 7 + i)) * 80 | ||
| 1105 | - + 64) | ||
| 1106 | - >> 7) as u16; | ||
| 1107 | - } | ||
| 1108 | - } | ||
| 1109 | - for r in 0..8 { | ||
| 1110 | - for c in 0..8 { | ||
| 1111 | - let acc = i32::from(tmp[r * 8 + c]) * 80 + i32::from(tmp[(r + 1) * 8 + c]) * 48 + 64; | ||
| 1112 | - assert_eq!(dst[r * 8 + c], (acc >> 7) as u8, "out[{r}][{c}]"); | ||
| 1113 | - } | ||
| 1114 | - } | ||
| 1115 | - } | ||
| 1116 | - | ||
| 1117 | #[test] | 977 | #[test] |
| 1118 | fn umv_border_clamps_match_libvpx_arithmetic() { | 978 | fn umv_border_clamps_match_libvpx_arithmetic() { |
| 1119 | let p = plane(); | 979 | let p = plane(); |
crates/ec-vp8/src/tokens.rsmodified+17 -43
| @@ -156,75 +156,55 @@ fn get_coeffs( | |||
| 156 | ac_factor: i16, | 156 | ac_factor: i16, |
| 157 | out: &mut [i16; 16], | 157 | out: &mut [i16; 16], |
| 158 | ) -> usize { | 158 | ) -> usize { |
| 159 | - let trace = crate::trace_enabled(); | ||
| 160 | - // One token decision: decode the bool, then — under EC_VP8_TRACE — | ||
| 161 | - // print the consulted (n, band, ctx, prob) and the decoded bit so the | ||
| 162 | - // stream can be diffed read-for-read against scripts/vp8ref_model.py. | ||
| 163 | - macro_rules! g { | ||
| 164 | - ($n:expr, $band:expr, $c:expr, $prob:expr) => {{ | ||
| 165 | - let bit = bc.read_bool($prob); | ||
| 166 | - if trace { | ||
| 167 | - eprintln!( | ||
| 168 | - "G n={} band={} ctx={} prob={} bit={}", | ||
| 169 | - $n, $band, $c, $prob, u8::from(bit) | ||
| 170 | - ); | ||
| 171 | - } | ||
| 172 | - bit | ||
| 173 | - }}; | ||
| 174 | - } | ||
| 175 | let mut n = n0; | 159 | let mut n = n0; |
| 176 | let mut band = BANDS[n0]; | 160 | let mut band = BANDS[n0]; |
| 177 | - let mut c = ctx; | 161 | + let mut p = &probs_t[band as usize][ctx]; |
| 178 | - let mut p = &probs_t[band as usize][c]; | 162 | + if !bc.read_bool(p[0]) { |
| 179 | - if !g!(n, band, c, p[0]) { | ||
| 180 | return 0; // immediate EOB | 163 | return 0; // immediate EOB |
| 181 | } | 164 | } |
| 182 | loop { | 165 | loop { |
| 183 | n += 1; | 166 | n += 1; |
| 184 | let mut v: i32; | 167 | let mut v: i32; |
| 185 | - if !g!(n, band, c, p[1]) { | 168 | + if !bc.read_bool(p[1]) { |
| 186 | // DCT_0: the next decision skips the EOB branch (§13.2) and | 169 | // DCT_0: the next decision skips the EOB branch (§13.2) and |
| 187 | // libvpx forces the context to 0 after a zero token. | 170 | // libvpx forces the context to 0 after a zero token. |
| 188 | - c = 0; | ||
| 189 | band = BANDS[n]; | 171 | band = BANDS[n]; |
| 190 | p = &probs_t[band as usize][0]; | 172 | p = &probs_t[band as usize][0]; |
| 191 | } else { | 173 | } else { |
| 192 | - if !g!(n, band, c, p[2]) { | 174 | + if !bc.read_bool(p[2]) { |
| 193 | - c = 1; | ||
| 194 | band = BANDS[n]; | 175 | band = BANDS[n]; |
| 195 | p = &probs_t[band as usize][1]; | 176 | p = &probs_t[band as usize][1]; |
| 196 | v = 1; | 177 | v = 1; |
| 197 | } else { | 178 | } else { |
| 198 | - if !g!(n, band, c, p[3]) { | 179 | + if !bc.read_bool(p[3]) { |
| 199 | - if !g!(n, band, c, p[4]) { | 180 | + if !bc.read_bool(p[4]) { |
| 200 | v = 2; | 181 | v = 2; |
| 201 | } else { | 182 | } else { |
| 202 | - v = 3 + i32::from(g!(n, band, c, p[5])); | 183 | + v = 3 + i32::from(bc.read_bool(p[5])); |
| 203 | } | 184 | } |
| 204 | } else { | 185 | } else { |
| 205 | - if !g!(n, band, c, p[6]) { | 186 | + if !bc.read_bool(p[6]) { |
| 206 | - if !g!(n, band, c, p[7]) { | 187 | + if !bc.read_bool(p[7]) { |
| 207 | - v = 5 + i32::from(g!(n, band, c, 159u8)); | 188 | + v = 5 + i32::from(bc.read_bool(159u8)); |
| 208 | } else { | 189 | } else { |
| 209 | - v = 7 + 2 * i32::from(g!(n, band, c, 165u8)); | 190 | + v = 7 + 2 * i32::from(bc.read_bool(165u8)); |
| 210 | - v += i32::from(g!(n, band, c, 145u8)); | 191 | + v += i32::from(bc.read_bool(145u8)); |
| 211 | } | 192 | } |
| 212 | } else { | 193 | } else { |
| 213 | - let bit1 = usize::from(g!(n, band, c, p[8])); | 194 | + let bit1 = usize::from(bc.read_bool(p[8])); |
| 214 | - let bit0 = usize::from(g!(n, band, c, p[9 + bit1])); | 195 | + let bit0 = usize::from(bc.read_bool(p[9 + bit1])); |
| 215 | let cat = 2 * bit1 + bit0; | 196 | let cat = 2 * bit1 + bit0; |
| 216 | v = 0; | 197 | v = 0; |
| 217 | for &prob in CAT_EXTRA[cat].iter() { | 198 | for &prob in CAT_EXTRA[cat].iter() { |
| 218 | if prob == 0 { | 199 | if prob == 0 { |
| 219 | break; | 200 | break; |
| 220 | } | 201 | } |
| 221 | - let g = i32::from(g!(n, band, c, prob)); | 202 | + let g = i32::from(bc.read_bool(prob)); |
| 222 | v = v + v + g; | 203 | v = v + v + g; |
| 223 | } | 204 | } |
| 224 | v += 3 + (8 << cat); | 205 | v += 3 + (8 << cat); |
| 225 | } | 206 | } |
| 226 | } | 207 | } |
| 227 | - c = 2; | ||
| 228 | band = BANDS[n]; | 208 | band = BANDS[n]; |
| 229 | p = &probs_t[band as usize][2]; | 209 | p = &probs_t[band as usize][2]; |
| 230 | } | 210 | } |
| @@ -232,14 +212,14 @@ fn get_coeffs( | |||
| 232 | // Sign flag, then dequantize (first coded position is DC). | 212 | // Sign flag, then dequantize (first coded position is DC). |
| 233 | // Shared by the ONE and magnitude paths, exactly like the | 213 | // Shared by the ONE and magnitude paths, exactly like the |
| 234 | // reference walk (libvpx detokenize.c GetCoeffs). | 214 | // reference walk (libvpx detokenize.c GetCoeffs). |
| 235 | - let neg = g!(n, band, c, 128u8); | 215 | + let neg = bc.read_bool(128u8); |
| 236 | let mag = if neg { -v } else { v }; | 216 | let mag = if neg { -v } else { v }; |
| 237 | out[ZIGZAG[n - 1]] = if n - 1 == 0 { | 217 | out[ZIGZAG[n - 1]] = if n - 1 == 0 { |
| 238 | (mag * i32::from(dc_factor)) as i16 | 218 | (mag * i32::from(dc_factor)) as i16 |
| 239 | } else { | 219 | } else { |
| 240 | (mag * i32::from(ac_factor)) as i16 | 220 | (mag * i32::from(ac_factor)) as i16 |
| 241 | }; | 221 | }; |
| 242 | - if n < 16 && !g!(n, band, c, p[0]) { | 222 | + if n < 16 && !bc.read_bool(p[0]) { |
| 243 | return n; // EOB | 223 | return n; // EOB |
| 244 | } | 224 | } |
| 245 | } | 225 | } |
| @@ -269,13 +249,7 @@ pub(crate) fn decode_mb_tokens( | |||
| 269 | let n0 = usize::from($ptype == 0); | 249 | let n0 = usize::from($ptype == 0); |
| 270 | let (l, a) = ctxs.ctx_pair(mb_col, $idx); | 250 | let (l, a) = ctxs.ctx_pair(mb_col, $idx); |
| 271 | let ctx = (usize::from(l) + usize::from(a)).min(2); | 251 | let ctx = (usize::from(l) + usize::from(a)).min(2); |
| 272 | - if crate::trace_enabled() { | ||
| 273 | - eprintln!("TB {} ctx={} l={} a={}", $idx, ctx, l, a); | ||
| 274 | - } | ||
| 275 | let eob = get_coeffs(bc, &probs[$ptype], ctx, n0, $dc, $ac, $slot); | 252 | let eob = get_coeffs(bc, &probs[$ptype], ctx, n0, $dc, $ac, $slot); |
| 276 | - if crate::trace_enabled() { | ||
| 277 | - eprintln!("TBE {} eob={}", $idx, eob); | ||
| 278 | - } | ||
| 279 | out.eobs[$idx] = eob as u8; | 253 | out.eobs[$idx] = eob as u8; |
| 280 | let t = u8::from(eob > 0); | 254 | let t = u8::from(eob > 0); |
| 281 | ctxs.set_ctx(mb_col, $idx, t); | 255 | ctxs.set_ctx(mb_col, $idx, t); |
crates/ec-vp8/src/transform.rsmodified+0 -127
| @@ -131,18 +131,6 @@ pub fn iwht4x4(input: &[i16; 16]) -> [i16; 16] { | |||
| 131 | output | 131 | output |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | -/// One-nonzero-DC shortcut of the inverse WHT | ||
| 135 | -/// (RFC 6386 §14.3 `vp8_short_inv_walsh4x4_1_c`, oracle | ||
| 136 | -/// `vp8_short_inv_walsh4x4_1_c` in `idctllm.c`). | ||
| 137 | -/// | ||
| 138 | -/// When only `input[0]` is non-zero, every Y-subblock DC equals | ||
| 139 | -/// `(input[0] + 3) >> 3`. Bit-identical to `iwht4x4` for such inputs. | ||
| 140 | -#[inline] | ||
| 141 | -pub fn iwht4x4_dc(input: &[i16; 16]) -> [i16; 16] { | ||
| 142 | - let a1 = ((input[0] as i32 + 3) >> 3) as i16; | ||
| 143 | - [a1; 16] | ||
| 144 | -} | ||
| 145 | - | ||
| 146 | /// Full inverse DCT of one dequantized 4x4 coefficient block | 134 | /// Full inverse DCT of one dequantized 4x4 coefficient block |
| 147 | /// (RFC 6386 §14.4; oracle `short_idct4x4llm_c` in `idctllm.c`). | 135 | /// (RFC 6386 §14.4; oracle `short_idct4x4llm_c` in `idctllm.c`). |
| 148 | /// | 136 | /// |
| @@ -211,18 +199,6 @@ pub fn idct4x4(coeffs: &[i16; 16]) -> [i16; 16] { | |||
| 211 | output | 199 | output |
| 212 | } | 200 | } |
| 213 | 201 | ||
| 214 | -/// DC-only inverse DCT shortcut (RFC 6386 §14.4 | ||
| 215 | -/// `vp8_dc_only_idct_add_c` math; oracle `idctllm.c`): when position 0 is | ||
| 216 | -/// the sole non-zero coefficient, every residual pixel is `(dc + 4) >> 3`. | ||
| 217 | -/// | ||
| 218 | -/// Bit-identical to `idct4x4` on such inputs. Not clamped; the caller | ||
| 219 | -/// adds and clamps (or uses [`idct4x4_add`]). | ||
| 220 | -#[inline] | ||
| 221 | -pub fn idct4x4_dc(dc: i16) -> [i16; 16] { | ||
| 222 | - let a1 = ((dc as i32 + 4) >> 3) as i16; | ||
| 223 | - [a1; 16] | ||
| 224 | -} | ||
| 225 | - | ||
| 226 | /// Combined per-block reconstruction kernel (RFC 6386 §14.4/§14.5; oracle | 202 | /// Combined per-block reconstruction kernel (RFC 6386 §14.4/§14.5; oracle |
| 227 | /// `short_idct4x4llm_c` final loop in `idctllm.c`): inverse-transforms | 203 | /// `short_idct4x4llm_c` final loop in `idctllm.c`): inverse-transforms |
| 228 | /// `coeffs` and writes `clamp(predict + residual)` into `recon`. | 204 | /// `coeffs` and writes `clamp(predict + residual)` into `recon`. |
| @@ -305,38 +281,6 @@ pub fn dequant( | |||
| 305 | mod tests { | 281 | mod tests { |
| 306 | use super::*; | 282 | use super::*; |
| 307 | 283 | ||
| 308 | - /// Hand-derived: impulse `input[0] = 8`, all else 0. First pass, the | ||
| 309 | - /// only touched column (0) reads (8,0,0,0): a1 = 8+0 = 8, b1 = 0, | ||
| 310 | - /// c1 = 0, d1 = 8, giving intermediate column 0 = [8,8,8,8]. Second | ||
| 311 | - /// pass, every row reads (8,0,0,0): a2 = b2 = c2 = d2 = 8, and | ||
| 312 | - /// (8 + 3) >> 3 = 1. Expected: all 16 outputs are 1. | ||
| 313 | - #[test] | ||
| 314 | - fn iwht_unit_impulse_yields_all_ones() { | ||
| 315 | - let mut input = [0i16; 16]; | ||
| 316 | - input[0] = 8; | ||
| 317 | - assert_eq!(iwht4x4(&input), [1i16; 16]); | ||
| 318 | - } | ||
| 319 | - | ||
| 320 | - /// Hand-derived: impulse `input[5] = 8` (row 1, col 1). First pass, | ||
| 321 | - /// column 1 reads (0,8,0,0): a1 = 0, b1 = 8, c1 = 8, d1 = 0, giving | ||
| 322 | - /// intermediate column 1 = [8, 8, -8, -8]. Second pass, rows 0-1 read | ||
| 323 | - /// (0,8,0,0) → outputs (1, 1, -1, -1); rows 2-3 read (0,-8,0,0) → | ||
| 324 | - /// (-1, -1, 1, 1) — the Hadamard basis pattern for position (1,1). | ||
| 325 | - #[test] | ||
| 326 | - fn iwht_impulse_at_row1_col1_yields_hadamard_pattern() { | ||
| 327 | - let mut input = [0i16; 16]; | ||
| 328 | - input[5] = 8; | ||
| 329 | - assert_eq!( | ||
| 330 | - iwht4x4(&input), | ||
| 331 | - [ | ||
| 332 | - 1, 1, -1, -1, // | ||
| 333 | - 1, 1, -1, -1, // | ||
| 334 | - -1, -1, 1, 1, // | ||
| 335 | - -1, -1, 1, 1, | ||
| 336 | - ] | ||
| 337 | - ); | ||
| 338 | - } | ||
| 339 | - | ||
| 340 | /// Mixed-coefficient oracle: expected values computed with a Python | 284 | /// Mixed-coefficient oracle: expected values computed with a Python |
| 341 | /// model of the exact libvpx integer algorithm (see the model in | 285 | /// model of the exact libvpx integer algorithm (see the model in |
| 342 | /// `idct_mixed_block_matches_oracle` below — the WHT variant is the | 286 | /// `idct_mixed_block_matches_oracle` below — the WHT variant is the |
| @@ -357,49 +301,6 @@ mod tests { | |||
| 357 | ); | 301 | ); |
| 358 | } | 302 | } |
| 359 | 303 | ||
| 360 | - /// The `_dc` shortcut must agree with the full transform whenever | ||
| 361 | - /// only `input[0]` is non-zero — across the whole practical range, | ||
| 362 | - /// including negatives and both i16 extremes (arithmetic shifts are | ||
| 363 | - /// floor rounding for negatives in both C and Rust). | ||
| 364 | - #[test] | ||
| 365 | - fn iwht_dc_shortcut_matches_full_transform() { | ||
| 366 | - for v in [ | ||
| 367 | - 0, | ||
| 368 | - 1, | ||
| 369 | - -1, | ||
| 370 | - 3, | ||
| 371 | - -3, | ||
| 372 | - 8, | ||
| 373 | - -8, | ||
| 374 | - 100, | ||
| 375 | - -100, | ||
| 376 | - 1234, | ||
| 377 | - -4321, | ||
| 378 | - i16::MAX, | ||
| 379 | - i16::MIN, | ||
| 380 | - ] { | ||
| 381 | - let input = { | ||
| 382 | - let mut i = [0i16; 16]; | ||
| 383 | - i[0] = v; | ||
| 384 | - i | ||
| 385 | - }; | ||
| 386 | - assert_eq!(iwht4x4(&input), iwht4x4_dc(&input), "mismatch at dc={v}"); | ||
| 387 | - } | ||
| 388 | - } | ||
| 389 | - | ||
| 390 | - /// §14.4 DC-only math: input [40, 0, ...] gives every pixel | ||
| 391 | - /// (40 + 4) >> 3 = 5. | ||
| 392 | - #[test] | ||
| 393 | - fn idct_dc_only_40_yields_five() { | ||
| 394 | - let coeffs = { | ||
| 395 | - let mut c = [0i16; 16]; | ||
| 396 | - c[0] = 40; | ||
| 397 | - c | ||
| 398 | - }; | ||
| 399 | - assert_eq!(idct4x4(&coeffs), [5i16; 16]); | ||
| 400 | - assert_eq!(idct4x4_dc(40), [5i16; 16]); | ||
| 401 | - } | ||
| 402 | - | ||
| 403 | /// Mixed-coefficient oracle. The Python model below is a line-for-line | 304 | /// Mixed-coefficient oracle. The Python model below is a line-for-line |
| 404 | /// transcription of libvpx `short_idct4x4llm_c` (same integer math, | 305 | /// transcription of libvpx `short_idct4x4llm_c` (same integer math, |
| 405 | /// `short` truncation between passes via `s16`); running it on | 306 | /// `short` truncation between passes via `s16`); running it on |
| @@ -446,34 +347,6 @@ mod tests { | |||
| 446 | ); | 347 | ); |
| 447 | } | 348 | } |
| 448 | 349 | ||
| 449 | - /// The DC-only shortcut must equal the full transform for any value | ||
| 450 | - /// at coefficient position 0 (with the rest zero), including the i16 | ||
| 451 | - /// extremes where the intermediate still fits. | ||
| 452 | - #[test] | ||
| 453 | - fn idct_dc_shortcut_matches_full_transform() { | ||
| 454 | - for v in [ | ||
| 455 | - 0, | ||
| 456 | - 1, | ||
| 457 | - -1, | ||
| 458 | - 8, | ||
| 459 | - -8, | ||
| 460 | - 40, | ||
| 461 | - -40, | ||
| 462 | - 100, | ||
| 463 | - -100, | ||
| 464 | - 4088, | ||
| 465 | - i16::MAX, | ||
| 466 | - i16::MIN, | ||
| 467 | - ] { | ||
| 468 | - let coeffs = { | ||
| 469 | - let mut c = [0i16; 16]; | ||
| 470 | - c[0] = v; | ||
| 471 | - c | ||
| 472 | - }; | ||
| 473 | - assert_eq!(idct4x4(&coeffs), idct4x4_dc(v), "mismatch at dc={v}"); | ||
| 474 | - } | ||
| 475 | - } | ||
| 476 | - | ||
| 477 | /// §14.5: `idct4x4_add` is `clamp255(predict + idct4x4(coeffs))` | 350 | /// §14.5: `idct4x4_add` is `clamp255(predict + idct4x4(coeffs))` |
| 478 | /// pixelwise. With a flat prediction of 100, every output byte must | 351 | /// pixelwise. With a flat prediction of 100, every output byte must |
| 479 | /// be the saturated sum; extreme residuals clamp to 0 and 255. | 352 | /// be the saturated sum; extreme residuals clamp to 0 and 255. |
crates/ec-vp8/tests/it/main.rsmodified+1 -0
| @@ -6,4 +6,5 @@ mod common; | |||
| 6 | mod fuzz_regressions; | 6 | mod fuzz_regressions; |
| 7 | mod header_parse; | 7 | mod header_parse; |
| 8 | mod keyframe_exact; | 8 | mod keyframe_exact; |
| 9 | +mod malformed_no_panic; | ||
| 9 | mod stream_exact; | 10 | mod stream_exact; |
crates/ec-vp8/tests/malformed_no_panic.rs → crates/ec-vp8/tests/it/malformed_no_panic.rsrenamed+0 -0