pub struct PixelViewMut<'a> { /* private fields */ }Expand description
Zero-copy mutable view of an interleaved image or rectangular crop.
Implementations§
Source§impl<'a> PixelViewMut<'a>
impl<'a> PixelViewMut<'a>
Sourcepub fn new(
data: &'a mut [u8],
width: u32,
height: u32,
stride_bytes: usize,
format: &'a PixelFormat,
) -> Result<PixelViewMut<'a>, At<BufferError>>
pub fn new( data: &'a mut [u8], width: u32, height: u32, stride_bytes: usize, format: &'a PixelFormat, ) -> Result<PixelViewMut<'a>, At<BufferError>>
Borrow mutable 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.
Sourcepub fn new_with_format_cow(
data: &'a mut [u8],
width: u32,
height: u32,
stride_bytes: usize,
format: FormatCow<'a>,
) -> Result<PixelViewMut<'a>, At<BufferError>>
pub fn new_with_format_cow( data: &'a mut [u8], width: u32, height: u32, stride_bytes: usize, format: FormatCow<'a>, ) -> Result<PixelViewMut<'a>, At<BufferError>>
Borrow mutable strided bytes with an explicit FormatCow<'a>.
Sourcepub fn hdr(&self) -> HdrMetadata
pub fn hdr(&self) -> HdrMetadata
Descriptive HDR container metadata attached to this mutable 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 fn with_hdr(self, hdr: HdrMetadata) -> PixelViewMut<'a>
pub fn with_hdr(self, hdr: HdrMetadata) -> PixelViewMut<'a>
Attach descriptive HDR metadata to this mutable view.
Sourcepub fn with_hdr_ref(self, hdr: &'a HdrMetadata) -> PixelViewMut<'a>
pub fn with_hdr_ref(self, hdr: &'a HdrMetadata) -> PixelViewMut<'a>
Borrow descriptive HDR metadata onto this mutable view with zero heap allocation and
zero atomic refcount overhead (ignores empty HdrMetadata::default()).
Sourcepub const fn orientation(&self) -> Orientation
pub const fn orientation(&self) -> Orientation
Pending EXIF display orientation attached to this mutable view.
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,
) -> PixelViewMut<'a>
pub const fn with_orientation( self, orientation: Orientation, ) -> PixelViewMut<'a>
Replace the pending EXIF display orientation on this mutable view.
Sourcepub fn set_orientation(&mut self, orientation: Orientation)
pub fn set_orientation(&mut self, orientation: Orientation)
Set the pending EXIF display orientation on this mutable view in place.
Sourcepub const fn compose_orientation(self, delta: Orientation) -> PixelViewMut<'a>
pub const fn compose_orientation(self, delta: Orientation) -> PixelViewMut<'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 const fn stride_bytes(&self) -> usize
pub const fn stride_bytes(&self) -> usize
Row stride in bytes.
Sourcepub fn format(&self) -> &PixelFormat
pub fn format(&self) -> &PixelFormat
Authoritative image specification.
Sourcepub fn row_as_mut<P>(&mut self, y: u32) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
pub fn row_as_mut<P>(&mut self, y: u32) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
Zero-copy layout-checked mutable typed slice of row y
(e.g. &mut [rgb::Rgba<u8>], &mut [[f32; 3]], &mut [u16]).
Semantically validates P::matches_layout(self.format().layout) — rejecting mismatched
sample types, mismatched channel orders, and non-Full BitPacking.
Use row_as_mut_with for explicit BitPackingAccess, or
row_transmute_mut for intentional raw-POD reinterpretation.
Sourcepub fn row_as_mut_with<P>(
&mut self,
y: u32,
packing: BitPackingAccess,
) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
pub fn row_as_mut_with<P>(
&mut self,
y: u32,
packing: BitPackingAccess,
) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
Zero-copy layout-checked mutable typed slice of row y with an explicit
BitPackingAccess policy (Fail or PassThrough).
Sourcepub fn row_samples_mut<S>(
&mut self,
y: u32,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
pub fn row_samples_mut<S>(
&mut self,
y: u32,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
Zero-copy sample-checked native-endian mutable slice of row y (e.g. &mut [u16]).
Rejects non-Full BitPacking and mismatched sample types with
BufferError::IncompatibleLayout.
Sourcepub fn row_samples_mut_with<S>(
&mut self,
y: u32,
packing: BitPackingAccess,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
pub fn row_samples_mut_with<S>(
&mut self,
y: u32,
packing: BitPackingAccess,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
Zero-copy sample-checked native-endian mutable slice of row y with an explicit
BitPackingAccess policy (Fail or PassThrough).
Sourcepub fn row_transmute_mut<P>(
&mut self,
y: u32,
) -> Result<&mut [P], At<BufferError>>where
P: Pod,
pub fn row_transmute_mut<P>(
&mut self,
y: u32,
) -> Result<&mut [P], At<BufferError>>where
P: Pod,
Safe raw-POD mutable byte reinterpretation of row y (bytemuck::try_cast_slice_mut),
checking bounds, alignment, and byte divisibility without semantic layout validation.
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 }).
When layout.packing == BitPacking::Full, runs f(y, row) directly with zero pre/post
overhead. When PrePost { norm, denorm } runs on a non-Full layout, norm(packing, row)
runs before f(y, row) and denorm(packing, row) is guaranteed to run afterwards (even on
Err or unwind) so rows are never left in a half-normalized state.
Sourcepub fn as_strided_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub fn as_strided_bytes_mut(&mut self) -> &mut [u8] ⓘ
Mutable 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_mut(&mut self) -> Option<&mut [u8]>
pub fn as_contiguous_bytes_mut(&mut self) -> Option<&mut [u8]>
Mutable contiguous bytes if rows are tightly packed.
Sourcepub fn as_contiguous_typed_mut<P>(
&mut self,
) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
pub fn as_contiguous_typed_mut<P>(
&mut self,
) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
Zero-copy layout-checked mutable contiguous typed slice across all rows
(e.g. &mut [rgb::Rgb<u16>], &mut [[f32; 4]], &mut [u16]).
Semantically validates P::matches_layout(self.format().layout) and tight row packing.
For intentional raw-POD reinterpretation, use
as_contiguous_transmute_mut.
Sourcepub fn as_contiguous_typed_mut_with<P>(
&mut self,
packing: BitPackingAccess,
) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
pub fn as_contiguous_typed_mut_with<P>(
&mut self,
packing: BitPackingAccess,
) -> Result<&mut [P], At<BufferError>>where
P: TypedElement,
Zero-copy layout-checked mutable contiguous typed slice across all rows with an explicit
BitPackingAccess policy (Fail or PassThrough).
Sourcepub fn as_contiguous_samples_mut<S>(
&mut self,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
pub fn as_contiguous_samples_mut<S>(
&mut self,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
Zero-copy sample-checked native-endian mutable contiguous slice across all rows
(e.g. &mut [u16]).
Rejects padded rows, non-Full bit packing, and mismatched sample types.
Sourcepub fn as_contiguous_samples_mut_with<S>(
&mut self,
packing: BitPackingAccess,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
pub fn as_contiguous_samples_mut_with<S>(
&mut self,
packing: BitPackingAccess,
) -> Result<&mut [S], At<BufferError>>where
S: StorageSample,
Zero-copy sample-checked native-endian mutable contiguous slice across all rows with an
explicit BitPackingAccess policy (Fail or PassThrough).
Sourcepub fn as_contiguous_transmute_mut<P>(
&mut self,
) -> Result<&mut [P], At<BufferError>>where
P: Pod,
pub fn as_contiguous_transmute_mut<P>(
&mut self,
) -> Result<&mut [P], At<BufferError>>where
P: Pod,
Safe raw-POD mutable byte reinterpretation across contiguous rows
(bytemuck::try_cast_slice_mut), checking tight row packing, alignment, and byte
divisibility without semantic layout validation.
Sourcepub fn as_view(&self) -> PixelView<'_>
pub fn as_view(&self) -> PixelView<'_>
Borrow as an immutable PixelView (zero Arc refcount bump).
Sourcepub fn into_view(self) -> PixelView<'a>
pub fn into_view(self) -> PixelView<'a>
Downgrade into an immutable PixelView<'a> keeping 'a.
Sourcepub fn into_strided_bytes_mut(self) -> &'a mut [u8] ⓘ
pub fn into_strided_bytes_mut(self) -> &'a mut [u8] ⓘ
Consume this mutable view and return the underlying strided backing slice tied to 'a.
Sourcepub fn crop_mut(
&mut self,
rect: PixelRect,
) -> Result<PixelViewMut<'_>, At<BufferError>>
pub fn crop_mut( &mut self, rect: PixelRect, ) -> Result<PixelViewMut<'_>, At<BufferError>>
Mutable rectangular subimage view (zero Arc refcount bump).
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>>
Mutable full-width strip view.
Sourcepub fn into_crop(
self,
rect: PixelRect,
) -> Result<PixelViewMut<'a>, At<BufferError>>
pub fn into_crop( self, rect: PixelRect, ) -> Result<PixelViewMut<'a>, At<BufferError>>
Consume this mutable view and narrow it to a rectangular crop retaining 'a.
Sourcepub fn into_sub_rows(
self,
start_y: u32,
row_count: u32,
) -> Result<PixelViewMut<'a>, At<BufferError>>
pub fn into_sub_rows( self, start_y: u32, row_count: u32, ) -> Result<PixelViewMut<'a>, At<BufferError>>
Consume this mutable view and narrow it to a full-width strip retaining 'a.
Source§impl PixelViewMut<'_>
impl PixelViewMut<'_>
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 mutable view.
Source§impl<'a> PixelViewMut<'a>
impl<'a> PixelViewMut<'a>
Sourcepub fn from_imgref_mut<P>(
img: Img<&'a mut [P]>,
color: ColorSpace,
) -> Result<PixelViewMut<'a>, At<BufferError>>where
P: PixelType,
pub fn from_imgref_mut<P>(
img: Img<&'a mut [P]>,
color: ColorSpace,
) -> Result<PixelViewMut<'a>, At<BufferError>>where
P: PixelType,
Borrow a mutable typed [imgref::ImgRefMut<'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_mut<P>(&mut self) -> Result<Img<&mut [P]>, At<BufferError>>where
P: PixelType,
pub fn as_imgref_mut<P>(&mut self) -> Result<Img<&mut [P]>, At<BufferError>>where
P: PixelType,
Borrow as a mutable zero-copy [imgref::ImgRefMut<'_, P>].
Sourcepub fn into_imgref_mut<P>(self) -> Result<Img<&'a mut [P]>, At<BufferError>>where
P: PixelType,
pub fn into_imgref_mut<P>(self) -> Result<Img<&'a mut [P]>, At<BufferError>>where
P: PixelType,
Consume this mutable view and convert into a zero-copy [imgref::ImgRefMut<'a, P>] retaining 'a.
Sourcepub fn as_sample_imgref_mut<S>(
&mut self,
) -> Result<Img<&mut [S]>, At<BufferError>>where
S: StorageSample,
pub fn as_sample_imgref_mut<S>(
&mut self,
) -> Result<Img<&mut [S]>, At<BufferError>>where
S: StorageSample,
Borrow as a mutable sample-strided zero-copy [imgref::ImgRefMut<'_, S>].
Source§impl<'a> PixelViewMut<'a>
impl<'a> PixelViewMut<'a>
Sourcepub fn from_image_buffer_mut<P, C>(
img: &'a mut ImageBuffer<P, C>,
) -> Result<PixelViewMut<'a>, At<BufferError>>where
P: Pixel + PixelWithColorType + 'static,
<P as Pixel>::Subpixel: StorageSample,
C: Deref<Target = [<P as Pixel>::Subpixel]> + DerefMut,
pub fn from_image_buffer_mut<P, C>(
img: &'a mut ImageBuffer<P, C>,
) -> Result<PixelViewMut<'a>, At<BufferError>>where
P: Pixel + PixelWithColorType + 'static,
<P as Pixel>::Subpixel: StorageSample,
C: Deref<Target = [<P as Pixel>::Subpixel]> + DerefMut,
Mutably borrow any image::ImageBuffer<P, C> zero-copy for all 10 standard formats.
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_mut(
img: &'a mut DynamicImage,
) -> Result<PixelViewMut<'a>, At<BufferError>>
pub fn from_dynamic_image_mut( img: &'a mut DynamicImage, ) -> Result<PixelViewMut<'a>, At<BufferError>>
Mutably borrow an image::DynamicImage zero-copy for all 10 standard variants.
Trait Implementations§
Source§impl<'a> Debug for PixelViewMut<'a>
impl<'a> Debug for PixelViewMut<'a>
Source§impl PixelSink for PixelViewMut<'_>
impl PixelSink for PixelViewMut<'_>
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 more