将 v4l crate 的 FourCC 转换为 rustcv-core 的 FourCC
(cc: V4lFourCC)
| 3 | |
| 4 | /// 将 v4l crate 的 FourCC 转换为 rustcv-core 的 FourCC |
| 5 | pub fn from_v4l_fourcc(cc: V4lFourCC) -> PixelFormat { |
| 6 | // 提取 u32 原始值 |
| 7 | let code: u32 = cc.into(); |
| 8 | let core_cc = FourCC(code); |
| 9 | |
| 10 | match core_cc { |
| 11 | // --- 1. 标准 YUV --- |
| 12 | FourCC::YUYV => PixelFormat::Known(FourCC::YUYV), |
| 13 | FourCC::UYVY => PixelFormat::Known(FourCC::UYVY), |
| 14 | FourCC::NV12 => PixelFormat::Known(FourCC::NV12), |
| 15 | FourCC::YV12 => PixelFormat::Known(FourCC::YV12), |
| 16 | |
| 17 | // --- 2. 标准 RGB --- |
| 18 | FourCC::BGR3 => PixelFormat::Known(FourCC::BGR3), |
| 19 | FourCC::RGB3 => PixelFormat::Known(FourCC::RGB3), |
| 20 | |
| 21 | // --- 3. 压缩格式 --- |
| 22 | FourCC::MJPEG => PixelFormat::Known(FourCC::MJPEG), |
| 23 | FourCC::H264 => PixelFormat::Known(FourCC::H264), |
| 24 | |
| 25 | // --- 4. Bayer 格式 (这部分最容易出问题,不同内核版本定义可能不同) --- |
| 26 | // V4L2 定义:BA81 (BGGR), GB RG, etc. |
| 27 | FourCC::BA81 => PixelFormat::Known(FourCC::BA81), |
| 28 | FourCC::GBRG => PixelFormat::Known(FourCC::GBRG), |
| 29 | FourCC::GRBG => PixelFormat::Known(FourCC::GRBG), |
| 30 | FourCC::RGGB => PixelFormat::Known(FourCC::RGGB), |
| 31 | |
| 32 | // --- 5. 未知/私有格式 --- |
| 33 | _ => { |
| 34 | tracing::warn!(target: "rustcv::v4l2", "Unknown V4L2 pixel format: {}", core_cc.to_string()); |
| 35 | PixelFormat::Unknown(code) |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /// 将 rustcv-core 的 FourCC 转换为 v4l 的 FourCC |
| 41 | /// 用于请求设备设置格式 |
no test coverage detected