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 {
8787 second_field: bool,
8888 }
8989
90-const MV_FRAME: u8 = 0;
91-const MV_FIELD_IN_FRAME: u8 = 1;
92-const MV_DUAL_FRAME: u8 = 2;
93-const MV_FIELD16: u8 = 3;
94-const MV_16X8: u8 = 4;
95-const MV_DUAL_FIELD: u8 = 5;
90+#[derive(Clone, Copy, Default, PartialEq, Eq)]
91+enum MotionKind {
92+ #[default]
93+ Frame,
94+ FieldInFrame,
95+ DualFrame,
96+ Field16,
97+ Mv16x8,
98+ DualField,
99+}
96100
97101 #[derive(Clone, Copy, Default)]
98102 struct Motion {
@@ -100,7 +104,7 @@ struct Motion {
100104 mv: [[[i32; 2]; 2]; 2],
101105 sel: [[u8; 2]; 2],
102106 dmv: [i32; 2],
103- kind: u8,
107+ kind: MotionKind,
104108 fwd: bool,
105109 bwd: bool,
106110 }
@@ -767,7 +771,7 @@ impl Core {
767771 // Same directions and vectors as the previous macroblock,
768772 // predicted frame-wise (field-wise from the same-parity
769773 // 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 };
771775 for s2 in 0..2 {
772776 m.mv[s2][0] = pmv[0][s2];
773777 m.mv[s2][1] = pmv[0][s2];
@@ -778,7 +782,7 @@ impl Core {
778782 pmv = [[[0; 2]; 2]; 2];
779783 m = Motion::default();
780784 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 };
782786 let sel = st.parity as u8;
783787 m.sel = [[sel; 2]; 2];
784788 motion = m;
@@ -834,19 +838,19 @@ impl Core {
834838 }
835839 m.kind = if field_pic {
836840 match kind_code {
837- 1 => MV_FIELD16,
838- 2 => MV_16X8,
839- _ => MV_DUAL_FIELD,
841+ 1 => MotionKind::Field16,
842+ 2 => MotionKind::Mv16x8,
843+ _ => MotionKind::DualField,
840844 }
841845 } else {
842846 match kind_code {
843- 1 => MV_FIELD_IN_FRAME,
844- 2 => MV_FRAME,
845- _ => MV_DUAL_FRAME,
847+ 1 => MotionKind::FieldInFrame,
848+ 2 => MotionKind::Frame,
849+ _ => MotionKind::DualFrame,
846850 }
847851 };
848852 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 };
850854 }
851855 // Motion vectors.
852856 if m.fwd || (intra && hdr.concealment_motion_vectors) {
@@ -869,7 +873,7 @@ impl Core {
869873 // No motion compensation: zero vector.
870874 pmv = [[[0; 2]; 2]; 2];
871875 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 };
873877 m.sel = [[st.parity as u8; 2]; 2];
874878 m.mv = [[[0; 2]; 2]; 2];
875879 }
@@ -1007,18 +1011,18 @@ impl Core {
10071011 let mvv = |r: usize| (m.mv[s][r][0], m.mv[s][r][1]);
10081012 let ptype = hdr.picture_type;
10091013 match m.kind {
1010- MV_FRAME => {
1014+ MotionKind::Frame => {
10111015 let (x, y) = mvv(0);
10121016 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 });
10131017 }
1014- MV_FIELD_IN_FRAME => {
1018+ MotionKind::FieldInFrame => {
10151019 for r in 0..2 {
10161020 let (x, y) = mvv(r);
10171021 let f = m.sel[s][r];
10181022 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 });
10191023 }
10201024 }
1021- MV_DUAL_FRAME => {
1025+ MotionKind::DualFrame => {
10221026 let (x, y) = mvv(0);
10231027 for p in 0..2usize {
10241028 let mm = if (p == 0) == hdr.top_field_first { 1 } else { 3 };
@@ -1030,20 +1034,19 @@ impl Core {
10301034 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 });
10311035 }
10321036 }
1033- MV_FIELD16 => {
1037+ MotionKind::Field16 => {
10341038 let (x, y) = mvv(0);
10351039 let f = m.sel[s][0];
10361040 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 });
10371041 }
1038- MV_16X8 => {
1042+ MotionKind::Mv16x8 => {
10391043 for r in 0..2 {
10401044 let (x, y) = mvv(r);
10411045 let f = m.sel[s][r];
10421046 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 });
10431047 }
10441048 }
1045- _ => {
1046- // MV_DUAL_FIELD
1049+ MotionKind::DualField => {
10471050 let (x, y) = mvv(0);
10481051 let p = st.parity as u8;
10491052 let e = if p == 0 { -1 } else { 1 };
@@ -1217,10 +1220,10 @@ fn read_motion(
12171220 s: usize,
12181221 ) -> std::result::Result<(), SliceError> {
12191222 let field_pic = hdr.structure != Structure::Frame;
1220- let dual = matches!(m.kind, MV_DUAL_FRAME | MV_DUAL_FIELD);
1221- let field_fmt = field_pic || m.kind != MV_FRAME;
1223+ let dual = matches!(m.kind, MotionKind::DualFrame | MotionKind::DualField);
1224+ let field_fmt = field_pic || m.kind != MotionKind::Frame;
12221225 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 };
12241227 let shift = if mpeg1 && hdr.full_pel[s] { 1 } else { 0 };
12251228 for r in 0..n {
12261229 if field_fmt && !dual {