diff --git a/crates/ui-egui/src/canvas/filter_preview.rs b/crates/ui-egui/src/canvas/filter_preview.rs index a7d3f8dc94..0144390b46 100644 --- a/crates/ui-egui/src/canvas/filter_preview.rs +++ b/crates/ui-egui/src/canvas/filter_preview.rs @@ -135,8 +135,9 @@ pub(crate) fn ensure_filter_preview(app: &mut PhotocraftApp, idx: usize, ctx: &e ctx.request_repaint_after(std::time::Duration::from_millis(16)); } let preview = app.filter_preview.as_ref()?; - // Keep the last preview during a drag, but never one from another source or dialog. - if !preview.key.same_target(&request) { + // Keep the last preview during a drag, but never one from another source or dialog. It is + // drawn at its own factor, so a drag that changes the factor keeps it too (#10474). + if !preview.key.same_target_at_any_scale(&request) { return None; } let result = preview.result.as_ref()?; diff --git a/crates/ui-egui/src/dialogs/filter_dialog.rs b/crates/ui-egui/src/dialogs/filter_dialog.rs index 0f87c26faf..08ce0f6ab1 100644 --- a/crates/ui-egui/src/dialogs/filter_dialog.rs +++ b/crates/ui-egui/src/dialogs/filter_dialog.rs @@ -276,6 +276,22 @@ pub fn preview_factor(command: &str, params: &Value, k: u32) -> u32 { }, _ => k, }); + // Minimum and Maximum measure the radius in whole pixels (Squareness rounds it, Roundness + // floors it, and 0 is the identity), so at k = 4 a typed 1.5 px became 0.375 = 0 proxy px and + // the preview showed the untouched document while OK applied a real effect (#10474). Keep at + // least one proxy pixel of radius, and for Squareness the largest k whose rounded proxy radius, + // scaled back, is within 1 px of the one OK applies (6 px at k = 4 rounded to 2 proxy px, 8 px). + // A large radius still previews on a proxy: at full size Roundness costs O(radius) per pixel. + if matches!(command, "filter.other.minimum" | "filter.other.maximum") { + let Some(r) = params.get("radius").and_then(Value::as_f64).filter(|r| r.is_finite()) else { return k }; + let r = r.clamp(0.2, 500.0); + let square = params.get("preserve").and_then(Value::as_str) != Some("roundness"); + let fits = |d: u32| { + let d = f64::from(d); + d <= r.floor() && (!square || ((r / d).round() * d - r.round()).abs() <= 1.0) + }; + return (1..=k).rev().find(|&d| fits(d)).unwrap_or(1); + } // Mosaic rounds its cells to whole pixels: 10 px cells at k = 4 became 3 proxy px = 12 px. // Divide the cell size evenly instead. match params.get("cellSize").and_then(Value::as_f64) { @@ -1353,13 +1369,20 @@ impl FilterPreviewKey { /// parameters moved on. A reopened dialog has a new id, a different command or a different /// document, and a committed document a new revision, so neither survives this test. pub fn same_target(&self, other: &Self) -> bool { + self.k == other.k && self.same_target_at_any_scale(other) + } + + /// [`Self::same_target`] at any proxy factor: whether the canvas may keep showing this frame, + /// drawn at its own `k`, while the factor moves under a drag. A parameter can set the factor + /// (Minimum and Maximum's radius, Mosaic's cell size, #10474), and the frame for the old one is + /// still the closest thing to the result until the new one lands. + pub fn same_target_at_any_scale(&self, other: &Self) -> bool { self.doc == other.doc && self.revision == other.revision && self.dialog == other.dialog && self.active == other.active && self.target == other.target && self.command == other.command - && self.k == other.k } } diff --git a/crates/ui-egui/src/dialogs/filter_dialog/tests.rs b/crates/ui-egui/src/dialogs/filter_dialog/tests.rs index 10f5a073a1..c5013adc25 100644 --- a/crates/ui-egui/src/dialogs/filter_dialog/tests.rs +++ b/crates/ui-egui/src/dialogs/filter_dialog/tests.rs @@ -133,6 +133,8 @@ fn same_target_ignores_parameters_but_nothing_else() { break_it(&mut other); assert!(!other.same_target(&base), "{other:?} must not pass as {base:?}"); assert!(!base.same_target(&other)); + // The canvas's display gate forgives the factor alone (#10474), nothing else. + assert_eq!(other.same_target_at_any_scale(&base), other.k != base.k, "{other:?}"); } } @@ -966,6 +968,13 @@ fn fixed_size_filters_preview_at_the_scale_they_apply() { ("filter.noise.dustAndScratches", json!({"radius": 4.0, "threshold": 0.0})), ("filter.noise.reduceNoise", json!({})), ("filter.other.custom", json!({"kernel": edge})), + // #10474: Minimum and Maximum work on whole-pixel radii (`round()` / `floor()`), so at + // k = 4 a typed 1.5 px radius previewed as 0.375 px = 0 px: the proxy showed the untouched + // document while OK writes a real 1.5 / 1 px effect. A radius under 2 px previews at k = 1. + ("filter.other.minimum", json!({"radius": 1.5, "preserve": "squareness"})), + ("filter.other.minimum", json!({"radius": 1.5, "preserve": "roundness"})), + ("filter.other.maximum", json!({"radius": 1.5, "preserve": "squareness"})), + ("filter.other.maximum", json!({"radius": 1.5, "preserve": "roundness"})), ("filter.video.deInterlace", json!({})), ("filter.stylize.traceContour", json!({})), ("filter.stylize.wind", json!({"method": "blast"})), @@ -1038,6 +1047,19 @@ fn proxy_previews_scale_only_lengths() { assert_eq!(preview_factor("filter.pixelate.mosaic", &json!({"cellSize": "x"}), 4), 4); let (k, diff) = error("filter.pixelate.mosaic", json!({"cellSize": 10.0})); assert!(k == 2 && diff < 0.01, "Mosaic: {diff}"); + // Minimum and Maximum keep at least one proxy pixel of radius (#10474), and a large radius + // keeps a proxy instead of a full-size preview that costs minutes at radius 500. Squareness + // also keeps its rounded radius within 1 px of OK's: 6 px is 2 proxy px at k = 3 (6 px), not + // at k = 4 (8 px); 50 px is 17 at k = 3 (51 px), not 13 at k = 4 (52 px). + let factors = |cmd: &str, preserve: &str| { + [0.2, 1.5, 2.5, 3.9, 6.0, 50.0, 500.0, 9999.0].map(|radius| preview_factor(cmd, &json!({"radius": radius, "preserve": preserve}), 4)) + }; + for cmd in ["filter.other.minimum", "filter.other.maximum"] { + assert_eq!(factors(cmd, "squareness"), [1, 1, 2, 3, 3, 3, 4, 4], "{cmd} squareness"); + assert_eq!(factors(cmd, "roundness"), [1, 1, 2, 3, 4, 4, 4, 4], "{cmd} roundness"); + assert_eq!(preview_factor(cmd, &json!({"radius": 6.0}), 4), 3, "{cmd}: Squareness is the default"); + assert_eq!(preview_factor(cmd, &json!({"radius": "x"}), 4), 4, "{cmd}: a junk radius keeps the proxy"); + } // Tree's and Picture Frame's sizes are relative, not pixels (and not shown as "px"). assert!(!is_pixel_param_of("filter.render.tree", "size") && !is_pixel_param_of("filter.render.pictureFrame", "size")); assert!(is_pixel_param_of("filter.stylize.extrude", "size"));