Make use of ImageFrame in the node system more extensively (#1055) (#1062)

Make the node system use ImageFrame more extensively (#1055)
This commit is contained in:
Alexandru Ică 2023-03-02 15:55:10 +02:00 committed by Keavon Chambers
parent 02d4565b0c
commit 0b813805d2
6 changed files with 215 additions and 158 deletions

View file

@ -1,7 +1,7 @@
use dyn_any::{DynAny, StaticType};
use glam::DAffine2;
use graphene_core::raster::{Color, Image};
use graphene_core::raster::{Color, Image, ImageFrame};
use graphene_core::Node;
use std::path::Path;
@ -107,6 +107,24 @@ where
image
}
#[derive(Debug, Clone, Copy)]
pub struct MapImageFrameNode<MapFn> {
map_fn: MapFn,
}
#[node_macro::node_fn(MapImageFrameNode)]
fn map_image<MapFn>(mut image_frame: ImageFrame, map_fn: &'any_input MapFn) -> ImageFrame
where
MapFn: for<'any_input> Node<'any_input, Color, Output = Color> + 'input,
{
let mut image_frame = image_frame;
for pixel in &mut image_frame.image.data {
*pixel = map_fn.eval(*pixel);
}
image_frame
}
#[derive(Debug, Clone, Copy)]
pub struct BlendImageNode<Second, MapFn> {
second: Second,
@ -131,9 +149,13 @@ pub struct ImaginateNode<E> {
}
#[node_macro::node_fn(ImaginateNode)]
fn imaginate(image: Image, cached: Option<std::sync::Arc<graphene_core::raster::Image>>) -> Image {
info!("Imaginating image with {} pixels", image.data.len());
cached.map(|mut x| std::sync::Arc::make_mut(&mut x).clone()).unwrap_or(image)
fn imaginate(image_frame: ImageFrame, cached: Option<std::sync::Arc<graphene_core::raster::Image>>) -> ImageFrame {
info!("Imaginating image with {} pixels", image_frame.image.data.len());
let cached_image = cached.map(|mut x| std::sync::Arc::make_mut(&mut x).clone()).unwrap_or(image_frame.image);
ImageFrame {
image: cached_image,
transform: image_frame.transform,
}
}
#[derive(Debug, Clone, Copy)]