Add 'Gradient Map' adjustment node

This commit is contained in:
Keavon Chambers
2024-08-09 23:19:22 -07:00
parent f6ffa45a81
commit 501b562d0f
5 changed files with 108 additions and 10 deletions

View File

@@ -5,6 +5,7 @@ use super::curve::{Curve, CurveManipulatorGroup, ValueMapperNode};
#[cfg(feature = "alloc")]
use super::ImageFrame;
use super::{Channel, Color, Node, RGBMut};
use crate::vector::style::GradientStops;
use crate::vector::VectorData;
use crate::GraphicGroup;
@@ -554,6 +555,21 @@ pub fn blend_colors(foreground: Color, background: Color, blend_mode: BlendMode,
background.alpha_blend(target_color.to_associated_alpha(opacity))
}
#[derive(Debug, Clone, Copy)]
pub struct GradientMapNode<Gradient, Reverse> {
gradient: Gradient,
reverse: Reverse,
// TODO: Add support for dithering to break up gradient color banding
// TODO: Add support for controlling the gradient interpolation method (instead of always `luminance_srgb()`)
}
#[node_macro::node_fn(GradientMapNode)]
fn gradient_map_node(color: Color, gradient: GradientStops, reverse: bool) -> Color {
let intensity = color.luminance_srgb();
let intensity = if reverse { 1. - intensity } else { intensity };
gradient.evalute(intensity as f64)
}
#[derive(Debug, Clone, Copy)]
pub struct VibranceNode<Vibrance> {
vibrance: Vibrance,