From b618a22c881e23a9ead2d14565c3de57018b5422 Mon Sep 17 00:00:00 2001 From: bendn Date: Wed, 6 Sep 2023 18:49:51 +0700 Subject: [PATCH] Image::take_buffer && Image::to_owned --- Cargo.toml | 2 +- src/lib.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5a3e147..1cacaa4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fimg" -version = "0.3.1" +version = "0.3.2" authors = ["bend-n "] license = "MIT" edition = "2021" diff --git a/src/lib.rs b/src/lib.rs index 79eb558..57cfa24 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -116,6 +116,11 @@ impl Image { } } + /// consumes the image, returning the image buffer + pub fn take_buffer(self) -> T { + self.buffer + } + /// returns a immutable reference to the backing buffer pub const fn buffer(&self) -> &T { &self.buffer @@ -165,6 +170,12 @@ impl Image<&[u8], CHANNELS> { buffer: &[0; CHANNELS * WIDTH as usize * HEIGHT as usize], } } + + /// Allocate a new Image>. + pub fn to_owned(&self) -> Image, CHANNELS> { + // SAFETY: we have been constructed already, so must be valid + unsafe { Image::new(self.width, self.height, self.buffer.to_vec()) } + } } impl, const CHANNELS: usize> Image {