pub struct PixelFormatInfo { /* private fields */ }Expand description
Compile-time pixel format properties.
This struct encapsulates all format-specific knowledge in one location, providing a single source of truth for buffer size calculations, stride computation, and format category detection.
§Examples
use grafton_ndi::{PixelFormat, FormatCategory};
let info = PixelFormat::BGRA.info();
assert_eq!(info.bytes_per_pixel(), 4);
assert_eq!(info.category(), FormatCategory::Packed);
let info = PixelFormat::NV12.info();
assert_eq!(info.bytes_per_pixel(), 1);
assert_eq!(info.category(), FormatCategory::SemiPlanar420);Implementations§
Source§impl PixelFormatInfo
impl PixelFormatInfo
Sourcepub const fn bytes_per_pixel(&self) -> u8
pub const fn bytes_per_pixel(&self) -> u8
Get bytes per pixel for packed formats, or Y-plane bytes per pixel for planar.
Sourcepub const fn category(&self) -> FormatCategory
pub const fn category(&self) -> FormatCategory
Get the format category.
Sourcepub const fn is_planar_420(&self) -> bool
pub const fn is_planar_420(&self) -> bool
Returns true if this is a planar 4:2:0 format (YV12, I420, or NV12).
Sourcepub fn try_buffer_len(&self, y_stride: i32, height: i32) -> Result<usize>
pub fn try_buffer_len(&self, y_stride: i32, height: i32) -> Result<usize>
Calculate total buffer size for given dimensions and stride using checked arithmetic.
§Arguments
y_stride- The Y-plane line stride in bytes (for planar formats) or total line stride (for packed formats)height- Frame height in pixels
§Errors
Returns Error::InvalidFrame if y_stride or height is not
positive, if planar 4:2:0 stride/height requirements are not met, if
arithmetic overflows, or if the result exceeds the crate’s maximum video
frame size.
§Format-specific calculations
- Packed RGB/YUV (BGRA/BGRX/RGBA/RGBX/UYVY/UYVA/P216/PA16):
y_stride * height - Planar 4:2:0 YV12/I420: requires even stride and height,
then
Y + U + Vwhere:- Y plane:
y_stride * height - U plane:
(y_stride/2) * (height/2) - V plane:
(y_stride/2) * (height/2)
- Y plane:
- Semi-planar 4:2:0 NV12: requires even height, then
Y + UVwhere:- Y plane:
y_stride * height - UV plane:
y_stride * (height/2)
- Y plane:
Trait Implementations§
Source§impl Clone for PixelFormatInfo
impl Clone for PixelFormatInfo
Source§fn clone(&self) -> PixelFormatInfo
fn clone(&self) -> PixelFormatInfo
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PixelFormatInfo
impl Debug for PixelFormatInfo
Source§impl PartialEq for PixelFormatInfo
impl PartialEq for PixelFormatInfo
impl Copy for PixelFormatInfo
impl Eq for PixelFormatInfo
impl StructuralPartialEq for PixelFormatInfo
Auto Trait Implementations§
impl Freeze for PixelFormatInfo
impl RefUnwindSafe for PixelFormatInfo
impl Send for PixelFormatInfo
impl Sync for PixelFormatInfo
impl Unpin for PixelFormatInfo
impl UnsafeUnpin for PixelFormatInfo
impl UnwindSafe for PixelFormatInfo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more