pub struct PixelView<'a> { /* private fields */ }Expand description
Full re-export of zenpixels core types (zero module name collisions!).
Zero-copy borrowed view of an interleaved image or rectangular crop.
Every slicing method (row, row_as, crop, sub_rows,
as_contiguous_bytes) returns references or subviews tied directly to 'a
rather than &self, so chaining (buf.as_view().crop(...)?.row(0)) works cleanly.
Implementations§
Source§impl<'a> PixelView<'a>
impl<'a> PixelView<'a>
Sourcepub fn new(
data: &'a [u8],
width: u32,
height: u32,
stride_bytes: usize,
format: &'a PixelFormat,
) -> Result<PixelView<'a>, At<BufferError>>
pub fn new( data: &'a [u8], width: u32, height: u32, stride_bytes: usize, format: &'a PixelFormat, ) -> Result<PixelView<'a>, At<BufferError>>
Borrow strided bytes with checked dimensions, alignment, and length (zero heap allocation).
Pass &formats::RGB8_SRGB (or any crate::formats::* preset) or a borrowed
&'a PixelFormat. If a view genuinely needs to own a dynamically constructed PixelFormat,
use new_with_format_cow with FormatCow::from_owned or
FormatCow::from_arc.
Trims any trailing bytes beyond the active (height - 1) * stride_bytes + row_bytes
extent so zero-copy interop bridges (as_imgref) never touch trailing slop.
Sourcepub fn new_with_format_cow(
data: &'a [u8],
width: u32,
height: u32,
stride_bytes: usize,
format: FormatCow<'a>,
) -> Result<PixelView<'a>, At<BufferError>>
pub fn new_with_format_cow( data: &'a [u8], width: u32, height: u32, stride_bytes: usize, format: FormatCow<'a>, ) -> Result<PixelView<'a>, At<BufferError>>
Borrow strided bytes with an explicit FormatCow<'a> (borrowed &'a PixelFormat or
shared Arc<PixelFormat> via FormatCow::from_owned /
FormatCow::from_arc).
Trims any trailing bytes beyond the active (height - 1) * stride_bytes + row_bytes extent.
Sourcepub fn from_bytes(
data: &'a [u8],
width: u32,
height: u32,
format: &'a PixelFormat,
) -> Result<PixelView<'a>, At<BufferError>>
pub fn from_bytes( data: &'a [u8], width: u32, height: u32, format: &'a PixelFormat, ) -> Result<PixelView<'a>, At<BufferError>>
Borrow tightly packed native-endian bytes (stride_bytes == width * bytes_per_pixel, zero allocation).
Sourcepub fn from_typed<P>(
pixels: &'a [P],
width: u32,
height: u32,
format: &'a PixelFormat,
) -> Result<PixelView<'a>, At<BufferError>>where
P: TypedElement,
pub fn from_typed<P>(
pixels: &'a [P],
width: u32,
height: u32,
format: &'a PixelFormat,
) -> Result<PixelView<'a>, At<BufferError>>where
P: TypedElement,
Borrow a tightly packed typed pixel or sample slice zero-copy via bytemuck (zero allocation).
Validates that P is structurally compatible with format.layout (rejecting
e.g. &[i32] as RGBF32). For intentional raw byte reinterpretation, use
from_pod_bytes.
Sourcepub fn from_samples<S>(
samples: &'a [S],
width: u32,
height: u32,
format: &'a PixelFormat,
) -> Result<PixelView<'a>, At<BufferError>>where
S: StorageSample,
pub fn from_samples<S>(
samples: &'a [S],
width: u32,
height: u32,
format: &'a PixelFormat,
) -> Result<PixelView<'a>, At<BufferError>>where
S: StorageSample,
Borrow a tightly packed scalar sample slice (&[u8], &[u16], &[f32], etc.) zero-copy (zero allocation).
Sourcepub fn from_pixels_with_color<P>(
pixels: &'a [P],
width: u32,
height: u32,
color: ColorSpace,
) -> Result<PixelView<'a>, At<BufferError>>where
P: PixelType,
pub fn from_pixels_with_color<P>(
pixels: &'a [P],
width: u32,
height: u32,
color: ColorSpace,
) -> Result<PixelView<'a>, At<BufferError>>where
P: PixelType,
Borrow a tightly packed rgb pixel slice (&[rgb::Rgb<u8>], etc.) zero-copy with an
explicit ColorSpace (deriving SampleLayout from P::LAYOUT).
Uses a zero-allocation &'static PixelFormat for all standard built-in presets, and
allocates an Arc<PixelFormat> only for custom/ICC color spaces.
Sourcepub fn from_pod_bytes<P>(
pixels: &'a [P],
width: u32,
height: u32,
format: &'a PixelFormat,
) -> Result<PixelView<'a>, At<BufferError>>where
P: Pod,
pub fn from_pod_bytes<P>(
pixels: &'a [P],
width: u32,
height: u32,
format: &'a PixelFormat,
) -> Result<PixelView<'a>, At<BufferError>>where
P: Pod,
Explicitly reinterpret any tightly packed bytemuck::Pod slice in native endianness
as raw pixel bytes matching format without checking element-to-layout compatibility
(zero allocation).
Sourcepub const fn stride_bytes(&self) -> usize
pub const fn stride_bytes(&self) -> usize
Byte distance between consecutive row starts.
Sourcepub fn format(&self) -> &PixelFormat
pub fn format(&self) -> &PixelFormat
Authoritative image specification (layout + color).
Sourcepub const fn attached_claims(&self) -> SampleClaims
pub const fn attached_claims(&self) -> SampleClaims
Read the sample claims already attached to this view in constant time.
Sourcepub fn hdr(&self) -> HdrMetadata
pub fn hdr(&self) -> HdrMetadata
Descriptive HDR container metadata attached to this view.
Sourcepub fn hdr_ref(&self) -> Option<&HdrMetadata>
pub fn hdr_ref(&self) -> Option<&HdrMetadata>
Zero-copy reference to attached non-empty HDR metadata (None if empty/unset).
Sourcepub const fn origin(&self) -> Option<&'a ColorOrigin>
pub const fn origin(&self) -> Option<&'a ColorOrigin>
Original container color provenance borrowed from the owning image, if attached.
Sourcepub const fn orientation(&self) -> Orientation
pub const fn orientation(&self) -> Orientation
Pending EXIF display orientation attached to this view (defaults to Orientation::Identity).
Sourcepub const fn display_dimensions(&self) -> (u32, u32)
pub const fn display_dimensions(&self) -> (u32, u32)
Display-oriented (width, height) after applying orientation.
Sourcepub fn with_assumed_claims(self, claims: SampleClaims) -> PixelView<'a>
pub fn with_assumed_claims(self, claims: SampleClaims) -> PixelView<'a>
Attach caller-asserted SampleClaims to this view (caller assumes responsibility for validity).
Sourcepub fn with_hdr(self, hdr: HdrMetadata) -> PixelView<'a>
pub fn with_hdr(self, hdr: HdrMetadata) -> PixelView<'a>
Attach descriptive HDR metadata to this view.
Sourcepub fn with_hdr_ref(self, hdr: &'a HdrMetadata) -> PixelView<'a>
pub fn with_hdr_ref(self, hdr: &'a HdrMetadata) -> PixelView<'a>
Borrow descriptive HDR metadata onto this view with zero heap allocation and zero
atomic refcount overhead (ignores empty HdrMetadata::default()).
Sourcepub const fn with_origin(self, origin: &'a ColorOrigin) -> PixelView<'a>
pub const fn with_origin(self, origin: &'a ColorOrigin) -> PixelView<'a>
Attach borrowed container color provenance to this view.
Sourcepub const fn with_orientation(self, orientation: Orientation) -> PixelView<'a>
pub const fn with_orientation(self, orientation: Orientation) -> PixelView<'a>
Replace the pending EXIF display orientation on this view.
Sourcepub const fn compose_orientation(self, delta: Orientation) -> PixelView<'a>
pub const fn compose_orientation(self, delta: Orientation) -> PixelView<'a>
Compose an additional display transform (including reflections) onto this view’s
pending orientation (self.orientation.then(delta)) in O(1) without touching pixels.
Sourcepub fn row(&self, y: u32) -> &'a [u8] ⓘ
pub fn row(&self, y: u32) -> &'a [u8] ⓘ
Active bytes of row y (excludes inter-row padding), tied to backing lifetime 'a.
§Panics
Panics if y >= self.height().
Sourcepub fn row_as<P>(&self, y: u32) -> Result<&'a [P], At<BufferError>>where
P: TypedElement,
pub fn row_as<P>(&self, y: u32) -> Result<&'a [P], At<BufferError>>where
P: TypedElement,
Zero-copy layout-checked typed slice view of row y
(e.g. view.row_as::<rgb::Rgb<u16>>(y), view.row_as::<[f32; 3]>(y), view.row_as::<u16>(y)).
Semantically validates P::matches_layout(self.format().layout) — rejecting mismatched
sample types, mismatched channel orders (e.g. Rgba<u8> on BGRA8), and non-Full
BitPacking (e.g. P010, U10_LSB, RGB10A2).
- For explicit handling of non-
Fullbit packing, userow_as_withorvisit_rows_with_packing. - For intentional raw-POD byte reinterpretation (e.g. viewing
f32bits asu32or a custom#[repr(C)]POD struct), userow_transmute.
Sourcepub fn row_as_with<P>(
&self,
y: u32,
packing: BitPackingAccess,
) -> Result<&'a [P], At<BufferError>>where
P: TypedElement,
pub fn row_as_with<P>(
&self,
y: u32,
packing: BitPackingAccess,
) -> Result<&'a [P], At<BufferError>>where
P: TypedElement,
Zero-copy layout-checked typed slice view of row y with an explicit BitPackingAccess
policy (Fail or PassThrough).
Sourcepub fn row_samples<S>(&self, y: u32) -> Result<&'a [S], At<BufferError>>where
S: StorageSample,
pub fn row_samples<S>(&self, y: u32) -> Result<&'a [S], At<BufferError>>where
S: StorageSample,
Zero-copy sample-checked native-endian slice view of row y (e.g. &[u16], &[f32]).
Rejects non-Full BitPacking and mismatched sample types with
BufferError::IncompatibleLayout. Use row_samples_with for
explicit BitPackingAccess::PassThrough.
Sourcepub fn row_samples_with<S>(
&self,
y: u32,
packing: BitPackingAccess,
) -> Result<&'a [S], At<BufferError>>where
S: StorageSample,
pub fn row_samples_with<S>(
&self,
y: u32,
packing: BitPackingAccess,
) -> Result<&'a [S], At<BufferError>>where
S: StorageSample,
Zero-copy sample-checked native-endian slice view of row y with an explicit
BitPackingAccess policy (Fail or PassThrough).
Sourcepub fn row_transmute<P>(&self, y: u32) -> Result<&'a [P], At<BufferError>>where
P: Pod,
pub fn row_transmute<P>(&self, y: u32) -> Result<&'a [P], At<BufferError>>where
P: Pod,
Safe raw-POD byte reinterpretation of row y (bytemuck::try_cast_slice), checking only
bounds, alignment, and byte divisibility without semantic layout/channel-order validation.
Prefer row_as or row_samples for normal pixel
access; use row_transmute for raw bit inspection (e.g. f32 bit patterns as &[u32])
or custom #[repr(C)] POD pixel structs.
Sourcepub fn visit_rows_with_packing<S, Norm, F>(
&self,
mode: BitPackingRead<Norm>,
f: F,
) -> Result<(), At<BufferError>>where
S: StorageSample,
Norm: FnMut(BitPacking, &mut [S]),
F: FnMut(u32, &[S]) -> Result<(), At<BufferError>>,
pub fn visit_rows_with_packing<S, Norm, F>(
&self,
mode: BitPackingRead<Norm>,
f: F,
) -> Result<(), At<BufferError>>where
S: StorageSample,
Norm: FnMut(BitPacking, &mut [S]),
F: FnMut(u32, &[S]) -> Result<(), At<BufferError>>,
Visit every row as &[S] with an explicit BitPackingRead policy (Fail,
PassThrough, or Norm(lambda)).
When layout.packing == BitPacking::Full (or PassThrough), borrows each row zero-copy
with zero allocation. When BitPackingRead::Norm(norm) runs on a non-Full layout,
allocates a single reusable one-row scratch buffer, runs norm(packing, &mut scratch),
and passes (y, &scratch) to f.
Sourcepub const fn as_strided_bytes(&self) -> &'a [u8] ⓘ
pub const fn as_strided_bytes(&self) -> &'a [u8] ⓘ
Raw strided byte backing starting at (0, 0) (includes inter-row padding).
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Whether rows are tightly packed (stride_bytes == row_bytes or height <= 1).
Sourcepub fn as_contiguous_bytes(&self) -> Option<&'a [u8]>
pub fn as_contiguous_bytes(&self) -> Option<&'a [u8]>
Contiguous packed bytes across all rows, or None if padded.
Sourcepub fn as_contiguous_typed<P>(&self) -> Result<&'a [P], At<BufferError>>where
P: TypedElement,
pub fn as_contiguous_typed<P>(&self) -> Result<&'a [P], At<BufferError>>where
P: TypedElement,
Zero-copy layout-checked contiguous typed slice across all rows
(e.g. &[rgb::Rgba<f32>], &[[u16; 3]], &[u16]).
Semantically validates P::matches_layout(self.format().layout) (rejecting mismatched
sample types, channel orders, and non-Full bit packing) and tight row packing.
For intentional raw-POD reinterpretation, use
as_contiguous_transmute.
Sourcepub fn as_contiguous_typed_with<P>(
&self,
packing: BitPackingAccess,
) -> Result<&'a [P], At<BufferError>>where
P: TypedElement,
pub fn as_contiguous_typed_with<P>(
&self,
packing: BitPackingAccess,
) -> Result<&'a [P], At<BufferError>>where
P: TypedElement,
Zero-copy layout-checked contiguous typed slice across all rows with an explicit
BitPackingAccess policy (Fail or PassThrough).
Sourcepub fn as_contiguous_samples<S>(&self) -> Result<&'a [S], At<BufferError>>where
S: StorageSample,
pub fn as_contiguous_samples<S>(&self) -> Result<&'a [S], At<BufferError>>where
S: StorageSample,
Zero-copy sample-checked native-endian contiguous slice across all rows (e.g. &[u16]).
Rejects padded rows, non-Full bit packing, and mismatched sample types.
Sourcepub fn as_contiguous_samples_with<S>(
&self,
packing: BitPackingAccess,
) -> Result<&'a [S], At<BufferError>>where
S: StorageSample,
pub fn as_contiguous_samples_with<S>(
&self,
packing: BitPackingAccess,
) -> Result<&'a [S], At<BufferError>>where
S: StorageSample,
Zero-copy sample-checked native-endian contiguous slice across all rows with an explicit
BitPackingAccess policy (Fail or PassThrough).
Sourcepub fn as_contiguous_transmute<P>(&self) -> Result<&'a [P], At<BufferError>>where
P: Pod,
pub fn as_contiguous_transmute<P>(&self) -> Result<&'a [P], At<BufferError>>where
P: Pod,
Safe raw-POD byte reinterpretation across contiguous rows (bytemuck::try_cast_slice),
checking tight row packing, alignment, and byte divisibility without semantic layout checks.
Sourcepub fn to_contiguous_bytes(&self) -> Result<Cow<'a, [u8]>, At<BufferError>>
pub fn to_contiguous_bytes(&self) -> Result<Cow<'a, [u8]>, At<BufferError>>
Borrow contiguous bytes if tightly packed, or fallibly copy active rows into a Vec<u8>.
Sourcepub fn crop(&self, rect: PixelRect) -> Result<PixelView<'a>, At<BufferError>>
pub fn crop(&self, rect: PixelRect) -> Result<PixelView<'a>, At<BufferError>>
Zero-copy rectangular subimage view retaining parent stride and 'a lifetime.
Sourcepub fn sub_rows(
&self,
start_y: u32,
row_count: u32,
) -> Result<PixelView<'a>, At<BufferError>>
pub fn sub_rows( &self, start_y: u32, row_count: u32, ) -> Result<PixelView<'a>, At<BufferError>>
Zero-copy full-width horizontal strip view retaining 'a lifetime.
Sourcepub fn to_tight_buf(&self) -> Result<PixelBuf, At<BufferError>>
pub fn to_tight_buf(&self) -> Result<PixelBuf, At<BufferError>>
Fallibly copy active pixels into a freshly allocated, tightly packed PixelBuf.
Sourcepub fn measure_float_claims(&self) -> FloatClaims
pub fn measure_float_claims(&self) -> FloatClaims
Measure exact FloatClaims across all active floating-point samples.
RGBX/BGRX padding is ignored. Integer sample types return FloatClaims::NONE.
Source§impl PixelView<'_>
impl PixelView<'_>
Sourcepub fn hash_with(&self, inclusions: HashInclusions) -> u64
pub fn hash_with(&self, inclusions: HashInclusions) -> u64
Compute a portable, endian- and stride-independent XXH3 fingerprint of this view.
Source§impl<'a> PixelView<'a>
impl<'a> PixelView<'a>
Sourcepub fn from_imgref<P>(
img: Img<&'a [P]>,
color: ColorSpace,
) -> Result<PixelView<'a>, At<BufferError>>where
P: PixelType,
pub fn from_imgref<P>(
img: Img<&'a [P]>,
color: ColorSpace,
) -> Result<PixelView<'a>, At<BufferError>>where
P: PixelType,
Borrow a typed [imgref::ImgRef<'a, P>] zero-copy with true 'a lifetime.
Uses a zero-allocation &'static PixelFormat for all standard built-in presets, and
allocates an Arc<PixelFormat> only for custom/ICC color spaces.
Sourcepub fn as_imgref<P>(&self) -> Result<Img<&'a [P]>, At<BufferError>>where
P: PixelType,
pub fn as_imgref<P>(&self) -> Result<Img<&'a [P]>, At<BufferError>>where
P: PixelType,
Borrow as a zero-copy [imgref::ImgRef<'a, P>] when layout, alignment, and pixel-whole stride match.
Sourcepub fn as_sample_imgref<S>(&self) -> Result<Img<&'a [S]>, At<BufferError>>where
S: StorageSample,
pub fn as_sample_imgref<S>(&self) -> Result<Img<&'a [S]>, At<BufferError>>where
S: StorageSample,
Borrow as a sample-strided zero-copy [imgref::ImgRef<'a, S>] where
img.width() == self.width() * channels and img.stride() == self.stride_bytes() / size_of::<S>().
Source§impl<'a> PixelView<'a>
impl<'a> PixelView<'a>
Sourcepub fn from_image_buffer<P, C>(
img: &'a ImageBuffer<P, C>,
) -> Result<PixelView<'a>, At<BufferError>>where
P: Pixel + PixelWithColorType + 'static,
<P as Pixel>::Subpixel: StorageSample,
C: Deref<Target = [<P as Pixel>::Subpixel]>,
pub fn from_image_buffer<P, C>(
img: &'a ImageBuffer<P, C>,
) -> Result<PixelView<'a>, At<BufferError>>where
P: Pixel + PixelWithColorType + 'static,
<P as Pixel>::Subpixel: StorageSample,
C: Deref<Target = [<P as Pixel>::Subpixel]>,
Borrow any image::ImageBuffer<P, C> zero-copy for all 10 standard formats
(Luma, LumaA, Rgb, Rgba × u8/u16/f32), reading its declared CICP color space.
Uses a zero-allocation &'static PixelFormat for all standard sRGB / linear formats, and
allocates an Arc<PixelFormat> only for non-preset CICP color spaces.
Sourcepub fn from_dynamic_image(
img: &'a DynamicImage,
) -> Result<PixelView<'a>, At<BufferError>>
pub fn from_dynamic_image( img: &'a DynamicImage, ) -> Result<PixelView<'a>, At<BufferError>>
Borrow an image::DynamicImage zero-copy for all 10 standard variants.
Trait Implementations§
Source§impl PixelScanExt for PixelView<'_>
impl PixelScanExt for PixelView<'_>
Source§fn measure_claims(&self) -> SampleClaims
fn measure_claims(&self) -> SampleClaims
Source§fn measure_and_attach_claims(&mut self) -> SampleClaims
fn measure_and_attach_claims(&mut self) -> SampleClaims
measure_claims
and return those fresh facts. On a view, updates the view’s own metadata.Source§fn check_samples(&self, bounds: SampleBounds) -> Result<(), PixelCheckError>
fn check_samples(&self, bounds: SampleBounds) -> Result<(), PixelCheckError>
SampleBounds. Read moreSource§fn verify_claims(
&self,
required: SampleClaims,
) -> Result<(), ClaimVerificationError>
fn verify_claims( &self, required: SampleClaims, ) -> Result<(), ClaimVerificationError>
Source§fn check_nominal_samples(&self) -> Result<(), PixelCheckError>
fn check_nominal_samples(&self) -> Result<(), PixelCheckError>
Source§impl PixelSource for PixelView<'_>
impl PixelSource for PixelView<'_>
Source§fn source_width(&self) -> u32
fn source_width(&self) -> u32
Source§fn source_height(&self) -> u32
fn source_height(&self) -> u32
Source§fn source_format(&self) -> &PixelFormat
fn source_format(&self) -> &PixelFormat
Source§fn source_claims(&self) -> SampleClaims
fn source_claims(&self) -> SampleClaims
Source§fn source_hdr(&self) -> HdrMetadata
fn source_hdr(&self) -> HdrMetadata
Source§fn source_origin(&self) -> Option<&ColorOrigin>
fn source_origin(&self) -> Option<&ColorOrigin>
Source§fn source_orientation(&self) -> Orientation
fn source_orientation(&self) -> Orientation
Orientation::Identity).Auto Trait Implementations§
impl<'a> Freeze for PixelView<'a>
impl<'a> RefUnwindSafe for PixelView<'a>
impl<'a> Send for PixelView<'a>
impl<'a> Sync for PixelView<'a>
impl<'a> Unpin for PixelView<'a>
impl<'a> UnsafeUnpin for PixelView<'a>
impl<'a> UnwindSafe for PixelView<'a>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S> PixelConvertExt for Swhere
S: PixelSource + ?Sized,
impl<S> PixelConvertExt for Swhere
S: PixelSource + ?Sized,
Source§fn convert_to(
&self,
destination_format: impl AsRef<PixelFormat>,
policy: &ConvertPolicy,
) -> Result<PixelBuf, At<ConvertError>>
fn convert_to( &self, destination_format: impl AsRef<PixelFormat>, policy: &ConvertPolicy, ) -> Result<PixelBuf, At<ConvertError>>
Source§fn convert_to_with_peak(
&self,
destination_format: impl AsRef<PixelFormat>,
policy: &ConvertPolicy,
peak: PeakSource,
) -> Result<PixelBuf, At<ConvertError>>
fn convert_to_with_peak( &self, destination_format: impl AsRef<PixelFormat>, policy: &ConvertPolicy, peak: PeakSource, ) -> Result<PixelBuf, At<ConvertError>>
Source§fn convert_into<D: PixelSink + ?Sized>(
&self,
dst: &mut D,
policy: &ConvertPolicy,
) -> Result<(), At<ConvertError>>
fn convert_into<D: PixelSink + ?Sized>( &self, dst: &mut D, policy: &ConvertPolicy, ) -> Result<(), At<ConvertError>>
Source§fn convert_into_with_peak<D: PixelSink + ?Sized>(
&self,
dst: &mut D,
policy: &ConvertPolicy,
peak: PeakSource,
) -> Result<(), At<ConvertError>>
fn convert_into_with_peak<D: PixelSink + ?Sized>( &self, dst: &mut D, policy: &ConvertPolicy, peak: PeakSource, ) -> Result<(), At<ConvertError>>
Source§fn to_rgb8_if_opaque(&self) -> Result<PixelBuf, At<ConvertError>>
fn to_rgb8_if_opaque(&self) -> Result<PixelBuf, At<ConvertError>>
self to full-range sRGB RGB8, refusing unproven alpha discard
(AlphaPolicy::DiscardIfOpaque). Read moreSource§fn to_gray8_if_opaque(&self) -> Result<PixelBuf, At<ConvertError>>
fn to_gray8_if_opaque(&self) -> Result<PixelBuf, At<ConvertError>>
self to full-range sRGB GRAY8, refusing unproven alpha discard
(AlphaPolicy::DiscardIfOpaque). Read more