use rustcv_core::pixel_format::{FourCC, PixelFormat};
use v4l::format::fourcc::FourCC as V4lFourCC;
pub fn from_v4l_fourcc(cc: V4lFourCC) -> PixelFormat {
let code: u32 = cc.into();
let core_cc = FourCC(code);
match core_cc {
FourCC::YUYV => PixelFormat::Known(FourCC::YUYV),
FourCC::UYVY => PixelFormat::Known(FourCC::UYVY),
FourCC::NV12 => PixelFormat::Known(FourCC::NV12),
FourCC::YV12 => PixelFormat::Known(FourCC::YV12),
FourCC::BGR3 => PixelFormat::Known(FourCC::BGR3),
FourCC::RGB3 => PixelFormat::Known(FourCC::RGB3),
FourCC::MJPEG => PixelFormat::Known(FourCC::MJPEG),
FourCC::H264 => PixelFormat::Known(FourCC::H264),
FourCC::BA81 => PixelFormat::Known(FourCC::BA81),
FourCC::GBRG => PixelFormat::Known(FourCC::GBRG),
FourCC::GRBG => PixelFormat::Known(FourCC::GRBG),
FourCC::RGGB => PixelFormat::Known(FourCC::RGGB),
_ => {
tracing::warn!(target: "rustcv::v4l2", "Unknown V4L2 pixel format: {}", core_cc.to_string());
PixelFormat::Unknown(code)
}
}
}
pub fn to_v4l_fourcc(fmt: PixelFormat) -> Option<V4lFourCC> {
match fmt {
PixelFormat::Known(cc) => Some(V4lFourCC::new(&cc.0.to_le_bytes())),
PixelFormat::Unknown(_) => None, }
}