forge
Explore
Log in

Don't you dare go Hollow

S12: mpeg2 motion kind is a MotionKind enum instead of u8 consts (same six kinds, same arms; DualField arm explicit instead of the catch-all)

Browse files at this commit

9f41bb02ec5e7007b03a35eacf6d3ef379208e17Ahmet Kaan GümüşParent: 9a9da9b
crates/ec-mpeg2/src/decoder.rsmodified+30 -27
@@ -87,12 +87,16 @@ struct PicState {
87 second_field: bool,87 second_field: bool,
88 }88 }
89 89
90-const MV_FRAME: u8 = 0;90+#[derive(Clone, Copy, Default, PartialEq, Eq)]
91-const MV_FIELD_IN_FRAME: u8 = 1;91+enum MotionKind {
92-const MV_DUAL_FRAME: u8 = 2;92+ #[default]
93-const MV_FIELD16: u8 = 3;93+ Frame,
94-const MV_16X8: u8 = 4;94+ FieldInFrame,
95-const MV_DUAL_FIELD: u8 = 5;95+ DualFrame,
96+ Field16,
97+ Mv16x8,
98+ DualField,
99+}
96 100
97 #[derive(Clone, Copy, Default)]101 #[derive(Clone, Copy, Default)]
98 struct Motion {102 struct Motion {
@@ -100,7 +104,7 @@ struct Motion {
100 mv: [[[i32; 2]; 2]; 2],104 mv: [[[i32; 2]; 2]; 2],
101 sel: [[u8; 2]; 2],105 sel: [[u8; 2]; 2],
102 dmv: [i32; 2],106 dmv: [i32; 2],
103- kind: u8,107+ kind: MotionKind,
104 fwd: bool,108 fwd: bool,
105 bwd: bool,109 bwd: bool,
106 }110 }
@@ -767,7 +771,7 @@ impl Core {
767 // Same directions and vectors as the previous macroblock,771 // Same directions and vectors as the previous macroblock,
768 // predicted frame-wise (field-wise from the same-parity772 // predicted frame-wise (field-wise from the same-parity
769 // field in a field picture).773 // field in a field picture).
770- m.kind = if field_pic { MV_FIELD16 } else { MV_FRAME };774+ m.kind = if field_pic { MotionKind::Field16 } else { MotionKind::Frame };
771 for s2 in 0..2 {775 for s2 in 0..2 {
772 m.mv[s2][0] = pmv[0][s2];776 m.mv[s2][0] = pmv[0][s2];
773 m.mv[s2][1] = pmv[0][s2];777 m.mv[s2][1] = pmv[0][s2];
@@ -778,7 +782,7 @@ impl Core {
778 pmv = [[[0; 2]; 2]; 2];782 pmv = [[[0; 2]; 2]; 2];
779 m = Motion::default();783 m = Motion::default();
780 m.fwd = true;784 m.fwd = true;
781- m.kind = if field_pic { MV_FIELD16 } else { MV_FRAME };785+ m.kind = if field_pic { MotionKind::Field16 } else { MotionKind::Frame };
782 let sel = st.parity as u8;786 let sel = st.parity as u8;
783 m.sel = [[sel; 2]; 2];787 m.sel = [[sel; 2]; 2];
784 motion = m;788 motion = m;
@@ -834,19 +838,19 @@ impl Core {
834 }838 }
835 m.kind = if field_pic {839 m.kind = if field_pic {
836 match kind_code {840 match kind_code {
837- 1 => MV_FIELD16,841+ 1 => MotionKind::Field16,
838- 2 => MV_16X8,842+ 2 => MotionKind::Mv16x8,
839- _ => MV_DUAL_FIELD,843+ _ => MotionKind::DualField,
840 }844 }
841 } else {845 } else {
842 match kind_code {846 match kind_code {
843- 1 => MV_FIELD_IN_FRAME,847+ 1 => MotionKind::FieldInFrame,
844- 2 => MV_FRAME,848+ 2 => MotionKind::Frame,
845- _ => MV_DUAL_FRAME,849+ _ => MotionKind::DualFrame,
846 }850 }
847 };851 };
848 if intra && hdr.concealment_motion_vectors {852 if intra && hdr.concealment_motion_vectors {
849- m.kind = if field_pic { MV_FIELD16 } else { MV_FRAME };853+ m.kind = if field_pic { MotionKind::Field16 } else { MotionKind::Frame };
850 }854 }
851 // Motion vectors.855 // Motion vectors.
852 if m.fwd || (intra && hdr.concealment_motion_vectors) {856 if m.fwd || (intra && hdr.concealment_motion_vectors) {
@@ -869,7 +873,7 @@ impl Core {
869 // No motion compensation: zero vector.873 // No motion compensation: zero vector.
870 pmv = [[[0; 2]; 2]; 2];874 pmv = [[[0; 2]; 2]; 2];
871 m.fwd = true;875 m.fwd = true;
872- m.kind = if field_pic { MV_FIELD16 } else { MV_FRAME };876+ m.kind = if field_pic { MotionKind::Field16 } else { MotionKind::Frame };
873 m.sel = [[st.parity as u8; 2]; 2];877 m.sel = [[st.parity as u8; 2]; 2];
874 m.mv = [[[0; 2]; 2]; 2];878 m.mv = [[[0; 2]; 2]; 2];
875 }879 }
@@ -1007,18 +1011,18 @@ impl Core {
1007 let mvv = |r: usize| (m.mv[s][r][0], m.mv[s][r][1]);1011 let mvv = |r: usize| (m.mv[s][r][0], m.mv[s][r][1]);
1008 let ptype = hdr.picture_type;1012 let ptype = hdr.picture_type;
1009 match m.kind {1013 match m.kind {
1010- MV_FRAME => {1014+ MotionKind::Frame => {
1011 let (x, y) = mvv(0);1015 let (x, y) = mvv(0);
1012 push(Part { dst0: 0, step: 1, rows: 16, src: self.ref_for(ptype, s, None, st, cur), field: None, src_row: (mb_y * 16) as i32, mvx: x, mvy: y, avg: false });1016 push(Part { dst0: 0, step: 1, rows: 16, src: self.ref_for(ptype, s, None, st, cur), field: None, src_row: (mb_y * 16) as i32, mvx: x, mvy: y, avg: false });
1013 }1017 }
1014- MV_FIELD_IN_FRAME => {1018+ MotionKind::FieldInFrame => {
1015 for r in 0..2 {1019 for r in 0..2 {
1016 let (x, y) = mvv(r);1020 let (x, y) = mvv(r);
1017 let f = m.sel[s][r];1021 let f = m.sel[s][r];
1018 push(Part { dst0: r, step: 2, rows: 8, src: self.ref_for(ptype, s, Some(f), st, cur), field: Some(f), src_row: (mb_y * 8) as i32, mvx: x, mvy: y, avg: false });1022 push(Part { dst0: r, step: 2, rows: 8, src: self.ref_for(ptype, s, Some(f), st, cur), field: Some(f), src_row: (mb_y * 8) as i32, mvx: x, mvy: y, avg: false });
1019 }1023 }
1020 }1024 }
1021- MV_DUAL_FRAME => {1025+ MotionKind::DualFrame => {
1022 let (x, y) = mvv(0);1026 let (x, y) = mvv(0);
1023 for p in 0..2usize {1027 for p in 0..2usize {
1024 let mm = if (p == 0) == hdr.top_field_first { 1 } else { 3 };1028 let mm = if (p == 0) == hdr.top_field_first { 1 } else { 3 };
@@ -1030,20 +1034,19 @@ impl Core {
1030 push(Part { dst0: p, step: 2, rows: 8, src, field: Some(1 - p as u8), src_row: (mb_y * 8) as i32, mvx: ox, mvy: oy, avg: true });1034 push(Part { dst0: p, step: 2, rows: 8, src, field: Some(1 - p as u8), src_row: (mb_y * 8) as i32, mvx: ox, mvy: oy, avg: true });
1031 }1035 }
1032 }1036 }
1033- MV_FIELD16 => {1037+ MotionKind::Field16 => {
1034 let (x, y) = mvv(0);1038 let (x, y) = mvv(0);
1035 let f = m.sel[s][0];1039 let f = m.sel[s][0];
1036 push(Part { dst0: 0, step: 1, rows: 16, src: self.ref_for(ptype, s, Some(f), st, cur), field: Some(f), src_row: (mb_y * 16) as i32, mvx: x, mvy: y, avg: false });1040 push(Part { dst0: 0, step: 1, rows: 16, src: self.ref_for(ptype, s, Some(f), st, cur), field: Some(f), src_row: (mb_y * 16) as i32, mvx: x, mvy: y, avg: false });
1037 }1041 }
1038- MV_16X8 => {1042+ MotionKind::Mv16x8 => {
1039 for r in 0..2 {1043 for r in 0..2 {
1040 let (x, y) = mvv(r);1044 let (x, y) = mvv(r);
1041 let f = m.sel[s][r];1045 let f = m.sel[s][r];
1042 push(Part { dst0: 8 * r, step: 1, rows: 8, src: self.ref_for(ptype, s, Some(f), st, cur), field: Some(f), src_row: (mb_y * 16 + 8 * r) as i32, mvx: x, mvy: y, avg: false });1046 push(Part { dst0: 8 * r, step: 1, rows: 8, src: self.ref_for(ptype, s, Some(f), st, cur), field: Some(f), src_row: (mb_y * 16 + 8 * r) as i32, mvx: x, mvy: y, avg: false });
1043 }1047 }
1044 }1048 }
1045- _ => {1049+ MotionKind::DualField => {
1046- // MV_DUAL_FIELD
1047 let (x, y) = mvv(0);1050 let (x, y) = mvv(0);
1048 let p = st.parity as u8;1051 let p = st.parity as u8;
1049 let e = if p == 0 { -1 } else { 1 };1052 let e = if p == 0 { -1 } else { 1 };
@@ -1217,10 +1220,10 @@ fn read_motion(
1217 s: usize,1220 s: usize,
1218 ) -> std::result::Result<(), SliceError> {1221 ) -> std::result::Result<(), SliceError> {
1219 let field_pic = hdr.structure != Structure::Frame;1222 let field_pic = hdr.structure != Structure::Frame;
1220- let dual = matches!(m.kind, MV_DUAL_FRAME | MV_DUAL_FIELD);1223+ let dual = matches!(m.kind, MotionKind::DualFrame | MotionKind::DualField);
1221- let field_fmt = field_pic || m.kind != MV_FRAME;1224+ let field_fmt = field_pic || m.kind != MotionKind::Frame;
1222 let frame_field = !field_pic && field_fmt;1225 let frame_field = !field_pic && field_fmt;
1223- let n = if matches!(m.kind, MV_FIELD_IN_FRAME | MV_16X8) { 2 } else { 1 };1226+ let n = if matches!(m.kind, MotionKind::FieldInFrame | MotionKind::Mv16x8) { 2 } else { 1 };
1224 let shift = if mpeg1 && hdr.full_pel[s] { 1 } else { 0 };1227 let shift = if mpeg1 && hdr.full_pel[s] { 1 } else { 0 };
1225 for r in 0..n {1228 for r in 0..n {
1226 if field_fmt && !dual {1229 if field_fmt && !dual {