use std::convert::TryFrom;
use std::fmt;
#[derive(Debug, Copy, Clone)]
#[repr(u32)]
pub enum FieldOrder {
Any = 0,
Progressive = 1,
Top = 2,
Bottom = 3,
Interlaced = 4,
SequentialTB = 5,
SequentialBT = 6,
Alternate = 7,
InterlacedTB = 8,
InterlacedBT = 9,
}
impl fmt::Display for FieldOrder {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Any => write!(f, "any"),
Self::Progressive => write!(f, "progressive"),
Self::Top => write!(f, "top"),
Self::Bottom => write!(f, "bottom"),
Self::Interlaced => write!(f, "interlaced"),
Self::SequentialTB => write!(f, "sequential, top then bottom"),
Self::SequentialBT => write!(f, "sequential, bottom then top"),
Self::Alternate => write!(f, "alternate between fields"),
Self::InterlacedTB => write!(f, "interlaced, starting with top"),
Self::InterlacedBT => write!(f, "interlaced, starting with bottom"),
}
}
}
impl TryFrom<u32> for FieldOrder {
type Error = ();
fn try_from(code: u32) -> Result<Self, Self::Error> {
match code {
0 => Ok(Self::Any),
1 => Ok(Self::Progressive),
2 => Ok(Self::Top),
3 => Ok(Self::Bottom),
4 => Ok(Self::Interlaced),
5 => Ok(Self::SequentialTB),
6 => Ok(Self::SequentialBT),
7 => Ok(Self::Alternate),
8 => Ok(Self::InterlacedTB),
9 => Ok(Self::InterlacedBT),
_ => Err(()),
}
}
}