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 {
95 #[derive(Clone, Default)]95 #[derive(Clone, Default)]
96 struct MbInfo {96 struct MbInfo {
97 /// [`modes::YMode`] as its coded integer.97 /// [`modes::YMode`] as its coded integer.
98- y_mode: u8,98+ y_mode: modes::YMode,
99- uv_mode: u8,99+ uv_mode: modes::YMode,
100- b_modes: [u8; 16],100+ b_modes: [modes::BMode; 16],
101 segment_id: u8,101 segment_id: u8,
102 skip: bool,102 skip: bool,
103 /// 0 = intra, 1 = last, 2 = golden, 3 = altref (§16.2). Key-frame103 /// 0 = intra, 1 = last, 2 = golden, 3 = altref (§16.2). Key-frame
@@ -105,7 +105,7 @@ struct MbInfo {
105 ref_frame: u8,105 ref_frame: u8,
106 /// Inter mv_ref leaf (§16.2): 0 = zero, 1 = nearest, 2 = near,106 /// Inter mv_ref leaf (§16.2): 0 = zero, 1 = nearest, 2 = near,
107 /// 3 = new, 4 = split. 0 when intra.107 /// 3 = new, 4 = split. 0 when intra.
108- mv_ref: u8,108+ mv_ref: modes::MvRef,
109 /// Whole-MB motion vector in eighth-pels; the bottom-right subblock's109 /// Whole-MB motion vector in eighth-pels; the bottom-right subblock's
110 /// vector for SPLITMV (what future neighbours' census sees).110 /// vector for SPLITMV (what future neighbours' census sees).
111 mv: (i16, i16),111 mv: (i16, i16),
@@ -135,7 +135,7 @@ const MC_BORDER: usize = 32;
135 135
136 impl MbInfo {136 impl MbInfo {
137 fn has_y2(&self) -> bool {137 fn has_y2(&self) -> bool {
138- self.y_mode != modes::YMode::BPred.as_u8()138+ self.y_mode != modes::YMode::BPred
139 }139 }
140 }140 }
141 141
@@ -517,15 +517,15 @@ impl Decoder {
517 if header.lf_delta_enabled {517 if header.lf_delta_enabled {
518 level += self.state.ref_lf_delta[usize::from(mb.ref_frame)];518 level += self.state.ref_lf_delta[usize::from(mb.ref_frame)];
519 let mode_idx = if mb.ref_frame == 0 {519 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 {
521 Some(0)521 Some(0)
522 } else {522 } else {
523 None523 None
524 }524 }
525 } else {525 } else {
526 match mb.mv_ref {526 match mb.mv_ref {
527- 0 => Some(1), // ZEROMV527+ modes::MvRef::Zero => Some(1), // ZEROMV
528- 4 => Some(3), // SPLITMV528+ modes::MvRef::Split => Some(3), // SPLITMV
529 _ => Some(2), // NEAREST / NEAR / NEW529 _ => Some(2), // NEAREST / NEAR / NEW
530 }530 }
531 };531 };
@@ -729,13 +729,13 @@ impl Decoder {
729 // context-dependent kf_bmode_prob table is key-frame-only).729 // context-dependent kf_bmode_prob table is key-frame-only).
730 mb.ref_frame = 0;730 mb.ref_frame = 0;
731 let ymode = modes::read_ymode(d, ymode_probs);731 let ymode = modes::read_ymode(d, ymode_probs);
732- mb.y_mode = ymode.as_u8();732+ mb.y_mode = ymode;
733 if ymode == modes::YMode::BPred {733 if ymode == modes::YMode::BPred {
734 for j in 0..16usize {734 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);
736 }736 }
737 }737 }
738- mb.uv_mode = modes::read_uvmode(d, uv_mode_probs).as_u8();738+ mb.uv_mode = modes::read_uvmode(d, uv_mode_probs);
739 return;739 return;
740 }740 }
741 741
@@ -755,17 +755,17 @@ impl Decoder {
755 let (mut near_mvs, cnt) = modes::find_near_mvs(above, left, aboveleft, to_bias);755 let (mut near_mvs, cnt) = modes::find_near_mvs(above, left, aboveleft, to_bias);
756 756
757 if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_INTRA] as usize][0]) {757 if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_INTRA] as usize][0]) {
758- mb.mv_ref = 0; // ZEROMV758+ mb.mv_ref = modes::MvRef::Zero;
759 return;759 return;
760 }760 }
761 if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_NEAREST] as usize][1]) {761 if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_NEAREST] as usize][1]) {
762- mb.mv_ref = 1; // NEARESTMV762+ mb.mv_ref = modes::MvRef::Nearest;
763 mb.mv = near_mvs[modes::CNT_NEAREST];763 mb.mv = near_mvs[modes::CNT_NEAREST];
764 modes::clamp_mv2(&mut mb.mv, edges);764 modes::clamp_mv2(&mut mb.mv, edges);
765 return;765 return;
766 }766 }
767 if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_NEAR] as usize][2]) {767 if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_NEAR] as usize][2]) {
768- mb.mv_ref = 2; // NEARMV768+ mb.mv_ref = modes::MvRef::Near;
769 mb.mv = near_mvs[modes::CNT_NEAR];769 mb.mv = near_mvs[modes::CNT_NEAR];
770 modes::clamp_mv2(&mut mb.mv, edges);770 modes::clamp_mv2(&mut mb.mv, edges);
771 return;771 return;
@@ -778,7 +778,7 @@ impl Decoder {
778 modes::clamp_mv2(&mut near_mvs[near_index], edges);778 modes::clamp_mv2(&mut near_mvs[near_index], edges);
779 let best = near_mvs[near_index];779 let best = near_mvs[near_index];
780 if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_SPLITMV] as usize][3]) {780 if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_SPLITMV] as usize][3]) {
781- mb.mv_ref = 3; // NEWMV781+ mb.mv_ref = modes::MvRef::New;
782 let mut mv = modes::read_mv(d, &self.state.mv_probs);782 let mut mv = modes::read_mv(d, &self.state.mv_probs);
783 mv.0 = mv.0.wrapping_add(best.0);783 mv.0 = mv.0.wrapping_add(best.0);
784 mv.1 = mv.1.wrapping_add(best.1);784 mv.1 = mv.1.wrapping_add(best.1);
@@ -806,7 +806,7 @@ impl Decoder {
806 intra: false,806 intra: false,
807 zero: mb.mv == (0, 0),807 zero: mb.mv == (0, 0),
808 mv: mb.mv,808 mv: mb.mv,
809- is_split: mb.mv_ref == 4,809+ is_split: mb.mv_ref == modes::MvRef::Split,
810 sign_bias: sign_bias[usize::from(mb.ref_frame) - 1],810 sign_bias: sign_bias[usize::from(mb.ref_frame) - 1],
811 }811 }
812 }812 }
@@ -830,7 +830,7 @@ impl Decoder {
830 let k = usize::from(modes::MBSPLIT_OFFSET[s][j]);830 let k = usize::from(modes::MBSPLIT_OFFSET[s][j]);
831 let leftmv = if k % 4 == 0 {831 let leftmv = if k % 4 == 0 {
832 let lm = self.mbi(row, col - 1);832 let lm = self.mbi(row, col - 1);
833- if lm.mv_ref == 4 {833+ if lm.mv_ref == modes::MvRef::Split {
834 lm.bmi[k + 3]834 lm.bmi[k + 3]
835 } else {835 } else {
836 lm.mv836 lm.mv
@@ -840,7 +840,7 @@ impl Decoder {
840 };840 };
841 let abovemv = if k < 4 {841 let abovemv = if k < 4 {
842 let am = self.mbi(row - 1, col);842 let am = self.mbi(row - 1, col);
843- if am.mv_ref == 4 {843+ if am.mv_ref == modes::MvRef::Split {
844 am.bmi[k + 12]844 am.bmi[k + 12]
845 } else {845 } else {
846 am.mv846 am.mv
@@ -866,9 +866,9 @@ impl Decoder {
866 mb.bmi[usize::from(off)] = blockmv;866 mb.bmi[usize::from(off)] = blockmv;
867 }867 }
868 }868 }
869- mb.mv_ref = 4;869+ mb.mv_ref = modes::MvRef::Split;
870 // 4x4 residual coding without a Y2 block (like B_PRED).870 // 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;
872 // Neighbours' census sees the bottom-right subblock's vector.872 // Neighbours' census sees the bottom-right subblock's vector.
873 mb.mv = mb.bmi[15];873 mb.mv = mb.bmi[15];
874 }874 }
@@ -907,7 +907,7 @@ impl Decoder {
907 // SPLITMV (identical output to libvpx's grouped predicts). Each907 // SPLITMV (identical output to libvpx's grouped predicts). Each
908 // predict lands at its own (bx, by) slot of one 16x16 patch.908 // predict lands at its own (bx, by) slot of one 16x16 patch.
909 let mut py = [0u8; 256];909 let mut py = [0u8; 256];
910- if mb.mv_ref == 4 {910+ if mb.mv_ref == modes::MvRef::Split {
911 for b in 0..16usize {911 for b in 0..16usize {
912 let (bx, by) = ((b % 4) * 4, (b / 4) * 4);912 let (bx, by) = ((b % 4) * 4, (b / 4) * 4);
913 // reconinter.c:370-374: the four corner subblocks clamp913 // reconinter.c:370-374: the four corner subblocks clamp
@@ -936,7 +936,7 @@ impl Decoder {
936 // clamps only under need_to_clamp_mvs.936 // clamps only under need_to_clamp_mvs.
937 let mut pu = [0u8; 256];937 let mut pu = [0u8; 256];
938 let mut pv = [0u8; 256];938 let mut pv = [0u8; 256];
939- if mb.mv_ref == 4 {939+ if mb.mv_ref == modes::MvRef::Split {
940 for q in 0..4usize {940 for q in 0..4usize {
941 // Quadrant q: 4x4 chroma pixels at (qx4, qy4) in the MB.941 // Quadrant q: 4x4 chroma pixels at (qx4, qy4) in the MB.
942 let (qx4, qy4) = ((q % 2) * 4, (q / 2) * 4);942 let (qx4, qy4) = ((q % 2) * 4, (q / 2) * 4);
@@ -1016,28 +1016,28 @@ impl Decoder {
1016 mb: &mut MbInfo,1016 mb: &mut MbInfo,
1017 ) {1017 ) {
1018 let ymode = modes::read_kf_ymode(d);1018 let ymode = modes::read_kf_ymode(d);
1019- mb.y_mode = ymode.as_u8();1019+ mb.y_mode = ymode;
1020 if ymode == modes::YMode::BPred {1020 if ymode == modes::YMode::BPred {
1021 for j in 0..16u8 {1021 for j in 0..16u8 {
1022 let a = self.above_block_mode(row, col, j, mb);1022 let a = self.above_block_mode(row, col, j, mb);
1023 let l = self.left_block_mode(row, col, j, mb);1023 let l = self.left_block_mode(row, col, j, mb);
1024 mb.b_modes[usize::from(j)] =1024 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())]);
1026 }1026 }
1027 }1027 }
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);
1029 }1029 }
1030 1030
1031 /// Above subblock mode context (dixie `above_block_mode`): subblocks1031 /// Above subblock mode context (dixie `above_block_mode`): subblocks
1032 /// 0-3 take the above MB's derived mode, inner subblocks the mode1032 /// 0-3 take the above MB's derived mode, inner subblocks the mode
1033 /// `j-4` of this same MB (already decoded into `mb`).1033 /// `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 {
1035 if j < 4 {1035 if j < 4 {
1036 let above = self.mbi(row - 1, col);1036 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 {
1038 above.b_modes[usize::from(j) + 12]1038 above.b_modes[usize::from(j) + 12]
1039 } else {1039 } else {
1040- ymode_as_bmode(above.y_mode)1040+ above.y_mode.as_bmode()
1041 }1041 }
1042 } else {1042 } else {
1043 mb.b_modes[usize::from(j) - 4]1043 mb.b_modes[usize::from(j) - 4]
@@ -1045,13 +1045,13 @@ impl Decoder {
1045 }1045 }
1046 1046
1047 /// Left subblock mode context (dixie `left_block_mode`).1047 /// 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 {
1049 if j.is_multiple_of(4) {1049 if j.is_multiple_of(4) {
1050 let left = self.mbi(row, col - 1);1050 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 {
1052 left.b_modes[usize::from(j) + 3]1052 left.b_modes[usize::from(j) + 3]
1053 } else {1053 } else {
1054- ymode_as_bmode(left.y_mode)1054+ left.y_mode.as_bmode()
1055 }1055 }
1056 } else {1056 } else {
1057 mb.b_modes[usize::from(j) - 1]1057 mb.b_modes[usize::from(j) - 1]
@@ -1087,7 +1087,7 @@ impl Decoder {
1087 [0; 16]1087 [0; 16]
1088 };1088 };
1089 1089
1090- if y_mode == modes::YMode::BPred.as_u8() {1090+ if y_mode == modes::YMode::BPred {
1091 for b in 0..16usize {1091 for b in 0..16usize {
1092 let bx = (b % 4) * 4;1092 let bx = (b % 4) * 4;
1093 let by = (b / 4) * 4;1093 let by = (b / 4) * 4;
@@ -1109,7 +1109,7 @@ impl Decoder {
1109 }1109 }
1110 let p = self.y.data[self.y.at_above_left(x + bx, y + by)];1110 let p = self.y.data[self.y.at_above_left(x + bx, y + by)];
1111 let mut block = [0u8; 16];1111 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)?;
1113 for i in 0..4 {1113 for i in 0..4 {
1114 let d = self.y.at(x + bx, y + by + i);1114 let d = self.y.at(x + bx, y + by + i);
1115 self.y.data[d..d + 4].copy_from_slice(&block[i * 4..i * 4 + 4]);1115 self.y.data[d..d + 4].copy_from_slice(&block[i * 4..i * 4 + 4]);
@@ -1139,7 +1139,7 @@ impl Decoder {
1139 };1139 };
1140 let mut pred = [0u8; 256];1140 let mut pred = [0u8; 256];
1141 intra::predict16(1141 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,
1143 )?;1143 )?;
1144 // loop indexes several parallel arrays; the index is clearer than zip chains1144 // loop indexes several parallel arrays; the index is clearer than zip chains
1145 #[allow(clippy::needless_range_loop)]1145 #[allow(clippy::needless_range_loop)]
@@ -1170,7 +1170,7 @@ impl Decoder {
1170 let mut pred_u = [0u8; 64];1170 let mut pred_u = [0u8; 64];
1171 let mut pred_v = [0u8; 64];1171 let mut pred_v = [0u8; 64];
1172 intra::predict8(1172 intra::predict8(
1173- uv_mode,1173+ uv_mode.as_u8(),
1174 have_above,1174 have_above,
1175 have_left,1175 have_left,
1176 &above_u,1176 &above_u,
@@ -1179,7 +1179,7 @@ impl Decoder {
1179 &mut pred_u,1179 &mut pred_u,
1180 )?;1180 )?;
1181 intra::predict8(1181 intra::predict8(
1182- uv_mode,1182+ uv_mode.as_u8(),
1183 have_above,1183 have_above,
1184 have_left,1184 have_left,
1185 &above_v,1185 &above_v,
@@ -1285,16 +1285,6 @@ impl Default for Decoder {
1285 /// Segment-map coding tree (RFC 6386 §10): plain two-level split of 0-3.1285 /// Segment-map coding tree (RFC 6386 §10): plain two-level split of 0-3.
1286 const SEGMENT_TREE: [i8; 6] = [2, 4, 0, -1, -2, -3];1286 const SEGMENT_TREE: [i8; 6] = [2, 4, 0, -1, -2, -3];
1287 1287
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-
1298 /// Add one 4x4 block's dequantized-coefficient residual to its1288 /// Add one 4x4 block's dequantized-coefficient residual to its
1299 /// prediction: reads the prediction patch from `pred`, clamps, writes1289 /// prediction: reads the prediction patch from `pred`, clamps, writes
1300 /// into the strided plane (§14.4/§14.5).1290 /// into the strided plane (§14.4/§14.5).
crates/ec-vp8/src/modes.rsmodified+6 -3
@@ -5,10 +5,11 @@ use crate::bool::BoolDecoder;
5 5
6 /// Intra macroblock luma modes (RFC 6386 §8.2 enum values are normative;6 /// Intra macroblock luma modes (RFC 6386 §8.2 enum values are normative;
7 /// chroma modes are the first four).7 /// chroma modes are the first four).
8-#[derive(Debug, Clone, Copy, PartialEq, Eq)]8+#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
9 #[repr(u8)]9 #[repr(u8)]
10 pub enum YMode {10 pub enum YMode {
11 /// Predict DC from the row above and column to the left.11 /// Predict DC from the row above and column to the left.
12+ #[default]
12 DcPred = 0,13 DcPred = 0,
13 /// Predict rows from the row above.14 /// Predict rows from the row above.
14 VPred = 1,15 VPred = 1,
@@ -40,10 +41,11 @@ impl YMode {
40 }41 }
41 42
42 /// The ten 4x4 subblock prediction modes (RFC 6386 §11.2).43 /// 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)]
44 #[repr(u8)]45 #[repr(u8)]
45 pub enum BMode {46 pub enum BMode {
46 /// DC from above row and left column.47 /// DC from above row and left column.
48+ #[default]
47 BDCPred = 0,49 BDCPred = 0,
48 /// True-motion.50 /// True-motion.
49 BTMPred = 1,51 BTMPred = 1,
@@ -158,10 +160,11 @@ pub fn read_bmode(d: &mut BoolDecoder<'_>, probs: &[u8]) -> BMode {
158 /// Inter-frame motion-vector reference modes (RFC 6386 §16.2), offset160 /// Inter-frame motion-vector reference modes (RFC 6386 §16.2), offset
159 /// from the intra modes by `num_ymodes` in the reference enum; here they161 /// from the intra modes by `num_ymodes` in the reference enum; here they
160 /// are their own small enum with the RFC's tree integers.162 /// 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)]
162 #[repr(u8)]164 #[repr(u8)]
163 pub enum MvRef {165 pub enum MvRef {
164 /// Zero motion vector ("10" second branch; coded 0).166 /// Zero motion vector ("10" second branch; coded 0).
167+ #[default]
165 Zero = 0,168 Zero = 0,
166 /// "Nearest" vector (coded 1).169 /// "Nearest" vector (coded 1).
167 Nearest = 1,170 Nearest = 1,