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 commit9f41bb02ec5e7007b03a35eacf6d3ef379208e17Parent: 9a9da9b1 changed file +30 -27
- crates/ec-mpeg2/src/decoder.rs +30 -27
crates/ec-mpeg2/src/decoder.rsmodified+30 -27
| @@ -87,12 +87,16 @@ struct PicState { | ||
| 87 | 87 | second_field: bool, |
| 88 | 88 | } |
| 89 | 89 | |
| 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 | +} | |
| 96 | 100 | |
| 97 | 101 | #[derive(Clone, Copy, Default)] |
| 98 | 102 | struct Motion { |
| @@ -100,7 +104,7 @@ struct Motion { | ||
| 100 | 104 | mv: [[[i32; 2]; 2]; 2], |
| 101 | 105 | sel: [[u8; 2]; 2], |
| 102 | 106 | dmv: [i32; 2], |
| 103 | - kind: u8, | |
| 107 | + kind: MotionKind, | |
| 104 | 108 | fwd: bool, |
| 105 | 109 | bwd: bool, |
| 106 | 110 | } |
| @@ -767,7 +771,7 @@ impl Core { | ||
| 767 | 771 | // Same directions and vectors as the previous macroblock, |
| 768 | 772 | // predicted frame-wise (field-wise from the same-parity |
| 769 | 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 | 775 | for s2 in 0..2 { |
| 772 | 776 | m.mv[s2][0] = pmv[0][s2]; |
| 773 | 777 | m.mv[s2][1] = pmv[0][s2]; |
| @@ -778,7 +782,7 @@ impl Core { | ||
| 778 | 782 | pmv = [[[0; 2]; 2]; 2]; |
| 779 | 783 | m = Motion::default(); |
| 780 | 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 | 786 | let sel = st.parity as u8; |
| 783 | 787 | m.sel = [[sel; 2]; 2]; |
| 784 | 788 | motion = m; |
| @@ -834,19 +838,19 @@ impl Core { | ||
| 834 | 838 | } |
| 835 | 839 | m.kind = if field_pic { |
| 836 | 840 | 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, | |
| 840 | 844 | } |
| 841 | 845 | } else { |
| 842 | 846 | 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, | |
| 846 | 850 | } |
| 847 | 851 | }; |
| 848 | 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 | 855 | // Motion vectors. |
| 852 | 856 | if m.fwd || (intra && hdr.concealment_motion_vectors) { |
| @@ -869,7 +873,7 @@ impl Core { | ||
| 869 | 873 | // No motion compensation: zero vector. |
| 870 | 874 | pmv = [[[0; 2]; 2]; 2]; |
| 871 | 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 | 877 | m.sel = [[st.parity as u8; 2]; 2]; |
| 874 | 878 | m.mv = [[[0; 2]; 2]; 2]; |
| 875 | 879 | } |
| @@ -1007,18 +1011,18 @@ impl Core { | ||
| 1007 | 1011 | let mvv = |r: usize| (m.mv[s][r][0], m.mv[s][r][1]); |
| 1008 | 1012 | let ptype = hdr.picture_type; |
| 1009 | 1013 | match m.kind { |
| 1010 | - MV_FRAME => { | |
| 1014 | + MotionKind::Frame => { | |
| 1011 | 1015 | let (x, y) = mvv(0); |
| 1012 | 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 | 1019 | for r in 0..2 { |
| 1016 | 1020 | let (x, y) = mvv(r); |
| 1017 | 1021 | let f = m.sel[s][r]; |
| 1018 | 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 | 1026 | let (x, y) = mvv(0); |
| 1023 | 1027 | for p in 0..2usize { |
| 1024 | 1028 | let mm = if (p == 0) == hdr.top_field_first { 1 } else { 3 }; |
| @@ -1030,20 +1034,19 @@ impl Core { | ||
| 1030 | 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 | 1038 | let (x, y) = mvv(0); |
| 1035 | 1039 | let f = m.sel[s][0]; |
| 1036 | 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 | 1043 | for r in 0..2 { |
| 1040 | 1044 | let (x, y) = mvv(r); |
| 1041 | 1045 | let f = m.sel[s][r]; |
| 1042 | 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 | - _ => { | |
| 1046 | - // MV_DUAL_FIELD | |
| 1049 | + MotionKind::DualField => { | |
| 1047 | 1050 | let (x, y) = mvv(0); |
| 1048 | 1051 | let p = st.parity as u8; |
| 1049 | 1052 | let e = if p == 0 { -1 } else { 1 }; |
| @@ -1217,10 +1220,10 @@ fn read_motion( | ||
| 1217 | 1220 | s: usize, |
| 1218 | 1221 | ) -> std::result::Result<(), SliceError> { |
| 1219 | 1222 | 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; | |
| 1222 | 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 | 1227 | let shift = if mpeg1 && hdr.full_pel[s] { 1 } else { 0 }; |
| 1225 | 1228 | for r in 0..n { |
| 1226 | 1229 | if field_fmt && !dual { |