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 {
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 {
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 }`, so46 /// transcribed verbatim from the C. libvpx's `POSITION` is `{ row, col }`, so
@@ -279,14 +277,6 @@ fn read_inter_segment_id(
279 segment_id277 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 true290 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 i16327 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/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.enabled159+ 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 true160 true
165 } else {161 } else {
166 r.read_bool(fc.skip[skip_ctx])162 r.read_bool(fc.skip[skip_ctx])