forge
Explore
Log in

Don't you dare go Hollow

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 commit

cbfe14ca2d8d3b2220a60d1409cd5e31bbdcf109Ahmet Kaan GümüşParent: 49102ee
crates/ec-vp9-syntax/src/header.rsmodified+11 -0
@@ -188,6 +188,17 @@ pub struct SegmentationParams {
188188 pub feature_data: [[i16; SEG_LVL_MAX]; MAX_SEGMENTS],
189189 }
190190
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+
191202 /// Tile layout (spec 6.2, `tile_info`).
192203 #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
193204 pub struct TileInfo {
crates/ec-vp9/src/inter.rsmodified+5 -15
@@ -40,9 +40,7 @@ const MV_BORDER: i32 = 16 << 3;
4040 const MV_HP_THRESH: i32 = 64;
4141 const CLASS0_SIZE: i32 = 2;
4242 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};
4644
4745 /// `mv_ref_blocks[BLOCK_SIZES]` (`vp9_mvref_common.h`): `(row, col)` offsets,
4846 /// transcribed verbatim from the C. libvpx's `POSITION` is `{ row, col }`, so
@@ -279,14 +277,6 @@ fn read_inter_segment_id(
279277 segment_id
280278 }
281279
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-
290280 /// `read_skip`.
291281 fn read_skip(
292282 r: &mut BoolDecoder,
@@ -296,7 +286,7 @@ fn read_skip(
296286 nb: Nb<'_>,
297287 counts: &mut Counts,
298288 ) -> bool {
299- if seg_feature(c.seg, segment_id, SEG_LVL_SKIP) {
289+ if c.seg.feature_active(segment_id, SEG_LVL_SKIP) {
300290 true
301291 } else {
302292 let ctx = usize::from(nb.above.is_some_and(|m| m.skip))
@@ -333,7 +323,7 @@ fn read_is_inter_block(
333323 nb: Nb<'_>,
334324 counts: &mut Counts,
335325 ) -> 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) {
337327 c.seg.feature_data[segment_id as usize][SEG_LVL_REF_FRAME] != INTRA_FRAME as i16
338328 } else {
339329 let ctx = intra_inter_context(nb);
@@ -1144,7 +1134,7 @@ fn read_ref_frames(
11441134 out: &mut [i8; 2],
11451135 counts: &mut Counts,
11461136 ) {
1147- if seg_feature(c.seg, segment_id, SEG_LVL_REF_FRAME) {
1137+ if c.seg.feature_active(segment_id, SEG_LVL_REF_FRAME) {
11481138 out[0] = c.seg.feature_data[segment_id as usize][SEG_LVL_REF_FRAME] as i8;
11491139 out[1] = NO_REF_FRAME;
11501140 return;
@@ -1193,7 +1183,7 @@ fn read_inter_block_mode_info(
11931183 let is_compound = usize::from(info.ref_frame[1] > INTRA_FRAME);
11941184 let inter_mode_ctx = get_mode_context(st, c, bsize, row, col);
11951185
1196- if seg_feature(c.seg, info.segment, SEG_LVL_SKIP) {
1186+ if c.seg.feature_active(info.segment, SEG_LVL_SKIP) {
11971187 info.mode = ZEROMV;
11981188 if bsize < 3 {
11991189 return Err(crate::Error::corrupt(
crates/ec-vp9/src/modes.rsmodified+2 -6
@@ -5,6 +5,7 @@
55 use crate::bool::BoolDecoder;
66 use crate::header::FrameContext;
77 use crate::tables::*;
8+use ec_vp9_syntax::SEG_LVL_SKIP;
89
910 /// One block's parsed prediction record (`MODE_INFO`).
1011 #[derive(Clone, Default)]
@@ -155,12 +156,7 @@ pub(crate) fn read_intra_frame_mode_info(
155156 let skip_ctx = above_mi.as_ref().map_or(0, |m| u32::from(m.skip))
156157 + left_mi.as_ref().map_or(0, |u| u32::from(u.skip));
157158 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) {
164160 true
165161 } else {
166162 r.read_bool(fc.skip[skip_ctx])