use std::rc::Rc;
use crate::{Error, Matrix, Result};
use super::VideoPixelFormat;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct PlaneExtent {
pub(crate) width: usize,
pub(crate) height: usize,
}
pub(crate) fn plane_count(format: VideoPixelFormat) -> usize {
match format {
VideoPixelFormat::Yuv420Planar8 | VideoPixelFormat::Yuv420Planar10 => 3,
VideoPixelFormat::Nv12 | VideoPixelFormat::P010 | VideoPixelFormat::P012 => 2,
}
}
pub(crate) fn plane_extents(
format: VideoPixelFormat,
width: usize,
height: usize,
) -> Result<Vec<PlaneExtent>> {
if width == 0 || height == 0 {
return Err(Error::invalid_argument(
"device-planar frames require a non-zero luma extent",
));
}
let chroma_width = width.div_ceil(2);
let chroma_height = height.div_ceil(2);
let extents = match format {
VideoPixelFormat::Yuv420Planar8 => vec![
PlaneExtent { width, height },
PlaneExtent {
width: chroma_width,
height: chroma_height,
},
PlaneExtent {
width: chroma_width,
height: chroma_height,
},
],
VideoPixelFormat::Nv12 => vec![
PlaneExtent { width, height },
PlaneExtent {
width: chroma_width * 2,
height: chroma_height,
},
],
VideoPixelFormat::Yuv420Planar10 | VideoPixelFormat::P010 | VideoPixelFormat::P012 => {
return Err(Error::missing_capability(
"10- and 12-bit planar frames wait for the VNV-01 storage decision",
));
}
};
Ok(extents)
}
#[derive(Clone)]
pub(crate) struct DevicePlanar {
pub(crate) planes: Rc<Vec<Matrix>>,
pub(crate) format: VideoPixelFormat,
pub(crate) width: usize,
pub(crate) height: usize,
}