From 366906b956ecbf918533450b0c9def86442e2874 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sun, 23 Apr 2023 19:42:34 +0200 Subject: [PATCH] Add Luma struct (#1154) * Make Luma usable for MaskImageNode --- node-graph/gcore/src/raster.rs | 2 +- node-graph/gcore/src/raster/color.rs | 28 +++++++++++++++++++ .../interpreted-executor/src/node_registry.rs | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/node-graph/gcore/src/raster.rs b/node-graph/gcore/src/raster.rs index 70b8cb7f2..41cac43fc 100644 --- a/node-graph/gcore/src/raster.rs +++ b/node-graph/gcore/src/raster.rs @@ -9,7 +9,7 @@ use num_traits::{cast::cast as num_cast, Num, NumCast}; #[cfg(target_arch = "spirv")] use spirv_std::num_traits::{cast::cast as num_cast, float::Float, FromPrimitive, Num, NumCast, ToPrimitive}; -pub use self::color::Color; +pub use self::color::{Color, Luma}; pub mod adjustments; #[cfg(not(target_arch = "spirv"))] diff --git a/node-graph/gcore/src/raster/color.rs b/node-graph/gcore/src/raster/color.rs index 7145f3dd9..f6b6d6374 100644 --- a/node-graph/gcore/src/raster/color.rs +++ b/node-graph/gcore/src/raster/color.rs @@ -14,6 +14,34 @@ use bytemuck::{Pod, Zeroable}; use super::{Alpha, AssociatedAlpha, Luminance, Pixel, Rec709Primaries, RGB, SRGB}; +#[repr(C)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "std", derive(specta::Type))] +#[derive(Debug, Default, Clone, Copy, PartialEq, DynAny, Pod, Zeroable)] +pub struct Luma(pub f32); + +impl Luminance for Luma { + type LuminanceChannel = f32; + fn luminance(&self) -> f32 { + self.0 + } +} + +impl RGB for Luma { + type ColorChannel = f32; + fn red(&self) -> f32 { + self.0 + } + fn green(&self) -> f32 { + self.0 + } + fn blue(&self) -> f32 { + self.0 + } +} + +impl Pixel for Luma {} + /// Structure that represents a color. /// Internally alpha is stored as `f32` that ranges from `0.0` (transparent) to `1.0` (opaque). /// The other components (RGB) are stored as `f32` that range from `0.0` up to `f32::MAX`, diff --git a/node-graph/interpreted-executor/src/node_registry.rs b/node-graph/interpreted-executor/src/node_registry.rs index 43f74ff7c..360b0d7d1 100644 --- a/node-graph/interpreted-executor/src/node_registry.rs +++ b/node-graph/interpreted-executor/src/node_registry.rs @@ -140,6 +140,7 @@ fn node_registry() -> HashMap, params: []), register_node!(graphene_std::raster::DownresNode<_>, input: ImageFrame, params: []), register_node!(graphene_std::raster::MaskImageNode<_, _, _>, input: ImageFrame, params: [ImageFrame]), + register_node!(graphene_std::raster::MaskImageNode<_, _, _>, input: ImageFrame, params: [ImageFrame]), register_node!(graphene_std::raster::EmptyImageNode<_, _>, input: DAffine2, params: [Color]), #[cfg(feature = "gpu")] register_node!(graphene_std::executor::MapGpuSingleImageNode<_>, input: Image, params: [String]),