From fea9f8ea24c4f05d451a748bd7d2c23c6905370e Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sat, 17 Jun 2023 22:39:10 +0200 Subject: [PATCH] Reenable hue saturation node for compilation --- node-graph/gcore/src/raster/adjustments.rs | 41 ++++++++++---------- node-graph/gpu-compiler/src/lib.rs | 7 ++-- node-graph/graph-craft/src/document.rs | 8 ++-- node-graph/graph-craft/src/document/value.rs | 1 + 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/node-graph/gcore/src/raster/adjustments.rs b/node-graph/gcore/src/raster/adjustments.rs index 1e26ffc479..2f1275025f 100644 --- a/node-graph/gcore/src/raster/adjustments.rs +++ b/node-graph/gcore/src/raster/adjustments.rs @@ -321,31 +321,30 @@ fn grayscale_color_node(color: Color, tint: Color, reds: f64, yellows: f64, gree color.to_linear_srgb() } +#[derive(Debug)] +pub struct HueSaturationNode { + hue_shift: Hue, + saturation_shift: Saturation, + lightness_shift: Lightness, +} - #[derive(Debug)] - pub struct HueSaturationNode { - hue_shift: Hue, - saturation_shift: Saturation, - lightness_shift: Lightness, - } +#[node_macro::node_fn(HueSaturationNode)] +fn hue_shift_color_node(color: Color, hue_shift: f64, saturation_shift: f64, lightness_shift: f64) -> Color { + let color = color.to_gamma_srgb(); - #[node_macro::node_fn(HueSaturationNode)] - fn hue_shift_color_node(color: Color, hue_shift: f64, saturation_shift: f64, lightness_shift: f64) -> Color { - let color = color.to_gamma_srgb(); + let [hue, saturation, lightness, alpha] = color.to_hsla(); - let [hue, saturation, lightness, alpha] = color.to_hsla(); + let color = Color::from_hsla( + (hue + hue_shift as f32 / 360.) % 1., + // TODO: Improve the way saturation works (it's slightly off) + (saturation + saturation_shift as f32 / 100.).clamp(0., 1.), + // TODO: Fix the way lightness works (it's very off) + (lightness + lightness_shift as f32 / 100.).clamp(0., 1.), + alpha, + ); - let color = Color::from_hsla( - (hue + hue_shift as f32 / 360.) % 1., - // TODO: Improve the way saturation works (it's slightly off) - (saturation + saturation_shift as f32 / 100.).clamp(0., 1.), - // TODO: Fix the way lightness works (it's very off) - (lightness + lightness_shift as f32 / 100.).clamp(0., 1.), - alpha, - ); - - color.to_linear_srgb() - } + color.to_linear_srgb() +} #[derive(Debug, Clone, Copy)] pub struct InvertRGBNode; diff --git a/node-graph/gpu-compiler/src/lib.rs b/node-graph/gpu-compiler/src/lib.rs index 5056f37a56..a44a25e657 100644 --- a/node-graph/gpu-compiler/src/lib.rs +++ b/node-graph/gpu-compiler/src/lib.rs @@ -215,9 +215,10 @@ pub fn compile(dir: &Path) -> Result TaggedValue { TaggedValue::F64(x) => x.to_string() + "_f64", TaggedValue::Bool(x) => x.to_string(), TaggedValue::BlendMode(blend_mode) => "BlendMode::".to_string() + &blend_mode.to_string(), + TaggedValue::Color(color) => "graphene_core::Color::from_rgbaf32_unchecked(0.,0.,0.,1.)".to_string(), _ => panic!("Cannot convert to primitive string"), } }