// wai-conformance: int-kernels //! `wai.video.int_motion` with **HALF-PEL** motion compensation — the decoder's //! `predict()` reconstructs sub-pixel block predictions by integer bilinear //! interpolation (`(a+b+1)>>1`, `(a+b+c+d+2)>>2`), gated on the bitstream's //! `mv_precision` field. This clip was encoded from REAL captured footage (a //! sub-pixel camera pan over a photograph), where half-pel measurably shrinks the //! residual vs whole-pel — yet the decode stays byte-exact, so every frame's hash //! is still portable (frame-state-equivalence). Committed vector; never skips. #![cfg(feature = "video_int")] use std::path::PathBuf; use wai::int_video::{decode, fnv1a}; fn dir() -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/vectors/int_video") } fn jload(name: &str) -> serde_json::Value { serde_json::from_slice(&std::fs::read(dir().join(name)).unwrap()).unwrap() } #[test] fn decodes_a_half_pel_real_footage_clip_byte_for_byte() { let bs = jload("video_real_bitstream.json"); let conf = jload("video_real.json"); assert_eq!(bs["mv_precision"].as_i64().unwrap(), 2, "this vector exercises half-pel MC"); // The half-pel decode — bilinear sub-pixel prediction in pure i64, no float — // must reproduce the exact frames the encoder's matching integer interpolation // produced. (If the Rust `predict()` and the Python port disagreed by even one // rounding, a frame hash would diverge here.) let clip = decode(&bs).expect("decode"); let (h, w) = (conf["h"].as_u64().unwrap() as usize, conf["w"].as_u64().unwrap() as usize); let want = conf["frame_hashes"].as_array().unwrap(); assert_eq!((clip.h, clip.w), (h, w)); assert_eq!(clip.frames.len(), want.len(), "frame count"); let mut all = Vec::new(); for (i, frame) in clip.frames.iter().enumerate() { assert_eq!(frame.len(), h * w * 3, "frame {i} size"); let got = format!("{:016x}", fnv1a(frame)); assert_eq!(got, want[i].as_str().unwrap(), "half-pel frame {i} must reproduce its committed hash"); for b in (0..8).map(|k| u8::from_str_radix(&got[k * 2..k * 2 + 2], 16).unwrap()) { all.push(b); } } let clip_hash = format!("{:016x}", fnv1a(&all)); assert_eq!(clip_hash, conf["clip_hash"].as_str().unwrap(), "clip hash"); println!("int_video half-pel: {} frames {h}x{w} (real footage, sub-pixel pan) -> byte-exact, clip {clip_hash}", clip.frames.len()); }