use crate::bindings;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Matrix {
Bt601,
Bt709,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Color {
pub matrix: Matrix,
pub full_range: bool,
}
impl Color {
pub const BT601: Self = Self {
matrix: Matrix::Bt601,
full_range: false,
};
pub const BT709: Self = Self {
matrix: Matrix::Bt709,
full_range: false,
};
pub fn infer(height: u32) -> Self {
match height <= 576 {
true => Self::BT601,
false => Self::BT709,
}
}
pub(crate) fn vui(self) -> (u8, u8, u8) {
match self.matrix {
Matrix::Bt601 => (6, 1, 6),
Matrix::Bt709 => (1, 1, 1),
}
}
pub(crate) fn va_standard(self) -> u8 {
(match self.matrix {
Matrix::Bt601 => bindings::_VAProcColorStandardType_VAProcColorStandardBT601,
Matrix::Bt709 => bindings::_VAProcColorStandardType_VAProcColorStandardBT709,
}) as u8
}
pub(crate) fn va_range(self) -> u8 {
(match self.full_range {
true => bindings::VA_SOURCE_RANGE_FULL,
false => bindings::VA_SOURCE_RANGE_REDUCED,
}) as u8
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn inference_splits_at_standard_definition() {
assert_eq!(Color::infer(480), Color::BT601);
assert_eq!(Color::infer(576), Color::BT601);
assert_eq!(Color::infer(720), Color::BT709);
}
}