fast image operations
must_use all cloner functions
bendn 2023-09-26
parent 89b1596 · commit 4eb9c33
-rw-r--r--src/affine.rs5
-rw-r--r--src/lib.rs1
-rw-r--r--src/overlay.rs5
3 files changed, 11 insertions, 0 deletions
diff --git a/src/affine.rs b/src/affine.rs
index d980cb6..acab7cc 100644
--- a/src/affine.rs
+++ b/src/affine.rs
@@ -18,6 +18,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
/// let a = Image::<_, 1>::build(2,2).buf(vec![21,42,90,01]);
/// assert_eq!(a.cloner().flip_v().take_buffer(), [90,01,21,42]);
/// ```
+ #[must_use = "function does not modify the original image"]
pub fn flip_v(&self) -> Image<Vec<u8>, CHANNELS> {
let mut out = self.alloc();
for y in 0..self.height() {
@@ -37,6 +38,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
/// let a = Image::<_,1>::build(2,2).buf(vec![90,01,21,42]);
/// assert_eq!(a.cloner().flip_h().take_buffer(), [01,90,42,21]);
/// ```
+ #[must_use = "function does not modify the original image"]
pub fn flip_h(&self) -> Image<Vec<u8>, CHANNELS> {
let mut out = self.alloc();
for y in 0..self.height() {
@@ -120,6 +122,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
/// let a = Image::<_,1>::build(2,2).buf(vec![00,01,02,10]);
/// assert_eq!(a.cloner().rot_180().take_buffer(), vec![10,02,01,00]);
/// ```
+ #[must_use = "function does not modify the original image"]
pub fn rot_180(&self) -> Image<Vec<u8>, CHANNELS> {
let s = (self.width() * self.height()) as usize;
let mut v: Vec<[u8; CHANNELS]> = Vec::with_capacity(s);
@@ -140,6 +143,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
/// # Safety
///
/// UB if the image is not square
+ #[must_use = "function does not modify the original image"]
pub unsafe fn rot_90(&self) -> Image<Vec<u8>, CHANNELS> {
let mut out = self.flip_v();
// SAFETY: sqar
@@ -151,6 +155,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
/// # Safety
///
/// UB if the image is not square
+ #[must_use = "function does not modify the original image"]
pub unsafe fn rot_270(&self) -> Image<Vec<u8>, CHANNELS> {
let mut out = self.flip_h();
// SAFETY: sqar
diff --git a/src/lib.rs b/src/lib.rs
index 0ff6d8b..8243b46 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -246,6 +246,7 @@ impl<T: std::ops::Deref<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS
}
/// Procure a [`ImageCloner`].
+ #[must_use = "function does not modify the original image"]
pub fn cloner(&self) -> ImageCloner<'_, CHANNELS> {
ImageCloner::from(self.as_ref())
}
diff --git a/src/overlay.rs b/src/overlay.rs
index 9c63c41..ba63b74 100644
--- a/src/overlay.rs
+++ b/src/overlay.rs
@@ -119,6 +119,7 @@ impl Overlay<Image<&[u8], 4>> for Image<&mut [u8], 4> {
impl ClonerOverlay<4, 4> for ImageCloner<'_, 4> {
#[inline]
+ #[must_use = "function does not modify the original image"]
unsafe fn overlay(&self, with: &Image<&[u8], 4>) -> Image<Vec<u8>, 4> {
let mut out = self.dup();
// SAFETY: same
@@ -153,6 +154,8 @@ impl OverlayAt<Image<&[u8], 4>> for Image<&mut [u8], 3> {
}
impl ClonerOverlayAt<4, 3> for ImageCloner<'_, 3> {
+ #[inline]
+ #[must_use = "function does not modify the original image"]
unsafe fn overlay_at(&self, with: &Image<&[u8], 4>, x: u32, y: u32) -> Image<Vec<u8>, 3> {
let mut new = self.dup();
// SAFETY: same
@@ -225,6 +228,7 @@ impl Overlay<Image<&[u8], 4>> for Image<&mut [u8], 3> {
impl ClonerOverlay<4, 3> for ImageCloner<'_, 3> {
#[inline]
+ #[must_use = "function does not modify the original image"]
unsafe fn overlay(&self, with: &Image<&[u8], 4>) -> Image<Vec<u8>, 3> {
let mut out = self.dup();
// SAFETY: same
@@ -271,6 +275,7 @@ impl OverlayAt<Image<&[u8], 4>> for Image<&mut [u8], 4> {
impl ClonerOverlayAt<4, 4> for ImageCloner<'_, 4> {
#[inline]
+ #[must_use = "function does not modify the original image"]
/// Overlay with => self at coordinates x, y, without blending, returning a new Image
///
/// # Safety