Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented macro for format_groups #198

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 52 additions & 76 deletions nokhwa-core/src/frame_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,82 +79,58 @@ pub enum FrameFormat {
Custom([u8; 8]),
}

// FIXME: Fix these frame format lists! Maybe move to using a macro..?
impl FrameFormat {
pub const ALL: &'static [FrameFormat] = &[
FrameFormat::H263,
FrameFormat::H264,
FrameFormat::H265,
FrameFormat::Av1,
FrameFormat::Avc1,
FrameFormat::Mpeg1,
FrameFormat::Mpeg2,
FrameFormat::Mpeg4,
FrameFormat::MJpeg,
FrameFormat::XVid,
FrameFormat::VP8,
FrameFormat::VP9,
FrameFormat::Yuyv422,
FrameFormat::Uyvy422,
FrameFormat::Nv12,
FrameFormat::Nv21,
FrameFormat::Yv12,
FrameFormat::Luma8,
FrameFormat::Luma16,
FrameFormat::Rgb332,
FrameFormat::RgbA8888,
];

pub const COMPRESSED: &'static [FrameFormat] = &[
FrameFormat::H263,
FrameFormat::H264,
FrameFormat::H265,
FrameFormat::Av1,
FrameFormat::Avc1,
FrameFormat::Mpeg1,
FrameFormat::Mpeg2,
FrameFormat::Mpeg4,
FrameFormat::MJpeg,
FrameFormat::XVid,
FrameFormat::VP8,
FrameFormat::VP9,
];

pub const CHROMA: &'static [FrameFormat] = &[
FrameFormat::Yuyv422,
FrameFormat::Uyvy422,
FrameFormat::Nv12,
FrameFormat::Nv21,
FrameFormat::Yv12,
];

pub const LUMA: &'static [FrameFormat] = &[FrameFormat::Luma8, FrameFormat::Luma16];

pub const RGB: &'static [FrameFormat] = &[FrameFormat::Rgb332, FrameFormat::RgbA8888];

pub const COLOR_FORMATS: &'static [FrameFormat] = &[
FrameFormat::H265,
FrameFormat::H264,
FrameFormat::H263,
FrameFormat::Av1,
FrameFormat::Avc1,
FrameFormat::Mpeg1,
FrameFormat::Mpeg2,
FrameFormat::Mpeg4,
FrameFormat::MJpeg,
FrameFormat::XVid,
FrameFormat::VP8,
FrameFormat::VP9,
FrameFormat::Yuyv422,
FrameFormat::Uyvy422,
FrameFormat::Nv12,
FrameFormat::Nv21,
FrameFormat::Yv12,
FrameFormat::Rgb332,
FrameFormat::RgbA8888,
];

pub const GRAYSCALE: &'static [FrameFormat] = &[FrameFormat::Luma8, FrameFormat::Luma16];
macro_rules! define_frame_format_groups {
(
$(
$group_name:ident => [
$($format:ident),* $(,)?
]
),* $(,)?
) => {
impl FrameFormat {
$(
pub const $group_name: &'static [FrameFormat] = &[
$(FrameFormat::$format),*
];
)*
}
};
}

define_frame_format_groups! {
ALL => [
H263, H264, H265, Av1, Avc1, Mpeg1, Mpeg2, Mpeg4, MJpeg, XVid,
VP8, VP9, Yuyv422, Uyvy422, Nv12, Nv21, Yv12, Ayuv444, Yvyu422,
I420, Yvu9, Luma8, Luma16, Depth16, Rgb332, Rgb555, Rgb565,
Rgb888, RgbA8888, ARgb8888, Bayer8, Bayer16
],
COMPRESSED => [
H263, H264, H265, Av1, Avc1, Mpeg1, Mpeg2, Mpeg4, MJpeg, XVid,
VP8, VP9
],
CHROMA => [
Yuyv422, Uyvy422, Nv12, Nv21, Yv12, Ayuv444, Yvyu422, I420, Yvu9
],
LUMA => [
Luma8, Luma16
],
RGB => [
Rgb332, Rgb555, Rgb565, Rgb888, RgbA8888, ARgb8888
],
COLOR_FORMATS => [
H265, H264, H263, Av1, Avc1, Mpeg1, Mpeg2, Mpeg4, MJpeg, XVid,
VP8, VP9, Yuyv422, Uyvy422, Nv12, Nv21, Yv12, Ayuv444, Yvyu422,
I420, Rgb332, Rgb555, Rgb565, Rgb888, RgbA8888, ARgb8888
],
GRAYSCALE => [
Luma8, Luma16
],
DEPTH => [
Depth16
],
BAYER => [
Bayer8, Bayer16
]
}

impl Display for FrameFormat {
Expand Down