Merge branch 'simplify/s6' into simplify/w2
Browse files at this commit6 changed files +204 -368
- crates/ec-vp9-syntax/src/header.rs +13 -2
- crates/ec-vp9/src/decode.rs +88 -323
- crates/ec-vp9/src/decode/tiles.rs +85 -0
- crates/ec-vp9/src/inter.rs +5 -15
- crates/ec-vp9/src/loopfilter.rs +11 -22
- crates/ec-vp9/src/modes.rs +2 -6
crates/ec-vp9-syntax/src/header.rsmodified+13 -2
| @@ -188,6 +188,17 @@ pub struct SegmentationParams { | |||
| 188 | pub feature_data: [[i16; SEG_LVL_MAX]; MAX_SEGMENTS], | 188 | pub feature_data: [[i16; SEG_LVL_MAX]; MAX_SEGMENTS], |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | +impl SegmentationParams { | ||
| 192 | + /// Whether `feature` (a `SEG_LVL_*` index) is on for `segment_id`. | ||
| 193 | + pub fn feature_active(&self, segment_id: u8, feature: usize) -> bool { | ||
| 194 | + self.enabled | ||
| 195 | + && self | ||
| 196 | + .feature_enabled | ||
| 197 | + .get(segment_id as usize) | ||
| 198 | + .is_some_and(|f| f[feature]) | ||
| 199 | + } | ||
| 200 | +} | ||
| 201 | + | ||
| 191 | /// Tile layout (spec 6.2, `tile_info`). | 202 | /// Tile layout (spec 6.2, `tile_info`). |
| 192 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] | 203 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 193 | pub struct TileInfo { | 204 | pub struct TileInfo { |
| @@ -638,9 +649,9 @@ impl Vp9Parser { | |||
| 638 | subsampling_x: h.subsampling_x, | 649 | subsampling_x: h.subsampling_x, |
| 639 | subsampling_y: h.subsampling_y, | 650 | subsampling_y: h.subsampling_y, |
| 640 | }; | 651 | }; |
| 641 | - for i in 0..NUM_REF_FRAMES { | 652 | + for (i, dst) in self.refs.iter_mut().enumerate() { |
| 642 | if h.refresh_frame_flags & (1 << i) != 0 { | 653 | if h.refresh_frame_flags & (1 << i) != 0 { |
| 643 | - self.refs[i] = slot; | 654 | + *dst = slot; |
| 644 | } | 655 | } |
| 645 | } | 656 | } |
| 646 | } | 657 | } |
crates/ec-vp9/src/decode.rsmodified+88 -323
| @@ -24,8 +24,11 @@ use crate::tokens::{PlaneContexts, decode_coefs, scan_for}; | |||
| 24 | use crate::transform::inverse_transform_add; | 24 | use crate::transform::inverse_transform_add; |
| 25 | use crate::tables::{ensure, corrupt}; | 25 | use crate::tables::{ensure, corrupt}; |
| 26 | use crate::{Error, Result, Sample}; | 26 | use crate::{Error, Result, Sample}; |
| 27 | +use tiles::{copy_mi_cols, copy_plane_cols, frame_aw, frame_ah, new_grids, split_tiles, tile_col_span}; | ||
| 27 | use ec_vp9_syntax::{FrameHeader, FrameType, Vp9Parser, superframe}; | 28 | use ec_vp9_syntax::{FrameHeader, FrameType, Vp9Parser, superframe}; |
| 28 | 29 | ||
| 30 | +mod tiles; | ||
| 31 | + | ||
| 29 | const SB_MI: usize = 8; // a 64x64 superblock in mi (8x8) units | 32 | const SB_MI: usize = 8; // a 64x64 superblock in mi (8x8) units |
| 30 | 33 | ||
| 31 | /// The compressed-header bytes of `frame`. Both sizes come from the input, so | 34 | /// The compressed-header bytes of `frame`. Both sizes come from the input, so |
| @@ -68,22 +71,22 @@ pub struct Picture { | |||
| 68 | pub subsampling_y: u8, | 71 | pub subsampling_y: u8, |
| 69 | } | 72 | } |
| 70 | 73 | ||
| 71 | -struct Planes { | 74 | +pub(crate) struct Planes { |
| 72 | - y: Vec<Sample>, | 75 | + pub(crate) y: Vec<Sample>, |
| 73 | - u: Vec<Sample>, | 76 | + pub(crate) u: Vec<Sample>, |
| 74 | - v: Vec<Sample>, | 77 | + pub(crate) v: Vec<Sample>, |
| 75 | - ys: usize, | 78 | + pub(crate) ys: usize, |
| 76 | - uvs: usize, | 79 | + pub(crate) uvs: usize, |
| 77 | aw: usize, | 80 | aw: usize, |
| 78 | ah: usize, | 81 | ah: usize, |
| 79 | /// Bits per sample this frame was decoded at. | 82 | /// Bits per sample this frame was decoded at. |
| 80 | - bd: u8, | 83 | + pub(crate) bd: u8, |
| 81 | /// Chroma horizontal subsampling (`subsampling_x`): 0 for 4:4:4, 1 for | 84 | /// Chroma horizontal subsampling (`subsampling_x`): 0 for 4:4:4, 1 for |
| 82 | /// 4:2:0/4:2:2. | 85 | /// 4:2:0/4:2:2. |
| 83 | - ss_x: usize, | 86 | + pub(crate) ss_x: usize, |
| 84 | /// Chroma vertical subsampling (`subsampling_y`): 0 for 4:4:4/4:2:2, 1 | 87 | /// Chroma vertical subsampling (`subsampling_y`): 0 for 4:4:4/4:2:2, 1 |
| 85 | /// for 4:2:0/4:4:0. | 88 | /// for 4:2:0/4:4:0. |
| 86 | - ss_y: usize, | 89 | + pub(crate) ss_y: usize, |
| 87 | } | 90 | } |
| 88 | 91 | ||
| 89 | /// VP9 level 6.2 caps a picture at 8192x4352 luma samples. Larger frame headers are refused | 92 | /// VP9 level 6.2 caps a picture at 8192x4352 luma samples. Larger frame headers are refused |
| @@ -113,7 +116,7 @@ impl Planes { | |||
| 113 | /// edge decode at FULL size), so the fill only backs the never-written | 116 | /// edge decode at FULL size), so the fill only backs the never-written |
| 114 | /// padding past the MI extent. Chroma planes are `aw >> ss_x` by | 117 | /// padding past the MI extent. Chroma planes are `aw >> ss_x` by |
| 115 | /// `ah >> ss_y`; since `aw`/`ah` are 64-multiples the shift is exact. | 118 | /// `ah >> ss_y`; since `aw`/`ah` are 64-multiples the shift is exact. |
| 116 | - fn new(aw: usize, ah: usize, bd: u8, ss_x: usize, ss_y: usize) -> Planes { | 119 | + pub(crate) fn new(aw: usize, ah: usize, bd: u8, ss_x: usize, ss_y: usize) -> Planes { |
| 117 | let fill = 1u16 << (bd - 1); | 120 | let fill = 1u16 << (bd - 1); |
| 118 | let (cw, ch) = (aw >> ss_x, ah >> ss_y); | 121 | let (cw, ch) = (aw >> ss_x, ah >> ss_y); |
| 119 | Planes { | 122 | Planes { |
| @@ -261,6 +264,11 @@ struct InterWalk { | |||
| 261 | impl Decoder { | 264 | impl Decoder { |
| 262 | /// Create an empty decoder; the first key frame sets the size. | 265 | /// Create an empty decoder; the first key frame sets the size. |
| 263 | pub fn new() -> Self { | 266 | pub fn new() -> Self { |
| 267 | + Self::with_threads(default_threads()) | ||
| 268 | + } | ||
| 269 | + | ||
| 270 | + /// Create an empty decoder that walks tile columns on `threads` workers. | ||
| 271 | + pub fn with_threads(threads: usize) -> Self { | ||
| 264 | Decoder { | 272 | Decoder { |
| 265 | parser: Vp9Parser::new(), | 273 | parser: Vp9Parser::new(), |
| 266 | ctx: Box::new(FrameContext::new(true)), | 274 | ctx: Box::new(FrameContext::new(true)), |
| @@ -277,7 +285,7 @@ impl Decoder { | |||
| 277 | iw: InterWalk::default(), | 285 | iw: InterWalk::default(), |
| 278 | mc_scratch: Vec::new(), | 286 | mc_scratch: Vec::new(), |
| 279 | mc_temp: vec![0; 64 * 135 + 64 * 64], | 287 | mc_temp: vec![0; 64 * 135 + 64 * 64], |
| 280 | - threads: default_threads(), | 288 | + threads: threads.clamp(1, 64), |
| 281 | } | 289 | } |
| 282 | } | 290 | } |
| 283 | 291 | ||
| @@ -344,14 +352,7 @@ impl Decoder { | |||
| 344 | self.frame_ctxs[hdr.frame_context_idx as usize] = self.ctx.as_ref().clone(); | 352 | self.frame_ctxs[hdr.frame_context_idx as usize] = self.ctx.as_ref().clone(); |
| 345 | } | 353 | } |
| 346 | // Reference refresh (spec 8.10): a keyframe updates all slots. | 354 | // Reference refresh (spec 8.10): a keyframe updates all slots. |
| 347 | - let frame = RefFrame { | 355 | + self.refresh_refs(&hdr, 0xff); |
| 348 | - planes: std::sync::Arc::new(self.planes.take().expect("frame scratch")), | ||
| 349 | - width: hdr.width as u16, | ||
| 350 | - height: hdr.height as u16, | ||
| 351 | - }; | ||
| 352 | - for slot in self.refs.iter_mut() { | ||
| 353 | - *slot = Some(frame.clone()); | ||
| 354 | - } | ||
| 355 | Ok(if hdr.show_frame { Some(pic) } else { None }) | 356 | Ok(if hdr.show_frame { Some(pic) } else { None }) |
| 356 | } | 357 | } |
| 357 | 358 | ||
| @@ -411,17 +412,7 @@ impl Decoder { | |||
| 411 | self.frame_ctxs[0] = self.ctx.as_ref().clone(); | 412 | self.frame_ctxs[0] = self.ctx.as_ref().clone(); |
| 412 | } | 413 | } |
| 413 | // Reference refresh (spec 8.10): only `refresh_frame_flags` slots. | 414 | // Reference refresh (spec 8.10): only `refresh_frame_flags` slots. |
| 414 | - let frame = RefFrame { | 415 | + self.refresh_refs(&hdr, hdr.refresh_frame_flags); |
| 415 | - planes: std::sync::Arc::new(self.planes.take().expect("frame scratch")), | ||
| 416 | - width: hdr.width as u16, | ||
| 417 | - height: hdr.height as u16, | ||
| 418 | - }; | ||
| 419 | - for slot in 0..8 { | ||
| 420 | - if hdr.refresh_frame_flags & (1 << slot) != 0 { | ||
| 421 | - let old = self.refs[slot].replace(frame.clone()); | ||
| 422 | - self.recycle(old); | ||
| 423 | - } | ||
| 424 | - } | ||
| 425 | Ok(if hdr.show_frame { Some(pic) } else { None }) | 416 | Ok(if hdr.show_frame { Some(pic) } else { None }) |
| 426 | } | 417 | } |
| 427 | 418 | ||
| @@ -576,44 +567,41 @@ impl Decoder { | |||
| 576 | // Loop filter post-pass: same extents as the keyframe path, but the | 567 | // Loop filter post-pass: same extents as the keyframe path, but the |
| 577 | // per-cell level comes from the block's own reference and mode class | 568 | // per-cell level comes from the block's own reference and mode class |
| 578 | // (`get_filter_level`, vp9_loopfilter.c:249). | 569 | // (`get_filter_level`, vp9_loopfilter.c:249). |
| 579 | - if hdr.loop_filter.level > 0 { | 570 | + self.loop_filter(&grids, hdr); |
| 580 | - let p = self.planes.as_mut().expect("frame scratch"); | ||
| 581 | - let (vw, vh) = (mi_cols * 8, mi_rows * 8); | ||
| 582 | - grids.filter_frame( | ||
| 583 | - &mut p.y, | ||
| 584 | - p.ys, | ||
| 585 | - &mut p.u, | ||
| 586 | - &mut p.v, | ||
| 587 | - p.uvs, | ||
| 588 | - vw, | ||
| 589 | - vh, | ||
| 590 | - vw >> ss_x, | ||
| 591 | - vh >> ss_y, | ||
| 592 | - ss_x, | ||
| 593 | - ss_y, | ||
| 594 | - hdr.loop_filter.sharpness, | ||
| 595 | - hdr.bit_depth, | ||
| 596 | - ); | ||
| 597 | - } | ||
| 598 | 571 | ||
| 599 | let pic = self.take_picture(hdr); | 572 | let pic = self.take_picture(hdr); |
| 573 | + // Reference refresh (spec 8.10 / `swap_frame_buffers`): bit i of | ||
| 574 | + // `refresh_frame_flags` replaces slot i with the frame just decoded — | ||
| 575 | + // the LOOP-FILTERED frame, which is what a later frame's prediction | ||
| 576 | + // reads. | ||
| 577 | + self.refresh_refs(hdr, hdr.refresh_frame_flags); | ||
| 578 | + Ok(if hdr.show_frame { Some(pic) } else { None }) | ||
| 579 | + } | ||
| 580 | + | ||
| 581 | + /// Move the frame scratch into every slot whose bit is set in `flags`. | ||
| 582 | + fn refresh_refs(&mut self, hdr: &FrameHeader, flags: u8) { | ||
| 600 | let frame = RefFrame { | 583 | let frame = RefFrame { |
| 601 | planes: std::sync::Arc::new(self.planes.take().expect("frame scratch")), | 584 | planes: std::sync::Arc::new(self.planes.take().expect("frame scratch")), |
| 602 | width: hdr.width as u16, | 585 | width: hdr.width as u16, |
| 603 | height: hdr.height as u16, | 586 | height: hdr.height as u16, |
| 604 | }; | 587 | }; |
| 605 | - | ||
| 606 | - // Reference refresh (spec 8.10 / `swap_frame_buffers`): bit i of | ||
| 607 | - // `refresh_frame_flags` replaces slot i with the frame just decoded — | ||
| 608 | - // the LOOP-FILTERED frame, which is what a later frame's prediction | ||
| 609 | - // reads. | ||
| 610 | for slot in 0..8 { | 588 | for slot in 0..8 { |
| 611 | - if hdr.refresh_frame_flags & (1 << slot) != 0 { | 589 | + if flags & (1 << slot) != 0 { |
| 612 | let old = self.refs[slot].replace(frame.clone()); | 590 | let old = self.refs[slot].replace(frame.clone()); |
| 613 | self.recycle(old); | 591 | self.recycle(old); |
| 614 | } | 592 | } |
| 615 | } | 593 | } |
| 616 | - Ok(if hdr.show_frame { Some(pic) } else { None }) | 594 | + } |
| 595 | + | ||
| 596 | + /// Loop-filter post-pass over the MI-aligned visible planes (level 0 | ||
| 597 | + /// disables it); the extents are not the padded buffer size. | ||
| 598 | + fn loop_filter(&mut self, grids: &LfGrids, hdr: &FrameHeader) { | ||
| 599 | + if hdr.loop_filter.level == 0 { | ||
| 600 | + return; | ||
| 601 | + } | ||
| 602 | + let p = self.planes.as_mut().expect("frame scratch"); | ||
| 603 | + let (vw, vh) = (hdr.mi_cols() as usize * 8, hdr.mi_rows() as usize * 8); | ||
| 604 | + grids.filter_frame(p, vw, vh, hdr.loop_filter.sharpness); | ||
| 617 | } | 605 | } |
| 618 | 606 | ||
| 619 | /// Crop the frame scratch to a [`Picture`]. | 607 | /// Crop the frame scratch to a [`Picture`]. |
| @@ -947,8 +935,6 @@ impl Decoder { | |||
| 947 | tx_mode: u8, | 935 | tx_mode: u8, |
| 948 | tail: &[u8], | 936 | tail: &[u8], |
| 949 | ) -> Result<Picture> { | 937 | ) -> Result<Picture> { |
| 950 | - let ss_x = hdr.subsampling_x as usize; | ||
| 951 | - let ss_y = hdr.subsampling_y as usize; | ||
| 952 | let mi_cols = hdr.mi_cols() as usize; | 938 | let mi_cols = hdr.mi_cols() as usize; |
| 953 | let mi_rows = hdr.mi_rows() as usize; | 939 | let mi_rows = hdr.mi_rows() as usize; |
| 954 | let tile_cols = 1usize << hdr.tile_info.cols_log2; | 940 | let tile_cols = 1usize << hdr.tile_info.cols_log2; |
| @@ -983,25 +969,7 @@ impl Decoder { | |||
| 983 | // Loop filter post-pass (level 0 disables it for the frame). | 969 | // Loop filter post-pass (level 0 disables it for the frame). |
| 984 | // The extents are the MI-aligned VISIBLE plane (libvpx's masks clear | 970 | // The extents are the MI-aligned VISIBLE plane (libvpx's masks clear |
| 985 | // everything past `mi_cols`/`mi_rows`), not the padded buffer size. | 971 | // everything past `mi_cols`/`mi_rows`), not the padded buffer size. |
| 986 | - if hdr.loop_filter.level > 0 { | 972 | + self.loop_filter(&grids, hdr); |
| 987 | - let p = self.planes.as_mut().expect("frame scratch"); | ||
| 988 | - let (vw, vh) = (mi_cols * 8, mi_rows * 8); | ||
| 989 | - grids.filter_frame( | ||
| 990 | - &mut p.y, | ||
| 991 | - p.ys, | ||
| 992 | - &mut p.u, | ||
| 993 | - &mut p.v, | ||
| 994 | - p.uvs, | ||
| 995 | - vw, | ||
| 996 | - vh, | ||
| 997 | - vw >> ss_x, | ||
| 998 | - vh >> ss_y, | ||
| 999 | - ss_x, | ||
| 1000 | - ss_y, | ||
| 1001 | - hdr.loop_filter.sharpness, | ||
| 1002 | - hdr.bit_depth, | ||
| 1003 | - ); | ||
| 1004 | - } | ||
| 1005 | 973 | ||
| 1006 | // `vp9_swap_current_and_last_seg_map` runs only when segmentation is | 974 | // `vp9_swap_current_and_last_seg_map` runs only when segmentation is |
| 1007 | // enabled: this frame's map becomes the next frame's prediction map. | 975 | // enabled: this frame's map becomes the next frame's prediction map. |
| @@ -1013,157 +981,52 @@ impl Decoder { | |||
| 1013 | } | 981 | } |
| 1014 | 982 | ||
| 1015 | /// `decode_partition` (decodeframe.c:1173). | 983 | /// `decode_partition` (decodeframe.c:1173). |
| 1016 | - #[allow(clippy::too_many_arguments)] | 984 | + fn decode_partition(&mut self, w: &mut TileWalk<'_, '_>, row: usize, col: usize, n4: usize) -> Result<()> { |
| 1017 | - fn decode_partition( | 985 | + if row >= w.mi.mi_rows || col >= w.mi.mi_cols { |
| 1018 | - &mut self, | ||
| 1019 | - r: &mut crate::bool::BoolDecoder, | ||
| 1020 | - mi: &mut MiState, | ||
| 1021 | - ectx: &mut [PlaneContexts; 3], | ||
| 1022 | - grids: &mut LfGrids, | ||
| 1023 | - level_of_seg: &[[u8; 2]; 8], | ||
| 1024 | - hdr: &FrameHeader, | ||
| 1025 | - row: usize, | ||
| 1026 | - col: usize, | ||
| 1027 | - n4: usize, | ||
| 1028 | - tile_col_start: usize, | ||
| 1029 | - tx_mode: u8, | ||
| 1030 | - counts: &mut crate::adapt::Counts, | ||
| 1031 | - ) -> Result<()> { | ||
| 1032 | - if row >= mi.mi_rows || col >= mi.mi_cols { | ||
| 1033 | return Ok(()); | 986 | return Ok(()); |
| 1034 | } | 987 | } |
| 1035 | let n8 = n4 - 1; | 988 | let n8 = n4 - 1; |
| 1036 | let hbs = (1usize << n8) >> 1; | 989 | let hbs = (1usize << n8) >> 1; |
| 1037 | - let has_rows = row + hbs < mi.mi_rows; | 990 | + let has_rows = row + hbs < w.mi.mi_rows; |
| 1038 | - let has_cols = col + hbs < mi.mi_cols; | 991 | + let has_cols = col + hbs < w.mi.mi_cols; |
| 1039 | // libvpx reads the partition symbol at EVERY level INCLUDING 8x8 | 992 | // libvpx reads the partition symbol at EVERY level INCLUDING 8x8 |
| 1040 | // (decodeframe.c:1188 runs before the `!hbs` branch): the 8x8 | 993 | // (decodeframe.c:1188 runs before the `!hbs` branch): the 8x8 |
| 1041 | // symbol picks 8x8 / 8x4 / 4x8 / 4x4-split — the sub-8x8 shapes. | 994 | // symbol picks 8x8 / 8x4 / 4x8 / 4x4-split — the sub-8x8 shapes. |
| 1042 | // Only the 4x4 level has no symbol, and SPLIT recursion never | 995 | // Only the 4x4 level has no symbol, and SPLIT recursion never |
| 1043 | // reaches it (it stops at n4 == 1). | 996 | // reaches it (it stops at n4 == 1). |
| 1044 | let partition = { | 997 | let partition = { |
| 1045 | - let ctx = mi.partition_ctx(row, col, n8 as u32); | 998 | + let ctx = w.mi.partition_ctx(row, col, n8 as u32); |
| 1046 | let probs = &self.ctx.partition[ctx]; | 999 | let probs = &self.ctx.partition[ctx]; |
| 1047 | let p = if has_rows && has_cols { | 1000 | let p = if has_rows && has_cols { |
| 1048 | - r.read_tree(&PARTITION_TREE, probs) | 1001 | + w.r.read_tree(&PARTITION_TREE, probs) |
| 1049 | } else if !has_rows && has_cols { | 1002 | } else if !has_rows && has_cols { |
| 1050 | - if r.read_bool(probs[1]) { 3 } else { 1 } | 1003 | + if w.r.read_bool(probs[1]) { 3 } else { 1 } |
| 1051 | } else if has_rows && !has_cols { | 1004 | } else if has_rows && !has_cols { |
| 1052 | - if r.read_bool(probs[2]) { 3 } else { 2 } | 1005 | + if w.r.read_bool(probs[2]) { 3 } else { 2 } |
| 1053 | } else { | 1006 | } else { |
| 1054 | 3 | 1007 | 3 |
| 1055 | }; | 1008 | }; |
| 1056 | // libvpx counts the implied SPLIT too (`++counts->partition[ctx][p]`). | 1009 | // libvpx counts the implied SPLIT too (`++counts->partition[ctx][p]`). |
| 1057 | - counts.partition[ctx][p as usize] += 1; | 1010 | + w.counts.partition[ctx][p as usize] += 1; |
| 1058 | p | 1011 | p |
| 1059 | }; | 1012 | }; |
| 1060 | let bsize = bsize_of_n4(n4); | 1013 | let bsize = bsize_of_n4(n4); |
| 1061 | let subsize = SUBSIZE_LOOKUP[partition as usize * 13 + bsize] as usize; | 1014 | let subsize = SUBSIZE_LOOKUP[partition as usize * 13 + bsize] as usize; |
| 1062 | if hbs == 0 { | 1015 | if hbs == 0 { |
| 1063 | - self.decode_block( | 1016 | + self.decode_block(w, row, col, subsize, 1, 1)?; |
| 1064 | - r, | ||
| 1065 | - mi, | ||
| 1066 | - ectx, | ||
| 1067 | - grids, | ||
| 1068 | - level_of_seg, | ||
| 1069 | - hdr, | ||
| 1070 | - row, | ||
| 1071 | - col, | ||
| 1072 | - subsize, | ||
| 1073 | - 1, | ||
| 1074 | - 1, | ||
| 1075 | - tile_col_start, | ||
| 1076 | - tx_mode, | ||
| 1077 | - counts, | ||
| 1078 | - )?; | ||
| 1079 | } else { | 1017 | } else { |
| 1080 | match partition { | 1018 | match partition { |
| 1081 | - 0 => self.decode_block( | 1019 | + 0 => self.decode_block(w, row, col, subsize, n4, n4)?, |
| 1082 | - r, | ||
| 1083 | - mi, | ||
| 1084 | - ectx, | ||
| 1085 | - grids, | ||
| 1086 | - level_of_seg, | ||
| 1087 | - hdr, | ||
| 1088 | - row, | ||
| 1089 | - col, | ||
| 1090 | - subsize, | ||
| 1091 | - n4, | ||
| 1092 | - n4, | ||
| 1093 | - tile_col_start, | ||
| 1094 | - tx_mode, | ||
| 1095 | - counts, | ||
| 1096 | - )?, | ||
| 1097 | 1 => { | 1020 | 1 => { |
| 1098 | - self.decode_block( | 1021 | + self.decode_block(w, row, col, subsize, n4, n8)?; |
| 1099 | - r, | ||
| 1100 | - mi, | ||
| 1101 | - ectx, | ||
| 1102 | - grids, | ||
| 1103 | - level_of_seg, | ||
| 1104 | - hdr, | ||
| 1105 | - row, | ||
| 1106 | - col, | ||
| 1107 | - subsize, | ||
| 1108 | - n4, | ||
| 1109 | - n8, | ||
| 1110 | - tile_col_start, | ||
| 1111 | - tx_mode, | ||
| 1112 | - counts, | ||
| 1113 | - )?; | ||
| 1114 | if has_rows { | 1022 | if has_rows { |
| 1115 | - self.decode_block( | 1023 | + self.decode_block(w, row + hbs, col, subsize, n4, n8)?; |
| 1116 | - r, | ||
| 1117 | - mi, | ||
| 1118 | - ectx, | ||
| 1119 | - grids, | ||
| 1120 | - level_of_seg, | ||
| 1121 | - hdr, | ||
| 1122 | - row + hbs, | ||
| 1123 | - col, | ||
| 1124 | - subsize, | ||
| 1125 | - n4, | ||
| 1126 | - n8, | ||
| 1127 | - tile_col_start, | ||
| 1128 | - tx_mode, | ||
| 1129 | - counts, | ||
| 1130 | - )?; | ||
| 1131 | } | 1024 | } |
| 1132 | } | 1025 | } |
| 1133 | 2 => { | 1026 | 2 => { |
| 1134 | - self.decode_block( | 1027 | + self.decode_block(w, row, col, subsize, n8, n4)?; |
| 1135 | - r, | ||
| 1136 | - mi, | ||
| 1137 | - ectx, | ||
| 1138 | - grids, | ||
| 1139 | - level_of_seg, | ||
| 1140 | - hdr, | ||
| 1141 | - row, | ||
| 1142 | - col, | ||
| 1143 | - subsize, | ||
| 1144 | - n8, | ||
| 1145 | - n4, | ||
| 1146 | - tile_col_start, | ||
| 1147 | - tx_mode, | ||
| 1148 | - counts, | ||
| 1149 | - )?; | ||
| 1150 | if has_cols { | 1028 | if has_cols { |
| 1151 | - self.decode_block( | 1029 | + self.decode_block(w, row, col + hbs, subsize, n8, n4)?; |
| 1152 | - r, | ||
| 1153 | - mi, | ||
| 1154 | - ectx, | ||
| 1155 | - grids, | ||
| 1156 | - level_of_seg, | ||
| 1157 | - hdr, | ||
| 1158 | - row, | ||
| 1159 | - col + hbs, | ||
| 1160 | - subsize, | ||
| 1161 | - n8, | ||
| 1162 | - n4, | ||
| 1163 | - tile_col_start, | ||
| 1164 | - tx_mode, | ||
| 1165 | - counts, | ||
| 1166 | - )?; | ||
| 1167 | } | 1030 | } |
| 1168 | } | 1031 | } |
| 1169 | _ => { | 1032 | _ => { |
| @@ -1173,49 +1036,21 @@ impl Decoder { | |||
| 1173 | (row + hbs, col), | 1036 | (row + hbs, col), |
| 1174 | (row + hbs, col + hbs), | 1037 | (row + hbs, col + hbs), |
| 1175 | ] { | 1038 | ] { |
| 1176 | - self.decode_partition( | 1039 | + self.decode_partition(w, rr, cc, n8)?; |
| 1177 | - r, | ||
| 1178 | - mi, | ||
| 1179 | - ectx, | ||
| 1180 | - grids, | ||
| 1181 | - level_of_seg, | ||
| 1182 | - hdr, | ||
| 1183 | - rr, | ||
| 1184 | - cc, | ||
| 1185 | - n8, | ||
| 1186 | - tile_col_start, | ||
| 1187 | - tx_mode, | ||
| 1188 | - counts, | ||
| 1189 | - )?; | ||
| 1190 | } | 1040 | } |
| 1191 | } | 1041 | } |
| 1192 | } | 1042 | } |
| 1193 | } | 1043 | } |
| 1194 | if bsize >= 3 && (bsize == 3 || partition != 3) { | 1044 | if bsize >= 3 && (bsize == 3 || partition != 3) { |
| 1195 | - mi.update_partition_ctx(row, col, subsize, 1 << n8); | 1045 | + w.mi.update_partition_ctx(row, col, subsize, 1 << n8); |
| 1196 | } | 1046 | } |
| 1197 | Ok(()) | 1047 | Ok(()) |
| 1198 | } | 1048 | } |
| 1199 | 1049 | ||
| 1200 | /// `decode_block` intra path (decodeframe.c:913). | 1050 | /// `decode_block` intra path (decodeframe.c:913). |
| 1201 | - #[allow(clippy::too_many_arguments)] | 1051 | + fn decode_block(&mut self, w: &mut TileWalk<'_, '_>, row: usize, col: usize, sb_type: usize, bwl: usize, bhl: usize) -> Result<()> { |
| 1202 | - fn decode_block( | 1052 | + let TileWalk { r, mi, ectx, grids, level_of_seg, hdr, tile_col_start, tx_mode, counts } = w; |
| 1203 | - &mut self, | 1053 | + let (level_of_seg, hdr, tile_col_start, tx_mode) = (&*level_of_seg, *hdr, *tile_col_start, *tx_mode); |
| 1204 | - r: &mut crate::bool::BoolDecoder, | ||
| 1205 | - mi: &mut MiState, | ||
| 1206 | - ectx: &mut [PlaneContexts; 3], | ||
| 1207 | - grids: &mut LfGrids, | ||
| 1208 | - level_of_seg: &[[u8; 2]; 8], | ||
| 1209 | - hdr: &FrameHeader, | ||
| 1210 | - row: usize, | ||
| 1211 | - col: usize, | ||
| 1212 | - sb_type: usize, | ||
| 1213 | - bwl: usize, | ||
| 1214 | - bhl: usize, | ||
| 1215 | - tile_col_start: usize, | ||
| 1216 | - tx_mode: u8, | ||
| 1217 | - counts: &mut crate::adapt::Counts, | ||
| 1218 | - ) -> Result<()> { | ||
| 1219 | let bw = 1 << (bwl - 1); | 1054 | let bw = 1 << (bwl - 1); |
| 1220 | let bh = 1 << (bhl - 1); | 1055 | let bh = 1 << (bhl - 1); |
| 1221 | let x_mis = bw.min(mi.mi_cols - col); | 1056 | let x_mis = bw.min(mi.mi_cols - col); |
| @@ -1950,6 +1785,18 @@ fn interp_filter_of(hdr: &FrameHeader) -> u8 { | |||
| 1950 | // the frame; the columns are then copied into the frame in column order. The | 1785 | // the frame; the columns are then copied into the frame in column order. The |
| 1951 | // counts are sums, so the result does not depend on the worker count. | 1786 | // counts are sums, so the result does not depend on the worker count. |
| 1952 | 1787 | ||
| 1788 | +struct TileWalk<'a, 'd> { | ||
| 1789 | + r: &'a mut crate::bool::BoolDecoder<'d>, | ||
| 1790 | + mi: &'a mut MiState, | ||
| 1791 | + ectx: &'a mut [PlaneContexts; 3], | ||
| 1792 | + grids: &'a mut LfGrids, | ||
| 1793 | + level_of_seg: &'a [[u8; 2]; 8], | ||
| 1794 | + hdr: &'a FrameHeader, | ||
| 1795 | + tile_col_start: usize, | ||
| 1796 | + tx_mode: u8, | ||
| 1797 | + counts: &'a mut crate::adapt::Counts, | ||
| 1798 | +} | ||
| 1799 | + | ||
| 1953 | /// Everything a tile walk reads that is fixed for the whole frame. | 1800 | /// Everything a tile walk reads that is fixed for the whole frame. |
| 1954 | struct TileJob<'a> { | 1801 | struct TileJob<'a> { |
| 1955 | hdr: &'a FrameHeader, | 1802 | hdr: &'a FrameHeader, |
| @@ -1960,86 +1807,6 @@ struct TileJob<'a> { | |||
| 1960 | tiles: &'a [&'a [u8]], | 1807 | tiles: &'a [&'a [u8]], |
| 1961 | } | 1808 | } |
| 1962 | 1809 | ||
| 1963 | -/// Split the tile payloads (spec 6.4). Every tile but the last carries a | ||
| 1964 | -/// 32-bit big-endian size (libvpx `get_tile_buffer`). | ||
| 1965 | -fn split_tiles(mut data: &[u8], tile_cols: usize, tile_rows: usize) -> Result<Vec<&[u8]>> { | ||
| 1966 | - let mut tiles = Vec::with_capacity(tile_cols * tile_rows); | ||
| 1967 | - for tr in 0..tile_rows { | ||
| 1968 | - for tc in 0..tile_cols { | ||
| 1969 | - let last = tr == tile_rows - 1 && tc == tile_cols - 1; | ||
| 1970 | - if last { | ||
| 1971 | - tiles.push(data); | ||
| 1972 | - } else { | ||
| 1973 | - ensure(data.len() >= 4, "truncated tile size")?; | ||
| 1974 | - let sz = u32::from_be_bytes([data[0], data[1], data[2], data[3]]) as usize; | ||
| 1975 | - data = &data[4..]; | ||
| 1976 | - ensure(data.len() >= sz, "truncated tile data")?; | ||
| 1977 | - tiles.push(&data[..sz]); | ||
| 1978 | - data = &data[sz..]; | ||
| 1979 | - } | ||
| 1980 | - } | ||
| 1981 | - } | ||
| 1982 | - Ok(tiles) | ||
| 1983 | -} | ||
| 1984 | - | ||
| 1985 | -fn new_grids(mi_cols: usize, mi_rows: usize) -> LfGrids { | ||
| 1986 | - LfGrids { | ||
| 1987 | - level8: vec![0; mi_cols * mi_rows], | ||
| 1988 | - blk: vec![(0u8, 0u32, 0u32); mi_cols * mi_rows], | ||
| 1989 | - otx: vec![0; mi_cols * mi_rows], | ||
| 1990 | - skip_inter: vec![false; mi_cols * mi_rows], | ||
| 1991 | - seg: vec![0; mi_cols * mi_rows], | ||
| 1992 | - mi_cols, | ||
| 1993 | - mi_rows, | ||
| 1994 | - } | ||
| 1995 | -} | ||
| 1996 | - | ||
| 1997 | -/// Mode-info column span `[lo, hi)` of tile column `tc` (spec 6.4). | ||
| 1998 | -fn tile_col_span(hdr: &FrameHeader, tc: usize) -> (usize, usize) { | ||
| 1999 | - let mi_cols = hdr.mi_cols() as usize; | ||
| 2000 | - let sb64_cols = mi_cols.div_ceil(SB_MI); | ||
| 2001 | - let log2 = hdr.tile_info.cols_log2; | ||
| 2002 | - let lo = (((sb64_cols * tc) >> log2) * SB_MI).min(mi_cols); | ||
| 2003 | - let hi = (((sb64_cols * (tc + 1)) >> log2) * SB_MI).min(mi_cols); | ||
| 2004 | - (lo, hi) | ||
| 2005 | -} | ||
| 2006 | - | ||
| 2007 | -/// Copy columns `[lo, hi)` of every row of a mode-info array. | ||
| 2008 | -fn copy_mi_cols<T: Copy>(dst: &mut [T], src: &[T], mi_cols: usize, mi_rows: usize, lo: usize, hi: usize) { | ||
| 2009 | - for r in 0..mi_rows { | ||
| 2010 | - let b = r * mi_cols; | ||
| 2011 | - dst[b + lo..b + hi].copy_from_slice(&src[b + lo..b + hi]); | ||
| 2012 | - } | ||
| 2013 | -} | ||
| 2014 | - | ||
| 2015 | -/// Copy the pixel columns of one tile column. The last tile column also owns | ||
| 2016 | -/// the padding past `mi_cols` (a block at the frame edge writes its full size). | ||
| 2017 | -/// Padded (64-multiple) luma width of a frame. | ||
| 2018 | -fn frame_aw(hdr: &FrameHeader) -> usize { | ||
| 2019 | - (hdr.width as usize).div_ceil(64) * 64 | ||
| 2020 | -} | ||
| 2021 | - | ||
| 2022 | -/// Padded (64-multiple) luma height of a frame. | ||
| 2023 | -fn frame_ah(hdr: &FrameHeader) -> usize { | ||
| 2024 | - (hdr.height as usize).div_ceil(64) * 64 | ||
| 2025 | -} | ||
| 2026 | - | ||
| 2027 | -fn copy_plane_cols(dst: &mut Planes, src: &Planes, lo_mi: usize, hi_mi: usize, last: bool) { | ||
| 2028 | - fn rows<T: Copy>(dst: &mut [T], src: &[T], stride: usize, rows: usize, x0: usize, x1: usize) { | ||
| 2029 | - for r in 0..rows { | ||
| 2030 | - let b = r * stride; | ||
| 2031 | - dst[b + x0..b + x1].copy_from_slice(&src[b + x0..b + x1]); | ||
| 2032 | - } | ||
| 2033 | - } | ||
| 2034 | - let x0 = lo_mi * 8; | ||
| 2035 | - let x1 = if last { dst.ys } else { hi_mi * 8 }; | ||
| 2036 | - rows(&mut dst.y, &src.y, dst.ys, dst.ah, x0, x1); | ||
| 2037 | - let (cx0, cx1) = (x0 >> dst.ss_x, if last { dst.uvs } else { x1 >> dst.ss_x }); | ||
| 2038 | - let ch = dst.ah >> dst.ss_y; | ||
| 2039 | - rows(&mut dst.u, &src.u, dst.uvs, ch, cx0, cx1); | ||
| 2040 | - rows(&mut dst.v, &src.v, dst.uvs, ch, cx0, cx1); | ||
| 2041 | -} | ||
| 2042 | - | ||
| 2043 | impl Decoder { | 1810 | impl Decoder { |
| 2044 | /// A frame buffer of this geometry, reusing a spare when one fits. | 1811 | /// A frame buffer of this geometry, reusing a spare when one fits. |
| 2045 | fn frame_planes(&mut self, aw: usize, ah: usize, bd: u8, ss_x: usize, ss_y: usize) -> Planes { | 1812 | fn frame_planes(&mut self, aw: usize, ah: usize, bd: u8, ss_x: usize, ss_y: usize) -> Planes { |
| @@ -2184,20 +1951,18 @@ impl Decoder { | |||
| 2184 | ectx.iter_mut().for_each(|p| p.left = [0; 32]); | 1951 | ectx.iter_mut().for_each(|p| p.left = [0; 32]); |
| 2185 | mi.left_seg = [0; 32]; | 1952 | mi.left_seg = [0; 32]; |
| 2186 | for sb_col in (col_lo..col_hi).step_by(SB_MI) { | 1953 | for sb_col in (col_lo..col_hi).step_by(SB_MI) { |
| 2187 | - self.decode_partition( | 1954 | + let mut w = TileWalk { |
| 2188 | - &mut r, | 1955 | + r: &mut r, |
| 2189 | - &mut mi, | 1956 | + mi: &mut mi, |
| 2190 | - &mut ectx, | 1957 | + ectx: &mut ectx, |
| 2191 | - grids, | 1958 | + grids: &mut *grids, |
| 2192 | - &job.level_of_seg, | 1959 | + level_of_seg: &job.level_of_seg, |
| 2193 | hdr, | 1960 | hdr, |
| 2194 | - sb_row, | 1961 | + tile_col_start: col_lo, |
| 2195 | - sb_col, | 1962 | + tx_mode: job.tx_mode, |
| 2196 | - 4, | 1963 | + counts: &mut *counts, |
| 2197 | - col_lo, | 1964 | + }; |
| 2198 | - job.tx_mode, | 1965 | + self.decode_partition(&mut w, sb_row, sb_col, 4)?; |
| 2199 | - counts, | ||
| 2200 | - )?; | ||
| 2201 | } | 1966 | } |
| 2202 | } | 1967 | } |
| 2203 | ensure( | 1968 | ensure( |
crates/ec-vp9/src/decode/tiles.rsadded+85 -0
| @@ -0,0 +1,85 @@ | |||
| 1 | +use super::{Planes, SB_MI}; | ||
| 2 | +use crate::loopfilter::LfGrids; | ||
| 3 | +use crate::tables::ensure; | ||
| 4 | +use crate::Result; | ||
| 5 | +use ec_vp9_syntax::FrameHeader; | ||
| 6 | + | ||
| 7 | +/// Split the tile payloads (spec 6.4). Every tile but the last carries a | ||
| 8 | +/// 32-bit big-endian size (libvpx `get_tile_buffer`). | ||
| 9 | +pub(super) fn split_tiles(mut data: &[u8], tile_cols: usize, tile_rows: usize) -> Result<Vec<&[u8]>> { | ||
| 10 | + let mut tiles = Vec::with_capacity(tile_cols * tile_rows); | ||
| 11 | + for tr in 0..tile_rows { | ||
| 12 | + for tc in 0..tile_cols { | ||
| 13 | + let last = tr == tile_rows - 1 && tc == tile_cols - 1; | ||
| 14 | + if last { | ||
| 15 | + tiles.push(data); | ||
| 16 | + } else { | ||
| 17 | + ensure(data.len() >= 4, "truncated tile size")?; | ||
| 18 | + let sz = u32::from_be_bytes([data[0], data[1], data[2], data[3]]) as usize; | ||
| 19 | + data = &data[4..]; | ||
| 20 | + ensure(data.len() >= sz, "truncated tile data")?; | ||
| 21 | + tiles.push(&data[..sz]); | ||
| 22 | + data = &data[sz..]; | ||
| 23 | + } | ||
| 24 | + } | ||
| 25 | + } | ||
| 26 | + Ok(tiles) | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +pub(super) fn new_grids(mi_cols: usize, mi_rows: usize) -> LfGrids { | ||
| 30 | + LfGrids { | ||
| 31 | + level8: vec![0; mi_cols * mi_rows], | ||
| 32 | + blk: vec![(0u8, 0u32, 0u32); mi_cols * mi_rows], | ||
| 33 | + otx: vec![0; mi_cols * mi_rows], | ||
| 34 | + skip_inter: vec![false; mi_cols * mi_rows], | ||
| 35 | + seg: vec![0; mi_cols * mi_rows], | ||
| 36 | + mi_cols, | ||
| 37 | + mi_rows, | ||
| 38 | + } | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +/// Mode-info column span `[lo, hi)` of tile column `tc` (spec 6.4). | ||
| 42 | +pub(super) fn tile_col_span(hdr: &FrameHeader, tc: usize) -> (usize, usize) { | ||
| 43 | + let mi_cols = hdr.mi_cols() as usize; | ||
| 44 | + let sb64_cols = mi_cols.div_ceil(SB_MI); | ||
| 45 | + let log2 = hdr.tile_info.cols_log2; | ||
| 46 | + let lo = (((sb64_cols * tc) >> log2) * SB_MI).min(mi_cols); | ||
| 47 | + let hi = (((sb64_cols * (tc + 1)) >> log2) * SB_MI).min(mi_cols); | ||
| 48 | + (lo, hi) | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +/// Copy columns `[lo, hi)` of every row of a mode-info array. | ||
| 52 | +pub(super) fn copy_mi_cols<T: Copy>(dst: &mut [T], src: &[T], mi_cols: usize, mi_rows: usize, lo: usize, hi: usize) { | ||
| 53 | + for r in 0..mi_rows { | ||
| 54 | + let b = r * mi_cols; | ||
| 55 | + dst[b + lo..b + hi].copy_from_slice(&src[b + lo..b + hi]); | ||
| 56 | + } | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +/// Padded (64-multiple) luma width of a frame. | ||
| 60 | +pub(super) fn frame_aw(hdr: &FrameHeader) -> usize { | ||
| 61 | + (hdr.width as usize).div_ceil(64) * 64 | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +/// Padded (64-multiple) luma height of a frame. | ||
| 65 | +pub(super) fn frame_ah(hdr: &FrameHeader) -> usize { | ||
| 66 | + (hdr.height as usize).div_ceil(64) * 64 | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +/// Copy the pixel columns of one tile column. The last tile column also owns | ||
| 70 | +/// the padding past `mi_cols` (a block at the frame edge writes its full size). | ||
| 71 | +pub(super) fn copy_plane_cols(dst: &mut Planes, src: &Planes, lo_mi: usize, hi_mi: usize, last: bool) { | ||
| 72 | + fn rows<T: Copy>(dst: &mut [T], src: &[T], stride: usize, rows: usize, x0: usize, x1: usize) { | ||
| 73 | + for r in 0..rows { | ||
| 74 | + let b = r * stride; | ||
| 75 | + dst[b + x0..b + x1].copy_from_slice(&src[b + x0..b + x1]); | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + let x0 = lo_mi * 8; | ||
| 79 | + let x1 = if last { dst.ys } else { hi_mi * 8 }; | ||
| 80 | + rows(&mut dst.y, &src.y, dst.ys, dst.ah, x0, x1); | ||
| 81 | + let (cx0, cx1) = (x0 >> dst.ss_x, if last { dst.uvs } else { x1 >> dst.ss_x }); | ||
| 82 | + let ch = dst.ah >> dst.ss_y; | ||
| 83 | + rows(&mut dst.u, &src.u, dst.uvs, ch, cx0, cx1); | ||
| 84 | + rows(&mut dst.v, &src.v, dst.uvs, ch, cx0, cx1); | ||
| 85 | +} | ||
crates/ec-vp9/src/inter.rsmodified+5 -15
| @@ -40,9 +40,7 @@ const MV_BORDER: i32 = 16 << 3; | |||
| 40 | const MV_HP_THRESH: i32 = 64; | 40 | const MV_HP_THRESH: i32 = 64; |
| 41 | const CLASS0_SIZE: i32 = 2; | 41 | const CLASS0_SIZE: i32 = 2; |
| 42 | const CLASS0_BITS: i32 = 1; | 42 | const CLASS0_BITS: i32 = 1; |
| 43 | -/// `SEG_LVL_SKIP` / `SEG_LVL_REF_FRAME`. | 43 | +use ec_vp9_syntax::{SEG_LVL_REF_FRAME, SEG_LVL_SKIP}; |
| 44 | -const SEG_LVL_REF_FRAME: usize = 2; | ||
| 45 | -const SEG_LVL_SKIP: usize = 3; | ||
| 46 | 44 | ||
| 47 | /// `mv_ref_blocks[BLOCK_SIZES]` (`vp9_mvref_common.h`): `(row, col)` offsets, | 45 | /// `mv_ref_blocks[BLOCK_SIZES]` (`vp9_mvref_common.h`): `(row, col)` offsets, |
| 48 | /// transcribed verbatim from the C. libvpx's `POSITION` is `{ row, col }`, so | 46 | /// transcribed verbatim from the C. libvpx's `POSITION` is `{ row, col }`, so |
| @@ -279,14 +277,6 @@ fn read_inter_segment_id( | |||
| 279 | segment_id | 277 | segment_id |
| 280 | } | 278 | } |
| 281 | 279 | ||
| 282 | -fn seg_feature(seg: &ec_vp9_syntax::SegmentationParams, segment_id: u8, feature: usize) -> bool { | ||
| 283 | - seg.enabled | ||
| 284 | - && seg | ||
| 285 | - .feature_enabled | ||
| 286 | - .get(segment_id as usize) | ||
| 287 | - .is_some_and(|f| f[feature]) | ||
| 288 | -} | ||
| 289 | - | ||
| 290 | /// `read_skip`. | 280 | /// `read_skip`. |
| 291 | fn read_skip( | 281 | fn read_skip( |
| 292 | r: &mut BoolDecoder, | 282 | r: &mut BoolDecoder, |
| @@ -296,7 +286,7 @@ fn read_skip( | |||
| 296 | nb: Nb<'_>, | 286 | nb: Nb<'_>, |
| 297 | counts: &mut Counts, | 287 | counts: &mut Counts, |
| 298 | ) -> bool { | 288 | ) -> bool { |
| 299 | - if seg_feature(c.seg, segment_id, SEG_LVL_SKIP) { | 289 | + if c.seg.feature_active(segment_id, SEG_LVL_SKIP) { |
| 300 | true | 290 | true |
| 301 | } else { | 291 | } else { |
| 302 | let ctx = usize::from(nb.above.is_some_and(|m| m.skip)) | 292 | let ctx = usize::from(nb.above.is_some_and(|m| m.skip)) |
| @@ -333,7 +323,7 @@ fn read_is_inter_block( | |||
| 333 | nb: Nb<'_>, | 323 | nb: Nb<'_>, |
| 334 | counts: &mut Counts, | 324 | counts: &mut Counts, |
| 335 | ) -> bool { | 325 | ) -> bool { |
| 336 | - if seg_feature(c.seg, segment_id, SEG_LVL_REF_FRAME) { | 326 | + if c.seg.feature_active(segment_id, SEG_LVL_REF_FRAME) { |
| 337 | c.seg.feature_data[segment_id as usize][SEG_LVL_REF_FRAME] != INTRA_FRAME as i16 | 327 | c.seg.feature_data[segment_id as usize][SEG_LVL_REF_FRAME] != INTRA_FRAME as i16 |
| 338 | } else { | 328 | } else { |
| 339 | let ctx = intra_inter_context(nb); | 329 | let ctx = intra_inter_context(nb); |
| @@ -1144,7 +1134,7 @@ fn read_ref_frames( | |||
| 1144 | out: &mut [i8; 2], | 1134 | out: &mut [i8; 2], |
| 1145 | counts: &mut Counts, | 1135 | counts: &mut Counts, |
| 1146 | ) { | 1136 | ) { |
| 1147 | - if seg_feature(c.seg, segment_id, SEG_LVL_REF_FRAME) { | 1137 | + if c.seg.feature_active(segment_id, SEG_LVL_REF_FRAME) { |
| 1148 | out[0] = c.seg.feature_data[segment_id as usize][SEG_LVL_REF_FRAME] as i8; | 1138 | out[0] = c.seg.feature_data[segment_id as usize][SEG_LVL_REF_FRAME] as i8; |
| 1149 | out[1] = NO_REF_FRAME; | 1139 | out[1] = NO_REF_FRAME; |
| 1150 | return; | 1140 | return; |
| @@ -1193,7 +1183,7 @@ fn read_inter_block_mode_info( | |||
| 1193 | let is_compound = usize::from(info.ref_frame[1] > INTRA_FRAME); | 1183 | let is_compound = usize::from(info.ref_frame[1] > INTRA_FRAME); |
| 1194 | let inter_mode_ctx = get_mode_context(st, c, bsize, row, col); | 1184 | let inter_mode_ctx = get_mode_context(st, c, bsize, row, col); |
| 1195 | 1185 | ||
| 1196 | - if seg_feature(c.seg, info.segment, SEG_LVL_SKIP) { | 1186 | + if c.seg.feature_active(info.segment, SEG_LVL_SKIP) { |
| 1197 | info.mode = ZEROMV; | 1187 | info.mode = ZEROMV; |
| 1198 | if bsize < 3 { | 1188 | if bsize < 3 { |
| 1199 | return Err(crate::Error::corrupt( | 1189 | return Err(crate::Error::corrupt( |
crates/ec-vp9/src/loopfilter.rsmodified+11 -22
| @@ -75,6 +75,7 @@ const LUMA_ABOVE_TXF: [u64; 4] = [u64::MAX, u64::MAX, 0x00ff00ff00ff00ff, 0x0000 | |||
| 75 | const LUMA_LEFT_BORDER: u64 = 0x1111111111111111; | 75 | const LUMA_LEFT_BORDER: u64 = 0x1111111111111111; |
| 76 | const LUMA_ABOVE_BORDER: u64 = 0x000000ff000000ff; | 76 | const LUMA_ABOVE_BORDER: u64 = 0x000000ff000000ff; |
| 77 | 77 | ||
| 78 | +use crate::decode::Planes; | ||
| 78 | use crate::Sample; | 79 | use crate::Sample; |
| 79 | 80 | ||
| 80 | /// `signed_char_clamp_high` (`vpx_dsp/loopfilter.c:23`): clamp to | 81 | /// `signed_char_clamp_high` (`vpx_dsp/loopfilter.c:23`): clamp to |
| @@ -1192,23 +1193,10 @@ impl LfGrids { | |||
| 1192 | /// `vp9_loop_filter_frame` (vp9_loopfilter.c:1430): luma always takes the | 1193 | /// `vp9_loop_filter_frame` (vp9_loopfilter.c:1430): luma always takes the |
| 1193 | /// ss00 path; chroma takes ss00 for 4:4:4, ss11 for 4:2:0, and the | 1194 | /// ss00 path; chroma takes ss00 for 4:4:4, ss11 for 4:2:0, and the |
| 1194 | /// non420 slow path otherwise (4:2:2 / 4:4:0). | 1195 | /// non420 slow path otherwise (4:2:2 / 4:4:0). |
| 1195 | - #[allow(clippy::too_many_arguments)] | 1196 | + pub(crate) fn filter_frame(&self, p: &mut Planes, vw: usize, vh: usize, sharpness: u8) { |
| 1196 | - pub(crate) fn filter_frame( | 1197 | + let (ss_x, ss_y, bd) = (p.ss_x, p.ss_y, p.bd); |
| 1197 | - &self, | 1198 | + let (uv_w, uv_h) = (vw >> ss_x, vh >> ss_y); |
| 1198 | - y: &mut [Sample], | 1199 | + let (stride, uv_stride) = (p.ys, p.uvs); |
| 1199 | - stride: usize, | ||
| 1200 | - u: &mut [Sample], | ||
| 1201 | - v: &mut [Sample], | ||
| 1202 | - uv_stride: usize, | ||
| 1203 | - y_w: usize, | ||
| 1204 | - y_h: usize, | ||
| 1205 | - uv_w: usize, | ||
| 1206 | - uv_h: usize, | ||
| 1207 | - ss_x: usize, | ||
| 1208 | - ss_y: usize, | ||
| 1209 | - sharpness: u8, | ||
| 1210 | - bd: u8, | ||
| 1211 | - ) { | ||
| 1212 | // The three planes are filtered from the same read-only grids and touch | 1200 | // The three planes are filtered from the same read-only grids and touch |
| 1213 | // disjoint buffers, so they run concurrently: luma on one thread, both | 1201 | // disjoint buffers, so they run concurrently: luma on one thread, both |
| 1214 | // chroma planes on another. Each plane's edge order is unchanged, so the | 1202 | // chroma planes on another. Each plane's edge order is unchanged, so the |
| @@ -1226,8 +1214,8 @@ impl LfGrids { | |||
| 1226 | } | 1214 | } |
| 1227 | }; | 1215 | }; |
| 1228 | std::thread::scope(|scope| { | 1216 | std::thread::scope(|scope| { |
| 1229 | - scope.spawn(|| chroma(u, v)); | 1217 | + scope.spawn(|| chroma(&mut p.u, &mut p.v)); |
| 1230 | - self.filter_ss00_plane(y, stride, y_w, y_h, sharpness, bd); | 1218 | + self.filter_ss00_plane(&mut p.y, stride, vw, vh, sharpness, bd); |
| 1231 | }); | 1219 | }); |
| 1232 | } | 1220 | } |
| 1233 | } | 1221 | } |
| @@ -1253,9 +1241,10 @@ mod tests { | |||
| 1253 | } | 1241 | } |
| 1254 | 1242 | ||
| 1255 | fn run(g: &LfGrids, y: &mut [Sample]) { | 1243 | fn run(g: &LfGrids, y: &mut [Sample]) { |
| 1256 | - let mut u = vec![128u16; 32 * 32]; | 1244 | + let mut p = Planes::new(64, 64, 8, 1, 1); |
| 1257 | - let mut v = vec![128u16; 32 * 32]; | 1245 | + p.y.copy_from_slice(y); |
| 1258 | - g.filter_frame(y, 64, &mut u, &mut v, 32, 64, 64, 32, 32, 1, 1, 0, 8); | 1246 | + g.filter_frame(&mut p, 64, 64, 0); |
| 1247 | + y.copy_from_slice(&p.y); | ||
| 1259 | } | 1248 | } |
| 1260 | 1249 | ||
| 1261 | /// The luma internal-4x4 horizontal edge fires on the frame's LAST MI row. | 1250 | /// The luma internal-4x4 horizontal edge fires on the frame's LAST MI row. |
crates/ec-vp9/src/modes.rsmodified+2 -6
| @@ -5,6 +5,7 @@ | |||
| 5 | use crate::bool::BoolDecoder; | 5 | use crate::bool::BoolDecoder; |
| 6 | use crate::header::FrameContext; | 6 | use crate::header::FrameContext; |
| 7 | use crate::tables::*; | 7 | use crate::tables::*; |
| 8 | +use ec_vp9_syntax::SEG_LVL_SKIP; | ||
| 8 | 9 | ||
| 9 | /// One block's parsed prediction record (`MODE_INFO`). | 10 | /// One block's parsed prediction record (`MODE_INFO`). |
| 10 | #[derive(Clone, Default)] | 11 | #[derive(Clone, Default)] |
| @@ -155,12 +156,7 @@ pub(crate) fn read_intra_frame_mode_info( | |||
| 155 | let skip_ctx = above_mi.as_ref().map_or(0, |m| u32::from(m.skip)) | 156 | let skip_ctx = above_mi.as_ref().map_or(0, |m| u32::from(m.skip)) |
| 156 | + left_mi.as_ref().map_or(0, |u| u32::from(u.skip)); | 157 | + left_mi.as_ref().map_or(0, |u| u32::from(u.skip)); |
| 157 | let skip_ctx = skip_ctx as usize; | 158 | let skip_ctx = skip_ctx as usize; |
| 158 | - let seg_skip = seg.enabled | 159 | + let skip = if seg.feature_active(segment, SEG_LVL_SKIP) { |
| 159 | - && seg | ||
| 160 | - .feature_enabled | ||
| 161 | - .get(segment as usize) | ||
| 162 | - .is_some_and(|f| f[3]); | ||
| 163 | - let skip = if seg_skip { | ||
| 164 | true | 160 | true |
| 165 | } else { | 161 | } else { |
| 166 | r.read_bool(fc.skip[skip_ctx]) | 162 | r.read_bool(fc.skip[skip_ctx]) |