mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Add raster module to graphene_core
This commit is contained in:
18
node-graph/gcore/src/raster.rs
Normal file
18
node-graph/gcore/src/raster.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use crate::Node;
|
||||
|
||||
use self::color::Color;
|
||||
|
||||
pub mod color;
|
||||
|
||||
pub struct GrayscaleNode<'n, N: Node<'n, Output = Color>>(pub N, PhantomData<&'n ()>);
|
||||
|
||||
impl<'n, N: Node<'n, Output = Color>> Node<'n> for GrayscaleNode<'n, N> {
|
||||
type Output = Color;
|
||||
fn eval(&'n self) -> Color {
|
||||
let color = self.0.eval();
|
||||
let avg = (color.r() + color.g() + color.b()) / 3.0;
|
||||
Color::from_rgbaf32(avg, avg, avg, color.a()).expect("Grayscale node created an invalid color")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user