#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Profile {
ConstrainedBaseline,
Baseline,
Main,
High,
Other(u8),
}
impl Profile {
pub fn profile_idc(self) -> u8 {
match self {
Profile::ConstrainedBaseline | Profile::Baseline => 66,
Profile::Main => 77,
Profile::High => 100,
Profile::Other(v) => v,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChromaFormat {
Monochrome,
Yuv420,
}
impl ChromaFormat {
pub fn idc(self) -> u8 {
match self {
ChromaFormat::Monochrome => 0,
ChromaFormat::Yuv420 => 1,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct YuvFrame {
pub width: usize,
pub height: usize,
pub y: Vec<u8>,
pub u: Vec<u8>,
pub v: Vec<u8>,
}
impl YuvFrame {
pub fn black(width: usize, height: usize) -> Self {
assert!(width % 2 == 0 && height % 2 == 0, "dimensions must be even");
let cw = width / 2;
let ch = height / 2;
Self {
width,
height,
y: vec![0; width * height],
u: vec![128; cw * ch],
v: vec![128; cw * ch],
}
}
pub fn chroma_width(&self) -> usize {
self.width / 2
}
pub fn chroma_height(&self) -> usize {
self.height / 2
}
pub fn is_valid(&self) -> bool {
self.y.len() == self.width * self.height
&& self.u.len() == self.chroma_width() * self.chroma_height()
&& self.v.len() == self.chroma_width() * self.chroma_height()
}
}