pub struct PlaneDescriptor {
pub semantic: PlaneSemantic,
pub channel_type: ChannelType,
pub h_subsample: u8,
pub v_subsample: u8,
}Expand description
Metadata describing a single plane in a multi-plane image.
This is a pure descriptor — no pixel data, no heap allocation. Subsample factors are explicit per-plane rather than inferred from dimension ratios, because strip-based pipelines don’t carry global image dimensions.
§Examples
use zenpixels::{PlaneDescriptor, PlaneSemantic, ChannelType};
let luma = PlaneDescriptor::new(PlaneSemantic::Luma, ChannelType::F32);
assert!(!luma.is_subsampled());
assert_eq!(luma.plane_width(1920), 1920);
let chroma = PlaneDescriptor::new(PlaneSemantic::ChromaCb, ChannelType::F32)
.with_subsampling(2, 2); // 4:2:0
assert!(chroma.is_subsampled());
assert_eq!(chroma.plane_width(1920), 960);
assert_eq!(chroma.plane_height(1080), 540);Fields§
§semantic: PlaneSemanticWhat this plane represents.
channel_type: ChannelTypeStorage type for each sample in this plane.
h_subsample: u8Horizontal subsampling factor (1 = full resolution, 2 = half, 4 = quarter).
v_subsample: u8Vertical subsampling factor (1 = full resolution, 2 = half).
Implementations§
Source§impl PlaneDescriptor
impl PlaneDescriptor
Sourcepub const fn new(
semantic: PlaneSemantic,
channel_type: ChannelType,
) -> PlaneDescriptor
pub const fn new( semantic: PlaneSemantic, channel_type: ChannelType, ) -> PlaneDescriptor
Create a full-resolution plane descriptor (no subsampling).
Sourcepub const fn with_subsampling(self, h: u8, v: u8) -> PlaneDescriptor
pub const fn with_subsampling(self, h: u8, v: u8) -> PlaneDescriptor
Sourcepub const fn plane_width(&self, ref_width: u32) -> u32
pub const fn plane_width(&self, ref_width: u32) -> u32
Compute the width of this plane given a reference (luma) width.
Uses ceiling division so subsampled planes always cover the full image.
Robustness: h_subsample is a public field, so a struct-literal
write or a codec mapping an out-of-range subsampling code to factor 0
can leave the divisor at 0 — which would panic the div_ceil in
release. We saturate the divisor at 1 here so production servers
never see a divide-by-zero abort; the
with_subsampling builder’s
debug_assert! still catches the misuse in dev/test.
Sourcepub const fn plane_height(&self, ref_height: u32) -> u32
pub const fn plane_height(&self, ref_height: u32) -> u32
Compute the height of this plane given a reference (luma) height.
Uses ceiling division so subsampled planes always cover the full image.
Robustness: see plane_width — same div-by-zero
guard for v_subsample.
Sourcepub const fn is_subsampled(&self) -> bool
pub const fn is_subsampled(&self) -> bool
Whether this plane is subsampled (either axis).
Sourcepub const fn bytes_per_sample(&self) -> usize
pub const fn bytes_per_sample(&self) -> usize
Bytes per sample in this plane.
Trait Implementations§
Source§impl Clone for PlaneDescriptor
impl Clone for PlaneDescriptor
Source§fn clone(&self) -> PlaneDescriptor
fn clone(&self) -> PlaneDescriptor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more