S6: SegmentationParams::feature_active replaces the seg_feature helper and the inline skip check; inter.rs uses the SEG_LVL_* constants from ec-vp9-syntax
Browse files at this commitcbfe14ca2d8d3b2220a60d1409cd5e31bbdcf109Parent: 49102ee3 changed files +18 -21
- crates/ec-vp9-syntax/src/header.rs +11 -0
- crates/ec-vp9/src/inter.rs +5 -15
- crates/ec-vp9/src/modes.rs +2 -6
crates/ec-vp9-syntax/src/header.rsmodified+11 -0
| @@ -188,6 +188,17 @@ pub struct SegmentationParams { | ||
| 188 | 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 | 202 | /// Tile layout (spec 6.2, `tile_info`). |
| 192 | 203 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 193 | 204 | pub struct TileInfo { |
crates/ec-vp9/src/inter.rsmodified+5 -15
| @@ -40,9 +40,7 @@ const MV_BORDER: i32 = 16 << 3; | ||
| 40 | 40 | const MV_HP_THRESH: i32 = 64; |
| 41 | 41 | const CLASS0_SIZE: i32 = 2; |
| 42 | 42 | const CLASS0_BITS: i32 = 1; |
| 43 | -/// `SEG_LVL_SKIP` / `SEG_LVL_REF_FRAME`. | |
| 44 | -const SEG_LVL_REF_FRAME: usize = 2; | |
| 45 | -const SEG_LVL_SKIP: usize = 3; | |
| 43 | +use ec_vp9_syntax::{SEG_LVL_REF_FRAME, SEG_LVL_SKIP}; | |
| 46 | 44 | |
| 47 | 45 | /// `mv_ref_blocks[BLOCK_SIZES]` (`vp9_mvref_common.h`): `(row, col)` offsets, |
| 48 | 46 | /// transcribed verbatim from the C. libvpx's `POSITION` is `{ row, col }`, so |
| @@ -279,14 +277,6 @@ fn read_inter_segment_id( | ||
| 279 | 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 | 280 | /// `read_skip`. |
| 291 | 281 | fn read_skip( |
| 292 | 282 | r: &mut BoolDecoder, |
| @@ -296,7 +286,7 @@ fn read_skip( | ||
| 296 | 286 | nb: Nb<'_>, |
| 297 | 287 | counts: &mut Counts, |
| 298 | 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 | 290 | true |
| 301 | 291 | } else { |
| 302 | 292 | let ctx = usize::from(nb.above.is_some_and(|m| m.skip)) |
| @@ -333,7 +323,7 @@ fn read_is_inter_block( | ||
| 333 | 323 | nb: Nb<'_>, |
| 334 | 324 | counts: &mut Counts, |
| 335 | 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 | 327 | c.seg.feature_data[segment_id as usize][SEG_LVL_REF_FRAME] != INTRA_FRAME as i16 |
| 338 | 328 | } else { |
| 339 | 329 | let ctx = intra_inter_context(nb); |
| @@ -1144,7 +1134,7 @@ fn read_ref_frames( | ||
| 1144 | 1134 | out: &mut [i8; 2], |
| 1145 | 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 | 1138 | out[0] = c.seg.feature_data[segment_id as usize][SEG_LVL_REF_FRAME] as i8; |
| 1149 | 1139 | out[1] = NO_REF_FRAME; |
| 1150 | 1140 | return; |
| @@ -1193,7 +1183,7 @@ fn read_inter_block_mode_info( | ||
| 1193 | 1183 | let is_compound = usize::from(info.ref_frame[1] > INTRA_FRAME); |
| 1194 | 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 | 1187 | info.mode = ZEROMV; |
| 1198 | 1188 | if bsize < 3 { |
| 1199 | 1189 | return Err(crate::Error::corrupt( |
crates/ec-vp9/src/modes.rsmodified+2 -6
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | use crate::bool::BoolDecoder; |
| 6 | 6 | use crate::header::FrameContext; |
| 7 | 7 | use crate::tables::*; |
| 8 | +use ec_vp9_syntax::SEG_LVL_SKIP; | |
| 8 | 9 | |
| 9 | 10 | /// One block's parsed prediction record (`MODE_INFO`). |
| 10 | 11 | #[derive(Clone, Default)] |
| @@ -155,12 +156,7 @@ pub(crate) fn read_intra_frame_mode_info( | ||
| 155 | 156 | let skip_ctx = above_mi.as_ref().map_or(0, |m| u32::from(m.skip)) |
| 156 | 157 | + left_mi.as_ref().map_or(0, |u| u32::from(u.skip)); |
| 157 | 158 | let skip_ctx = skip_ctx as usize; |
| 158 | - let seg_skip = seg.enabled | |
| 159 | - && seg | |
| 160 | - .feature_enabled | |
| 161 | - .get(segment as usize) | |
| 162 | - .is_some_and(|f| f[3]); | |
| 163 | - let skip = if seg_skip { | |
| 159 | + let skip = if seg.feature_active(segment, SEG_LVL_SKIP) { | |
| 164 | 160 | true |
| 165 | 161 | } else { |
| 166 | 162 | r.read_bool(fc.skip[skip_ctx]) |