Skip to main content

PixelFormat

Enum PixelFormat 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

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);
Source

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.

Source

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

Source§

fn clone(&self) -> PixelFormat

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PixelFormat

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<PixelFormat> for i32

Source§

fn from(value: PixelFormat) -> Self

Converts to this type from the input type.
Source§

impl From<PixelFormat> for u32

Source§

fn from(enum_value: PixelFormat) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for PixelFormat

Source§

fn eq(&self, other: &PixelFormat) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<u32> for PixelFormat

Source§

type Error = TryFromPrimitiveError<PixelFormat>

The type returned in the event of a conversion error.
Source§

fn try_from(number: u32) -> Result<Self, TryFromPrimitiveError<Self>>

Performs the conversion.
Source§

impl TryFromPrimitive for PixelFormat

Source§

const NAME: &'static str = "PixelFormat"

Source§

type Primitive = u32

Source§

type Error = TryFromPrimitiveError<PixelFormat>

Source§

fn try_from_primitive( number: Self::Primitive, ) -> Result<Self, TryFromPrimitiveError<Self>>

Source§

impl Copy for PixelFormat

Source§

impl Eq for PixelFormat

Source§

impl StructuralPartialEq for PixelFormat

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.