Skip to main content

PlaneFormat

Struct PlaneFormat 

Source
#[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

Source

pub const SUBSAMPLING_444: (NonZero<u8>, NonZero<u8>)

Full-resolution (1, 1) subsampling divisors (4:4:4).

Source

pub const SUBSAMPLING_422: (NonZero<u8>, NonZero<u8>)

Horizontal-half (2, 1) subsampling divisors (4:2:2).

Source

pub const SUBSAMPLING_420: (NonZero<u8>, NonZero<u8>)

Half-both-axes (2, 2) subsampling divisors (4:2:0).

Source

pub const SUBSAMPLING_440: (NonZero<u8>, NonZero<u8>)

Vertical-half (1, 2) subsampling divisors (4:4:0).

Source

pub const SUBSAMPLING_411: (NonZero<u8>, NonZero<u8>)

Quarter-horizontal (4, 1) subsampling divisors (4:1:1).

Source

pub const fn role(self) -> PlaneRole

The role of this layout.

Source

pub const fn sample(self) -> SampleType

The sample of this layout.

Source

pub const fn packing(self) -> BitPacking

The packing of this layout.

Source

pub const fn new(role: PlaneRole, sample: SampleType) -> PlaneFormat

Construct a full-resolution plane specification (subsampling = (1, 1), BitPacking::Full).

Source

pub const fn components(self) -> u8

Number of interleaved components per element (1..=4), derived from PlaneRole.

Source

pub const fn subsampling(self) -> (NonZero<u8>, NonZero<u8>)

Nonzero horizontal and vertical subsampling divisors.

Source

pub const fn subsampling_divisors(self) -> (u8, u8)

Subsampling divisors (hx, vy) as plain u8 values (both guaranteed >= 1).

Source

pub const fn try_with_packing( self, packing: BitPacking, ) -> Result<PlaneFormat, LayoutError>

Set bit packing compatible with the sample type and plane role.

Source

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.

Source

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.

Source

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.

Source

pub const fn with_subsampling_420(self) -> PlaneFormat

Set 4:2:0 (2, 2) subsampling divisors.

Source

pub const fn with_subsampling_422(self) -> PlaneFormat

Set 4:2:2 (2, 1) subsampling divisors.

Source

pub const fn with_subsampling_440(self) -> PlaneFormat

Set 4:4:0 (1, 2) subsampling divisors.

Source

pub const fn with_subsampling_411(self) -> PlaneFormat

Set 4:1:1 (4, 1) subsampling divisors.

Source

pub const fn bytes_per_element(self) -> usize

Bytes per plane element (one luma sample or one CbCr pair).

Source

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).

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> PlaneFormat

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for PlaneFormat

Source§

impl Debug for PlaneFormat

Source§

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

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

impl Eq for PlaneFormat

Source§

impl Hash for PlaneFormat

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PlaneFormat

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PlaneFormat

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.