pub struct PixelBuf { /* private fields */ }Expand description
Full re-export of zenpixels core types (zero module name collisions!).
Owned, unparameterized, alignment-exact pixel image buffer.
Every allocating constructor is fallible and returns Result<Self, At<BufferError>>.
Mutable access automatically invalidates attached SampleClaims.
Implementations§
Source§impl PixelBuf
impl PixelBuf
Sourcepub fn try_clone(&self) -> Result<PixelBuf, At<BufferError>>
pub fn try_clone(&self) -> Result<PixelBuf, At<BufferError>>
Fallibly clone this buffer, preserving alignment, metadata, claims, origin, and orientation.
Sourcepub fn new(
width: u32,
height: u32,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, At<BufferError>>
pub fn new( width: u32, height: u32, format: impl Into<PixelFormat>, ) -> Result<PixelBuf, At<BufferError>>
Fallibly allocate a tightly packed black-filled buffer backed by native sample storage.
When spec.color.alpha() == AlphaMode::Opaque, the alpha channel is initialized to
canonical full opacity (255, 65535, 1.0, or packed max code) so stored pixels
honor the AlphaMode::Opaque invariant immediately.
For solid opaque signal-white initialization, use
new_signal_white or
new_with_fill. To skip the alpha-fill pass when you will
overwrite every pixel, allocate via new_raw_zeroed with
AlphaMode::Straight, fill all pixels, and retag zero-copy with
into_opaque_verified or assume_opaque.
Sourcepub fn new_signal_white(
width: u32,
height: u32,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, At<BufferError>>
pub fn new_signal_white( width: u32, height: u32, format: impl Into<PixelFormat>, ) -> Result<PixelBuf, At<BufferError>>
Fallibly allocate a tightly packed buffer filled with the format’s nominal signal-white sample pattern and canonical maximum on any alpha slot.
RGB and gray use the code for nominal signal white (1.0 after range
normalization). On PQ that code represents 10,000 cd/m². On
display-rendered HLG it represents the selected display peak. Linear
RGB uses 1.0 even when the format can store larger values.
XYZ uses the format’s white-point chromaticity at Y = 1.0. Oklab
uses [1, 0, 0] and non-inverted CMYK uses zero ink. For a
luminance-calibrated fill, convert from linear samples with an explicit
DiffuseWhite anchor.
Sourcepub fn new_aligned(
width: u32,
height: u32,
format: impl Into<PixelFormat>,
align: RowAlign,
) -> Result<PixelBuf, At<BufferError>>
pub fn new_aligned( width: u32, height: u32, format: impl Into<PixelFormat>, align: RowAlign, ) -> Result<PixelBuf, At<BufferError>>
Fallibly allocate a black-filled buffer with explicit row alignment
(Tight, Cache64, PixelCache64, Samples(n)).
For Cache64 and PixelCache64, storage is allocated as 64-byte aligned
AlignedSamples so both the first pixel and every
row start land on a 64-byte boundary. When format.color.alpha() == AlphaMode::Opaque,
alpha samples are initialized to full opacity.
Sourcepub fn new_with_fill(
width: u32,
height: u32,
format: impl Into<PixelFormat>,
align: RowAlign,
fill: BufFill,
) -> Result<PixelBuf, At<BufferError>>
pub fn new_with_fill( width: u32, height: u32, format: impl Into<PixelFormat>, align: RowAlign, fill: BufFill, ) -> Result<PixelBuf, At<BufferError>>
Fallibly allocate a buffer with explicit row alignment and initial BufFill
(Black or SignalWhite).
Sourcepub fn new_raw_zeroed(
width: u32,
height: u32,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, At<BufferError>>
pub fn new_raw_zeroed( width: u32, height: u32, format: impl Into<PixelFormat>, ) -> Result<PixelBuf, At<BufferError>>
Fallibly allocate raw zero-filled OS pages with no alpha-fill pass for maximum decoder/renderer write throughput.
Refuses AlphaMode::Opaque on layouts with an alpha slot with
BufferError::UnverifiedOpaqueAlpha so an opaque-tagged buffer can never silently
contain zero alpha. Allocate with AlphaMode::Straight, write every
pixel including full alpha, then retag zero-copy via
into_opaque_verified,
into_opaque_filled, or assume_opaque.
Sourcepub fn new_raw_zeroed_aligned(
width: u32,
height: u32,
format: impl Into<PixelFormat>,
align: RowAlign,
) -> Result<PixelBuf, At<BufferError>>
pub fn new_raw_zeroed_aligned( width: u32, height: u32, format: impl Into<PixelFormat>, align: RowAlign, ) -> Result<PixelBuf, At<BufferError>>
Fallibly allocate raw zero-filled aligned OS pages with no alpha-fill pass,
refusing AlphaMode::Opaque on layouts with an alpha slot.
Sourcepub fn new_for_interop(
width: u32,
height: u32,
format: impl Into<PixelFormat>,
target: InteropTarget,
) -> Result<PixelBuf, At<BufferError>>
pub fn new_for_interop( width: u32, height: u32, format: impl Into<PixelFormat>, target: InteropTarget, ) -> Result<PixelBuf, At<BufferError>>
Fallibly allocate tight native storage validated upfront for a zero-copy InteropTarget.
Sourcepub fn from_bytes(
bytes: Vec<u8>,
width: u32,
height: u32,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, At<BufferError>>
pub fn from_bytes( bytes: Vec<u8>, width: u32, height: u32, format: impl Into<PixelFormat>, ) -> Result<PixelBuf, At<BufferError>>
Adopt tightly packed bytes (Vec<u8>), handling odd-address allocators safely.
- For 1-byte sample formats (
U8,I8), adoptsbyteszero-copy at any address. - For wider samples (
U16,F16,F32,F64), adopts zero-copy when the pointer happens to be sample-aligned, and fallibly copies into properly aligned nativePixelStoragewhen the allocator returned a misaligned address (e.g. odd address).
To recover bytes intact on error, use from_bytes_recover.
Sourcepub fn from_bytes_recover(
bytes: Vec<u8>,
width: u32,
height: u32,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, (At<BufferError>, Vec<u8>)>
pub fn from_bytes_recover( bytes: Vec<u8>, width: u32, height: u32, format: impl Into<PixelFormat>, ) -> Result<PixelBuf, (At<BufferError>, Vec<u8>)>
Adopt tightly packed bytes (Vec<u8>), returning Err((err, bytes)) with the original
Vec<u8> untouched on validation or allocation failure.
Sourcepub fn from_typed<P>(
pixels: Vec<P>,
width: u32,
height: u32,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, At<BufferError>>where
P: TypedElement,
pub fn from_typed<P>(
pixels: Vec<P>,
width: u32,
height: u32,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, At<BufferError>>where
P: TypedElement,
Adopt a tightly packed typed Vec<P> (pixels like Vec<rgb::Rgb<u16>>, arrays [u8; 3],
or raw samples like Vec<f32>).
Validates that P is structurally compatible with format.layout (preventing silent
reinterpretation such as Vec<i32> as RGBF32). Note that untyped integer literals
(vec![255, 0, 0]) default to Vec<i32> in Rust and will be rejected for U8 layouts;
annotate the first element (e.g. vec![255u8, 0, 0]) or use from_bytes.
For intentional raw byte reinterpretation, use from_pod_bytes.
Zero-copy whenever align_of::<P>() == format.layout.min_alignment() and
bytemuck::allocation::try_cast_vec succeeds (preserving exact deallocation alignment!).
Otherwise fallibly copies into native-aligned PixelStorage.
To recover pixels intact on error, use from_typed_recover.
Sourcepub fn from_typed_recover<P>(
pixels: Vec<P>,
width: u32,
height: u32,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, (At<BufferError>, Vec<P>)>where
P: TypedElement,
pub fn from_typed_recover<P>(
pixels: Vec<P>,
width: u32,
height: u32,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, (At<BufferError>, Vec<P>)>where
P: TypedElement,
Adopt a tightly packed typed Vec<P>, returning Err((err, pixels)) with the original
Vec<P> untouched on validation or allocation failure.
Sourcepub fn from_samples<S>(
samples: Vec<S>,
width: u32,
height: u32,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, At<BufferError>>where
S: StorageSample,
pub fn from_samples<S>(
samples: Vec<S>,
width: u32,
height: u32,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, At<BufferError>>where
S: StorageSample,
Adopt a tightly packed scalar sample Vec<S> (Vec<u8>, Vec<u16>, Vec<f32>, etc.).
Sourcepub fn from_pixels_with_color<P>(
pixels: Vec<P>,
width: u32,
height: u32,
color: ColorSpace,
) -> Result<PixelBuf, At<BufferError>>where
P: PixelType,
pub fn from_pixels_with_color<P>(
pixels: Vec<P>,
width: u32,
height: u32,
color: ColorSpace,
) -> Result<PixelBuf, At<BufferError>>where
P: PixelType,
Adopt a tightly packed rgb pixel Vec<P> (Vec<rgb::Rgb<u8>>, etc.) with an explicit
ColorSpace (deriving SampleLayout from P::LAYOUT).
Sourcepub fn from_pod_bytes<P>(
pixels: Vec<P>,
width: u32,
height: u32,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, At<BufferError>>where
P: Pod,
pub fn from_pod_bytes<P>(
pixels: Vec<P>,
width: u32,
height: u32,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, At<BufferError>>where
P: Pod,
Explicitly reinterpret any tightly packed Vec<P: bytemuck::Pod> in native endianness
as raw pixel bytes matching format without checking element-to-layout compatibility.
Sourcepub fn from_storage_parts(
storage: PixelStorage,
byte_offset: usize,
width: u32,
height: u32,
stride_bytes: usize,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, At<BufferError>>
pub fn from_storage_parts( storage: PixelStorage, byte_offset: usize, width: u32, height: u32, stride_bytes: usize, format: impl Into<PixelFormat>, ) -> Result<PixelBuf, At<BufferError>>
Checked construction from owned PixelStorage, byte offset, dimensions, byte stride, and
format with fresh default metadata (claims = NONE, hdr = empty, origin = assumed,
orientation = Identity).
To restore descriptive metadata from PixelBuf::into_parts, use
from_parts or from_parts_recover.
Sourcepub fn from_parts(parts: PixelBufParts) -> Result<PixelBuf, At<BufferError>>
pub fn from_parts(parts: PixelBufParts) -> Result<PixelBuf, At<BufferError>>
Checked reconstruction from a PixelBufParts struct (preserving hdr, origin,
and orientation, starting with SampleClaims::NONE).
Because detached storage can be mutated while outside PixelBuf, reconstructed
buffers never inherit pre-decomposition sample claims.
On validation failure, parts is dropped; use
from_parts_recover to recover the allocation intact.
Sourcepub fn from_parts_recover(
parts: PixelBufParts,
) -> Result<PixelBuf, (At<BufferError>, PixelBufParts)>
pub fn from_parts_recover( parts: PixelBufParts, ) -> Result<PixelBuf, (At<BufferError>, PixelBufParts)>
Checked reconstruction from PixelBufParts, returning Err((err, parts)) with the
original allocation and metadata intact on validation failure.
Starts with SampleClaims::NONE because detached storage may have been edited.
Sourcepub fn from_external<S>(
storage: S,
width: u32,
height: u32,
stride_bytes: usize,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, (At<BufferError>, S)>
pub fn from_external<S>( storage: S, width: u32, height: u32, stride_bytes: usize, format: impl Into<PixelFormat>, ) -> Result<PixelBuf, (At<BufferError>, S)>
Adopt an immutable external owned backing (Arc<[u8]>, Arc<[u16]>, &'static [u8],
memory-mapped file wrapper, shared buffer pool handle, etc.) zero-copy.
Validates geometry and sample alignment BEFORE boxing storage; on error, returns
Err((err, storage)) with zero heap allocation and storage completely untouched.
Read access (as_view, row, PixelSource) is strictly zero-copy. Requesting
mutable access (as_view_mut, try_cow_view_mut, make_mut) transparently
performs copy-on-write into owned aligned storage without mutating storage.
Call into_external to recover S zero-copy.
Sourcepub fn from_external_with_byte_offset<S>(
storage: S,
byte_offset: usize,
width: u32,
height: u32,
stride_bytes: usize,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, (At<BufferError>, S)>
pub fn from_external_with_byte_offset<S>( storage: S, byte_offset: usize, width: u32, height: u32, stride_bytes: usize, format: impl Into<PixelFormat>, ) -> Result<PixelBuf, (At<BufferError>, S)>
Adopt an immutable external owned backing starting at byte_offset bytes zero-copy.
Returns Err((err, storage)) untouched on validation failure with zero heap allocation.
Sourcepub fn from_external_mut<S>(
storage: S,
width: u32,
height: u32,
stride_bytes: usize,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, (At<BufferError>, S)>
pub fn from_external_mut<S>( storage: S, width: u32, height: u32, stride_bytes: usize, format: impl Into<PixelFormat>, ) -> Result<PixelBuf, (At<BufferError>, S)>
Adopt a mutable external owned backing (Box<[T]>, custom-allocator wrapper, mutable
pool lease, FFI writable buffer, etc.) zero-copy for both reads and in-place writes.
Validates geometry and sample alignment BEFORE boxing storage; on error, returns
Err((err, storage)) with zero heap allocation and storage completely untouched.
Call into_external_mut to recover S zero-copy.
Sourcepub fn from_external_mut_with_byte_offset<S>(
storage: S,
byte_offset: usize,
width: u32,
height: u32,
stride_bytes: usize,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, (At<BufferError>, S)>
pub fn from_external_mut_with_byte_offset<S>( storage: S, byte_offset: usize, width: u32, height: u32, stride_bytes: usize, format: impl Into<PixelFormat>, ) -> Result<PixelBuf, (At<BufferError>, S)>
Adopt a mutable external owned backing starting at byte_offset bytes zero-copy.
Returns Err((err, storage)) untouched on validation failure with zero heap allocation.
Sourcepub const fn is_external(&self) -> bool
pub const fn is_external(&self) -> bool
Whether this buffer is backed by an external owner (from_external or from_external_mut).
Sourcepub const fn is_mutable_in_place(&self) -> bool
pub const fn is_mutable_in_place(&self) -> bool
Whether mutable access modifies the current backing in place without copy-on-write.
Sourcepub fn external_ref<S>(&self) -> Option<&S>where
S: 'static,
pub fn external_ref<S>(&self) -> Option<&S>where
S: 'static,
Borrow the external owner if backed by an external owner of concrete type S.
Sourcepub fn into_external<S>(self) -> Result<S, PixelBuf>where
S: 'static,
pub fn into_external<S>(self) -> Result<S, PixelBuf>where
S: 'static,
Recover an immutable external owner S zero-copy; returns Err(self) untouched otherwise.
Sourcepub fn into_external_mut<S>(self) -> Result<S, PixelBuf>where
S: 'static,
pub fn into_external_mut<S>(self) -> Result<S, PixelBuf>where
S: 'static,
Recover a mutable external owner S zero-copy; returns Err(self) untouched otherwise.
Sourcepub fn make_mut(&mut self) -> Result<(), At<BufferError>>
pub fn make_mut(&mut self) -> Result<(), At<BufferError>>
Ensure backing storage is mutable in place, fallibly promoting immutable external
storage (PixelStorage::External) via copy-on-write into properly aligned owned storage.
No-op (zero copy, zero allocation) for native Vec, Aligned64, and ExternalMut buffers.
Sourcepub const fn stride_bytes(&self) -> usize
pub const fn stride_bytes(&self) -> usize
Stride in bytes.
Sourcepub const fn byte_offset(&self) -> usize
pub const fn byte_offset(&self) -> usize
Leading byte offset inside backing storage.
Sourcepub fn format(&self) -> &PixelFormat
pub fn format(&self) -> &PixelFormat
Authoritative image specification.
Sourcepub fn relabel_format(
self,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, At<BufferError>>
pub fn relabel_format( self, format: impl Into<PixelFormat>, ) -> Result<PixelBuf, At<BufferError>>
Relabel specification metadata without modifying pixel bytes, preserving numeric sample
type, bit packing, and bytes_per_pixel (e.g. relabeling color space or channel order).
Rejects changes to sample type or packing (use
reinterpret_bytes for deliberate raw-byte reinterpretation
across sample types). Clears cached SampleClaims and resets ColorOrigin to
ColorOrigin::assumed whenever format.color changes.
Sourcepub fn relabel_color(
self,
color: ColorSpace,
) -> Result<PixelBuf, At<BufferError>>
pub fn relabel_color( self, color: ColorSpace, ) -> Result<PixelBuf, At<BufferError>>
Relabel only the color space metadata without modifying pixel bytes, keeping the exact
SampleLayout.
Does not convert pixel values (use zenpixels-convert to convert colors). Resets
ColorOrigin to ColorOrigin::assumed when color changes and clears cached
SampleClaims when signal range, alpha mode, or color model changes.
Sourcepub fn reinterpret_bytes(
self,
format: impl Into<PixelFormat>,
) -> Result<PixelBuf, At<BufferError>>
pub fn reinterpret_bytes( self, format: impl Into<PixelFormat>, ) -> Result<PixelBuf, At<BufferError>>
Deliberately reinterpret the raw pixel bytes under a new PixelFormat with identical
bytes_per_pixel and satisfied sample alignment (permits changing sample type and
packing, e.g. U8 ↔ I8 or U16 ↔ F16).
Does not convert pixel values. Always clears cached SampleClaims, ColorOrigin,
and HdrMetadata.
Sourcepub fn into_opaque_verified(self) -> Result<PixelBuf, At<BufferError>>
pub fn into_opaque_verified(self) -> Result<PixelBuf, At<BufferError>>
Scan every active pixel to verify its alpha slot equals its canonical maximum value, then
retag this buffer as AlphaMode::Opaque with claims.all_opaque = true (zero copy).
Performs the full-pixel scan itself — no prior assume_claims call is
required. Returns BufferError::IncompatibleLayout if the layout has no alpha slot, or
BufferError::UnverifiedOpaqueAlpha if any alpha sample is not at channel maximum.
Sourcepub fn into_opaque_filled(self) -> Result<PixelBuf, At<BufferError>>
pub fn into_opaque_filled(self) -> Result<PixelBuf, At<BufferError>>
Fill every active pixel’s alpha slot to its canonical maximum value and retag this buffer
as AlphaMode::Opaque with claims.all_opaque = true (in place, promoting immutable
external storage via copy-on-write if needed).
Sourcepub fn assume_opaque(self) -> Result<PixelBuf, At<BufferError>>
pub fn assume_opaque(self) -> Result<PixelBuf, At<BufferError>>
Retag this buffer as AlphaMode::Opaque in O(1) without scanning pixels, asserting
that the caller already filled every active alpha sample to channel maximum.
Pairs with new_raw_zeroed for maximum-speed decoder/renderer fill loops:
allocate zeroed with AlphaMode::Straight, write every pixel including A = max,
then call assume_opaque().
Sourcepub const fn attached_claims(&self) -> SampleClaims
pub const fn attached_claims(&self) -> SampleClaims
Read the sample claims attached to the buffer in constant time.
Sourcepub fn assume_claims(&mut self, claims: SampleClaims)
pub fn assume_claims(&mut self, claims: SampleClaims)
Attach caller-asserted SampleClaims (caller assumes responsibility for validity;
cleared on next mutable pixel access).
Sourcepub fn hdr(&self) -> HdrMetadata
pub fn hdr(&self) -> HdrMetadata
Descriptive HDR container metadata.
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 fn with_hdr(self, hdr: HdrMetadata) -> PixelBuf
pub fn with_hdr(self, hdr: HdrMetadata) -> PixelBuf
Attach descriptive HDR container metadata.
Sourcepub fn origin(&self) -> &ColorOrigin
pub fn origin(&self) -> &ColorOrigin
Original container color provenance.
Sourcepub fn with_origin(self, origin: ColorOrigin) -> PixelBuf
pub fn with_origin(self, origin: ColorOrigin) -> PixelBuf
Attach container color provenance.
Sourcepub const fn orientation(&self) -> Orientation
pub const fn orientation(&self) -> Orientation
Pending EXIF display orientation attached to this buffer (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 const fn with_orientation(self, orientation: Orientation) -> PixelBuf
pub const fn with_orientation(self, orientation: Orientation) -> PixelBuf
Replace the pending EXIF display orientation on this buffer.
Sourcepub fn set_orientation(&mut self, orientation: Orientation)
pub fn set_orientation(&mut self, orientation: Orientation)
Set the pending EXIF display orientation on this buffer in place.
Sourcepub const fn compose_orientation(self, delta: Orientation) -> PixelBuf
pub const fn compose_orientation(self, delta: Orientation) -> PixelBuf
Compose an additional display transform (including reflections) onto this buffer’s
pending orientation (self.orientation.then(delta)) in O(1) without touching or copying pixels.
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<&[u8]>
pub fn as_contiguous_bytes(&self) -> Option<&[u8]>
Borrow contiguous packed pixel bytes across all rows, or None if padded.
Sourcepub fn row_as<P>(&self, y: u32) -> Result<&[P], At<BufferError>>where
P: TypedElement,
pub fn row_as<P>(&self, y: u32) -> Result<&[P], At<BufferError>>where
P: TypedElement,
Zero-copy layout-checked typed slice view of row y
(e.g. buf.row_as::<rgb::Rgb<u16>>(y), buf.row_as::<[f32; 3]>(y), buf.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. Use row_as_with for explicit BitPackingAccess,
or row_transmute for intentional raw-POD byte reinterpretation.
Sourcepub fn row_as_with<P>(
&self,
y: u32,
packing: BitPackingAccess,
) -> Result<&[P], At<BufferError>>where
P: TypedElement,
pub fn row_as_with<P>(
&self,
y: u32,
packing: BitPackingAccess,
) -> Result<&[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<&[S], At<BufferError>>where
S: StorageSample,
pub fn row_samples<S>(&self, y: u32) -> Result<&[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.
Sourcepub fn row_samples_with<S>(
&self,
y: u32,
packing: BitPackingAccess,
) -> Result<&[S], At<BufferError>>where
S: StorageSample,
pub fn row_samples_with<S>(
&self,
y: u32,
packing: BitPackingAccess,
) -> Result<&[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<&[P], At<BufferError>>where
P: Pod,
pub fn row_transmute<P>(&self, y: u32) -> Result<&[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 validation.
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)).
Sourcepub fn as_contiguous_typed<P>(&self) -> Result<&[P], At<BufferError>>where
P: TypedElement,
pub fn as_contiguous_typed<P>(&self) -> Result<&[P], At<BufferError>>where
P: TypedElement,
Zero-copy layout-checked contiguous typed slice across all rows
(e.g. &[rgb::Rgb<u16>], &[[f32; 3]], &[u16]).
Semantically validates P::matches_layout(self.format().layout) and tight row packing.
For intentional raw-POD reinterpretation, use
as_contiguous_transmute.
Sourcepub fn as_contiguous_typed_with<P>(
&self,
packing: BitPackingAccess,
) -> Result<&[P], At<BufferError>>where
P: TypedElement,
pub fn as_contiguous_typed_with<P>(
&self,
packing: BitPackingAccess,
) -> Result<&[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<&[S], At<BufferError>>where
S: StorageSample,
pub fn as_contiguous_samples<S>(&self) -> Result<&[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<&[S], At<BufferError>>where
S: StorageSample,
pub fn as_contiguous_samples_with<S>(
&self,
packing: BitPackingAccess,
) -> Result<&[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<&[P], At<BufferError>>where
P: Pod,
pub fn as_contiguous_transmute<P>(&self) -> Result<&[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 try_cow_row_as_mut<P>(
&mut self,
y: u32,
) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
pub fn try_cow_row_as_mut<P>(
&mut self,
y: u32,
) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
Fallibly borrow a layout-checked mutable typed slice of row y
(e.g. &mut [rgb::Rgb<u16>], &mut [[f32; 3]], &mut [u16]).
Rejects mismatched layouts and non-Full BitPacking before triggering CoW promotion
or clearing SampleClaims.
Sourcepub fn try_cow_row_as_mut_with<P>(
&mut self,
y: u32,
packing: BitPackingAccess,
) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
pub fn try_cow_row_as_mut_with<P>(
&mut self,
y: u32,
packing: BitPackingAccess,
) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
Fallibly borrow a layout-checked mutable typed slice of row y with an explicit
BitPackingAccess policy (Fail or PassThrough).
Sourcepub fn try_cow_row_samples_mut<S>(
&mut self,
y: u32,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
pub fn try_cow_row_samples_mut<S>(
&mut self,
y: u32,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
Fallibly borrow a sample-checked native-endian mutable slice of row y (e.g. &mut [u16]).
Rejects non-Full BitPacking and mismatched sample types before triggering CoW
promotion or clearing SampleClaims.
Sourcepub fn try_cow_row_samples_mut_with<S>(
&mut self,
y: u32,
packing: BitPackingAccess,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
pub fn try_cow_row_samples_mut_with<S>(
&mut self,
y: u32,
packing: BitPackingAccess,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
Fallibly borrow a sample-checked native-endian mutable slice of row y with an explicit
BitPackingAccess policy (Fail or PassThrough).
Sourcepub fn try_cow_row_transmute_mut<P>(
&mut self,
y: u32,
) -> Result<&mut [P], At<BufferError>>where
P: Pod,
pub fn try_cow_row_transmute_mut<P>(
&mut self,
y: u32,
) -> Result<&mut [P], At<BufferError>>where
P: Pod,
Fallibly borrow a safe raw-POD mutable reinterpretation of row y, copy-on-write promoting
immutable external storage and clearing cached SampleClaims only once bounds,
divisibility, and alignment checks pass.
Sourcepub fn try_cow_contiguous_typed_mut<P>(
&mut self,
) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
pub fn try_cow_contiguous_typed_mut<P>(
&mut self,
) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
Fallibly borrow a layout-checked mutable contiguous typed slice across all rows
(e.g. &mut [rgb::Rgba<f32>], &mut [[u16; 3]], &mut [u16]).
Rejects padded rows, mismatched layouts, and non-Full BitPacking before triggering
CoW promotion or clearing SampleClaims.
Sourcepub fn try_cow_contiguous_typed_mut_with<P>(
&mut self,
packing: BitPackingAccess,
) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
pub fn try_cow_contiguous_typed_mut_with<P>(
&mut self,
packing: BitPackingAccess,
) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
Fallibly borrow a layout-checked mutable contiguous typed slice across all rows with an
explicit BitPackingAccess policy (Fail or PassThrough).
Sourcepub fn try_cow_contiguous_samples_mut<S>(
&mut self,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
pub fn try_cow_contiguous_samples_mut<S>(
&mut self,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
Fallibly borrow a sample-checked native-endian mutable contiguous slice across all rows
(e.g. &mut [u16]).
Rejects padded rows, non-Full BitPacking, and mismatched sample types before
triggering CoW promotion or clearing SampleClaims.
Sourcepub fn try_cow_contiguous_samples_mut_with<S>(
&mut self,
packing: BitPackingAccess,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
pub fn try_cow_contiguous_samples_mut_with<S>(
&mut self,
packing: BitPackingAccess,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
Fallibly borrow a sample-checked native-endian mutable contiguous slice across all rows
with an explicit BitPackingAccess policy (Fail or PassThrough).
Sourcepub fn try_cow_contiguous_transmute_mut<P>(
&mut self,
) -> Result<&mut [P], At<BufferError>>where
P: Pod,
pub fn try_cow_contiguous_transmute_mut<P>(
&mut self,
) -> Result<&mut [P], At<BufferError>>where
P: Pod,
Fallibly borrow a safe raw-POD mutable reinterpretation across contiguous rows,
copy-on-write promoting immutable external storage and clearing cached SampleClaims
only once contiguity, divisibility, and alignment checks pass.
Sourcepub fn mutate_rows_with_packing<S, Pre, Post, F>(
&mut self,
mode: BitPackingTransform<Pre, Post>,
f: F,
) -> Result<(), At<BufferError>>where
S: StorageSample,
Pre: FnMut(BitPacking, &mut [S]),
Post: FnMut(BitPacking, &mut [S]),
F: FnMut(u32, &mut [S]) -> Result<(), At<BufferError>>,
pub fn mutate_rows_with_packing<S, Pre, Post, F>(
&mut self,
mode: BitPackingTransform<Pre, Post>,
f: F,
) -> Result<(), At<BufferError>>where
S: StorageSample,
Pre: FnMut(BitPacking, &mut [S]),
Post: FnMut(BitPacking, &mut [S]),
F: FnMut(u32, &mut [S]) -> Result<(), At<BufferError>>,
Mutate every row in place as &mut [S] with an explicit BitPackingTransform policy
(Fail, PassThrough, or PrePost { norm, denorm }).
Validates S::SAMPLE_TYPE and Fail packing before copy-on-write promotion or
clearing SampleClaims. For PrePost, denorm(packing, row) is guaranteed to run on
every normalized row even if f returns Err or unwinds.
Sourcepub fn row_mut(&mut self, y: u32) -> &mut [u8] ⓘ
pub fn row_mut(&mut self, y: u32) -> &mut [u8] ⓘ
Mutably borrow active pixel bytes for row y (len == row_bytes()), clearing cached
SampleClaims and copy-on-write promoting immutable external storage if needed.
For fallible external-storage CoW without panicking on OOM, use
buf.try_cow_view_mut()?.row_mut(y).
§Panics
Panics if y >= self.height(), or if copy-on-write promotion of immutable external storage
fails to allocate.
Sourcepub fn as_view(&self) -> PixelView<'_>
pub fn as_view(&self) -> PixelView<'_>
Borrow an immutable PixelView of the whole image (zero Arc refcount bump).
Sourcepub fn try_cow_view_mut(&mut self) -> Result<PixelViewMut<'_>, At<BufferError>>
pub fn try_cow_view_mut(&mut self) -> Result<PixelViewMut<'_>, At<BufferError>>
Fallibly borrow a mutable PixelViewMut, clearing cached SampleClaims and
performing copy-on-write promotion of immutable external storage without panicking on OOM
(zero Arc refcount bump).
Never fails merely because storage is immutable External; returns
Err(BufferError::AllocationFailed) only on OOM during copy-on-write promotion.
Sourcepub fn as_view_mut(&mut self) -> PixelViewMut<'_>
pub fn as_view_mut(&mut self) -> PixelViewMut<'_>
Borrow a mutable PixelViewMut, automatically clearing cached SampleClaims.
If backed by immutable external storage (from_external), promotes via copy-on-write;
use try_cow_view_mut for fallible OOM handling.
Sourcepub fn sub_rows(
&self,
start_y: u32,
row_count: u32,
) -> Result<PixelView<'_>, At<BufferError>>
pub fn sub_rows( &self, start_y: u32, row_count: u32, ) -> Result<PixelView<'_>, At<BufferError>>
Borrow a full-width horizontal strip of row_count rows starting at start_y without copying pixels.
Sourcepub fn sub_rows_mut(
&mut self,
start_y: u32,
row_count: u32,
) -> Result<PixelViewMut<'_>, At<BufferError>>
pub fn sub_rows_mut( &mut self, start_y: u32, row_count: u32, ) -> Result<PixelViewMut<'_>, At<BufferError>>
Borrow a mutable full-width horizontal strip of row_count rows starting at start_y,
automatically clearing cached SampleClaims and fallibly copy-on-write promoting
immutable external storage if needed.
Sourcepub fn crop_view(
&self,
rect: PixelRect,
) -> Result<PixelView<'_>, At<BufferError>>
pub fn crop_view( &self, rect: PixelRect, ) -> Result<PixelView<'_>, At<BufferError>>
Borrow a rectangular cropped subimage view without copying pixels.
Sourcepub fn crop_view_mut(
&mut self,
rect: PixelRect,
) -> Result<PixelViewMut<'_>, At<BufferError>>
pub fn crop_view_mut( &mut self, rect: PixelRect, ) -> Result<PixelViewMut<'_>, At<BufferError>>
Borrow a mutable rectangular cropped subimage view without copying pixels,
automatically clearing cached SampleClaims and fallibly copy-on-write promoting
immutable external storage if needed.
Sourcepub fn into_crop(self, rect: PixelRect) -> Result<PixelBuf, At<BufferError>>
pub fn into_crop(self, rect: PixelRect) -> Result<PixelBuf, At<BufferError>>
Consume this buffer and narrow it to a rectangular crop in O(1) with zero pixel copies.
Keeps the underlying PixelStorage and row stride_bytes intact while advancing the active
byte offset and narrowing (width, height). Preserves sample alignment, cached
SampleClaims, HdrMetadata, ColorOrigin, and Orientation. Chain
into_tight_rows afterwards to compact the cropped region into
tightly packed rows if desired.
Sourcepub fn mutate_with_claims<F>(&mut self, f: F) -> Result<(), At<BufferError>>
pub fn mutate_with_claims<F>(&mut self, f: F) -> Result<(), At<BufferError>>
Mutate pixels in place with access to the starting SampleClaims, atomically committing
the resulting SampleClaims returned by f.
Unlike try_cow_view_mut (which clears SampleClaims eagerly
before returning &mut), this scoped helper hands (PixelViewMut<'_>, old_claims) to the
closure so in-place algorithms can skip unnecessary work (e.g. skipping alpha normalization
when old_claims.all_opaque is already true) and propagate output claims without
rescanning.
Panic & error safety: self.claims is cleared to SampleClaims::NONE before invoking
f. If f returns Err(_) or panics, cached claims remain cleared rather than stale. If
copy-on-write promotion fails (BufferError::AllocationFailed), pixels are untouched and
existing claims remain intact.
Sourcepub fn transform_in_place<F>(&mut self, f: F) -> Result<(), At<BufferError>>
pub fn transform_in_place<F>(&mut self, f: F) -> Result<(), At<BufferError>>
Atomically transform this buffer’s bytes and metadata in place with zero reallocation.
The closure receives (active_bytes, input) where active_bytes starts at pixel (0, 0)
and input.claims carries the buffer’s starting SampleClaims. Return
InPlaceTransformDecision::Updated to validate and atomically adopt the new
stride/format/origin/claims against existing storage, or
InPlaceTransformDecision::Unchanged (asserting pixel bytes were not modified) to keep
existing metadata and claims intact.
Panic & error safety: self.claims is cleared to SampleClaims::NONE before invoking
f so a panic or post-transform metadata validation error never leaves stale claims behind.
Sourcepub fn into_tight_rows(self) -> Result<PixelBuf, At<BufferError>>
pub fn into_tight_rows(self) -> Result<PixelBuf, At<BufferError>>
Fallibly compact strided rows into tight row packing (stride_bytes() == row_bytes()).
Compacts in place inside the existing allocation for owned mutable storage; promotes
shared or immutable external storage via fallible copy-on-write
(BufferError::AllocationFailed on OOM).
Note: preserves byte_offset() == 0 whenever the backing base pointer satisfies
format().layout.min_alignment(), and otherwise retains the smallest aligned
byte_offset() < min_alignment() (e.g. an odd-aligned Vec<u8> holding U16 samples)
so sample alignment is never violated without reallocating.
Sourcepub fn swizzle_in_place(
&mut self,
target_order: ChannelOrder,
) -> Result<(), At<BufferError>>
pub fn swizzle_in_place( &mut self, target_order: ChannelOrder, ) -> Result<(), At<BufferError>>
Permute equal-width color channels in place (Rgb ↔ Bgr, Rgba ↔ Bgra, Rgbx ↔ Bgrx)
without reallocating for owned mutable storage (copy-on-write promotes immutable external
storage via make_mut()).
Works for any unpacked sample type (U8, U16, F16, F32, etc.), preserving
stride_bytes(), SampleClaims, and ColorSpace.
For lossless 4→3 padding or opaque-alpha lane drops (Rgbx/Bgrx/Opaque Rgba/Opaque Bgra
→ Rgb/Bgr), use drop_unused_lane_in_place.
Refuses channel-count changes, packed-word layouts, and unsupported channel orders with
BufferError::IncompatibleLayout.
Sourcepub fn drop_unused_lane_in_place(
&mut self,
target_order: ChannelOrder,
) -> Result<(), At<BufferError>>
pub fn drop_unused_lane_in_place( &mut self, target_order: ChannelOrder, ) -> Result<(), At<BufferError>>
Losslessly drop a redundant 4th lane (undefined padding in Rgbx/Bgrx, or
AlphaMode::Opaque in Rgba/Bgra) in place to 3-channel Rgb or Bgr,
compacting active pixels within each row (copy-on-write promoting immutable external
storage via make_mut()).
Keeps existing stride_bytes() unchanged (leaving trailing inter-row slack so multi-row
buffers do not shift across rows; chain into_tight_rows afterwards
if tight stride_bytes() == row_bytes() packing is required), clears cached SampleClaims,
and updates AlphaMode::Opaque / AlphaMode::Undefined to AlphaMode::None.
Refuses live alpha (Straight/Premultiplied), packed-word layouts, and unsupported
source/target orders with BufferError::IncompatibleLayout.
Sourcepub fn into_vec_zero_copy<P>(self) -> Result<Vec<P>, PixelBuf>where
P: Pod,
pub fn into_vec_zero_copy<P>(self) -> Result<Vec<P>, PixelBuf>where
P: Pod,
Move the backing allocation into a tightly packed Vec<P> strictly zero-copy.
Succeeds only when offset == 0, rows are contiguous, active byte length
matches the backing storage length, align_of::<P>() equals the backing
allocation’s exact alignment, and capacity in bytes is a multiple of
size_of::<P>(). Returns Err(self) untouched otherwise.
Sourcepub fn into_vec<P>(self) -> Result<Vec<P>, At<BufferError>>where
P: Pod,
pub fn into_vec<P>(self) -> Result<Vec<P>, At<BufferError>>where
P: Pod,
Extract tightly packed pixels into Vec<P>, moving zero-copy when
allocation alignment & capacity match, or fallibly copying active rows otherwise.
Never violates deallocation alignment, never drops row tails on cross-row elements, and never panics on OOM.
Sourcepub fn into_parts(self) -> PixelBufParts
pub fn into_parts(self) -> PixelBufParts
Decompose into owned backing storage and descriptive metadata (drops attached SampleClaims).
Sourcepub fn storage(&self) -> &PixelStorage
pub fn storage(&self) -> &PixelStorage
Access underlying storage reference (for diagnostics and interop checks).
Source§impl PixelBuf
impl PixelBuf
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 buffer.
Source§impl PixelBuf
impl PixelBuf
Sourcepub fn from_imgvec<P>(
img: Img<Vec<P>>,
color: ColorSpace,
) -> Result<PixelBuf, At<BufferError>>where
P: PixelType,
pub fn from_imgvec<P>(
img: Img<Vec<P>>,
color: ColorSpace,
) -> Result<PixelBuf, At<BufferError>>where
P: PixelType,
Adopt an [imgref::ImgVec<P>] zero-copy when tightly packed and alignment-compatible.
Sourcepub fn into_imgvec_zero_copy<P>(self) -> Result<Img<Vec<P>>, PixelBuf>where
P: PixelType,
pub fn into_imgvec_zero_copy<P>(self) -> Result<Img<Vec<P>>, PixelBuf>where
P: PixelType,
Move into an [imgref::ImgVec<P>] strictly zero-copy without copying or allocating.
Returns Err(self) completely untouched if layout, contiguity, alignment, or allocation
capacity prevent a zero-copy Vec<P> cast.
Sourcepub fn into_imgvec<P>(self) -> Result<Img<Vec<P>>, At<BufferError>>where
P: PixelType,
pub fn into_imgvec<P>(self) -> Result<Img<Vec<P>>, At<BufferError>>where
P: PixelType,
Move into an [imgref::ImgVec<P>], zero-copy when allocation alignment & capacity match.
Source§impl PixelBuf
impl PixelBuf
Sourcepub fn into_image_buffer<P>(
self,
) -> Result<ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>, At<BufferError>>where
P: Pixel + PixelWithColorType + 'static,
<P as Pixel>::Subpixel: StorageSample,
pub fn into_image_buffer<P>(
self,
) -> Result<ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>, At<BufferError>>where
P: Pixel + PixelWithColorType + 'static,
<P as Pixel>::Subpixel: StorageSample,
Move into an image::ImageBuffer<P, Vec<P::Subpixel>> zero-copy when layout and color match,
propagating CICP color-space metadata onto the resulting ImageBuffer.
When self.format().color.alpha() == AlphaMode::Opaque and attached claims do not already assert
all_opaque, canonicalizes the stored alpha channel to full opacity so image’s straight-alpha
Rgba/LumaA buffer never receives non-opaque alpha samples.
Source§impl PixelBuf
impl PixelBuf
Sourcepub fn from_image_buffer<P>(
img: ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>,
) -> Result<PixelBuf, At<BufferError>>where
P: Pixel + PixelWithColorType + 'static,
<P as Pixel>::Subpixel: StorageSample,
pub fn from_image_buffer<P>(
img: ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>,
) -> Result<PixelBuf, At<BufferError>>where
P: Pixel + PixelWithColorType + 'static,
<P as Pixel>::Subpixel: StorageSample,
Adopt any image::ImageBuffer<P, Vec<P::Subpixel>> zero-copy across all 10 standard
formats (Luma, LumaA, Rgb, Rgba × u8/u16/f32), preserving its declared
image::metadata::Cicp color space.
Sourcepub fn from_image_buffer_with_color<P>(
img: ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>,
color: ColorSpace,
) -> Result<PixelBuf, At<BufferError>>where
P: Pixel + PixelWithColorType + 'static,
<P as Pixel>::Subpixel: StorageSample,
pub fn from_image_buffer_with_color<P>(
img: ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>,
color: ColorSpace,
) -> Result<PixelBuf, At<BufferError>>where
P: Pixel + PixelWithColorType + 'static,
<P as Pixel>::Subpixel: StorageSample,
Adopt any image::ImageBuffer<P, Vec<P::Subpixel>> zero-copy with an explicit
color, rejecting contradictory non-default CICP declarations.
Sourcepub fn from_dynamic_image(
img: DynamicImage,
) -> Result<PixelBuf, At<BufferError>>
pub fn from_dynamic_image( img: DynamicImage, ) -> Result<PixelBuf, At<BufferError>>
Adopt an image::DynamicImage zero-copy across all 10 standard variants, reading
its declared image::metadata::Cicp color space.
Note: image 0.25 defaults DynamicImage::color_space() to Cicp::SRGB even for
ImageRgb32F/ImageRgba32F. Use from_dynamic_image_with_color
when adopting untagged linear float DynamicImage buffers whose CICP was left default.
Sourcepub fn from_dynamic_image_with_color(
img: DynamicImage,
color: ColorSpace,
) -> Result<PixelBuf, At<BufferError>>
pub fn from_dynamic_image_with_color( img: DynamicImage, color: ColorSpace, ) -> Result<PixelBuf, At<BufferError>>
Adopt an image::DynamicImage zero-copy across all 10 standard variants with an
explicit color (e.g. ColorSpace::LINEAR_SRGB for ImageRgb32F), rejecting
contradictory non-default CICP declarations.
Sourcepub fn from_rgb8_image(
img: ImageBuffer<Rgb<u8>, Vec<u8>>,
) -> Result<PixelBuf, At<BufferError>>
pub fn from_rgb8_image( img: ImageBuffer<Rgb<u8>, Vec<u8>>, ) -> Result<PixelBuf, At<BufferError>>
Adopt an image::RgbImage zero-copy, reading its declared image::metadata::Cicp color space.
Sourcepub fn from_rgba8_image(
img: ImageBuffer<Rgba<u8>, Vec<u8>>,
) -> Result<PixelBuf, At<BufferError>>
pub fn from_rgba8_image( img: ImageBuffer<Rgba<u8>, Vec<u8>>, ) -> Result<PixelBuf, At<BufferError>>
Adopt an image::RgbaImage zero-copy, reading its declared image::metadata::Cicp color space.
Sourcepub fn from_rgb8_image_with_color(
img: ImageBuffer<Rgb<u8>, Vec<u8>>,
color: ColorSpace,
) -> Result<PixelBuf, At<BufferError>>
pub fn from_rgb8_image_with_color( img: ImageBuffer<Rgb<u8>, Vec<u8>>, color: ColorSpace, ) -> Result<PixelBuf, At<BufferError>>
Adopt an image::ImageBuffer<image::Rgb<u8>, Vec<u8>> zero-copy with explicit color.
Rejects contradictory color spaces when img declares a non-default CICP space
that disagrees with color (use from_rgb8_image to
preserve img’s own declared CICP automatically).
Sourcepub fn from_rgba8_image_with_color(
img: ImageBuffer<Rgba<u8>, Vec<u8>>,
color: ColorSpace,
) -> Result<PixelBuf, At<BufferError>>
pub fn from_rgba8_image_with_color( img: ImageBuffer<Rgba<u8>, Vec<u8>>, color: ColorSpace, ) -> Result<PixelBuf, At<BufferError>>
Adopt an image::ImageBuffer<image::Rgba<u8>, Vec<u8>> zero-copy with explicit color.
Rejects contradictory color spaces when img declares a non-default CICP space
that disagrees with color (use from_rgba8_image to
preserve img’s own declared CICP automatically).
Sourcepub fn into_dynamic_image(self) -> Result<DynamicImage, At<BufferError>>
pub fn into_dynamic_image(self) -> Result<DynamicImage, At<BufferError>>
Move into an image::DynamicImage zero-copy when InteropTarget::DynamicImage is satisfied.
Sourcepub const fn try_image_srgb_default_color(
order: ChannelOrder,
) -> Option<ColorSpace>
pub const fn try_image_srgb_default_color( order: ChannelOrder, ) -> Option<ColorSpace>
Helper: construct an sRGB ColorSpace matching image 0.25’s default Cicp::SRGB
convention for standard grayscale and RGB/BGR channel orders.
Returns Some(...) for Gray, GrayAlpha, Rgb, Bgr, Rgba, Bgra, Rgbx, and
Bgrx (mapping Rgb/Bgr to AlphaMode::None, Rgbx/Bgrx to AlphaMode::Undefined,
and Rgba/Bgra/GrayAlpha to AlphaMode::Straight), and None for non-sRGB orders
(Cmyk, Generic).
Note: from_image_buffer and from_dynamic_image
read each buffer’s declared image::metadata::Cicp rather than calling this helper.
Trait Implementations§
Source§impl Clone for PixelBuf
impl Clone for PixelBuf
Source§fn clone(&self) -> PixelBuf
fn clone(&self) -> PixelBuf
Clone this buffer, preserving alignment, metadata, claims, origin, and orientation.
§Panics
Panics on allocation failure when repacking misaligned backing storage; use
PixelBuf::try_clone for fallible cloning.
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl PixelScanExt for PixelBuf
impl PixelScanExt for PixelBuf
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 PixelSink for PixelBuf
impl PixelSink for PixelBuf
Source§fn sink_width(&self) -> u32
fn sink_width(&self) -> u32
Source§fn sink_height(&self) -> u32
fn sink_height(&self) -> u32
Source§fn sink_format(&self) -> &PixelFormat
fn sink_format(&self) -> &PixelFormat
Source§fn sink_row_mut(&mut self, y: u32) -> Result<&mut [u8], At<BufferError>>
fn sink_row_mut(&mut self, y: u32) -> Result<&mut [u8], At<BufferError>>
y. Read moreSource§fn sink_finish(&mut self, claims: SampleClaims, hdr: HdrMetadata)
fn sink_finish(&mut self, claims: SampleClaims, hdr: HdrMetadata)
Source§fn sink_set_origin(&mut self, origin: ColorOrigin)
fn sink_set_origin(&mut self, origin: ColorOrigin)
Source§fn sink_set_orientation(&mut self, orientation: Orientation)
fn sink_set_orientation(&mut self, orientation: Orientation)
Source§impl PixelSource for PixelBuf
impl PixelSource for PixelBuf
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 !RefUnwindSafe for PixelBuf
impl !UnwindSafe for PixelBuf
impl Freeze for PixelBuf
impl Send for PixelBuf
impl Sync for PixelBuf
impl Unpin for PixelBuf
impl UnsafeUnpin for PixelBuf
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