This commit is contained in:
Ponj 2024-07-13 10:05:27 +02:00
parent e34287df9e
commit 825bcfa5a1
Signed by: p6nj
GPG key ID: CEAB625B75A836B2
2 changed files with 40 additions and 2 deletions

View file

@ -10,5 +10,5 @@ keywords.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
fundsp = { workspace = true }
num-traits = { workspace = true }
image = { workspace = true }
derive-new = { workspace = true }

View file

@ -1,5 +1,8 @@
use std::{borrow::Cow, ops::Deref};
use derive_new::new;
use image::{DynamicImage, RgbImage};
type Bytes<'a> = Cow<'a, [u8]>;
pub trait Metadata {}
@ -48,3 +51,38 @@ where
}
}
}
#[derive(new)]
pub struct ImageMetadata {
width: u32,
height: u32,
}
impl Metadata for ImageMetadata {}
pub type RawImage<'a> = RawData<'a, ImageMetadata>;
impl From<DynamicImage> for RawImage<'_> {
fn from(value: DynamicImage) -> Self {
value.to_rgb8().into()
}
}
impl From<RgbImage> for RawImage<'_> {
fn from(value: RgbImage) -> Self {
let metadata = ImageMetadata::new(value.width(), value.height());
Self {
data: Cow::Owned(value.into_raw()),
metadata,
}
}
}
impl<'a> From<RawImage<'a>> for RgbImage {
fn from(value: RawImage<'a>) -> Self {
RgbImage::from_raw(
value.metadata.width,
value.metadata.height,
value.data.to_vec(),
)
.unwrap()
}
}