mirror of
https://github.com/bend-n/fimg.git
synced 2024-12-22 02:28:19 -06:00
Image::take_buffer && Image::to_owned
This commit is contained in:
parent
5139fa82f7
commit
b618a22c88
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "fimg"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
authors = ["bend-n <bend.n@outlook.com>"]
|
||||
license = "MIT"
|
||||
edition = "2021"
|
||||
|
|
11
src/lib.rs
11
src/lib.rs
|
@ -116,6 +116,11 @@ impl<T, const CHANNELS: usize> Image<T, CHANNELS> {
|
|||
}
|
||||
}
|
||||
|
||||
/// 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<const CHANNELS: usize> Image<&[u8], CHANNELS> {
|
|||
buffer: &[0; CHANNELS * WIDTH as usize * HEIGHT as usize],
|
||||
}
|
||||
}
|
||||
|
||||
/// Allocate a new Image<Vec<u8>>.
|
||||
pub fn to_owned(&self) -> Image<Vec<u8>, CHANNELS> {
|
||||
// SAFETY: we have been constructed already, so must be valid
|
||||
unsafe { Image::new(self.width, self.height, self.buffer.to_vec()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: std::ops::Deref<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
||||
|
|
Loading…
Reference in a new issue