#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PixelFormat {
Rgb8,
Rgba8,
}
impl PixelFormat {
#[must_use]
pub fn bytes_per_pixel(self) -> usize {
match self {
PixelFormat::Rgb8 => 3,
PixelFormat::Rgba8 => 4,
}
}
}
#[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
}
}
#[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 pixel_format_bpp() {
assert_eq!(PixelFormat::Rgb8.bytes_per_pixel(), 3);
assert_eq!(PixelFormat::Rgba8.bytes_per_pixel(), 4);
}
#[test]
fn bit_depth_bits() {
assert_eq!(BitDepth::Eight.bits(), 8);
assert_eq!(BitDepth::Ten.bits(), 10);
assert_eq!(BitDepth::Twelve.bits(), 12);
}
#[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));
}
}