v4l/format/
quantization.rs

1use std::convert::TryFrom;
2use std::fmt;
3
4#[derive(Debug, Copy, Clone)]
5#[repr(u32)]
6/// Quantization for the colorspace.
7///
8/// The driver decides this for capture streams and the user sets
9/// it for output streams.
10pub enum Quantization {
11    /// default for the colorspace
12    Default = 0,
13    /// maps to the full range; 0 goes to 0 and 1 goes to 255
14    FullRange = 1,
15    /// maps to a limited range; 0 goes to 16 and 1 goes to 235
16    LimitedRange = 2,
17}
18
19impl fmt::Display for Quantization {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            Self::Default => write!(f, "default"),
23            Self::FullRange => write!(f, "full range"),
24            Self::LimitedRange => write!(f, "limited range"),
25        }
26    }
27}
28
29impl TryFrom<u32> for Quantization {
30    type Error = ();
31
32    fn try_from(code: u32) -> Result<Self, Self::Error> {
33        match code {
34            0 => Ok(Self::Default),
35            1 => Ok(Self::FullRange),
36            2 => Ok(Self::LimitedRange),
37            _ => Err(()),
38        }
39    }
40}