Skip to main content

PixelView

Struct PixelView 

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

Source

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.

Source

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.

Source

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

Source

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.

Source

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

Source

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.

Source

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

Source

pub const fn width(&self) -> u32

Image width in pixels.

Source

pub const fn height(&self) -> u32

Image height in rows.

Source

pub const fn stride_bytes(&self) -> usize

Byte distance between consecutive row starts.

Source

pub fn row_bytes(&self) -> usize

Active bytes per row (width * bytes_per_pixel).

Source

pub fn format(&self) -> &PixelFormat

Authoritative image specification (layout + color).

Source

pub const fn attached_claims(&self) -> SampleClaims

Read the sample claims already attached to this view in constant time.

Source

pub fn hdr(&self) -> HdrMetadata

Descriptive HDR container metadata attached to this view.

Source

pub fn hdr_ref(&self) -> Option<&HdrMetadata>

Zero-copy reference to attached non-empty HDR metadata (None if empty/unset).

Source

pub const fn origin(&self) -> Option<&'a ColorOrigin>

Original container color provenance borrowed from the owning image, if attached.

Source

pub const fn orientation(&self) -> Orientation

Pending EXIF display orientation attached to this view (defaults to Orientation::Identity).

Source

pub const fn display_dimensions(&self) -> (u32, u32)

Display-oriented (width, height) after applying orientation.

Source

pub fn with_assumed_claims(self, claims: SampleClaims) -> PixelView<'a>

Attach caller-asserted SampleClaims to this view (caller assumes responsibility for validity).

Source

pub fn with_hdr(self, hdr: HdrMetadata) -> PixelView<'a>

Attach descriptive HDR metadata to this view.

Source

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

Source

pub const fn with_origin(self, origin: &'a ColorOrigin) -> PixelView<'a>

Attach borrowed container color provenance to this view.

Source

pub const fn with_orientation(self, orientation: Orientation) -> PixelView<'a>

Replace the pending EXIF display orientation on this view.

Source

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.

Source

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

Source

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

Source

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

Source

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.

Source

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

Source

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.

Source

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.

Source

pub const fn as_strided_bytes(&self) -> &'a [u8] ⓘ

Raw strided byte backing starting at (0, 0) (includes inter-row padding).

Source

pub fn is_contiguous(&self) -> bool

Whether rows are tightly packed (stride_bytes == row_bytes or height <= 1).

Source

pub fn as_contiguous_bytes(&self) -> Option<&'a [u8]>

Contiguous packed bytes across all rows, or None if padded.

Source

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.

Source

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

Source

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.

Source

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

Source

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.

Source

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

Source

pub fn crop(&self, rect: PixelRect) -> Result<PixelView<'a>, At<BufferError>>

Zero-copy rectangular subimage view retaining parent stride and 'a lifetime.

Source

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.

Source

pub fn to_tight_buf(&self) -> Result<PixelBuf, At<BufferError>>

Fallibly copy active pixels into a freshly allocated, tightly packed PixelBuf.

Source

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<'_>

Source

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>

Source

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.

Source

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.

Source

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>

Source

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.

Source

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<'a> Clone for PixelView<'a>

Source§

fn clone(&self) -> PixelView<'a>

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<'a> Debug for PixelView<'a>

Source§

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

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

impl PixelScanExt for PixelView<'_>

Source§

fn measure_claims(&self) -> SampleClaims

Scan active pixels and return fresh evidence about opacity, grayscale, binary alpha, float values, and exact integer code depth. Read more
Source§

fn measure_and_attach_claims(&mut self) -> SampleClaims

Replace the attached claims with the result of 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>

Check stored values against the requested SampleBounds. Read more
Source§

fn verify_claims( &self, required: SampleClaims, ) -> Result<(), ClaimVerificationError>

Check caller-supplied facts directly against stored samples. Read more
Source§

fn check_nominal_samples(&self) -> Result<(), PixelCheckError>

Check nominal sample bounds and report the bad pixel on failure. Read more
Source§

impl PixelSource for PixelView<'_>

Source§

fn source_width(&self) -> u32

Frame width in pixels.
Source§

fn source_height(&self) -> u32

Frame height in rows.
Source§

fn source_format(&self) -> &PixelFormat

Authoritative image specification.
Source§

fn source_claims(&self) -> SampleClaims

Attached sample claims.
Source§

fn source_hdr(&self) -> HdrMetadata

Descriptive HDR metadata.
Source§

fn source_origin(&self) -> Option<&ColorOrigin>

Original container color provenance, if attached.
Source§

fn source_orientation(&self) -> Orientation

Pending EXIF display orientation (defaults to Orientation::Identity).
Source§

fn source_row(&self, y: u32) -> &[u8] ⓘ

Active bytes of row y.

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> 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<S> PixelConvertExt for S
where S: PixelSource + ?Sized,

Source§

fn convert_to( &self, destination_format: impl AsRef<PixelFormat>, policy: &ConvertPolicy, ) -> Result<PixelBuf, At<ConvertError>>

Convert self into a newly allocated tightly packed PixelBuf. Read more
Source§

fn convert_to_with_peak( &self, destination_format: impl AsRef<PixelFormat>, policy: &ConvertPolicy, peak: PeakSource, ) -> Result<PixelBuf, At<ConvertError>>

Convert self into a newly allocated PixelBuf with an explicit PeakSource.
Source§

fn convert_into<D: PixelSink + ?Sized>( &self, dst: &mut D, policy: &ConvertPolicy, ) -> Result<(), At<ConvertError>>

Convert self directly into any existing PixelSink (PixelBuf, PixelViewMut, or BandedBuf).
Source§

fn convert_into_with_peak<D: PixelSink + ?Sized>( &self, dst: &mut D, policy: &ConvertPolicy, peak: PeakSource, ) -> Result<(), At<ConvertError>>

Convert self directly into any existing PixelSink with an explicit PeakSource.
Source§

fn to_rgb8_if_opaque(&self) -> Result<PixelBuf, At<ConvertError>>

Convert self to full-range sRGB RGB8, refusing unproven alpha discard (AlphaPolicy::DiscardIfOpaque). Read more
Source§

fn to_rgba8(&self) -> Result<PixelBuf, At<ConvertError>>

Convert self to full-range sRGB straight-alpha RGBA8 under ConvertPolicy::permissive.
Source§

fn to_gray8_if_opaque(&self) -> Result<PixelBuf, At<ConvertError>>

Convert self to full-range sRGB GRAY8, refusing unproven alpha discard (AlphaPolicy::DiscardIfOpaque). Read more
Source§

fn to_bgra8(&self) -> Result<PixelBuf, At<ConvertError>>

Convert self to full-range sRGB straight-alpha BGRA8 under ConvertPolicy::permissive.
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.