forge
Explore
Log in

Don't you dare go Hollow

S7: vp8 MbInfo stores YMode, BMode and MvRef enums (no u8 codes); ymode_as_bmode replaced by YMode::as_bmode (same mapping)

Browse files at this commit

5a9ec7a323cee02556efa9ac125842470dfd50e7Ahmet Kaan GümüşParent: 381f98c
crates/ec-vp8/src/decode.rsmodified+36 -46
@@ -95,9 +95,9 @@ impl Plane {
9595 #[derive(Clone, Default)]
9696 struct MbInfo {
9797 /// [`modes::YMode`] as its coded integer.
98- y_mode: u8,
99- uv_mode: u8,
100- b_modes: [u8; 16],
98+ y_mode: modes::YMode,
99+ uv_mode: modes::YMode,
100+ b_modes: [modes::BMode; 16],
101101 segment_id: u8,
102102 skip: bool,
103103 /// 0 = intra, 1 = last, 2 = golden, 3 = altref (§16.2). Key-frame
@@ -105,7 +105,7 @@ struct MbInfo {
105105 ref_frame: u8,
106106 /// Inter mv_ref leaf (§16.2): 0 = zero, 1 = nearest, 2 = near,
107107 /// 3 = new, 4 = split. 0 when intra.
108- mv_ref: u8,
108+ mv_ref: modes::MvRef,
109109 /// Whole-MB motion vector in eighth-pels; the bottom-right subblock's
110110 /// vector for SPLITMV (what future neighbours' census sees).
111111 mv: (i16, i16),
@@ -135,7 +135,7 @@ const MC_BORDER: usize = 32;
135135
136136 impl MbInfo {
137137 fn has_y2(&self) -> bool {
138- self.y_mode != modes::YMode::BPred.as_u8()
138+ self.y_mode != modes::YMode::BPred
139139 }
140140 }
141141
@@ -517,15 +517,15 @@ impl Decoder {
517517 if header.lf_delta_enabled {
518518 level += self.state.ref_lf_delta[usize::from(mb.ref_frame)];
519519 let mode_idx = if mb.ref_frame == 0 {
520- if mb.y_mode == modes::YMode::BPred.as_u8() {
520+ if mb.y_mode == modes::YMode::BPred {
521521 Some(0)
522522 } else {
523523 None
524524 }
525525 } else {
526526 match mb.mv_ref {
527- 0 => Some(1), // ZEROMV
528- 4 => Some(3), // SPLITMV
527+ modes::MvRef::Zero => Some(1), // ZEROMV
528+ modes::MvRef::Split => Some(3), // SPLITMV
529529 _ => Some(2), // NEAREST / NEAR / NEW
530530 }
531531 };
@@ -729,13 +729,13 @@ impl Decoder {
729729 // context-dependent kf_bmode_prob table is key-frame-only).
730730 mb.ref_frame = 0;
731731 let ymode = modes::read_ymode(d, ymode_probs);
732- mb.y_mode = ymode.as_u8();
732+ mb.y_mode = ymode;
733733 if ymode == modes::YMode::BPred {
734734 for j in 0..16usize {
735- mb.b_modes[j] = modes::read_bmode(d, &modes::INTER_BMODE_PROBS).as_u8();
735+ mb.b_modes[j] = modes::read_bmode(d, &modes::INTER_BMODE_PROBS);
736736 }
737737 }
738- mb.uv_mode = modes::read_uvmode(d, uv_mode_probs).as_u8();
738+ mb.uv_mode = modes::read_uvmode(d, uv_mode_probs);
739739 return;
740740 }
741741
@@ -755,17 +755,17 @@ impl Decoder {
755755 let (mut near_mvs, cnt) = modes::find_near_mvs(above, left, aboveleft, to_bias);
756756
757757 if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_INTRA] as usize][0]) {
758- mb.mv_ref = 0; // ZEROMV
758+ mb.mv_ref = modes::MvRef::Zero;
759759 return;
760760 }
761761 if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_NEAREST] as usize][1]) {
762- mb.mv_ref = 1; // NEARESTMV
762+ mb.mv_ref = modes::MvRef::Nearest;
763763 mb.mv = near_mvs[modes::CNT_NEAREST];
764764 modes::clamp_mv2(&mut mb.mv, edges);
765765 return;
766766 }
767767 if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_NEAR] as usize][2]) {
768- mb.mv_ref = 2; // NEARMV
768+ mb.mv_ref = modes::MvRef::Near;
769769 mb.mv = near_mvs[modes::CNT_NEAR];
770770 modes::clamp_mv2(&mut mb.mv, edges);
771771 return;
@@ -778,7 +778,7 @@ impl Decoder {
778778 modes::clamp_mv2(&mut near_mvs[near_index], edges);
779779 let best = near_mvs[near_index];
780780 if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_SPLITMV] as usize][3]) {
781- mb.mv_ref = 3; // NEWMV
781+ mb.mv_ref = modes::MvRef::New;
782782 let mut mv = modes::read_mv(d, &self.state.mv_probs);
783783 mv.0 = mv.0.wrapping_add(best.0);
784784 mv.1 = mv.1.wrapping_add(best.1);
@@ -806,7 +806,7 @@ impl Decoder {
806806 intra: false,
807807 zero: mb.mv == (0, 0),
808808 mv: mb.mv,
809- is_split: mb.mv_ref == 4,
809+ is_split: mb.mv_ref == modes::MvRef::Split,
810810 sign_bias: sign_bias[usize::from(mb.ref_frame) - 1],
811811 }
812812 }
@@ -830,7 +830,7 @@ impl Decoder {
830830 let k = usize::from(modes::MBSPLIT_OFFSET[s][j]);
831831 let leftmv = if k % 4 == 0 {
832832 let lm = self.mbi(row, col - 1);
833- if lm.mv_ref == 4 {
833+ if lm.mv_ref == modes::MvRef::Split {
834834 lm.bmi[k + 3]
835835 } else {
836836 lm.mv
@@ -840,7 +840,7 @@ impl Decoder {
840840 };
841841 let abovemv = if k < 4 {
842842 let am = self.mbi(row - 1, col);
843- if am.mv_ref == 4 {
843+ if am.mv_ref == modes::MvRef::Split {
844844 am.bmi[k + 12]
845845 } else {
846846 am.mv
@@ -866,9 +866,9 @@ impl Decoder {
866866 mb.bmi[usize::from(off)] = blockmv;
867867 }
868868 }
869- mb.mv_ref = 4;
869+ mb.mv_ref = modes::MvRef::Split;
870870 // 4x4 residual coding without a Y2 block (like B_PRED).
871- mb.y_mode = modes::YMode::BPred.as_u8();
871+ mb.y_mode = modes::YMode::BPred;
872872 // Neighbours' census sees the bottom-right subblock's vector.
873873 mb.mv = mb.bmi[15];
874874 }
@@ -907,7 +907,7 @@ impl Decoder {
907907 // SPLITMV (identical output to libvpx's grouped predicts). Each
908908 // predict lands at its own (bx, by) slot of one 16x16 patch.
909909 let mut py = [0u8; 256];
910- if mb.mv_ref == 4 {
910+ if mb.mv_ref == modes::MvRef::Split {
911911 for b in 0..16usize {
912912 let (bx, by) = ((b % 4) * 4, (b / 4) * 4);
913913 // reconinter.c:370-374: the four corner subblocks clamp
@@ -936,7 +936,7 @@ impl Decoder {
936936 // clamps only under need_to_clamp_mvs.
937937 let mut pu = [0u8; 256];
938938 let mut pv = [0u8; 256];
939- if mb.mv_ref == 4 {
939+ if mb.mv_ref == modes::MvRef::Split {
940940 for q in 0..4usize {
941941 // Quadrant q: 4x4 chroma pixels at (qx4, qy4) in the MB.
942942 let (qx4, qy4) = ((q % 2) * 4, (q / 2) * 4);
@@ -1016,28 +1016,28 @@ impl Decoder {
10161016 mb: &mut MbInfo,
10171017 ) {
10181018 let ymode = modes::read_kf_ymode(d);
1019- mb.y_mode = ymode.as_u8();
1019+ mb.y_mode = ymode;
10201020 if ymode == modes::YMode::BPred {
10211021 for j in 0..16u8 {
10221022 let a = self.above_block_mode(row, col, j, mb);
10231023 let l = self.left_block_mode(row, col, j, mb);
10241024 mb.b_modes[usize::from(j)] =
1025- modes::read_bmode(d, &KF_BMODE_PROB[usize::from(a)][usize::from(l)]).as_u8();
1025+ modes::read_bmode(d, &KF_BMODE_PROB[usize::from(a.as_u8())][usize::from(l.as_u8())]);
10261026 }
10271027 }
1028- mb.uv_mode = modes::read_uvmode(d, &modes::KF_UV_MODE_PROBS).as_u8();
1028+ mb.uv_mode = modes::read_uvmode(d, &modes::KF_UV_MODE_PROBS);
10291029 }
10301030
10311031 /// Above subblock mode context (dixie `above_block_mode`): subblocks
10321032 /// 0-3 take the above MB's derived mode, inner subblocks the mode
10331033 /// `j-4` of this same MB (already decoded into `mb`).
1034- fn above_block_mode(&self, row: usize, col: usize, j: u8, mb: &MbInfo) -> u8 {
1034+ fn above_block_mode(&self, row: usize, col: usize, j: u8, mb: &MbInfo) -> modes::BMode {
10351035 if j < 4 {
10361036 let above = self.mbi(row - 1, col);
1037- if above.y_mode == modes::YMode::BPred.as_u8() {
1037+ if above.y_mode == modes::YMode::BPred {
10381038 above.b_modes[usize::from(j) + 12]
10391039 } else {
1040- ymode_as_bmode(above.y_mode)
1040+ above.y_mode.as_bmode()
10411041 }
10421042 } else {
10431043 mb.b_modes[usize::from(j) - 4]
@@ -1045,13 +1045,13 @@ impl Decoder {
10451045 }
10461046
10471047 /// Left subblock mode context (dixie `left_block_mode`).
1048- fn left_block_mode(&self, row: usize, col: usize, j: u8, mb: &MbInfo) -> u8 {
1048+ fn left_block_mode(&self, row: usize, col: usize, j: u8, mb: &MbInfo) -> modes::BMode {
10491049 if j.is_multiple_of(4) {
10501050 let left = self.mbi(row, col - 1);
1051- if left.y_mode == modes::YMode::BPred.as_u8() {
1051+ if left.y_mode == modes::YMode::BPred {
10521052 left.b_modes[usize::from(j) + 3]
10531053 } else {
1054- ymode_as_bmode(left.y_mode)
1054+ left.y_mode.as_bmode()
10551055 }
10561056 } else {
10571057 mb.b_modes[usize::from(j) - 1]
@@ -1087,7 +1087,7 @@ impl Decoder {
10871087 [0; 16]
10881088 };
10891089
1090- if y_mode == modes::YMode::BPred.as_u8() {
1090+ if y_mode == modes::YMode::BPred {
10911091 for b in 0..16usize {
10921092 let bx = (b % 4) * 4;
10931093 let by = (b / 4) * 4;
@@ -1109,7 +1109,7 @@ impl Decoder {
11091109 }
11101110 let p = self.y.data[self.y.at_above_left(x + bx, y + by)];
11111111 let mut block = [0u8; 16];
1112- intra::predict4(b_modes[b], &a8, &l4, p, &mut block)?;
1112+ intra::predict4(b_modes[b].as_u8(), &a8, &l4, p, &mut block)?;
11131113 for i in 0..4 {
11141114 let d = self.y.at(x + bx, y + by + i);
11151115 self.y.data[d..d + 4].copy_from_slice(&block[i * 4..i * 4 + 4]);
@@ -1139,7 +1139,7 @@ impl Decoder {
11391139 };
11401140 let mut pred = [0u8; 256];
11411141 intra::predict16(
1142- y_mode, have_above, have_left, &above, &left, above_left, &mut pred,
1142+ y_mode.as_u8(), have_above, have_left, &above, &left, above_left, &mut pred,
11431143 )?;
11441144 // loop indexes several parallel arrays; the index is clearer than zip chains
11451145 #[allow(clippy::needless_range_loop)]
@@ -1170,7 +1170,7 @@ impl Decoder {
11701170 let mut pred_u = [0u8; 64];
11711171 let mut pred_v = [0u8; 64];
11721172 intra::predict8(
1173- uv_mode,
1173+ uv_mode.as_u8(),
11741174 have_above,
11751175 have_left,
11761176 &above_u,
@@ -1179,7 +1179,7 @@ impl Decoder {
11791179 &mut pred_u,
11801180 )?;
11811181 intra::predict8(
1182- uv_mode,
1182+ uv_mode.as_u8(),
11831183 have_above,
11841184 have_left,
11851185 &above_v,
@@ -1285,16 +1285,6 @@ impl Default for Decoder {
12851285 /// Segment-map coding tree (RFC 6386 §10): plain two-level split of 0-3.
12861286 const SEGMENT_TREE: [i8; 6] = [2, 4, 0, -1, -2, -3];
12871287
1288-fn ymode_as_bmode(y: u8) -> u8 {
1289- match y {
1290- 0 => 0, // DC_PRED -> B_DC_PRED
1291- 1 => 2, // V_PRED -> B_VE_PRED
1292- 2 => 3, // H_PRED -> B_HE_PRED
1293- 3 => 1, // TM_PRED -> B_TM_PRED
1294- _ => unreachable!("non-B_PRED luma mode {y}"),
1295- }
1296-}
1297-
12981288 /// Add one 4x4 block's dequantized-coefficient residual to its
12991289 /// prediction: reads the prediction patch from `pred`, clamps, writes
13001290 /// into the strided plane (§14.4/§14.5).
crates/ec-vp8/src/modes.rsmodified+6 -3
@@ -5,10 +5,11 @@ use crate::bool::BoolDecoder;
55
66 /// Intra macroblock luma modes (RFC 6386 §8.2 enum values are normative;
77 /// chroma modes are the first four).
8-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8+#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
99 #[repr(u8)]
1010 pub enum YMode {
1111 /// Predict DC from the row above and column to the left.
12+ #[default]
1213 DcPred = 0,
1314 /// Predict rows from the row above.
1415 VPred = 1,
@@ -40,10 +41,11 @@ impl YMode {
4041 }
4142
4243 /// The ten 4x4 subblock prediction modes (RFC 6386 §11.2).
43-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
44+#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
4445 #[repr(u8)]
4546 pub enum BMode {
4647 /// DC from above row and left column.
48+ #[default]
4749 BDCPred = 0,
4850 /// True-motion.
4951 BTMPred = 1,
@@ -158,10 +160,11 @@ pub fn read_bmode(d: &mut BoolDecoder<'_>, probs: &[u8]) -> BMode {
158160 /// Inter-frame motion-vector reference modes (RFC 6386 §16.2), offset
159161 /// from the intra modes by `num_ymodes` in the reference enum; here they
160162 /// are their own small enum with the RFC's tree integers.
161-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
163+#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
162164 #[repr(u8)]
163165 pub enum MvRef {
164166 /// Zero motion vector ("10" second branch; coded 0).
167+ #[default]
165168 Zero = 0,
166169 /// "Nearest" vector (coded 1).
167170 Nearest = 1,