PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge PR #7396: Auto-Blend Layers: Seamless Tones and Colors turns on gain compensation
aiongg698aef6babbc
diff --cc crates/engine/src/align_cmds.rsindex 45081950f,b402957a6..0a508cc91--- a/crates/engine/src/align_cmds.rs+++ b/crates/engine/src/align_cmds.rs@@@ -454,28 -454,30 +456,52 @@@ mod tests}}+ /// #5745: the Background can't take a mask, so Auto-Blend turns it into a normal layer first.+ #[test]+ fn auto_blend_turns_the_background_into_a_layer() {+ let mut s = Session::new();+ s.execute("file.new", json!({"width": 200, "height": 60, "background": "white"})).unwrap();+ let bg = s.active().unwrap().doc.background().unwrap().id;+ s.execute("layer.new.layer", json!({"name": "right"})).unwrap();+ s.edit("r", |doc, active| {+ doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap().fill_rect(Rect::new(70, 0, 200, 60), &[0.9, 0.6, 0.2, 1.0]);+ Ok(())+ })+ .unwrap();+ let right = s.active().unwrap().active_layer.unwrap();+ select(&mut s, &[bg, right]);+ s.execute("edit.autoBlendLayers", json!({"method": "panorama"})).unwrap();+ let doc = &s.active().unwrap().doc;+ assert!(!doc.is_background(bg), "the Background became a layer to take its mask");+ assert!(doc.layer(bg).unwrap().mask.is_some());+ s.undo();+ assert!(s.active().unwrap().doc.is_background(bg), "undo restores the Background");+ }++ /// Seamless Tones and Colors evens out a 10% exposure step between two panorama layers.+ #[test]+ fn auto_blend_panorama_seamless_matches_exposure() {+ let mut s = Session::new();+ s.execute("file.new", json!({"width": 200, "height": 60, "background": "transparent"})).unwrap();+ let mut ids = Vec::new();+ for (name, x0, x1, gain) in [("left", 0, 130, 1.0f32), ("right", 70, 200, 1.1)] {+ s.execute("layer.new.layer", json!({ "name": name })).unwrap();+ s.edit(name, |doc, active| {+ doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap().fill_rect(Rect::new(x0, 0, x1, 60), &[0.2 * gain, 0.4 * gain, 0.5 * gain, 1.0]);+ Ok(())+ })+ .unwrap();+ ids.push(s.active().unwrap().active_layer.unwrap());+ }+ select(&mut s, &ids);+ let r = s.execute("edit.autoBlendLayers", json!({"method": "panorama"})).unwrap();+ let doc = &s.active().unwrap().doc;+ let blended = doc.layer(LayerId(r["blended"].as_u64().unwrap())).unwrap().surface().unwrap();+ let (a, b) = (blended.pixel(10, 30), blended.pixel(190, 30));+ // 0.5 vs 0.55 without gain compensation.+ assert!((a[2] - b[2]).abs() < 0.015, "{a:?} {b:?}");+ }+#[test]fn auto_blend_stack_without_seamless() {let mut s = Session::new();