Skip to main content

moq_v4l/format/
transfer.rs

1use std::convert::TryFrom;
2use std::fmt;
3
4#[derive(Debug, Copy, Clone)]
5#[repr(u32)]
6/// Transfer function for the colorspace. The driver decides this for capture streams and the user
7/// sets it for output streams.
8pub enum TransferFunction {
9	/// default from the colorspace
10	Default = 0,
11	/// Rec. 709 transfer function
12	Rec709 = 1,
13	/// sRGB transfer function
14	SRGB = 2,
15	/// opRGB transfer function
16	OPRGB = 3,
17	/// SMPTE 230M transfer function
18	SMPTE240M = 4,
19	/// No transfer function
20	None = 5,
21	/// DCI-P3 transfer function
22	DCIP3 = 6,
23	/// SMPTE 2084 transfer function
24	SMPTE2084 = 7,
25}
26
27impl fmt::Display for TransferFunction {
28	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29		match self {
30			Self::Default => write!(f, "default transfer function"),
31			Self::Rec709 => write!(f, "Rec. 709 transfer function"),
32			Self::SRGB => write!(f, "sRGB transfer function"),
33			Self::OPRGB => write!(f, "opRGB transfer function"),
34			Self::SMPTE240M => write!(f, "SMPTE 240M transfer function"),
35			Self::None => write!(f, "No transfer function"),
36			Self::DCIP3 => write!(f, "DCI-P3 transfer function"),
37			Self::SMPTE2084 => write!(f, "SMPTE 2084 transfer function"),
38		}
39	}
40}
41
42impl TryFrom<u32> for TransferFunction {
43	type Error = ();
44
45	fn try_from(colorspace_code: u32) -> Result<Self, Self::Error> {
46		match colorspace_code {
47			0 => Ok(Self::Default),
48			1 => Ok(Self::Rec709),
49			2 => Ok(Self::SRGB),
50			3 => Ok(Self::OPRGB),
51			4 => Ok(Self::SMPTE240M),
52			5 => Ok(Self::None),
53			6 => Ok(Self::DCIP3),
54			7 => Ok(Self::SMPTE2084),
55			_ => Err(()),
56		}
57	}
58}