use std::convert::TryFrom;
use std::fmt;
#[derive(Debug, Copy, Clone)]
#[repr(u32)]
pub enum Colorspace {
Default = 0,
SMPTE170M = 1,
SMPTE240M = 2,
Rec709 = 3,
NTSC = 5,
EBUTech3212 = 6,
JPEG = 7,
SRGB = 8,
OPRGB = 9,
Rec2020 = 10,
RAW = 11,
DCIP3 = 12,
}
impl fmt::Display for Colorspace {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Default => write!(f, "default"),
Self::SMPTE170M => write!(f, "SMPTE 170M"),
Self::SMPTE240M => write!(f, "SMPTE 240M"),
Self::Rec709 => write!(f, "Rec. 709"),
Self::NTSC => write!(f, "NTSC"),
Self::EBUTech3212 => write!(f, "EBU Tech 3213"),
Self::JPEG => write!(f, "JPEG"),
Self::SRGB => write!(f, "sRGB"),
Self::OPRGB => write!(f, "opRGB"),
Self::Rec2020 => write!(f, "Rec. 2020"),
Self::RAW => write!(f, "RAW"),
Self::DCIP3 => write!(f, "DCI-P3"),
}
}
}
impl TryFrom<u32> for Colorspace {
type Error = ();
fn try_from(code: u32) -> Result<Self, Self::Error> {
match code {
0 => Ok(Self::Default),
1 => Ok(Self::SMPTE170M),
2 => Ok(Self::SMPTE240M),
3 => Ok(Self::Rec709),
5 => Ok(Self::NTSC),
6 => Ok(Self::EBUTech3212),
7 => Ok(Self::JPEG),
8 => Ok(Self::SRGB),
9 => Ok(Self::OPRGB),
10 => Ok(Self::Rec2020),
11 => Ok(Self::RAW),
12 => Ok(Self::DCIP3),
_ => Err(()),
}
}
}