diff --git a/jaenokhwa-core/src/pixel_format.rs b/jaenokhwa-core/src/pixel_format.rs index a35eb8a..c6dc9d6 100644 --- a/jaenokhwa-core/src/pixel_format.rs +++ b/jaenokhwa-core/src/pixel_format.rs @@ -1,11 +1,11 @@ use four_cc::FourCC; -pub const YUV420: FourCC = FourCC(*b"420v"); -pub const MJPEG: FourCC = FourCC(*b"MJPG"); -pub const YUYV: FourCC = FourCC(*b"YUYV"); -pub const RAWRGB: FourCC = FourCC(*b"RGB3"); +pub const YUV420V: FourCC = FourCC(*b"420v"); +pub const MJPEG: FourCC = FourCC(*b"mjpg"); +pub const YUYV: FourCC = FourCC(*b"yuyv"); +pub const RAWRGB: FourCC = FourCC(*b"rgb3"); pub const NV12: FourCC = FourCC(*b"nv12"); pub const UYVY: FourCC = FourCC(*b"uyvy"); // Also known as 2vuy pub const UYVY_APPLE: FourCC = FourCC(*b"2vuy"); -pub const GRAY: FourCC = FourCC(*b"GRAY"); +pub const GRAY: FourCC = FourCC(*b"gray"); diff --git a/src/convert_to_rgb.rs b/src/convert_to_rgb.rs index c9e2365..ff43a80 100644 --- a/src/convert_to_rgb.rs +++ b/src/convert_to_rgb.rs @@ -3,8 +3,11 @@ use ffmpeg_next::{ frame::Video, software::scaling::{Context, Flags}, }; -use jaenokhwa_core::buffer::FrameBuffer; -use jaenokhwa_core::pixel_format::{UYVY_APPLE, YUV420}; +use jaenokhwa_core::pixel_format::{UYVY, UYVY_APPLE, YUV420, YUV420V, YUYV}; +use jaenokhwa_core::{ + buffer::FrameBuffer, + pixel_format::{GRAY, MJPEG, NV12, RAWRGB}, +}; pub trait ConvertToRgb { fn convert_to_rgb(&self, _output_format: Pixel) -> Vec { @@ -14,9 +17,21 @@ pub trait ConvertToRgb { impl ConvertToRgb for FrameBuffer { fn convert_to_rgb(&self, output_format: Pixel) -> Vec { + if self.source_frame_format() == MJPEG { + panic!("MJPEG format is not supported"); + } + + if self.source_frame_format() == RAWRGB { + return self.buffer().to_vec(); + } + let pixel_format = match self.source_frame_format() { - YUV420 => Pixel::YUV420P, + YUV420V => Pixel::YUV420P, UYVY_APPLE => Pixel::UYVY422, + NV12 => Pixel::NV12, + YUYV => Pixel::YUYV422, + UYVY => Pixel::UYVY422, + GRAY => Pixel::GRAY8, _ => panic!("Unsupported pixel format {}", self.source_frame_format()), };