Skip to main content

PixelSliceMut

Struct PixelSliceMut 

Source
#[non_exhaustive]
pub struct PixelSliceMut<'a, P = ()> { /* private fields */ }
Expand description

Mutable borrowed view of pixel data.

Same semantics as PixelSlice but allows writing to rows. The type parameter P tracks pixel format at compile time.

Implementations§

Source§

impl<'a> PixelSliceMut<'a>

Source

pub fn new( data: &'a mut [u8], width: u32, rows: u32, stride_bytes: usize, descriptor: PixelDescriptor, ) -> Result<PixelSliceMut<'a>, At<BufferError>>

Create a new mutable pixel slice with validation.

stride_bytes is the byte distance between the start of consecutive rows.

§Errors

Returns an error if the data is too small, the stride is too small, or the data is not aligned for the channel type.

Source§

impl<'a, P> PixelSliceMut<'a, P>

Source

pub fn erase(self) -> PixelSliceMut<'a>

Erase the pixel type, returning a type-erased mutable slice.

Source

pub fn try_typed<Q>(self) -> Option<PixelSliceMut<'a, Q>>
where Q: Pixel,

Try to reinterpret as a typed mutable pixel slice.

Succeeds if the descriptors are layout-compatible.

Source

pub fn with_descriptor( self, descriptor: PixelDescriptor, ) -> PixelSliceMut<'a, P>

Replace the descriptor with a layout-compatible one.

See PixelSlice::with_descriptor() for details.

Source

pub fn reinterpret( self, descriptor: PixelDescriptor, ) -> Result<PixelSliceMut<'a, P>, At<BufferError>>

Reinterpret the buffer with a different physical layout.

See PixelSlice::reinterpret() for details.

Source

pub fn with_transfer(self, tf: TransferFunction) -> PixelSliceMut<'a, P>

Return a copy with a different transfer function.

Source

pub fn with_primaries(self, cp: ColorPrimaries) -> PixelSliceMut<'a, P>

Return a copy with different color primaries.

Source

pub fn with_signal_range(self, sr: SignalRange) -> PixelSliceMut<'a, P>

Return a copy with a different signal range.

Source

pub fn with_alpha_mode(self, am: Option<AlphaMode>) -> PixelSliceMut<'a, P>

Return a copy with a different alpha mode.

Source

pub fn width(&self) -> u32

Image width in pixels.

Source

pub fn rows(&self) -> u32

Number of rows in this slice.

Source

pub fn stride(&self) -> usize

Byte stride between row starts.

Source

pub fn descriptor(&self) -> PixelDescriptor

Pixel format descriptor.

Source

pub fn color_context(&self) -> Option<&Arc<ColorContext>>

Source color context (ICC/CICP metadata), if set.

Source

pub fn with_color_context(self, ctx: Arc<ColorContext>) -> PixelSliceMut<'a, P>

Return a copy of this slice with a color context attached.

Source

pub fn as_pixel_slice(&self) -> PixelSlice<'_, P>

Reborrow as an immutable PixelSlice (zero-copy).

The returned slice borrows from self, so the mutable slice cannot be used while the immutable reborrow is alive.

Source

pub fn as_strided_bytes(&self) -> &[u8]

Zero-copy access to the raw backing bytes, including any stride padding.

Unlike PixelSlice::as_strided_bytes() (which clips to the image extent), this returns the full backing buffer so callers can write stride padding (zeroing, codec requirements, etc.).

Source

pub fn as_strided_bytes_mut(&mut self) -> &mut [u8]

Mutable access to the raw backing bytes, including any stride padding.

Returns the full backing buffer so callers can write stride padding.

Source

pub fn row(&self, y: u32) -> &[u8]

Pixel bytes for row y (immutable, no padding).

§Panics

Panics if y >= rows.

Source

pub fn row_mut(&mut self, y: u32) -> &mut [u8]

Mutable pixel bytes for row y (no padding).

§Panics

Panics if y >= rows.

Source

pub fn sub_rows_mut(&mut self, y: u32, count: u32) -> PixelSliceMut<'_, P>

Borrow a mutable sub-range of rows.

§Panics

Panics if y + count > rows.

Source§

impl<'a, P> PixelSliceMut<'a, P>
where P: Pixel,

Source

pub fn new_typed( data: &'a mut [u8], width: u32, rows: u32, stride_pixels: u32, ) -> Result<PixelSliceMut<'a, P>, At<BufferError>>

Create a typed mutable pixel slice.

stride_pixels is the number of pixels per row (>= width). The byte stride is stride_pixels * size_of::<P>().

Source§

impl<'a> PixelSliceMut<'a, Rgbx>

Source

pub fn swap_to_bgrx(self) -> PixelSliceMut<'a, Bgrx>

Byte-swap R<->B channels in place, converting to BGRX.

Source§

impl<'a> PixelSliceMut<'a, Bgrx>

Source

pub fn swap_to_rgbx(self) -> PixelSliceMut<'a, Rgbx>

Byte-swap B<->R channels in place, converting to RGBX.

Trait Implementations§

Source§

impl<P> Debug for PixelSliceMut<'_, P>

Source§

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

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

impl<'a, P> From<PixelSliceMut<'a, P>> for PixelSlice<'a, P>

Consume a mutable pixel slice and produce an immutable one (zero-copy).

Source§

fn from(mut_slice: PixelSliceMut<'a, P>) -> PixelSlice<'a, P>

Converts to this type from the input type.
Source§

impl<'a, P> From<PixelSliceMut<'a, P>> for PixelSliceMut<'a>
where P: Pixel,

Source§

fn from(typed: PixelSliceMut<'a, P>) -> PixelSliceMut<'a>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a, P> Freeze for PixelSliceMut<'a, P>

§

impl<'a, P> RefUnwindSafe for PixelSliceMut<'a, P>
where P: RefUnwindSafe,

§

impl<'a, P> Send for PixelSliceMut<'a, P>
where P: Send,

§

impl<'a, P> Sync for PixelSliceMut<'a, P>
where P: Sync,

§

impl<'a, P> Unpin for PixelSliceMut<'a, P>
where P: Unpin,

§

impl<'a, P> UnsafeUnpin for PixelSliceMut<'a, P>

§

impl<'a, P = ()> !UnwindSafe for PixelSliceMut<'a, P>

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