diff --git a/crates/ec-vp9/src/decode.rs b/crates/ec-vp9/src/decode.rs index 8818ab01..3c548d92 100644 --- a/crates/ec-vp9/src/decode.rs +++ b/crates/ec-vp9/src/decode.rs @@ -567,25 +567,7 @@ impl Decoder { // Loop filter post-pass: same extents as the keyframe path, but the // per-cell level comes from the block's own reference and mode class // (`get_filter_level`, vp9_loopfilter.c:249). - if hdr.loop_filter.level > 0 { - let p = self.planes.as_mut().expect("frame scratch"); - let (vw, vh) = (mi_cols * 8, mi_rows * 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, - ); - } + self.loop_filter(&grids, hdr); let pic = self.take_picture(hdr); // Reference refresh (spec 8.10 / `swap_frame_buffers`): bit i of @@ -611,6 +593,32 @@ impl Decoder { } } + /// Loop-filter post-pass over the MI-aligned visible planes (level 0 + /// disables it); the extents are not the padded buffer size. + fn loop_filter(&mut self, grids: &LfGrids, hdr: &FrameHeader) { + if hdr.loop_filter.level == 0 { + 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, + ); + } + /// Crop the frame scratch to a [`Picture`]. fn take_picture(&self, hdr: &FrameHeader) -> Picture { crop_picture( @@ -942,8 +950,6 @@ impl Decoder { tx_mode: u8, tail: &[u8], ) -> Result { - let ss_x = hdr.subsampling_x as usize; - let ss_y = hdr.subsampling_y as usize; let mi_cols = hdr.mi_cols() as usize; let mi_rows = hdr.mi_rows() as usize; let tile_cols = 1usize << hdr.tile_info.cols_log2; @@ -978,25 +984,7 @@ impl Decoder { // Loop filter post-pass (level 0 disables it for the frame). // The extents are the MI-aligned VISIBLE plane (libvpx's masks clear // everything past `mi_cols`/`mi_rows`), not the padded buffer size. - if hdr.loop_filter.level > 0 { - let p = self.planes.as_mut().expect("frame scratch"); - let (vw, vh) = (mi_cols * 8, mi_rows * 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, - ); - } + self.loop_filter(&grids, hdr); // `vp9_swap_current_and_last_seg_map` runs only when segmentation is // enabled: this frame's map becomes the next frame's prediction map.