With Protect Detail on (the default), local_sharpen clamped each result to
the range of the pixel and its 8 neighbours, which always contains the
original value, so a step or a lone pixel did not change at all.
Protect Detail is now an unsharp mask against a wider Gaussian (sigma
2.5 px) whose differences are soft-limited to 6 levels per pass:
v + amount*d*L/(L + |d|). Uniform areas stay as they are, and Protect
Detail off is unchanged. With Protect Detail on, Strength applies once per
dab instead of being spread over the overlapping dabs, so a click at 50 %
does half of what 100 % does, as in the reference application.
Review on #11013. A dab whose centre and size are both huge gave infinity
over infinity for a node's distance, and the NaN slipped past the falloff
check. The changed rectangle is now worked out in f64 before the cast, so
a far-off centre with a radius reaching the image no longer reports empty.
Co-Authored-By: Claude <[email protected]>
crates/algo/tests/it/main.rs conflicted on the module list: main added
gallery_reach_extreme (the merged Filter Gallery fix, #10850) and this branch adds
liquify_extreme_stroke. Kept both, in alphabetical order. photocraft-algo: 758 unit
and 17 integration tests pass; fmt and clippy clean.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A stroke in a project file may name any f64 for its size and points. The dab turned them into
grid indexes and a snapshot margin with bare casts: a position past the grid saturated to
usize::MAX, wrapped negative as an isize, slipped past the emptiness check and underflowed the
snapshot bounds; the margin and the dirty-rect padding overflowed too. The indexes are now
clamped to the grid before the casts and the margins saturate. The new test fails without the
change (attempt to subtract with overflow at liquify.rs:496).
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The tile halo was sized from the clamped effect values, but the pixel code still read the raw
stored ones, so a stored value past its range could have a kernel larger than its halo and show
seams where tiles meet. `run` and `Prepared::new` now clamp the stack once at the entry, so the
reach and the pixels use the same values. The new test renders every gallery filter with its
range values at three times the maximum and requires the same pixels as at the maximum; it fails
without the change (ColoredPencil first).
Addresses the CodeRabbit review on this PR.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
* perf(algo): row-parallel local_sharpen with fast-path protect_detail (#5426)
Refs #5426. Follow-up to #5499.
Cause:
While #5499 parallelized local_blur and the per-dab mix in DabTool::Focus,
local_sharpen in crates/algo/src/retouch.rs remained single-threaded.
In addition, protect_detail redundantly evaluated coordinate clamping
and strided memory lookups across 8 neighbors inside the per-channel
inner loop for every pixel in the dab. On large brush sizes (e.g. 1000–2500 px),
strokes took seconds and stalled the application.
Change:
- Process local_sharpen window rows in parallel with Rayon across threads,
with wasm32 serial fallback matching local_blur.
- Hoist protect_detail 3x3 neighborhood offset calculations outside the
channel loop.
- Fast-path interior pixels (x > 0 && x + 1 < w && y > 0 && y + 1 < h)
with direct stride offsets, skipping boundary clamping entirely for >99.9%
of pixels in large brush dabs.
- Add retouch_sharpen_exact integration test verifying bit-for-bit parity
against the frozen scalar implementation across layouts, edges, and channels.
* bench(engine): add bench_sharpen_tool example
Every tests/*.rs file is its own executable that links the whole crate
graph. Move each crate's test files into tests/it/ as modules of one
tests/it/main.rs; helper modules under tests/common move with them.
These keep their own binary (own process):
- engine panic_hunt: a process-wide panic hook counts every panic.
- engine text_gamma: changes the process-wide text gamma.
- engine smart_filter_stages, mask_cache_purge: assert on global caches.
- codecs pnm_peak_memory: reads the process's peak RSS.
- photocraft mac_menu_appkit: harness = false.
warp() computed the source-centre fallback as (x0 + x1) in i32 and the
inverse-mapped tile footprint as `floor() as i32 - 3` / `ceil() as i32 + 3`.
With a strongly skewed finite affine (for example Homography
[1, 1e12, 0, 0, 1, 0, 0, 0, 1] on a 32x32 clip) the float-to-int cast
saturates at i32::MIN/MAX and the following -3/+3 overflows, panicking in
debug builds and wrapping in release. A source rect with coordinates near
1.5e9 would overflow the centre sum the same way.
Widen the centre sum to f64 and use saturating_sub/saturating_add for the
footprint, which is intersected with src_rect afterwards anyway.
Add crates/algo/tests/warp_clipped.rs covering clipped-vs-full equivalence,
huge scale allocation, the extreme-affine footprint, and the far-origin
source centre.
Refs #3446