mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-03 21:08:18 +00:00
Add some raster protonodes
This commit is contained in:
parent
b2a90ddc2c
commit
d142a9092c
7 changed files with 263 additions and 17 deletions
|
@ -26,3 +26,4 @@ proc-macro2 = {version = "1.0", default-features = false, features = ["proc-macr
|
|||
quote = {version = "1.0", default-features = false }
|
||||
image = "*"
|
||||
rand_chacha = "0.3.1"
|
||||
dyn-clone = "1.0"
|
||||
|
|
|
@ -144,6 +144,36 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Boxes the input and downcasts the output.
|
||||
/// Wraps around a node taking Box<dyn DynAny> and returning Box<dyn DynAny>
|
||||
pub struct DowncastBothNode<N, I: StaticType, O: StaticType>(pub N, pub PhantomData<(I, O)>);
|
||||
impl<N: Copy + Clone, I: StaticType, O: StaticType> Clone for DowncastBothNode<N, I, O> {
|
||||
fn clone(&self) -> Self {
|
||||
Self(self.0, self.1)
|
||||
}
|
||||
}
|
||||
impl<N: Copy + Clone, I: StaticType, O: StaticType> Copy for DowncastBothNode<N, I, O> {}
|
||||
|
||||
impl<'n, N, I: 'n + StaticType, O: 'n + StaticType> Node<I> for DowncastBothNode<N, I, O>
|
||||
where
|
||||
N: Node<Any<'n>, Output = Any<'n>>,
|
||||
{
|
||||
type Output = O;
|
||||
fn eval(self, input: I) -> Self::Output {
|
||||
let input = Box::new(input) as Box<dyn DynAny>;
|
||||
let output = self.0.eval(input);
|
||||
*dyn_any::downcast(output).unwrap_or_else(|| panic!("DowncastBothNode Output: {}", fmt_error::<O>()))
|
||||
}
|
||||
}
|
||||
impl<'n, N, I: StaticType, O: StaticType> DowncastBothNode<N, I, O>
|
||||
where
|
||||
N: Node<Any<'n>>,
|
||||
{
|
||||
pub fn new(n: N) -> Self {
|
||||
DowncastBothNode(n, PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/// If we store a `Box<dyn RefNode>` in the stack then the origional DynAnyNode is dropped (because it is not stored by reference)
|
||||
/// This trait is implemented directly by `DynAnyNode` so this means the borrow stack will hold by value
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use core::marker::PhantomData;
|
||||
use dyn_any::{DynAny, StaticType};
|
||||
use graphene_core::ops::FlatMapResultNode;
|
||||
use graphene_core::raster::color::Color;
|
||||
use graphene_core::structural::{ComposeNode, ConsNode};
|
||||
|
@ -23,6 +24,17 @@ impl<I: IntoIterator<Item = S>, MN: Node<S>, S> MapNode<MN, I, S> {
|
|||
|
||||
pub struct MapImageNode<MN: Node<Color, Output = Color> + Copy>(pub MN);
|
||||
|
||||
impl<MN: Node<Color, Output = Color> + Copy> Node<Image> for MapImageNode<MN> {
|
||||
type Output = Image;
|
||||
fn eval(self, input: Image) -> Self::Output {
|
||||
Image {
|
||||
width: input.width,
|
||||
height: input.height,
|
||||
data: input.data.iter().map(|x| self.0.eval(*x)).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'n, MN: Node<Color, Output = Color> + Copy> Node<Image> for &'n MapImageNode<MN> {
|
||||
type Output = Image;
|
||||
fn eval(self, input: Image) -> Self::Output {
|
||||
|
@ -40,7 +52,7 @@ impl<MN: Node<Color, Output = Color> + Copy> MapImageNode<MN> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, DynAny)]
|
||||
pub enum Error {
|
||||
IO(std::io::Error),
|
||||
Image(image::ImageError),
|
||||
|
@ -86,7 +98,7 @@ impl<Reader: std::io::Read> Node<Reader> for BufferNode {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, DynAny)]
|
||||
pub struct Image {
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue