#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BitDepth {
Eight = 8,
Ten = 10,
Twelve = 12,
}
impl BitDepth {
#[must_use]
pub fn bits(self) -> u8 {
self as u8
}
#[must_use]
pub fn from_bits(bits: u32) -> Option<Self> {
match bits {
8 => Some(BitDepth::Eight),
10 => Some(BitDepth::Ten),
12 => Some(BitDepth::Twelve),
_ => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ChromaSubsampling {
Cs444,
Cs422,
Cs420,
Cs400,
}
impl ChromaSubsampling {
#[must_use]
pub fn subsampling(self) -> (u8, u8) {
match self {
ChromaSubsampling::Cs444 | ChromaSubsampling::Cs400 => (0, 0),
ChromaSubsampling::Cs422 => (1, 0),
ChromaSubsampling::Cs420 => (1, 1),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn bit_depth_bits() {
assert_eq!(BitDepth::Eight.bits(), 8);
assert_eq!(BitDepth::Ten.bits(), 10);
assert_eq!(BitDepth::Twelve.bits(), 12);
for d in [BitDepth::Eight, BitDepth::Ten, BitDepth::Twelve] {
assert_eq!(BitDepth::from_bits(u32::from(d.bits())), Some(d));
}
assert_eq!(BitDepth::from_bits(16), None);
assert_eq!(BitDepth::from_bits(0), None);
}
#[test]
fn subsampling_flags() {
assert_eq!(ChromaSubsampling::Cs444.subsampling(), (0, 0));
assert_eq!(ChromaSubsampling::Cs420.subsampling(), (1, 1));
assert_eq!(ChromaSubsampling::Cs422.subsampling(), (1, 0));
}
}