mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-10 00:08:03 +00:00
Implement the Gaussian Blur node (#933)
This commit is contained in:
parent
74bfd630a9
commit
a9601ab164
11 changed files with 578 additions and 51 deletions
|
@ -31,7 +31,8 @@ where
|
|||
{
|
||||
type Output = Any<'n>;
|
||||
fn eval(self, input: Any<'n>) -> Self::Output {
|
||||
let input: Box<I> = dyn_any::downcast(input).expect("DynAnyNode Input");
|
||||
let node = core::any::type_name::<N>();
|
||||
let input: Box<I> = dyn_any::downcast(input).expect(format!("DynAnyNode Input in:\n{node}").as_str());
|
||||
Box::new(self.0.eval(*input))
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +42,8 @@ where
|
|||
{
|
||||
type Output = Any<'n>;
|
||||
fn eval(self, input: Any<'n>) -> Self::Output {
|
||||
let input: Box<I> = dyn_any::downcast(input).expect("DynAnyNode Input");
|
||||
let node = core::any::type_name::<N>();
|
||||
let input: Box<I> = dyn_any::downcast(input).expect(format!("DynAnyNode Input in:\n{node}").as_str());
|
||||
Box::new((&self.0).eval_ref(*input))
|
||||
}
|
||||
}
|
||||
|
@ -161,6 +163,17 @@ where
|
|||
*dyn_any::downcast(output).expect("DowncastBothNode Output")
|
||||
}
|
||||
}
|
||||
impl<'n, N, I: 'n + StaticType, O: 'n + StaticType> Node<I> for &DowncastBothNode<N, I, O>
|
||||
where
|
||||
N: Node<Any<'n>, Output = Any<'n>> + Copy,
|
||||
{
|
||||
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).expect("DowncastBothNode Output")
|
||||
}
|
||||
}
|
||||
impl<'n, N, I: StaticType, O: StaticType> DowncastBothNode<N, I, O>
|
||||
where
|
||||
N: Node<Any<'n>>,
|
||||
|
|
|
@ -2,35 +2,32 @@ use graphene_core::{Cache, Node};
|
|||
use once_cell::sync::OnceCell;
|
||||
|
||||
/// Caches the output of a given Node and acts as a proxy
|
||||
pub struct CacheNode<CachedNode: Node<I>, I> {
|
||||
node: CachedNode,
|
||||
cache: OnceCell<CachedNode::Output>,
|
||||
pub struct CacheNode<T> {
|
||||
cache: OnceCell<T>,
|
||||
}
|
||||
impl<'n, CashedNode: Node<I> + Copy, I> Node<I> for &'n CacheNode<CashedNode, I> {
|
||||
type Output = &'n CashedNode::Output;
|
||||
fn eval(self, input: I) -> Self::Output {
|
||||
impl<'n, T> Node<T> for &'n CacheNode<T> {
|
||||
type Output = &'n T;
|
||||
fn eval(self, input: T) -> Self::Output {
|
||||
self.cache.get_or_init(|| {
|
||||
trace!("Creating new cache node");
|
||||
self.node.eval(input)
|
||||
input
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'n, CachedNode: Node<I>, I> CacheNode<CachedNode, I> {
|
||||
pub fn clear(&'n mut self) {
|
||||
self.cache = OnceCell::new();
|
||||
}
|
||||
pub fn new(node: CachedNode) -> CacheNode<CachedNode, I> {
|
||||
CacheNode { node, cache: OnceCell::new() }
|
||||
impl<T> Node<T> for CacheNode<T> {
|
||||
type Output = T;
|
||||
fn eval(self, input: T) -> Self::Output {
|
||||
input
|
||||
}
|
||||
}
|
||||
impl<CachedNode: Node<I>, I> Cache for CacheNode<CachedNode, I> {
|
||||
|
||||
impl<T> CacheNode<T> {
|
||||
pub fn new() -> CacheNode<T> {
|
||||
CacheNode { cache: OnceCell::new() }
|
||||
}
|
||||
}
|
||||
impl<T> Cache for CacheNode<T> {
|
||||
fn clear(&mut self) {
|
||||
self.cache = OnceCell::new();
|
||||
}
|
||||
}
|
||||
|
||||
/*use dyn_any::{DynAny, StaticType};
|
||||
#[derive(DynAny)]
|
||||
struct Boo<'a>(&'a u8);
|
||||
*/
|
||||
|
|
|
@ -132,7 +132,7 @@ pub fn export_image_node<'n>() -> impl Node<(Image, &'n str), Output = Result<()
|
|||
FnNode::new(|input: (Image, &str)| {
|
||||
let (image, path) = input;
|
||||
let mut new_image = image::ImageBuffer::new(image.width, image.height);
|
||||
for ((x, y, pixel), color) in new_image.enumerate_pixels_mut().zip((&image).into_iter()) {
|
||||
for ((x, y, pixel), color) in new_image.enumerate_pixels_mut().zip((&image).data.iter()) {
|
||||
let color: Color = *color;
|
||||
assert!(x < image.width);
|
||||
assert!(y < image.height);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue