mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +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:
committed by
Dennis Kobert
parent
244a7e0f78
commit
6e32e97ba1
@@ -44,10 +44,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 }
|
||||
});
|
||||
|
||||
|
||||
@@ -23,16 +23,19 @@ fn gradient_map<T: Adjust<Color> + Clone + Send + Sync + core_types::CacheHash +
|
||||
if gradient.is_empty() {
|
||||
return image;
|
||||
}
|
||||
let gradient_spread = gradient.lane(0).attr::<vector_types::markers::GradientSpread>();
|
||||
let gradient_space = gradient.lane(0).attr::<vector_types::markers::GradientSpace>();
|
||||
let gradient_hue_direction = gradient.lane(0).attr::<vector_types::markers::GradientHueDirection>();
|
||||
let gradient_cyclic = gradient.lane(0).attr::<vector_types::markers::GradientCyclic>();
|
||||
let gradient = gradient.element_ref(0);
|
||||
let settings = vector_types::GradientSettings {
|
||||
spread: gradient.lane(0).attr::<vector_types::markers::GradientSpread>(),
|
||||
cyclic: gradient.lane(0).attr::<vector_types::markers::GradientCyclic>(),
|
||||
space: gradient.lane(0).attr::<vector_types::markers::GradientSpace>(),
|
||||
hue_direction: gradient.lane(0).attr::<vector_types::markers::GradientHueDirection>(),
|
||||
interpolation: gradient.lane(0).attr::<vector_types::markers::GradientInterpolation>(),
|
||||
};
|
||||
let evaluator = gradient.element_ref(0).evaluator(settings);
|
||||
|
||||
image.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