mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-22 04:48:12 +08:00
Make gradient evaluation follow the ramp's interpolation space attribute (#4414)
This commit is contained in:
@@ -41,13 +41,16 @@ mod blend_std {
|
||||
}
|
||||
}
|
||||
impl Blend<Color> for Gradient {
|
||||
// TODO: This joining is unfaithful in several ways: it samples only at stop positions so midpoint curves flatten away;
|
||||
// it evaluates both sources with the default spread and interpolation rather than their own attributes (which this
|
||||
// element-level impl cannot read); and the output keeps over's attributes despite being sampled in the default space
|
||||
fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self {
|
||||
let mut combined_stops = self.positions().into_iter().chain(under.positions()).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 stops = combined_stops.into_iter().map(|position| {
|
||||
let over_color = self.evaluate(position, Default::default());
|
||||
let under_color = under.evaluate(position, Default::default());
|
||||
let over_color = self.evaluate(position, Default::default(), Default::default());
|
||||
let under_color = under.evaluate(position, Default::default(), Default::default());
|
||||
let color = blend_fn(over_color, under_color);
|
||||
GradientStop { position, midpoint: 0.5, color }
|
||||
});
|
||||
|
||||
@@ -23,13 +23,14 @@ async fn gradient_map<T: Adjust<Color> + Send>(
|
||||
) -> Item<T> {
|
||||
let mut image = image;
|
||||
let gradient_spread = gradient.attribute_cloned_or_default::<vector_types::GradientSpread>(core_types::ATTR_GRADIENT_SPREAD);
|
||||
let gradient_interpolation = gradient.attribute_cloned_or_default::<vector_types::GradientInterpolation>(core_types::ATTR_GRADIENT_INTERPOLATION);
|
||||
let gradient = gradient.into_element();
|
||||
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.evaluate(intensity as f64, gradient_spread, gradient_interpolation)
|
||||
});
|
||||
|
||||
image
|
||||
|
||||
Reference in New Issue
Block a user