diff --git a/crates/ec-vp9/src/decode.rs b/crates/ec-vp9/src/decode.rs index 3c548d92..3791035b 100644 --- a/crates/ec-vp9/src/decode.rs +++ b/crates/ec-vp9/src/decode.rs @@ -71,22 +71,22 @@ pub struct Picture { pub subsampling_y: u8, } -struct Planes { - y: Vec, - u: Vec, - v: Vec, - ys: usize, - uvs: usize, +pub(crate) struct Planes { + pub(crate) y: Vec, + pub(crate) u: Vec, + pub(crate) v: Vec, + pub(crate) ys: usize, + pub(crate) uvs: usize, aw: usize, ah: usize, /// Bits per sample this frame was decoded at. - bd: u8, + pub(crate) bd: u8, /// Chroma horizontal subsampling (`subsampling_x`): 0 for 4:4:4, 1 for /// 4:2:0/4:2:2. - ss_x: usize, + pub(crate) ss_x: usize, /// Chroma vertical subsampling (`subsampling_y`): 0 for 4:4:4/4:2:2, 1 /// for 4:2:0/4:4:0. - ss_y: usize, + pub(crate) ss_y: usize, } /// VP9 level 6.2 caps a picture at 8192x4352 luma samples. Larger frame headers are refused @@ -116,7 +116,7 @@ impl Planes { /// edge decode at FULL size), so the fill only backs the never-written /// padding past the MI extent. Chroma planes are `aw >> ss_x` by /// `ah >> ss_y`; since `aw`/`ah` are 64-multiples the shift is exact. - fn new(aw: usize, ah: usize, bd: u8, ss_x: usize, ss_y: usize) -> Planes { + pub(crate) fn new(aw: usize, ah: usize, bd: u8, ss_x: usize, ss_y: usize) -> Planes { let fill = 1u16 << (bd - 1); let (cw, ch) = (aw >> ss_x, ah >> ss_y); Planes { @@ -600,23 +600,8 @@ impl Decoder { return; } let p = self.planes.as_mut().expect("frame scratch"); - let (ss_x, ss_y) = (hdr.subsampling_x as usize, hdr.subsampling_y as usize); let (vw, vh) = (hdr.mi_cols() as usize * 8, hdr.mi_rows() as usize * 8); - grids.filter_frame( - &mut p.y, - p.ys, - &mut p.u, - &mut p.v, - p.uvs, - vw, - vh, - vw >> ss_x, - vh >> ss_y, - ss_x, - ss_y, - hdr.loop_filter.sharpness, - hdr.bit_depth, - ); + grids.filter_frame(p, vw, vh, hdr.loop_filter.sharpness); } /// Crop the frame scratch to a [`Picture`]. diff --git a/crates/ec-vp9/src/loopfilter.rs b/crates/ec-vp9/src/loopfilter.rs index a7d66a92..8579c9fc 100644 --- a/crates/ec-vp9/src/loopfilter.rs +++ b/crates/ec-vp9/src/loopfilter.rs @@ -75,6 +75,7 @@ const LUMA_ABOVE_TXF: [u64; 4] = [u64::MAX, u64::MAX, 0x00ff00ff00ff00ff, 0x0000 const LUMA_LEFT_BORDER: u64 = 0x1111111111111111; const LUMA_ABOVE_BORDER: u64 = 0x000000ff000000ff; +use crate::decode::Planes; use crate::Sample; /// `signed_char_clamp_high` (`vpx_dsp/loopfilter.c:23`): clamp to @@ -1192,23 +1193,10 @@ impl LfGrids { /// `vp9_loop_filter_frame` (vp9_loopfilter.c:1430): luma always takes the /// ss00 path; chroma takes ss00 for 4:4:4, ss11 for 4:2:0, and the /// non420 slow path otherwise (4:2:2 / 4:4:0). - #[allow(clippy::too_many_arguments)] - pub(crate) fn filter_frame( - &self, - y: &mut [Sample], - stride: usize, - u: &mut [Sample], - v: &mut [Sample], - uv_stride: usize, - y_w: usize, - y_h: usize, - uv_w: usize, - uv_h: usize, - ss_x: usize, - ss_y: usize, - sharpness: u8, - bd: u8, - ) { + pub(crate) fn filter_frame(&self, p: &mut Planes, vw: usize, vh: usize, sharpness: u8) { + let (ss_x, ss_y, bd) = (p.ss_x, p.ss_y, p.bd); + let (uv_w, uv_h) = (vw >> ss_x, vh >> ss_y); + let (stride, uv_stride) = (p.ys, p.uvs); // The three planes are filtered from the same read-only grids and touch // disjoint buffers, so they run concurrently: luma on one thread, both // chroma planes on another. Each plane's edge order is unchanged, so the @@ -1226,8 +1214,8 @@ impl LfGrids { } }; std::thread::scope(|scope| { - scope.spawn(|| chroma(u, v)); - self.filter_ss00_plane(y, stride, y_w, y_h, sharpness, bd); + scope.spawn(|| chroma(&mut p.u, &mut p.v)); + self.filter_ss00_plane(&mut p.y, stride, vw, vh, sharpness, bd); }); } } @@ -1253,9 +1241,10 @@ mod tests { } fn run(g: &LfGrids, y: &mut [Sample]) { - let mut u = vec![128u16; 32 * 32]; - let mut v = vec![128u16; 32 * 32]; - g.filter_frame(y, 64, &mut u, &mut v, 32, 64, 64, 32, 32, 1, 1, 0, 8); + let mut p = Planes::new(64, 64, 8, 1, 1); + p.y.copy_from_slice(y); + g.filter_frame(&mut p, 64, 64, 0); + y.copy_from_slice(&p.y); } /// The luma internal-4x4 horizontal edge fires on the frame's LAST MI row.