Skip to main content

v4l/format/
field.rs

1use std::convert::TryFrom;
2use std::fmt;
3
4#[derive(Debug, Copy, Clone)]
5#[repr(u32)]
6/// Represents how fields are interlaced (if they are)
7pub enum FieldOrder {
8    /// Progressive, Top, Bottom, or Interlaced is acceptable; driver will pick one
9    Any = 0,
10    /// progressive, not interlaced
11    Progressive = 1,
12    /// top, or odd, field
13    Top = 2,
14    /// bottom, or even, field
15    Bottom = 3,
16    /// both fields interlaced
17    Interlaced = 4,
18    /// top field stored first, then bottom field
19    SequentialTB = 5,
20    /// bottom field stored first, then top field
21    SequentialBT = 6,
22    /// one field at a time, alternates between top and bottom
23    Alternate = 7,
24    /// both fields interlaced, starts with top
25    InterlacedTB = 8,
26    /// both fields interlaced, starts with bottom
27    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}