Skip to content

Commit

Permalink
Missing RGB pixel formats
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHayton committed Jul 31, 2024
1 parent d81b469 commit f30c6d3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
10 changes: 5 additions & 5 deletions jaenokhwa-core/src/pixel_format.rs
Original file line number Diff line number Diff line change
@@ -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");
21 changes: 18 additions & 3 deletions src/convert_to_rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Check failure on line 6 in src/convert_to_rgb.rs

View workflow job for this annotation

GitHub Actions / compile_examples (capture, ubuntu-latest)

unresolved import `jaenokhwa_core::pixel_format::YUV420`

Check failure on line 6 in src/convert_to_rgb.rs

View workflow job for this annotation

GitHub Actions / compile_and_check (ubuntu-latest)

unresolved import `jaenokhwa_core::pixel_format::YUV420`

Check failure on line 6 in src/convert_to_rgb.rs

View workflow job for this annotation

GitHub Actions / compile_and_check (macos-latest)

unresolved import `jaenokhwa_core::pixel_format::YUV420`

Check failure on line 6 in src/convert_to_rgb.rs

View workflow job for this annotation

GitHub Actions / compile_examples (capture, macos-latest)

unresolved import `jaenokhwa_core::pixel_format::YUV420`

Check failure on line 6 in src/convert_to_rgb.rs

View workflow job for this annotation

GitHub Actions / compile_examples (convert-to-rgb, ubuntu-latest)

unresolved import `jaenokhwa_core::pixel_format::YUV420`

Check failure on line 6 in src/convert_to_rgb.rs

View workflow job for this annotation

GitHub Actions / compile_examples (convert-to-rgb, macos-latest)

unresolved import `jaenokhwa_core::pixel_format::YUV420`

Check failure on line 6 in src/convert_to_rgb.rs

View workflow job for this annotation

GitHub Actions / compile_examples (threaded-capture, ubuntu-latest)

unresolved import `jaenokhwa_core::pixel_format::YUV420`

Check failure on line 6 in src/convert_to_rgb.rs

View workflow job for this annotation

GitHub Actions / compile_examples (threaded-capture, macos-latest)

unresolved import `jaenokhwa_core::pixel_format::YUV420`
use jaenokhwa_core::{
buffer::FrameBuffer,
pixel_format::{GRAY, MJPEG, NV12, RAWRGB},
};

pub trait ConvertToRgb {
fn convert_to_rgb(&self, _output_format: Pixel) -> Vec<u8> {
Expand All @@ -14,9 +17,21 @@ pub trait ConvertToRgb {

impl ConvertToRgb for FrameBuffer {
fn convert_to_rgb(&self, output_format: Pixel) -> Vec<u8> {
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()),
};

Expand Down

0 comments on commit f30c6d3

Please sign in to comment.