Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Merge main into Gradient Overlay method branch

Yonghyuk Choidc029b93c55f
diff --cc crates/compose/src/tests.rs
index 6588ced47,af87a8b65..7ecb7aea3
--- a/crates/compose/src/tests.rs
+++ b/crates/compose/src/tests.rs
@@@ -1082,6 -1381,34 +1381,39 @@@ fn glow_gradient_follows_the_shape()
assert!(edge[0] > 0.8 && edge[2] < 0.2, "{edge:?}");
}
+ // A Gradient Overlay spans the layer's frame: growing the layer repaints all of it, not just the
+ // new pixels (#4053). Effects that don't depend on the frame repaint only what changed.
+ #[test]
+ fn relayout_damage_covers_a_layer_whose_gradient_frame_moved() {
- let overlay = Effect::GradientOverlay { common: FxCommon::new(photocraft_color::BlendMode::Normal, 1.0), gradient: Gradient::default(), dither: false };
++ let overlay = Effect::GradientOverlay {
++ common: FxCommon::new(photocraft_color::BlendMode::Normal, 1.0),
++ gradient: Gradient::default(),
++ dither: false,
++ interpolation: None,
++ };
+ let grown = |a: &Document, rect: Rect, rgba: [f32; 4]| {
+ let mut b = a.clone();
+ let old = b.layers.last().unwrap().clone();
+ let mut l = solid_layer("sq", rect, rgba);
+ (l.id, l.effects) = (old.id, old.effects);
+ *b.layers.last_mut().unwrap() = l;
+ b
+ };
+ let a = fx_doc(vec![overlay.clone()]);
+ let b = grown(&a, Rect::new(10, 10, 36, 34), [1.0, 0.0, 0.0, 1.0]);
+ let d = crate::relayout_damage(&a, &b);
+ assert!(d.contains_rect(&Rect::new(10, 10, 36, 34)), "{d:?}");
+ // Same bounds, other pixels: the frame stays, the pixels' own damage is enough.
+ assert_eq!(crate::relayout_damage(&a, &grown(&a, Rect::new(10, 10, 30, 30), [0.0, 1.0, 0.0, 1.0])), Rect::EMPTY);
+ // A Color Overlay doesn't depend on the frame.
+ let c = fx_doc(vec![Effect::ColorOverlay { common: FxCommon::new(photocraft_color::BlendMode::Normal, 1.0), color: Color::BLACK }]);
+ assert_eq!(crate::relayout_damage(&c, &grown(&c, Rect::new(10, 10, 36, 34), [1.0, 0.0, 0.0, 1.0])), Rect::EMPTY);
+ // Nor does a disabled overlay.
+ let mut off = a.clone();
+ off.layers.last_mut().unwrap().effects.enabled = false;
+ assert_eq!(crate::relayout_damage(&off, &grown(&off, Rect::new(10, 10, 36, 34), [1.0, 0.0, 0.0, 1.0])), Rect::EMPTY);
+ }
+
#[test]
fn gradient_overlay_follows_angle_and_reverse() {
let g = Gradient { stops: vec![(0.0, Color::BLACK), (1.0, Color::WHITE)], angle: 0.0, ..Gradient::default() };
diff --cc crates/engine/src/layer_style.rs
index 538473817,1647e8782..dc1d5b096
--- a/crates/engine/src/layer_style.rs
+++ b/crates/engine/src/layer_style.rs
@@@ -88,15 -86,15 +88,15 @@@ pub fn effect_defaults(kind: &str) -> V
json!({"blend": "Multiply", "color": "#000000", "opacity": 75, "angle": 120, "useGlobalLight": true, "distance": 5, "choke": 0, "size": 5, "contour": "Linear", "antiAlias": false, "noise": 0})
}
"outerGlow" => {
- json!({"blend": "Screen", "opacity": 75, "color": "#ffffbe", "spread": 0, "size": 5, "range": 50, "contour": "Linear", "antiAlias": false, "noise": 0})
+ json!({"blend": "Screen", "opacity": 75, "color": "#ffffbe", "technique": "softer", "spread": 0, "size": 5, "range": 50, "contour": "Linear", "antiAlias": false, "noise": 0})
}
"innerGlow" => {
- json!({"blend": "Screen", "opacity": 75, "color": "#ffffbe", "source": "edge", "choke": 0, "size": 5, "contour": "Linear", "antiAlias": false, "noise": 0})
+ json!({"blend": "Screen", "opacity": 75, "color": "#ffffbe", "technique": "softer", "source": "edge", "choke": 0, "size": 5, "range": 50, "contour": "Linear", "antiAlias": false, "noise": 0})
}
- "stroke" => json!({"size": 3, "position": "outside", "blend": "Normal", "opacity": 100, "color": "#000000"}),
+ "stroke" => json!({"size": 1, "position": "inside", "blend": "Normal", "opacity": 100, "overprint": false, "color": "#000000"}),
"colorOverlay" => json!({"blend": "Normal", "color": "#ff0000", "opacity": 100}),
"gradientOverlay" => {
- json!({"blend": "Normal", "opacity": 100, "from": "#000000", "to": "#ffffff", "reverse": false, "style": "linear", "angle": 90, "scale": 100})
+ json!({"blend": "Normal", "opacity": 100, "from": "#000000", "to": "#ffffff", "reverse": false, "style": "linear", "angle": 90, "scale": 100, "method": "custom"})
}
"patternOverlay" => json!({"blend": "Normal", "opacity": 100, "pattern": "", "angle": 0, "scale": 100, "link": true}),
"bevelEmboss" => {
@@@ -509,14 -507,13 +509,15 @@@ fn fresh_effect(kind: &str) -> Option<E
"innerGlow" => Effect::InnerGlow(glow()),
"stroke" => Effect::Stroke(StrokeFx {
common: FxCommon::new(BlendMode::Normal, 1.0),
- size: 3.0,
- position: StrokePosition::Outside,
- paint: FxPaint::Color(Color::rgb(1.0, 0.0, 0.0)),
+ size: 1.0,
+ position: StrokePosition::Inside,
+ paint: FxPaint::Color(Color::BLACK),
+ overprint: false,
}),
"colorOverlay" => Effect::ColorOverlay { common: FxCommon::new(BlendMode::Normal, 1.0), color: Color::rgb(1.0, 0.0, 0.0) },
- "gradientOverlay" => Effect::GradientOverlay { common: FxCommon::new(BlendMode::Normal, 1.0), gradient: Gradient::default(), dither: false },
+ "gradientOverlay" => {
+ Effect::GradientOverlay { common: FxCommon::new(BlendMode::Normal, 1.0), gradient: Gradient::default(), dither: false, interpolation: None }
+ }
"patternOverlay" => Effect::PatternOverlay {
common: FxCommon::new(BlendMode::Normal, 1.0),
name: String::new(),
diff --cc crates/gpu/tests/parity.rs
index 209d40bc0,cacd79c0f..7aa9a3cf3
--- a/crates/gpu/tests/parity.rs
+++ b/crates/gpu/tests/parity.rs
@@@ -854,8 -913,14 +913,14 @@@ fn hard_stop_effects_and_gradient_maps_
}
let paint = FxPaint::Gradient(gradient.clone());
let effects = [
- Effect::GradientOverlay { common: FxCommon::new(BlendMode::Normal, 1.0), gradient, dither: false },
+ Effect::GradientOverlay { common: FxCommon::new(BlendMode::Normal, 1.0), gradient, dither: false, interpolation: None },
- Effect::Stroke(StrokeFx { common: FxCommon::new(BlendMode::Normal, 1.0), size: 1.0, position: StrokePosition::Inside, paint: paint.clone() }),
+ Effect::Stroke(StrokeFx {
+ common: FxCommon::new(BlendMode::Normal, 1.0),
+ size: 1.0,
+ position: StrokePosition::Inside,
+ paint: paint.clone(),
+ overprint: false,
+ }),
Effect::InnerGlow(glow(paint.clone(), GlowTechnique::Softer, 1.0, 0.0, GlowSource::Edge)),
Effect::OuterGlow(glow(paint, GlowTechnique::Softer, 1.0, 0.0, GlowSource::Edge)),
];
diff --cc crates/io/src/effects_map.rs
index cb374f935,45e0d7469..a028f4a50
--- a/crates/io/src/effects_map.rs
+++ b/crates/io/src/effects_map.rs
@@@ -688,9 -691,10 +693,10 @@@ mod tests
size: 6.0,
position: StrokePosition::Center,
paint: FxPaint::Gradient(g.clone()),
+ overprint: true,
}),
Effect::ColorOverlay { common: FxCommon::new(BlendMode::Overlay, 0.5), color: Color::rgb(0.0, 0.0, 1.0) },
- Effect::GradientOverlay { common: FxCommon::new(BlendMode::Normal, 1.0), gradient: g, dither: true },
+ Effect::GradientOverlay { common: FxCommon::new(BlendMode::Normal, 1.0), gradient: g, dither: true, interpolation: None },
Effect::PatternOverlay {
common: FxCommon::new(BlendMode::Normal, 1.0),
name: "Bubbles".into(),