mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Add a gradient interpolation attribute with Stepped, Linear (existing), and Smooth modes (#4418)
* Delete dead code function * Add a Gradient Interpolation axis with Stepped, Linear, and Smooth paths through the stops * Keep the gradient interpolation attached when dragging stops in the picker * Give the gradient popover's dropdowns the same tooltips as their row labels * Order the gradient popover with Intrp. above Space * Hold gradient stops in place when the cyclic flag is toggled * Fix wrong Smooth gradient colors around stops sitting on the ramp boundaries * Consolidate gradient settings plumbing and fix bugs * Bundle whole-ramp gradient settings into GradientSettings across the editor plumbing * Name the Smooth gradient interpolation's spline type in its tooltip * Linearize the gamma hex stop colors recovered from imported Graphite SVGs * Code review * Aim the Smooth bake's seam subdivision at the copied boundary color * Add GradientEvaluator to build gradient sampling state once per loop instead of per sample * Correct the gradient evaluator's documented setup cost to O(n log n)
This commit is contained in:
@@ -48,10 +48,10 @@ mod blend_std {
|
||||
let mut combined_stops = self.positions(false).into_iter().chain(under.positions(false)).collect::<Vec<_>>();
|
||||
combined_stops.sort_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal));
|
||||
combined_stops.dedup_by(|a, b| (*a - *b).abs() < 1e-6);
|
||||
let over_evaluator = self.evaluator(Default::default());
|
||||
let under_evaluator = under.evaluator(Default::default());
|
||||
let stops = combined_stops.into_iter().map(|position| {
|
||||
let over_color = self.evaluate(position, Default::default(), false, Default::default(), Default::default());
|
||||
let under_color = under.evaluate(position, Default::default(), false, Default::default(), Default::default());
|
||||
let color = blend_fn(over_color, under_color);
|
||||
let color = blend_fn(over_evaluator.evaluate(position), under_evaluator.evaluate(position));
|
||||
GradientStop { position, midpoint: 0.5, color }
|
||||
});
|
||||
|
||||
|
||||
@@ -22,17 +22,14 @@ async fn gradient_map<T: Adjust<Color> + Send>(
|
||||
reverse: Item<bool>,
|
||||
) -> Item<T> {
|
||||
let mut image = image;
|
||||
let gradient_spread = gradient.attribute_cloned_or_default::<vector_types::GradientSpread>(core_types::ATTR_GRADIENT_SPREAD);
|
||||
let gradient_space = gradient.attribute_cloned_or_default::<vector_types::GradientSpace>(core_types::ATTR_GRADIENT_SPACE);
|
||||
let gradient_cyclic = gradient.attribute_cloned_or_default::<bool>(core_types::ATTR_GRADIENT_CYCLIC);
|
||||
let gradient_hue_direction = gradient.attribute_cloned_or_default::<vector_types::GradientHueDirection>(core_types::ATTR_GRADIENT_HUE_DIRECTION);
|
||||
let gradient = gradient.into_element();
|
||||
let settings = vector_types::GradientSettings::from(&gradient);
|
||||
let evaluator = gradient.into_element().evaluator(settings);
|
||||
let reverse = reverse.into_element();
|
||||
|
||||
image.element_mut().adjust(|color| {
|
||||
let intensity = color.luminance_rec_709();
|
||||
let intensity = if reverse { 1. - intensity } else { intensity };
|
||||
gradient.evaluate(intensity as f64, gradient_spread, gradient_cyclic, gradient_space, gradient_hue_direction)
|
||||
evaluator.evaluate(intensity as f64)
|
||||
});
|
||||
|
||||
image
|
||||
|
||||
Reference in New Issue
Block a user