#[non_exhaustive]#[repr(u32)]pub enum PixelFormat {
UYVY = 1_498_831_189,
UYVA = 1_096_178_005,
P216 = 909_193_808,
PA16 = 909_197_648,
YV12 = 842_094_169,
I420 = 808_596_553,
NV12 = 842_094_158,
BGRA = 1_095_911_234,
BGRX = 1_481_787_202,
RGBA = 1_094_862_674,
RGBX = 1_480_738_642,
}Expand description
Video pixel format identifiers (FourCC codes).
These represent the various pixel formats supported by NDI for video frames. The most common formats are BGRA/RGBA for full quality and UYVY for bandwidth-efficient streaming.
This enum is marked #[non_exhaustive] to allow future NDI SDK versions to add new formats
without breaking existing code. Always use a wildcard pattern when matching.
§Examples
use grafton_ndi::PixelFormat;
// For maximum compatibility and quality
let format = PixelFormat::BGRA;
// For bandwidth-efficient streaming
let format = PixelFormat::UYVY;
// When matching, always include a wildcard for forward compatibility
match format {
PixelFormat::BGRA | PixelFormat::RGBA => println!("Full quality RGB"),
PixelFormat::UYVY => println!("Compressed YUV"),
_ => println!("Other format"),
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
UYVY = 1_498_831_189
YCbCr 4:2:2 format (16 bits per pixel) - bandwidth efficient.
UYVA = 1_096_178_005
YCbCr 4:2:2 with alpha channel (24 bits per pixel).
P216 = 909_193_808
16-bit YCbCr 4:2:2 format.
PA16 = 909_197_648
16-bit YCbCr 4:2:2 with alpha.
YV12 = 842_094_169
Planar YCbCr 4:2:0 format (12 bits per pixel).
I420 = 808_596_553
Planar YCbCr 4:2:0 format (12 bits per pixel).
NV12 = 842_094_158
Semi-planar YCbCr 4:2:0 format (12 bits per pixel).
BGRA = 1_095_911_234
Blue-Green-Red-Alpha format (32 bits per pixel) - full quality.
BGRX = 1_481_787_202
Blue-Green-Red with padding (32 bits per pixel).
RGBA = 1_094_862_674
Red-Green-Blue-Alpha format (32 bits per pixel) - full quality.
RGBX = 1_480_738_642
Red-Green-Blue with padding (32 bits per pixel).
Implementations§
Source§impl PixelFormat
impl PixelFormat
Sourcepub const fn info(self) -> PixelFormatInfo
pub const fn info(self) -> PixelFormatInfo
Get compile-time format properties.
This provides a single source of truth for all format-specific knowledge, including bytes per pixel and format category.
§Examples
use grafton_ndi::{PixelFormat, FormatCategory};
// Get properties for BGRA (32 bpp packed)
let info = PixelFormat::BGRA.info();
assert_eq!(info.bytes_per_pixel(), 4);
assert_eq!(info.category(), FormatCategory::Packed);
// Get properties for YV12 (planar 4:2:0)
let info = PixelFormat::YV12.info();
assert_eq!(info.bytes_per_pixel(), 1);
assert_eq!(info.category(), FormatCategory::Planar420);Sourcepub fn try_line_stride(self, width: i32) -> Result<i32>
pub fn try_line_stride(self, width: i32) -> Result<i32>
Calculate line stride in bytes for a given width using checked arithmetic.
For packed formats, this returns the total bytes per row. For planar formats, this returns the Y-plane stride.
§Examples
use grafton_ndi::PixelFormat;
// BGRA: 4 bytes per pixel
assert_eq!(PixelFormat::BGRA.try_line_stride(1920)?, 7680);
// UYVY: 2 bytes per pixel
assert_eq!(PixelFormat::UYVY.try_line_stride(1920)?, 3840);
// NV12: Y-plane has 1 byte per pixel
assert_eq!(PixelFormat::NV12.try_line_stride(1920)?, 1920);§Errors
Returns Error::InvalidFrame if the width is invalid for this format
or if the stride does not fit in i32.
Sourcepub fn try_buffer_size(self, width: i32, height: i32) -> Result<usize>
pub fn try_buffer_size(self, width: i32, height: i32) -> Result<usize>
Calculate the total buffer size needed for a frame with given dimensions using checked arithmetic.
This computes the validated minimum stride from the width and delegates to the shared video layout validator.
§Examples
use grafton_ndi::PixelFormat;
// BGRA 1920x1080: 1920 * 4 * 1080 = 8,294,400 bytes
assert_eq!(PixelFormat::BGRA.try_buffer_size(1920, 1080)?, 8_294_400);
// NV12 1920x1080: Y (1920*1080) + UV (1920*540) = 3,110,400 bytes
assert_eq!(PixelFormat::NV12.try_buffer_size(1920, 1080)?, 3_110_400);§Errors
Returns Error::InvalidFrame if dimensions are invalid for this
format, if arithmetic overflows, or if the result exceeds the crate’s
maximum video frame size.
Trait Implementations§
Source§impl Clone for PixelFormat
impl Clone for PixelFormat
Source§fn clone(&self) -> PixelFormat
fn clone(&self) -> PixelFormat
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more