diff --git a/crates/ec-vp9/src/decode.rs b/crates/ec-vp9/src/decode.rs index 3791035b..6195781b 100644 --- a/crates/ec-vp9/src/decode.rs +++ b/crates/ec-vp9/src/decode.rs @@ -981,157 +981,52 @@ impl Decoder { } /// `decode_partition` (decodeframe.c:1173). - #[allow(clippy::too_many_arguments)] - fn decode_partition( - &mut self, - r: &mut crate::bool::BoolDecoder, - mi: &mut MiState, - ectx: &mut [PlaneContexts; 3], - grids: &mut LfGrids, - level_of_seg: &[[u8; 2]; 8], - hdr: &FrameHeader, - row: usize, - col: usize, - n4: usize, - tile_col_start: usize, - tx_mode: u8, - counts: &mut crate::adapt::Counts, - ) -> Result<()> { - if row >= mi.mi_rows || col >= mi.mi_cols { + fn decode_partition(&mut self, w: &mut TileWalk<'_, '_>, row: usize, col: usize, n4: usize) -> Result<()> { + if row >= w.mi.mi_rows || col >= w.mi.mi_cols { return Ok(()); } let n8 = n4 - 1; let hbs = (1usize << n8) >> 1; - let has_rows = row + hbs < mi.mi_rows; - let has_cols = col + hbs < mi.mi_cols; + let has_rows = row + hbs < w.mi.mi_rows; + let has_cols = col + hbs < w.mi.mi_cols; // libvpx reads the partition symbol at EVERY level INCLUDING 8x8 // (decodeframe.c:1188 runs before the `!hbs` branch): the 8x8 // symbol picks 8x8 / 8x4 / 4x8 / 4x4-split — the sub-8x8 shapes. // Only the 4x4 level has no symbol, and SPLIT recursion never // reaches it (it stops at n4 == 1). let partition = { - let ctx = mi.partition_ctx(row, col, n8 as u32); + let ctx = w.mi.partition_ctx(row, col, n8 as u32); let probs = &self.ctx.partition[ctx]; let p = if has_rows && has_cols { - r.read_tree(&PARTITION_TREE, probs) + w.r.read_tree(&PARTITION_TREE, probs) } else if !has_rows && has_cols { - if r.read_bool(probs[1]) { 3 } else { 1 } + if w.r.read_bool(probs[1]) { 3 } else { 1 } } else if has_rows && !has_cols { - if r.read_bool(probs[2]) { 3 } else { 2 } + if w.r.read_bool(probs[2]) { 3 } else { 2 } } else { 3 }; // libvpx counts the implied SPLIT too (`++counts->partition[ctx][p]`). - counts.partition[ctx][p as usize] += 1; + w.counts.partition[ctx][p as usize] += 1; p }; let bsize = bsize_of_n4(n4); let subsize = SUBSIZE_LOOKUP[partition as usize * 13 + bsize] as usize; if hbs == 0 { - self.decode_block( - r, - mi, - ectx, - grids, - level_of_seg, - hdr, - row, - col, - subsize, - 1, - 1, - tile_col_start, - tx_mode, - counts, - )?; + self.decode_block(w, row, col, subsize, 1, 1)?; } else { match partition { - 0 => self.decode_block( - r, - mi, - ectx, - grids, - level_of_seg, - hdr, - row, - col, - subsize, - n4, - n4, - tile_col_start, - tx_mode, - counts, - )?, + 0 => self.decode_block(w, row, col, subsize, n4, n4)?, 1 => { - self.decode_block( - r, - mi, - ectx, - grids, - level_of_seg, - hdr, - row, - col, - subsize, - n4, - n8, - tile_col_start, - tx_mode, - counts, - )?; + self.decode_block(w, row, col, subsize, n4, n8)?; if has_rows { - self.decode_block( - r, - mi, - ectx, - grids, - level_of_seg, - hdr, - row + hbs, - col, - subsize, - n4, - n8, - tile_col_start, - tx_mode, - counts, - )?; + self.decode_block(w, row + hbs, col, subsize, n4, n8)?; } } 2 => { - self.decode_block( - r, - mi, - ectx, - grids, - level_of_seg, - hdr, - row, - col, - subsize, - n8, - n4, - tile_col_start, - tx_mode, - counts, - )?; + self.decode_block(w, row, col, subsize, n8, n4)?; if has_cols { - self.decode_block( - r, - mi, - ectx, - grids, - level_of_seg, - hdr, - row, - col + hbs, - subsize, - n8, - n4, - tile_col_start, - tx_mode, - counts, - )?; + self.decode_block(w, row, col + hbs, subsize, n8, n4)?; } } _ => { @@ -1141,49 +1036,21 @@ impl Decoder { (row + hbs, col), (row + hbs, col + hbs), ] { - self.decode_partition( - r, - mi, - ectx, - grids, - level_of_seg, - hdr, - rr, - cc, - n8, - tile_col_start, - tx_mode, - counts, - )?; + self.decode_partition(w, rr, cc, n8)?; } } } } if bsize >= 3 && (bsize == 3 || partition != 3) { - mi.update_partition_ctx(row, col, subsize, 1 << n8); + w.mi.update_partition_ctx(row, col, subsize, 1 << n8); } Ok(()) } /// `decode_block` intra path (decodeframe.c:913). - #[allow(clippy::too_many_arguments)] - fn decode_block( - &mut self, - r: &mut crate::bool::BoolDecoder, - mi: &mut MiState, - ectx: &mut [PlaneContexts; 3], - grids: &mut LfGrids, - level_of_seg: &[[u8; 2]; 8], - hdr: &FrameHeader, - row: usize, - col: usize, - sb_type: usize, - bwl: usize, - bhl: usize, - tile_col_start: usize, - tx_mode: u8, - counts: &mut crate::adapt::Counts, - ) -> Result<()> { + fn decode_block(&mut self, w: &mut TileWalk<'_, '_>, row: usize, col: usize, sb_type: usize, bwl: usize, bhl: usize) -> Result<()> { + let TileWalk { r, mi, ectx, grids, level_of_seg, hdr, tile_col_start, tx_mode, counts } = w; + let (level_of_seg, hdr, tile_col_start, tx_mode) = (&*level_of_seg, *hdr, *tile_col_start, *tx_mode); let bw = 1 << (bwl - 1); let bh = 1 << (bhl - 1); let x_mis = bw.min(mi.mi_cols - col); @@ -1918,6 +1785,18 @@ fn interp_filter_of(hdr: &FrameHeader) -> u8 { // the frame; the columns are then copied into the frame in column order. The // counts are sums, so the result does not depend on the worker count. +struct TileWalk<'a, 'd> { + r: &'a mut crate::bool::BoolDecoder<'d>, + mi: &'a mut MiState, + ectx: &'a mut [PlaneContexts; 3], + grids: &'a mut LfGrids, + level_of_seg: &'a [[u8; 2]; 8], + hdr: &'a FrameHeader, + tile_col_start: usize, + tx_mode: u8, + counts: &'a mut crate::adapt::Counts, +} + /// Everything a tile walk reads that is fixed for the whole frame. struct TileJob<'a> { hdr: &'a FrameHeader, @@ -2072,20 +1951,18 @@ impl Decoder { ectx.iter_mut().for_each(|p| p.left = [0; 32]); mi.left_seg = [0; 32]; for sb_col in (col_lo..col_hi).step_by(SB_MI) { - self.decode_partition( - &mut r, - &mut mi, - &mut ectx, - grids, - &job.level_of_seg, + let mut w = TileWalk { + r: &mut r, + mi: &mut mi, + ectx: &mut ectx, + grids: &mut *grids, + level_of_seg: &job.level_of_seg, hdr, - sb_row, - sb_col, - 4, - col_lo, - job.tx_mode, - counts, - )?; + tile_col_start: col_lo, + tx_mode: job.tx_mode, + counts: &mut *counts, + }; + self.decode_partition(&mut w, sb_row, sb_col, 4)?; } } ensure(