#[non_exhaustive]pub struct PixelBuffer<P = ()> { /* private fields */ }Expand description
Owned pixel buffer with format metadata.
Wraps a Vec<u8> with an optional alignment offset so that pixel
rows start at the correct alignment for the channel type. The
backing vec can be recovered with into_vec for
pool reuse.
The type parameter P tracks pixel format at compile time, same as
PixelSlice.
Implementations§
Source§impl PixelBuffer
impl PixelBuffer
Sourcepub fn new(width: u32, height: u32, descriptor: PixelDescriptor) -> PixelBuffer
pub fn new(width: u32, height: u32, descriptor: PixelDescriptor) -> PixelBuffer
Sourcepub fn try_new(
width: u32,
height: u32,
descriptor: PixelDescriptor,
) -> Result<PixelBuffer, At<BufferError>>
pub fn try_new( width: u32, height: u32, descriptor: PixelDescriptor, ) -> Result<PixelBuffer, At<BufferError>>
Try to allocate a zero-filled buffer for the given dimensions and format.
Returns BufferError::InvalidDimensions if the total size overflows,
or BufferError::AllocationFailed if allocation fails.
Sourcepub fn new_simd_aligned(
width: u32,
height: u32,
descriptor: PixelDescriptor,
simd_align: usize,
) -> PixelBuffer
pub fn new_simd_aligned( width: u32, height: u32, descriptor: PixelDescriptor, simd_align: usize, ) -> PixelBuffer
Allocate a SIMD-aligned buffer for the given dimensions and format.
Row stride is a multiple of lcm(bpp, simd_align), ensuring every
row start is both pixel-aligned and SIMD-aligned when the buffer
itself starts at a SIMD-aligned address.
simd_align must be a power of 2 (e.g. 16, 32, 64).
§Panics
Panics if allocation fails. Use try_new_simd_aligned
for fallible allocation.
Sourcepub fn try_new_simd_aligned(
width: u32,
height: u32,
descriptor: PixelDescriptor,
simd_align: usize,
) -> Result<PixelBuffer, At<BufferError>>
pub fn try_new_simd_aligned( width: u32, height: u32, descriptor: PixelDescriptor, simd_align: usize, ) -> Result<PixelBuffer, At<BufferError>>
Try to allocate a SIMD-aligned buffer for the given dimensions and format.
Returns BufferError::InvalidDimensions if the total size overflows,
or BufferError::AllocationFailed if allocation fails.
Sourcepub fn from_vec(
data: Vec<u8>,
width: u32,
height: u32,
descriptor: PixelDescriptor,
) -> Result<PixelBuffer, At<BufferError>>
pub fn from_vec( data: Vec<u8>, width: u32, height: u32, descriptor: PixelDescriptor, ) -> Result<PixelBuffer, At<BufferError>>
Wrap an existing Vec<u8> as a pixel buffer.
The vec must be large enough to hold aligned_stride(width) * height
bytes (plus any alignment offset). Stride is computed from the
descriptor – rows are assumed tightly packed.
§Errors
Returns BufferError::InsufficientData if the vec is too small.
Source§impl<P> PixelBuffer<P>where
P: Pixel,
impl<P> PixelBuffer<P>where
P: Pixel,
Sourcepub fn new_typed(width: u32, height: u32) -> PixelBuffer<P>
pub fn new_typed(width: u32, height: u32) -> PixelBuffer<P>
Allocate a typed zero-filled buffer for the given dimensions.
The descriptor is derived from P::DESCRIPTOR.
§Panics
Panics if allocation fails. Use try_new_typed
for fallible allocation.
Sourcepub fn try_new_typed(
width: u32,
height: u32,
) -> Result<PixelBuffer<P>, At<BufferError>>
pub fn try_new_typed( width: u32, height: u32, ) -> Result<PixelBuffer<P>, At<BufferError>>
Try to allocate a typed zero-filled buffer for the given dimensions.
Returns BufferError::InvalidDimensions if the total size overflows,
or BufferError::AllocationFailed if allocation fails.
Source§impl<P> PixelBuffer<P>
impl<P> PixelBuffer<P>
Sourcepub fn erase(self) -> PixelBuffer
pub fn erase(self) -> PixelBuffer
Erase the pixel type, returning a type-erased buffer.
Sourcepub fn try_typed<Q>(self) -> Option<PixelBuffer<Q>>where
Q: Pixel,
pub fn try_typed<Q>(self) -> Option<PixelBuffer<Q>>where
Q: Pixel,
Try to reinterpret as a typed pixel buffer.
Succeeds if the descriptors are layout-compatible.
Sourcepub fn with_descriptor(self, descriptor: PixelDescriptor) -> PixelBuffer<P>
pub fn with_descriptor(self, descriptor: PixelDescriptor) -> PixelBuffer<P>
Replace the descriptor with a layout-compatible one.
See PixelSlice::with_descriptor() for details.
Sourcepub fn reinterpret(
self,
descriptor: PixelDescriptor,
) -> Result<PixelBuffer<P>, At<BufferError>>
pub fn reinterpret( self, descriptor: PixelDescriptor, ) -> Result<PixelBuffer<P>, At<BufferError>>
Reinterpret the buffer with a different physical layout.
See PixelSlice::reinterpret() for details.
Sourcepub fn with_transfer(self, tf: TransferFunction) -> PixelBuffer<P>
pub fn with_transfer(self, tf: TransferFunction) -> PixelBuffer<P>
Return a copy with a different transfer function.
Sourcepub fn with_primaries(self, cp: ColorPrimaries) -> PixelBuffer<P>
pub fn with_primaries(self, cp: ColorPrimaries) -> PixelBuffer<P>
Return a copy with different color primaries.
Sourcepub fn with_signal_range(self, sr: SignalRange) -> PixelBuffer<P>
pub fn with_signal_range(self, sr: SignalRange) -> PixelBuffer<P>
Return a copy with a different signal range.
Sourcepub fn with_alpha_mode(self, am: Option<AlphaMode>) -> PixelBuffer<P>
pub fn with_alpha_mode(self, am: Option<AlphaMode>) -> PixelBuffer<P>
Return a copy with a different alpha mode.
Sourcepub fn is_grayscale(&self) -> bool
pub fn is_grayscale(&self) -> bool
Whether this buffer is grayscale (Gray or GrayAlpha layout).
Sourcepub fn into_vec(self) -> Vec<u8> ⓘ
pub fn into_vec(self) -> Vec<u8> ⓘ
Consume the buffer and return the backing Vec<u8> for pool reuse.
Sourcepub fn as_contiguous_bytes(&self) -> Option<&[u8]>
pub fn as_contiguous_bytes(&self) -> Option<&[u8]>
Zero-copy access to the raw pixel bytes when rows are tightly packed.
Returns Some(&[u8]) if stride == width * bpp (no padding),
None if rows have stride padding.
Sourcepub fn copy_to_contiguous_bytes(&self) -> Vec<u8> ⓘ
pub fn copy_to_contiguous_bytes(&self) -> Vec<u8> ⓘ
Copy pixel data to a new contiguous byte Vec without stride padding.
Returns exactly width * height * bytes_per_pixel bytes in row-major order.
For buffers already tightly packed (stride == width * bpp), this is a single memcpy.
For padded buffers, this strips the padding row by row.
Sourcepub fn descriptor(&self) -> PixelDescriptor
pub fn descriptor(&self) -> PixelDescriptor
Pixel format descriptor.
Sourcepub fn color_context(&self) -> Option<&Arc<ColorContext>>
pub fn color_context(&self) -> Option<&Arc<ColorContext>>
Source color context (ICC/CICP metadata), if set.
Sourcepub fn with_color_context(self, ctx: Arc<ColorContext>) -> PixelBuffer<P>
pub fn with_color_context(self, ctx: Arc<ColorContext>) -> PixelBuffer<P>
Set the color context on this buffer.
Sourcepub fn as_slice(&self) -> PixelSlice<'_, P>
pub fn as_slice(&self) -> PixelSlice<'_, P>
Borrow the full buffer as an immutable PixelSlice.
Sourcepub fn as_slice_mut(&mut self) -> PixelSliceMut<'_, P>
pub fn as_slice_mut(&mut self) -> PixelSliceMut<'_, P>
Borrow the full buffer as a mutable PixelSliceMut.
Sourcepub fn rows(&self, y: u32, count: u32) -> PixelSlice<'_, P>
pub fn rows(&self, y: u32, count: u32) -> PixelSlice<'_, P>
Sourcepub fn rows_mut(&mut self, y: u32, count: u32) -> PixelSliceMut<'_, P>
pub fn rows_mut(&mut self, y: u32, count: u32) -> PixelSliceMut<'_, P>
Sourcepub fn crop_copy(&self, x: u32, y: u32, w: u32, h: u32) -> PixelBuffer<P>
pub fn crop_copy(&self, x: u32, y: u32, w: u32, h: u32) -> PixelBuffer<P>
Copy a sub-region into a new, tightly-packed PixelBuffer.
§Panics
Panics if the crop region is out of bounds.
Trait Implementations§
Source§impl<P> Debug for PixelBuffer<P>
impl<P> Debug for PixelBuffer<P>
Source§impl<P> From<PixelBuffer<P>> for PixelBufferwhere
P: Pixel,
impl<P> From<PixelBuffer<P>> for PixelBufferwhere
P: Pixel,
Source§fn from(typed: PixelBuffer<P>) -> PixelBuffer
fn from(typed: PixelBuffer<P>) -> PixelBuffer
Source§impl PixelBufferConvertExt for PixelBuffer
impl PixelBufferConvertExt for PixelBuffer
Source§fn convert_to(
&self,
target: PixelDescriptor,
) -> Result<PixelBuffer, At<ConvertError>>
fn convert_to( &self, target: PixelDescriptor, ) -> Result<PixelBuffer, At<ConvertError>>
Source§fn try_add_alpha(&self) -> Result<PixelBuffer, At<ConvertError>>
fn try_add_alpha(&self) -> Result<PixelBuffer, At<ConvertError>>
PixelBuffer. Read moreSource§fn try_widen_to_u16(&self) -> Result<PixelBuffer, At<ConvertError>>
fn try_widen_to_u16(&self) -> Result<PixelBuffer, At<ConvertError>>
PixelBuffer.Source§fn try_narrow_to_u8(&self) -> Result<PixelBuffer, At<ConvertError>>
fn try_narrow_to_u8(&self) -> Result<PixelBuffer, At<ConvertError>>
PixelBuffer.