From bf655268d7eb5c920a1ad7b26acc275cb42624f2 Mon Sep 17 00:00:00 2001 From: texjer Date: Wed, 18 Nov 2026 16:09:33 -0500 Subject: [PATCH] craft-develop: a cancelled inpaint with an impossible patch radius is still cancelled --- crates/develop/src/inpaint.rs | 3 +++ crates/develop/src/inpaint/patchmatch.rs | 1 + 2 files changed, 4 insertions(+) diff --git a/crates/develop/src/inpaint.rs b/crates/develop/src/inpaint.rs index 853eaa51b..e33347901 100644 --- a/crates/develop/src/inpaint.rs +++ b/crates/develop/src/inpaint.rs @@ -57,6 +57,9 @@ mod tests { let p = CompleteParams { patch_radius, ..CompleteParams::default() }; assert_eq!(complete(32, 32, 1, &[0.5; 32 * 32], &hole, &p), None, "radius {patch_radius}"); } + // Cancelled is still cancelled, not "nothing to copy from". + let p = CompleteParams { patch_radius: 16, ..CompleteParams::default() }; + assert_eq!(complete_with(32, 32, 1, &[0.5; 32 * 32], &hole, &p, &|| true), Err(Cancelled)); // A radius the image has room for still fills. let p = CompleteParams { patch_radius: 5, ..CompleteParams::default() }; assert!(complete(32, 32, 1, &[0.5; 32 * 32], &hole, &p).is_some()); diff --git a/crates/develop/src/inpaint/patchmatch.rs b/crates/develop/src/inpaint/patchmatch.rs index 175a5f69d..aa9ff2873 100644 --- a/crates/develop/src/inpaint/patchmatch.rs +++ b/crates/develop/src/inpaint/patchmatch.rs @@ -401,6 +401,7 @@ pub fn complete_with( // A patch wider than the image has no place to be copied from, which is the `None` the search below // would reach anyway. Said here, before `2 * r + 1` and `r as i32` can overflow on an absurd radius. if r > (w.min(h) - 1) / 2 { + check()?; return Ok(None); } let psz = 2 * r + 1;