#[non_exhaustive]pub struct PlaneFormat { /* private fields */ }Expand description
Storage specification for one plane in a multi-plane image (16 B, zero invalid arity or zero subsampling).
Implementations§
Source§impl PlaneFormat
impl PlaneFormat
Sourcepub const SUBSAMPLING_444: (NonZero<u8>, NonZero<u8>)
pub const SUBSAMPLING_444: (NonZero<u8>, NonZero<u8>)
Full-resolution (1, 1) subsampling divisors (4:4:4).
Sourcepub const SUBSAMPLING_422: (NonZero<u8>, NonZero<u8>)
pub const SUBSAMPLING_422: (NonZero<u8>, NonZero<u8>)
Horizontal-half (2, 1) subsampling divisors (4:2:2).
Sourcepub const SUBSAMPLING_420: (NonZero<u8>, NonZero<u8>)
pub const SUBSAMPLING_420: (NonZero<u8>, NonZero<u8>)
Half-both-axes (2, 2) subsampling divisors (4:2:0).
Sourcepub const SUBSAMPLING_440: (NonZero<u8>, NonZero<u8>)
pub const SUBSAMPLING_440: (NonZero<u8>, NonZero<u8>)
Vertical-half (1, 2) subsampling divisors (4:4:0).
Sourcepub const SUBSAMPLING_411: (NonZero<u8>, NonZero<u8>)
pub const SUBSAMPLING_411: (NonZero<u8>, NonZero<u8>)
Quarter-horizontal (4, 1) subsampling divisors (4:1:1).
Sourcepub const fn sample(self) -> SampleType
pub const fn sample(self) -> SampleType
The sample of this layout.
Sourcepub const fn packing(self) -> BitPacking
pub const fn packing(self) -> BitPacking
The packing of this layout.
Sourcepub const fn new(role: PlaneRole, sample: SampleType) -> PlaneFormat
pub const fn new(role: PlaneRole, sample: SampleType) -> PlaneFormat
Construct a full-resolution plane specification (subsampling = (1, 1), BitPacking::Full).
Sourcepub const fn components(self) -> u8
pub const fn components(self) -> u8
Number of interleaved components per element (1..=4), derived from PlaneRole.
Sourcepub const fn subsampling(self) -> (NonZero<u8>, NonZero<u8>)
pub const fn subsampling(self) -> (NonZero<u8>, NonZero<u8>)
Nonzero horizontal and vertical subsampling divisors.
Sourcepub const fn subsampling_divisors(self) -> (u8, u8)
pub const fn subsampling_divisors(self) -> (u8, u8)
Subsampling divisors (hx, vy) as plain u8 values (both guaranteed >= 1).
Sourcepub const fn try_with_packing(
self,
packing: BitPacking,
) -> Result<PlaneFormat, LayoutError>
pub const fn try_with_packing( self, packing: BitPacking, ) -> Result<PlaneFormat, LayoutError>
Set bit packing compatible with the sample type and plane role.
Sourcepub const fn with_subsampling_nz(
self,
horizontal_divisor: NonZero<u8>,
vertical_divisor: NonZero<u8>,
) -> PlaneFormat
pub const fn with_subsampling_nz( self, horizontal_divisor: NonZero<u8>, vertical_divisor: NonZero<u8>, ) -> PlaneFormat
Set non-zero subsampling divisors (horizontal_divisor, vertical_divisor) infallibly.
Sourcepub const fn try_with_subsampling(
self,
horizontal_divisor: u8,
vertical_divisor: u8,
) -> Option<PlaneFormat>
pub const fn try_with_subsampling( self, horizontal_divisor: u8, vertical_divisor: u8, ) -> Option<PlaneFormat>
Fallibly set subsampling divisors (horizontal_divisor, vertical_divisor), returning
None if either divisor is 0.
Sourcepub const fn with_subsampling(
self,
horizontal_divisor: u8,
vertical_divisor: u8,
) -> PlaneFormat
pub const fn with_subsampling( self, horizontal_divisor: u8, vertical_divisor: u8, ) -> PlaneFormat
Set subsampling divisors (horizontal_divisor, vertical_divisor) (panics if either is 0;
prefer try_with_subsampling, with_subsampling_nz,
or with_subsampling_420 for infallible/fallible callers).
§Panics
Panics if horizontal_divisor == 0 or vertical_divisor == 0.
Sourcepub const fn with_subsampling_420(self) -> PlaneFormat
pub const fn with_subsampling_420(self) -> PlaneFormat
Set 4:2:0 (2, 2) subsampling divisors.
Sourcepub const fn with_subsampling_422(self) -> PlaneFormat
pub const fn with_subsampling_422(self) -> PlaneFormat
Set 4:2:2 (2, 1) subsampling divisors.
Sourcepub const fn with_subsampling_440(self) -> PlaneFormat
pub const fn with_subsampling_440(self) -> PlaneFormat
Set 4:4:0 (1, 2) subsampling divisors.
Sourcepub const fn with_subsampling_411(self) -> PlaneFormat
pub const fn with_subsampling_411(self) -> PlaneFormat
Set 4:1:1 (4, 1) subsampling divisors.
Sourcepub const fn bytes_per_element(self) -> usize
pub const fn bytes_per_element(self) -> usize
Bytes per plane element (one luma sample or one CbCr pair).
Sourcepub const fn plane_dimensions_for_frame(
self,
frame_width: u32,
frame_height: u32,
) -> (u32, u32)
pub const fn plane_dimensions_for_frame( self, frame_width: u32, frame_height: u32, ) -> (u32, u32)
Compute this plane’s (width, height) in elements for a full luma frame of (frame_width, frame_height).
Sourcepub const fn cropped_plane_dimensions(
self,
crop: PixelRect,
) -> Option<(u32, u32)>
pub const fn cropped_plane_dimensions( self, crop: PixelRect, ) -> Option<(u32, u32)>
Compute this plane’s (width, height) in elements for a cropped luma rectangle
crop (PixelRect { x, y, width, height }) within its parent full-resolution luma frame.
Preserves chroma phase at odd crop origins: a 2×2 subsampled plane for a crop
[crop.x .. crop.x + crop.width) covers chroma columns
[crop.x / hx .. ceil((crop.x + crop.width) / hx)).
Returns None only if crop.x + crop.width or crop.y + crop.height overflows u32.
Sourcepub const fn aligned_stride_for_plane_width(
self,
plane_width: u32,
align: RowAlign,
) -> Result<usize, LayoutError>
pub const fn aligned_stride_for_plane_width( self, plane_width: u32, align: RowAlign, ) -> Result<usize, LayoutError>
Compute the row byte stride for plane_width plane elements (post-subsampling) under align.
Sourcepub const fn sample_encoding(self) -> Option<SampleEncoding>
pub const fn sample_encoding(self) -> Option<SampleEncoding>
Derive the SampleEncoding for unpacked integer planes
(U8/U16/U32 with Full, Lsb, Msb, or Shifted packing), or None for
floating-point or packed bitfield words.
Sourcepub const fn validate(self) -> Result<(), LayoutError>
pub const fn validate(self) -> Result<(), LayoutError>
Validate bit packing compatibility with sample and components().
Role component arity (1..=4) and non-zero subsampling divisors are guaranteed by type.
Trait Implementations§
Source§impl Clone for PlaneFormat
impl Clone for PlaneFormat
Source§fn clone(&self) -> PlaneFormat
fn clone(&self) -> PlaneFormat
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more