fast image operations
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 9de0643..9388a3f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,6 +3,7 @@
//! Provides fast image operations, such as rotation, flipping, and overlaying.
#![feature(
slice_swap_unchecked,
+ stmt_expr_attributes,
generic_const_exprs,
slice_as_chunks,
unchecked_math,
@@ -218,6 +219,13 @@ impl<T: std::ops::Deref<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS
self.buffer.array_chunks::<CHANNELS>()
}
+ #[inline]
+ /// Flatten the chunks of this image into a slice of slices.
+ pub fn flatten(&mut self) -> &[[u8; CHANNELS]] {
+ // SAFETY: buffer cannot have half pixels
+ unsafe { self.buffer.as_chunks_unchecked::<CHANNELS>() }
+ }
+
/// Return a pixel at (x, y).
/// # Safety
///
@@ -258,6 +266,13 @@ impl<T: std::ops::DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANN
self.buffer.array_chunks_mut::<CHANNELS>()
}
+ #[inline]
+ /// Flatten the chunks of this image into a mutable slice of slices.
+ pub fn flatten_mut(&mut self) -> &mut [[u8; CHANNELS]] {
+ // SAFETY: buffer cannot have half pixels
+ unsafe { self.buffer.as_chunks_unchecked_mut::<CHANNELS>() }
+ }
+
/// Set the pixel at x, y
///
/// # Safety