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 first-plane bytes per pixel for planar and semi-planar formats (the Y plane, or the UYVY plane of UYVA).
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 first-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):
y_stride * height - Packed 4:2:2 with alpha UYVA: requires even stride, then
UYVY + Awhere:- UYVY plane:
y_stride * height - Alpha plane:
(y_stride/2) * height
- UYVY plane:
- Semi-planar 4:2:2 P216:
Y + CbCrwhere each plane isy_stride * height - Semi-planar 4:2:2 with alpha PA16:
Y + CbCr + Awhere each plane isy_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
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more