1use std::convert::TryFrom;
2use std::fmt;
3
4#[derive(Debug, Copy, Clone)]
5#[repr(u32)]
6pub enum FieldOrder {
8 Any = 0,
10 Progressive = 1,
12 Top = 2,
14 Bottom = 3,
16 Interlaced = 4,
18 SequentialTB = 5,
20 SequentialBT = 6,
22 Alternate = 7,
24 InterlacedTB = 8,
26 InterlacedBT = 9,
28}
29
30impl fmt::Display for FieldOrder {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 Self::Any => write!(f, "any"),
34 Self::Progressive => write!(f, "progressive"),
35 Self::Top => write!(f, "top"),
36 Self::Bottom => write!(f, "bottom"),
37 Self::Interlaced => write!(f, "interlaced"),
38 Self::SequentialTB => write!(f, "sequential, top then bottom"),
39 Self::SequentialBT => write!(f, "sequential, bottom then top"),
40 Self::Alternate => write!(f, "alternate between fields"),
41 Self::InterlacedTB => write!(f, "interlaced, starting with top"),
42 Self::InterlacedBT => write!(f, "interlaced, starting with bottom"),
43 }
44 }
45}
46
47impl TryFrom<u32> for FieldOrder {
48 type Error = ();
49
50 fn try_from(code: u32) -> Result<Self, Self::Error> {
51 match code {
52 0 => Ok(Self::Any),
53 1 => Ok(Self::Progressive),
54 2 => Ok(Self::Top),
55 3 => Ok(Self::Bottom),
56 4 => Ok(Self::Interlaced),
57 5 => Ok(Self::SequentialTB),
58 6 => Ok(Self::SequentialBT),
59 7 => Ok(Self::Alternate),
60 8 => Ok(Self::InterlacedTB),
61 9 => Ok(Self::InterlacedBT),
62 _ => Err(()),
63 }
64 }
65}