diff --git a/crates/engine/src/cmd/redeye_cmds.rs b/crates/engine/src/cmd/redeye_cmds.rs index 305b094846..15ebb9b16b 100644 --- a/crates/engine/src/cmd/redeye_cmds.rs +++ b/crates/engine/src/cmd/redeye_cmds.rs @@ -249,18 +249,22 @@ fn red_eye(s: &mut Session, p: &Value) -> Result { let pupil = pupil_raw.clamp(1.0, 100.0); let darken = darken.clamp(0.0, 100.0); let id = if p.get("layer").is_some() { Some(crate::commands::layer_param(s, p)?) } else { s.active().and_then(|d| d.active_layer) }; + // The press point decides (#12576): a press outside the selection does nothing, not clipped, and + // like Photoshop it is silent (#13096): no pixels, no state, no message. Feathered (partly + // selected) and off-canvas presses were not measured and keep today's behaviour: any value above + // 0 counts as inside, and off-canvas presses are not checked. + if let (Some(&first), Some(d)) = (pts.first(), s.active()) + && d.doc.bounds().contains(first.0, first.1) + && d.doc.selection.as_ref().is_some_and(|m| m.sample_channel(first.0, first.1, 0) <= 0.0) + { + return Ok(json!({ "damage": [0, 0, 0, 0], "pixels": 0, "outsideSelection": true })); + } let (damage, total) = s.edit("Red Eye Removal Tool", |doc, active| { let canvas = doc.bounds(); let sel = doc.selection.clone(); let layer = id.or(*active); let (surf, lock) = crate::channel_cmds::target_surface(doc, layer, p)?; let Some(&first) = pts.first() else { return Err(EngineError::Other(MISS.into())) }; - // The press point decides (#12576): a press outside the selection is refused like a miss, - // not clipped. Feathered (partly selected) and off-canvas presses were not measured and keep - // today's behaviour: any value above 0 counts as inside, and off-canvas presses are not checked. - if canvas.contains(first.0, first.1) && sel.as_ref().is_some_and(|m| m.sample_channel(first.0, first.1, 0) <= 0.0) { - return Err(EngineError::Other(MISS.into())); - } // The Background always locks transparency, so only a click on a clear pixel counts. let on_locked_clear = lock && surf.rgba(first.0, first.1)[3] <= 1.0e-5; let mut total = 0u32; @@ -286,7 +290,7 @@ pub fn specs() -> Vec { label: "Red Eye", menu: &[], shortcut: None, - params: r#"{"x":px, "y":px} | {"points":[[x,y],…] (at most 64)},"pupilSize":1..100=50,"darken":0..100=50,"layer":id?=active,"target":"pixels"|"mask"|"filterMask"|"quickMask"|{"channel":i} → {"damage":[x,y,w,h], "pixels":n}"#, + params: r#"{"x":px, "y":px} | {"points":[[x,y],…] (at most 64)},"pupilSize":1..100=50,"darken":0..100=50,"layer":id?=active,"target":"pixels"|"mask"|"filterMask"|"quickMask"|{"channel":i} → {"damage":[x,y,w,h], "pixels":n, "outsideSelection":true?}"#, enabled, run: red_eye, journal: true, diff --git a/crates/engine/src/cmd/redeye_history_state_tests.rs b/crates/engine/src/cmd/redeye_history_state_tests.rs index 20fb8c7a6b..73bc74b55e 100644 --- a/crates/engine/src/cmd/redeye_history_state_tests.rs +++ b/crates/engine/src/cmd/redeye_history_state_tests.rs @@ -127,7 +127,13 @@ fn refused_clicks_add_no_state() { refused(&mut s, params, case); } s.execute("select.rect", json!({"x": 40, "y": 40, "width": 10, "height": 10})).unwrap(); - refused(&mut s, json!({"x": 8, "y": 8}), "a click outside the selection"); + // #13096: a click outside the selection does nothing silently: an Ok with no state. + let (n, _) = last(&s); + let before = pixels(&s); + let r = s.execute("paint.redEye", json!({"x": 8, "y": 8})).unwrap(); + assert_eq!((r["pixels"].as_u64(), r["outsideSelection"].as_bool()), (Some(0), Some(true)), "{r}"); + assert_eq!(last(&s).0, n, "a click outside the selection: no state"); + assert!(pixels(&s) == before, "a click outside the selection"); unchanged_state(&mut s, json!({"x": 44, "y": 44}), "a click inside the selection"); s.execute("select.deselect", json!({})).unwrap(); let id = s.active().unwrap().active_layer.unwrap(); diff --git a/crates/engine/src/cmd/redeye_outside_selection_tests.rs b/crates/engine/src/cmd/redeye_outside_selection_tests.rs index 8bc173e223..9c1ffce326 100644 --- a/crates/engine/src/cmd/redeye_outside_selection_tests.rs +++ b/crates/engine/src/cmd/redeye_outside_selection_tests.rs @@ -1,5 +1,6 @@ //! #12576: a Red Eye press outside the selection does nothing and adds no History state; a press //! inside it is clipped to the selection as before, and with no selection nothing changes. +//! #13096: the outside press is silent, an `Ok` that says so, not the miss error. use serde_json::{Value, json}; @@ -23,7 +24,7 @@ fn eyes() -> Session { /// The left half of eye B: x 450–499. fn select_left_half_of_eye_b(s: &mut Session) { - s.execute("select.rect", json!({"x": 450, "y": 0, "width": 50, "height": 600})).unwrap(); + s.execute("select.rect", json!({"x": 450, "y": 0, "width": 50, "height": 1000})).unwrap(); } /// History length, and the Background's pixels as one value per channel. @@ -53,10 +54,46 @@ fn a_press_outside_the_selection_changes_nothing_and_adds_no_state() { let (states, cols, r) = press(&mut s, params.clone()); assert_eq!(cols, None, "{params}: pixels changed"); assert_eq!(states, 0, "{params}: a history state was added"); - assert_eq!(r, Err(MISS.to_string()), "{params}"); + let r = r.unwrap_or_else(|e| panic!("{params}: an outside press is not an error: {e}")); + assert_eq!(r, json!({"damage": [0, 0, 0, 0], "pixels": 0, "outsideSelection": true}), "{params}"); } } +#[test] +fn an_outside_press_is_silent_at_every_depth() { + for depth in [8, 16, 32] { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 64, "height": 64, "mode": "rgb", "depth": depth})).unwrap(); + s.execute("edit.fill", json!({"color": "#d22828"})).unwrap(); + s.execute("select.rect", json!({"x": 40, "y": 40, "width": 10, "height": 10})).unwrap(); + let n = s.active().unwrap().history.past_len(); + let r = s.execute("paint.redEye", json!({"x": 8, "y": 8})).unwrap_or_else(|e| panic!("{depth} bit: {e}")); + assert_eq!(r["pixels"], 0, "{depth} bit"); + assert_eq!(r["outsideSelection"], true, "{depth} bit"); + assert_eq!(s.active().unwrap().history.past_len(), n, "{depth} bit: no state"); + } +} + +#[test] +fn a_miss_inside_the_selection_keeps_its_result() { + // On a dark blue patch inside the selection: the tool runs and leaves one unchanged state, as before. + let mut s = eyes(); + s.execute("select.rect", json!({"x": 450, "y": 0, "width": 50, "height": 100})).unwrap(); + s.execute("edit.fill", json!({"color": "#283c78"})).unwrap(); + select_left_half_of_eye_b(&mut s); + let (states, cols, r) = press(&mut s, json!({"x": 475, "y": 40, "pupilSize": 1})); + let r = r.unwrap(); + assert_eq!((r["pixels"].as_u64(), r.get("outsideSelection")), (Some(0), None), "{r}"); + assert_eq!((states, cols), (1, None)); + // On a clear pixel under Lock transparent pixels inside the selection: still the miss error. + s.execute("layer.new.layer", json!({})).unwrap(); + s.execute("layer.lockLayers", json!({"transparency": true})).unwrap(); + let n = s.active().unwrap().history.past_len(); + let r = s.execute("paint.redEye", json!({"x": 475, "y": 40, "pupilSize": 1})).map_err(|e| e.to_string()); + assert_eq!(r, Err(MISS.to_string())); + assert_eq!(s.active().unwrap().history.past_len(), n); +} + #[test] fn a_press_inside_the_selection_is_clipped_and_adds_one_state() { // A batch whose first point is inside runs, and x 499.5 is still on the last selected column. diff --git a/crates/ui-egui/src/tools/retouch_ui/tests.rs b/crates/ui-egui/src/tools/retouch_ui/tests.rs index 62ecc823d2..c2ee4e7a2b 100644 --- a/crates/ui-egui/src/tools/retouch_ui/tests.rs +++ b/crates/ui-egui/src/tools/retouch_ui/tests.rs @@ -834,3 +834,38 @@ fn an_empty_clone_source_slot_refuses_to_paint() { assert!(app.ui.clone_source.is_some(), "the old ⌥-click point is still remembered"); assert!(crate::retouch_ui::clone_params(&app).is_none()); } + +/// #13096: a Red Eye press outside the selection does nothing and says nothing, as in Photoshop: +/// no status message, no error, no History state and no pixel change. +#[test] +fn a_red_eye_press_outside_the_selection_is_silent() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 800, "height": 600, "mode": "rgb", "depth": 8})).unwrap(); + app.run("edit.fill", json!({"color": "#c08a68"})).unwrap(); + for cx in [200, 500] { + for (r, color) in [(40, "#ffffff"), (30, "#d22828")] { + app.run("select.rect", json!({"x": cx - r, "y": 200 - r, "width": 2 * r, "height": 2 * r, "ellipse": true})).unwrap(); + app.run("edit.fill", json!({"color": color})).unwrap(); + } + } + // The left half of eye B: x 450–499. A press at x 500.0 lands on pixel 499, so press at 500.5. + app.run("select.rect", json!({"x": 450, "y": 0, "width": 50, "height": 600})).unwrap(); + app.ui.tool = Tool::RedEye; + app.ui.status.clear(); + app.ui.status_error = false; + let snapshot = |app: &PhotocraftApp| { + let st = app.session.active().unwrap(); + (st.history.past_len(), active(app).surface().unwrap().read_region(st.doc.bounds())) + }; + let (states, pixels) = snapshot(&app); + gesture(&mut app, &[[500.5, 200.5]]); + assert_eq!(app.ui.status, "", "no status message"); + assert!(!app.ui.status_error); + let (after_states, after_pixels) = snapshot(&app); + assert_eq!(after_states, states, "no History state"); + assert!(after_pixels == pixels, "no pixel change"); + // A press inside the selection still corrects the left half. + gesture(&mut app, &[[490.5, 200.5]]); + assert!(!app.ui.status_error, "{}", app.ui.status); + assert_eq!(snapshot(&app).0, states + 1); +}