Clone Stamp and Healing Brush clone from a source set in another open document (#10381)

* Clone Stamp and Healing Brush clone from a source set in another open document

Alt-clicking a clone source in one document and painting in another sampled the
painted document at the source point: a clone source slot held a point and a layer
but not the document. Slots now record the document (and its layer) they were set
in, and painting elsewhere samples that document, as in Photoshop.

- Engine: CloneSource gains `document` (serde default, so older slots read as
  "the document being painted"). Clone Stamp, Healing Brush, the live stroke, the
  Pattern Preview wrap and the brush-tip preview read the source document. Pixels
  are converted to the painted document's colour mode and depth like Edit > Paste
  (no ICC conversion, same as Paste). Current Layer / Current & Below use the
  layer the source was set on (that document's active layer if it was deleted);
  All Layers uses its composite.
- A source whose document was closed is an error asking for a new source, and
  stores no aligned anchor, instead of silently sampling the wrong document.
- cloneSource.set takes an optional `"document": index` (with `source`);
  cloneSource.list and set report each slot's document index.
- UI: the Clone Source panel names the source document (or says it was closed),
  the source crosshair isn't drawn over another document, and the brush preview
  cache includes the source document's revision.

Tests: engine tests for 8/16/32-bit with and without wrap, colour-mode conversion
(Gray > RGB16, RGB > CMYK), sampled layer, Healing Brush, live stroke vs commit,
preview, closed/invalid documents and cloneSource.set/list; a UI test that
Alt-clicks in one document and paints in another.

* Clone test: the aligned stroke past the smaller source document's edge leaves the destination unchanged

Review follow-up: with "aligned": false the stroke sampled inside the source, so it didn't test the edge its comment named, and nothing was asserted.

* Clone Stamp / Healing Brush: an empty Clone Source slot refuses to paint

clone_params fell back to ui.clone_source / ui.clone_offset when the active
slot was empty. Those coordinates carry no document, so after Alt-clicking in
one document and picking an empty slot in another, the stroke read the first
document's coordinates from the second one's pixels.

* fix: reject stale cross-document clone previews

* Clone Source: a copy opened after the source document closed isn't its source

A native copy keeps its document's ID, and a reopened document may keep its ID. A slot set in
a document that was then closed resolved that ID again once a copy was open, and painted from
the copy instead of reporting the closed source (CodeRabbit, clone_source.rs).

Session::close now marks the slots set in the closing document closed (CloneSources::forget_doc,
next to the other per-feature forget_doc calls). A closed slot refuses the stroke and its live
preview with the closed-source error, shows "Source: document closed" in the panel, reports no
`document` in cloneSource.list/set, and draws no overlay or crosshair, whatever document has the
ID now. Setting a new source clears it.
This commit is contained in:
Alan Rockefeller authored and GitHub committed 2026-11-12 18:00:54 +01:00
1 parent aa6f0d1b73
commit f75cfd5a56
16 files changed
+544 -94

No files matched your search

+97 -18
View File
@@ -1,16 +1,76 @@
use super::heal::history_source;
use super::sampling::{SampleLayers, sample, sample_layers};
use super::sampling::{SampleLayers, composite_region, sample, sample_layers};
use super::{
BlendMode, BrushSettings, Document, EngineError, LayerId, PixelFormat, Rect, Region, Result, SampleType, Session, Stroke, StrokePoint, Surface, Value,
alpha_index, apply_coverage, bad, blend_from_str, coverage, damage_json, flag, has_pixel_layer, json, parse_brush, pattern_stamp, periodic, point,
reject_huge_stroke, run_stroke, to_rgba,
};
/// Where a clone stroke reads its pixels: the document it paints, or the other open document its
/// clone source was set in (⌥-click in one document, paint in another, as in Photoshop).
#[derive(Clone)]
pub(super) enum CloneFrom {
Here,
/// Current Layer and Current & Below read `layer` (the layer the source was set on, else that
/// document's active layer); All Layers reads the document's composite.
Other {
doc: std::sync::Arc<Document>,
layer: Option<LayerId>,
revision: u64,
},
}
/// The document `map` samples, for a stroke in the active document.
pub(super) fn clone_from(s: &Session, map: &crate::presets::clone_source::Mapping, cmd: &str) -> Result<CloneFrom> {
let Some(src) = map.document else { return Ok(CloneFrom::Here) };
if s.active().is_some_and(|st| st.doc.id == src.id) {
return Ok(CloneFrom::Here);
}
let st = s.documents().iter().find(|st| st.doc.id == src.id).ok_or_else(|| bad(cmd, crate::presets::clone_source::SOURCE_CLOSED))?;
let layer = src.layer.filter(|l| st.doc.layer(*l).is_some()).or(st.active_layer);
Ok(CloneFrom::Other { doc: st.doc.clone(), layer, revision: st.revision })
}
/// Pixels of `rect` in another document, in the painted surface's format `fmt`.
fn sample_other(doc: &Document, layer: Option<LayerId>, which: SampleLayers, rect: Rect, fmt: PixelFormat, cmd: &str) -> Result<Region> {
if which != SampleLayers::Current {
return Ok(composite_region(doc, layer, which, rect, fmt));
}
let surf = layer
.and_then(|l| doc.layer(l))
.and_then(|l| l.surface())
.ok_or_else(|| bad(cmd, "the clone source's layer has no pixels: set Sample to All Layers, or set the source on a pixel layer"))?;
Ok(convert_region(Region::read(surf, rect), &surf.format(), &fmt))
}
/// `r`, whose pixels are in `from`, in `to`: another document's colour mode or alpha. Depth needs
/// nothing (regions hold normalised floats). Converted as Edit › Paste converts between documents
/// ([`photocraft_raster::convert_pixel`]).
fn convert_region(r: Region, from: &PixelFormat, to: &PixelFormat) -> Region {
if from.mode == to.mode && from.alpha == to.alpha {
return r;
}
let mut out = Region::new(r.rect, to.channels());
for (src, dst) in r.data.chunks_exact(from.channels()).zip(out.data.chunks_exact_mut(to.channels())) {
for (d, v) in dst.iter_mut().zip(photocraft_raster::convert_pixel(from, to, src)) {
*d = v;
}
}
out
}
/// Where a clone stroke samples: `offset` / `source` params, else the active Clone Source slot,
/// with the slot's (or the call's) scale, rotation and flips (see `presets::clone_source`).
pub(super) fn clone_mapping(s: &mut Session, p: &Value, stroke: &Stroke, cmd: &str) -> Result<crate::presets::clone_source::Mapping> {
/// with the slot's (or the call's) scale, rotation and flips (see `presets::clone_source`), and
/// the document it reads. An aligned stroke from the slot remembers its anchor, once the source
/// is known to be readable.
pub(super) fn clone_mapping(s: &mut Session, p: &Value, stroke: &Stroke, cmd: &str) -> Result<(crate::presets::clone_source::Mapping, CloneFrom)> {
let f = stroke.points[0];
crate::presets::clone_source::mapping(s, p, (f.x, f.y), cmd)
let (map, anchor) = crate::presets::clone_source::resolve(s, p, (f.x, f.y), cmd)?;
let from = clone_from(s, &map, cmd)?;
if let Some(a) = anchor {
s.presets.clone.active_mut().anchor = Some(a);
}
Ok((map, from))
}
/// Most source pixels one clone sample may read (a 8192 x 8192 window); real strokes stay far below.
@@ -23,14 +83,21 @@ pub(super) fn clone_sample(
pre: &Document,
id: Option<LayerId>,
surf: &Surface,
from: &CloneFrom,
which: SampleLayers,
rect: Rect,
map: &crate::presets::clone_source::Mapping,
wrap: bool,
cmd: &str,
) -> Result<Region> {
let read = |rect| {
if wrap { periodic::sample(pre, id, surf, which, rect, cmd) } else { Ok(sample(pre, id, surf, which, rect)) }
let fmt = surf.format();
let read = |rect| match from {
CloneFrom::Here if wrap => periodic::sample(pre, id, surf, which, rect, cmd),
CloneFrom::Here => Ok(sample(pre, id, surf, which, rect)),
CloneFrom::Other { doc, layer, .. } if wrap => {
periodic::sample_with(doc.bounds(), fmt.channels(), rect, cmd, |r| sample_other(doc, *layer, which, r, fmt, cmd))
}
CloneFrom::Other { doc, layer, .. } => sample_other(doc, *layer, which, rect, fmt, cmd),
};
if map.is_translation() {
let off = map.offset();
@@ -87,7 +154,8 @@ pub fn clone_preview_periodic(
let id = d.active_layer.ok_or_else(|| bad("clone.preview", "no active layer"))?;
let surf = d.doc.layer(id).and_then(|l| l.surface()).ok_or_else(|| bad("clone.preview", "no pixel surface"))?;
let which = sample_layers(&json!({"sampleLayer": sample_layer}), "clone.preview")?;
let region = clone_sample(&d.doc, Some(id), surf, which, rect, map, wrap, "clone.preview")?;
let from = clone_from(s, map, "clone.preview")?;
let region = clone_sample(&d.doc, Some(id), surf, &from, which, rect, map, wrap, "clone.preview")?;
let px = region.data.chunks_exact(surf.format().channels()).map(|p| to_rgba(&surf.format(), p)).collect();
Ok(photocraft_compose::Buffer { rect, px })
}
@@ -137,7 +205,7 @@ pub(super) fn clone_stamp(s: &mut Session, p: &Value) -> Result<Value> {
// rendering the stroke again (the hitch on release).
let live = s.live_commit.take().filter(|l| l.matches(s, CMD, p, &stroke.points));
let from_live = live.is_some();
let map = clone_mapping(s, p, &stroke, CMD)?;
let (map, from) = clone_mapping(s, p, &stroke, CMD)?;
let off = map.offset();
let dmg = run_stroke(s, "Clone Stamp", id, p, |pre, surf, sel, lock| {
if let Some(l) = live {
@@ -145,11 +213,11 @@ pub(super) fn clone_stamp(s: &mut Session, p: &Value) -> Result<Value> {
return Ok(l.bounds);
}
if flag(p, "wrap", false) {
return periodic::stroke(pre, surf, &stroke, sel, lock, mode, CMD, |before, r| clone_sample(pre, id, before, which, r, &map, true, CMD));
return periodic::stroke(pre, surf, &stroke, sel, lock, mode, CMD, |before, r| clone_sample(pre, id, before, &from, which, r, &map, true, CMD));
}
let (bounds, cov) = coverage(CMD, &stroke)?;
// Samples come from the pre-stroke state, so pixels painted earlier in the stroke are never re-cloned.
let paint = clone_sample(pre, id, surf, which, bounds, &map, flag(p, "wrap", false), CMD)?;
let paint = clone_sample(pre, id, surf, &from, which, bounds, &map, flag(p, "wrap", false), CMD)?;
Ok(apply_coverage(surf, bounds, &cov, stroke.brush.opacity, sel, lock, &paint, mode))
})?;
let mut r = clone_result(dmg, off, aligned, p, &stroke);
@@ -163,7 +231,7 @@ pub(super) fn clone_stamp(s: &mut Session, p: &Value) -> Result<Value> {
enum LivePaint {
/// The clone source (Clone Stamp; the Healing Brush shows its texture while drawing and
/// blends it on release).
Clone { which: SampleLayers, map: crate::presets::clone_source::Mapping, cmd: &'static str },
Clone { which: SampleLayers, map: crate::presets::clone_source::Mapping, from: CloneFrom, cmd: &'static str },
/// The History Brush's history state.
History(Surface),
/// The Pattern Stamp's pattern, tiled from its aligned placement (Impressionist strokes are
@@ -218,9 +286,11 @@ impl LiveRetouch {
let paint = match cmd {
"paint.cloneStamp" | "paint.healingBrush" => {
let f = *stroke.points.first().ok_or_else(|| bad(cmd, "`points` is empty"))?;
let map = crate::presets::clone_source::resolve(s, p, (f.x, f.y), cmd)?.0;
LivePaint::Clone {
which: sample_layers(p, cmd)?,
map: crate::presets::clone_source::resolve(s, p, (f.x, f.y), cmd)?.0,
from: clone_from(s, &map, cmd)?,
map,
cmd: if cmd == "paint.healingBrush" { "paint.healingBrush" } else { "paint.cloneStamp" },
}
}
@@ -291,10 +361,19 @@ impl LiveRetouch {
/// The finished stroke as its commit would take it over ([`Session::offer_live_retouch`]).
/// Only the Clone Stamp and History Brush draw what they commit (the Healing Brush blends on
/// release), and only while the brush, layer and clone source are still the ones the stroke
/// started with: the document revision doesn't cover those.
/// release), and only while the brush, layer, clone mapping and source document revision are
/// still the ones the stroke started with.
pub(crate) fn into_commit(mut self, s: &Session) -> Result<crate::brush_cmds::LiveCommit> {
let (stroke, id) = parse_brush(s, &self.params, &self.cmd)?;
let source_revision_unchanged = match &self.paint {
LivePaint::Clone { from: CloneFrom::Other { doc, revision, .. }, .. } => {
s.documents().iter().any(|st| st.doc.id == doc.id && st.revision == *revision)
}
_ => true,
};
if !source_revision_unchanged {
return Err(bad(&self.cmd, "the clone source document changed during the stroke"));
}
let source_unchanged = match &self.paint {
LivePaint::Clone { map, .. } if self.cmd == "paint.cloneStamp" => {
let f = stroke.points.first().ok_or_else(|| bad(&self.cmd, "`points` is empty"))?;
@@ -362,11 +441,11 @@ impl LiveRetouch {
let mut tail = self.renderer.tail_preview();
self.tail = tail.as_mut().map_or(Rect::EMPTY, |t| t.take_dirty_rect());
dirty = dirty.union(&self.tail);
let LivePaint::Clone { which, map, cmd } = &self.paint else {
let LivePaint::Clone { which, map, from, cmd } = &self.paint else {
return Err(bad(&self.cmd, "periodic painting requires a clone source"));
};
let (pre, id, pre_surf, live_cmd) = (&self.pre, self.id, &self.pre_surf, self.cmd.as_str());
let paint = |r| clone_sample(pre, id, pre_surf, *which, r, map, true, cmd);
let paint = |r| clone_sample(pre, id, pre_surf, from, *which, r, map, true, cmd);
let (surf, _) = crate::channel_cmds::target_surface(std::sync::Arc::make_mut(&mut self.doc), self.id, &self.params)?;
periodic::Composite {
target: surf,
@@ -387,8 +466,8 @@ impl LiveRetouch {
return Ok(r);
}
let paint = match &self.paint {
LivePaint::Clone { which, map, cmd } => {
clone_sample(&self.pre, self.id, &self.pre_surf, *which, r, map, *cmd == "paint.cloneStamp" && flag(&self.params, "wrap", false), cmd)?
LivePaint::Clone { which, map, from, cmd } => {
clone_sample(&self.pre, self.id, &self.pre_surf, from, *which, r, map, *cmd == "paint.cloneStamp" && flag(&self.params, "wrap", false), cmd)?
}
LivePaint::History(src) => Region::read(src, r),
LivePaint::Pattern { tile, place, .. } => pattern_stamp::paint_region(tile, place, &self.pre_surf.format(), r),
+2 -2
View File
@@ -58,7 +58,7 @@ pub(super) fn healing_brush(s: &mut Session, p: &Value) -> Result<Value> {
let which = sample_layers(p, CMD)?;
let mode = blend_param(p, CMD)?;
let aligned = flag(p, "aligned", true);
let map = clone_mapping(s, p, &stroke, CMD)?;
let (map, from) = clone_mapping(s, p, &stroke, CMD)?;
let off = map.offset();
let dmg = run_stroke(s, "Healing Brush", id, p, |pre, surf, sel, lock| {
// Pattern Preview: source and destination repeat across the canvas edges, so a stroke over
@@ -67,7 +67,7 @@ pub(super) fn healing_brush(s: &mut Session, p: &Value) -> Result<Value> {
let (bounds, cov) = coverage(CMD, &stroke)?;
let (g, cov) = pad_coverage(bounds, &cov, 2);
let fmt = surf.format();
let src = clone_sample(pre, id, surf, which, g, &map, wrap, CMD)?;
let src = clone_sample(pre, id, surf, &from, which, g, &map, wrap, CMD)?;
// The destination the texture is fitted to: the layer itself, or what the user sees when
// sampling several layers (so healing onto an empty layer matches the composite).
let dst = if wrap {
@@ -263,14 +263,19 @@ impl PatchStroke {
}
pub(super) fn sample(pre: &Document, id: Option<LayerId>, surf: &Surface, which: SampleLayers, rect: Rect, cmd: &str) -> Result<Region> {
let tile = pre.bounds();
sample_with(pre.bounds(), surf.channels(), rect, cmd, |r| Ok(super::sample(pre, id, surf, which, r)))
}
/// [`sample`] through `read`, which returns `n`-channel pixels of a rectangle inside `tile` (the
/// bounds of the document the source repeats).
pub(super) fn sample_with(tile: Rect, n: usize, rect: Rect, cmd: &str, mut read: impl FnMut(Rect) -> Result<Region>) -> Result<Region> {
if tile.is_empty() {
return Err(bad(cmd, "cannot repeat an empty document"));
}
if rect.is_empty() {
return Ok(Region::new(Rect::EMPTY, surf.channels()));
return Ok(Region::new(Rect::EMPTY, n));
}
let (w, h, n) = (rect.width() as usize, rect.height() as usize, surf.channels());
let (w, h) = (rect.width() as usize, rect.height() as usize);
let len = w
.checked_mul(h)
.and_then(|v| v.checked_mul(n))
@@ -287,7 +292,7 @@ pub(super) fn sample(pre: &Document, id: Option<LayerId>, surf: &Surface, which:
while dx < w {
let sx = (i64::from(rect.x0) + dx as i64 - i64::from(tile.x0)).rem_euclid(i64::from(tile.width())) as i32 + tile.x0;
let cols = (w - dx).min((tile.x1 - sx) as usize);
let part = super::sample(pre, id, surf, which, Rect::new(sx, sy, sx + cols as i32, sy + rows as i32));
let part = read(Rect::new(sx, sy, sx + cols as i32, sy + rows as i32))?;
for (dst, src) in out.data.chunks_exact_mut(w * n).skip(dy).take(rows).zip(part.data.chunks_exact(cols * n)) {
if let Some(dst) = dst.get_mut(dx * n..(dx + cols) * n) {
dst.copy_from_slice(src);
+244 -5
View File
@@ -69,7 +69,7 @@ fn periodic_clone_projection_is_disjoint_and_matches_pixel_modulo() {
#[test]
fn a_hugely_scaled_clone_source_is_refused_before_the_dense_read() {
use super::clone::clone_sample;
use super::clone::{CloneFrom, clone_sample};
use super::sampling::sample_layers;
use crate::presets::clone_source::Mapping;
let s = session(32, 24, 8, "rgb");
@@ -78,8 +78,8 @@ fn a_hugely_scaled_clone_source_is_refused_before_the_dense_read() {
let surf = d.doc.layer(id).unwrap().surface().unwrap();
let which = sample_layers(&json!({"sampleLayer": "current"}), "paint.cloneStamp").unwrap();
// 1000x: a 100x100 destination asks for a ~100000x100000 source window.
let map = Mapping { source: (0.0, 0.0), anchor: (0.0, 0.0), m: [1000.0, 0.0, 0.0, 1000.0] };
let r = clone_sample(&d.doc, Some(id), surf, which, Rect::new(0, 0, 100, 100), &map, false, "paint.cloneStamp");
let map = Mapping { source: (0.0, 0.0), anchor: (0.0, 0.0), m: [1000.0, 0.0, 0.0, 1000.0], document: None };
let r = clone_sample(&d.doc, Some(id), surf, &CloneFrom::Here, which, Rect::new(0, 0, 100, 100), &map, false, "paint.cloneStamp");
assert!(r.is_err());
}
@@ -91,7 +91,7 @@ fn periodic_clone_preview_interpolates_across_transformed_source_seam() {
paint_layer(&mut s, |x, _| if x == 0 { [1.0, 0.0, 0.0, 1.0] } else { [0.0, 0.0, 1.0, 1.0] });
let before = s.active().unwrap().doc.clone();
// A rotated mapping samples halfway between the last and first columns.
let map = Mapping { source: (31.5, 10.0), anchor: (0.0, 0.0), m: [0.0, 1.0, -1.0, 0.0] };
let map = Mapping { source: (31.5, 10.0), anchor: (0.0, 0.0), m: [0.0, 1.0, -1.0, 0.0], document: None };
let r = Rect::new(0, 0, 1, 1);
let wrapped = clone_preview_periodic(&s, r, &map, "current", true).unwrap();
assert_eq!(wrapped.px, [[0.5, 0.0, 0.5, 1.0]]);
@@ -224,7 +224,7 @@ fn clone_preview_matches_source_without_mutating_session() {
s.execute("cloneSource.set", json!({"source": [8,8]})).unwrap();
let revision = s.active().unwrap().revision;
let slots = s.presets.clone.clone();
let map = Mapping { source: (8.0, 8.0), anchor: (20.0, 20.0), m: [1.0, 0.0, 0.0, 1.0] };
let map = Mapping { source: (8.0, 8.0), anchor: (20.0, 20.0), m: [1.0, 0.0, 0.0, 1.0], document: None };
let buf = clone_preview(&s, Rect::new(20, 20, 21, 21), &map, "current").unwrap();
let expected = rgba(&s, 8, 8);
for (actual, expected) in buf.px[0].iter().zip(expected) {
@@ -2791,6 +2791,245 @@ fn periodic_clone_interior_matches_ordinary_brush_masks_and_transparency() {
}
}
// ---------------------------------------------------------------------------------------------
// Clone source in another document
// ---------------------------------------------------------------------------------------------
/// Two open documents: 0 holds `source`, 1 (active) holds `dest`; the clone source is set at
/// `at` in document 0.
fn two_documents(depth: u64, source: impl Fn(i32, i32) -> [f32; 4], dest: impl Fn(i32, i32) -> [f32; 4], at: [i32; 2]) -> Session {
let mut s = session(48, 40, depth, "rgb");
paint_layer(&mut s, source);
s.execute("cloneSource.set", json!({"source": at})).unwrap();
s.execute("file.new", json!({"width": 64, "height": 48, "depth": depth, "mode": "rgb"})).unwrap();
paint_layer(&mut s, dest);
s
}
/// Straight RGBA of document `i`'s active layer at a pixel.
fn doc_rgba(s: &Session, i: usize, x: i32, y: i32) -> [f32; 4] {
let d = &s.documents()[i];
d.doc.layer(d.active_layer.unwrap()).unwrap().surface().unwrap().rgba(x, y)
}
fn ramp(x: i32, y: i32) -> [f32; 4] {
[x as f32 / 48.0, y as f32 / 40.0, ((x * 7 + y * 3) % 11) as f32 / 11.0, 1.0]
}
#[test]
fn clone_stamp_paints_from_the_document_the_source_was_set_in() {
for depth in DEPTHS {
for wrap in [false, true] {
let mut s = two_documents(depth, ramp, |_, _| [0.0, 0.0, 1.0, 1.0], [10, 12]);
let source_before = s.documents()[0].doc.clone();
assert_eq!(s.active_index(), Some(1));
let r = s.execute("paint.cloneStamp", json!({"points": [[30, 20], [40, 20]], "size": 8, "hardness": 100, "wrap": wrap})).unwrap();
assert_eq!(r["offset"], json!([-20, -8]));
for x in [30, 35, 40] {
let (got, want) = (doc_rgba(&s, 1, x, 20), doc_rgba(&s, 0, x - 20, 12));
for c in 0..4 {
assert!((got[c] - want[c]).abs() <= tol(depth), "depth {depth} wrap {wrap} x {x}: {got:?} vs {want:?}");
}
}
assert_eq!(s.documents()[0].doc, source_before, "the source document is only read");
// Aligned: the next stroke keeps the pairing, still in the other document.
s.execute("paint.cloneStamp", json!({"points": [[50, 30]], "size": 4, "hardness": 100, "wrap": wrap})).unwrap();
let (got, want) = (doc_rgba(&s, 1, 50, 30), doc_rgba(&s, 0, 30, 22));
assert!((got[0] - want[0]).abs() <= tol(depth) && (got[1] - want[1]).abs() <= tol(depth), "{got:?} vs {want:?}");
assert!(s.undo() && s.undo());
assert_eq!(doc_rgba(&s, 1, 35, 20), [0.0, 0.0, 1.0, 1.0], "undo restores the painted document");
}
}
}
#[test]
fn clone_source_in_the_painted_document_still_samples_it() {
let mut s = two_documents(8, ramp, |x, _| [0.0, x as f32 / 64.0, 1.0, 1.0], [10, 12]);
// ⌥-click in the document being painted: it is its own source again.
s.execute("cloneSource.set", json!({"source": [10, 12]})).unwrap();
s.execute("paint.cloneStamp", json!({"points": [[30, 20]], "size": 4, "hardness": 100})).unwrap();
let (got, want) = (doc_rgba(&s, 1, 30, 20), doc_rgba(&s, 1, 10, 12));
assert!((got[1] - want[1]).abs() <= tol(8), "{got:?} vs {want:?}");
assert_eq!(s.execute("cloneSource.list", json!({})).unwrap()["sources"][0]["document"], json!(1));
}
#[test]
fn clone_from_another_document_converts_its_colour_mode() {
// A grayscale 8-bit source cloned into a 16-bit RGB document, and an RGB source into CMYK.
let mut s = session(24, 24, 8, "gray");
paint_layer(&mut s, |x, _| [x as f32 / 24.0, x as f32 / 24.0, x as f32 / 24.0, 1.0]);
s.execute("cloneSource.set", json!({"source": [12, 12]})).unwrap();
s.execute("file.new", json!({"width": 40, "height": 40, "depth": 16, "mode": "rgb"})).unwrap();
paint_layer(&mut s, |_, _| [1.0, 0.0, 0.0, 1.0]);
s.execute("paint.cloneStamp", json!({"points": [[30, 30]], "size": 4, "hardness": 100})).unwrap();
let got = doc_rgba(&s, 1, 30, 30);
let want = doc_rgba(&s, 0, 12, 12);
for c in 0..3 {
assert!((got[c] - want[0]).abs() <= tol(8), "gray copied into every channel: {got:?} vs {want:?}");
}
// Aligned, (38, 2) maps to source (20, -16): past the smaller source document's edge there is
// nothing to clone, so the destination keeps its pixels.
let before = doc_rgba(&s, 1, 38, 2);
s.execute("paint.cloneStamp", json!({"points": [[38, 2]], "size": 2, "hardness": 100})).unwrap();
assert_eq!(doc_rgba(&s, 1, 38, 2), before, "no source pixels: the destination is unchanged");
let mut s = two_documents(8, |_, _| [0.0, 1.0, 1.0, 1.0], |_, _| [1.0, 1.0, 1.0, 1.0], [5, 5]);
s.execute("file.new", json!({"width": 16, "height": 16, "depth": 8, "mode": "cmyk"})).unwrap();
paint_layer(&mut s, |_, _| [1.0, 1.0, 1.0, 1.0]);
s.execute("paint.cloneStamp", json!({"points": [[8, 8]], "size": 4, "hardness": 100})).unwrap();
let cyan = doc_rgba(&s, 2, 8, 8);
assert!(cyan[0] < 0.3 && cyan[1] > 0.6 && cyan[2] > 0.6, "cyan through CMYK: {cyan:?}");
}
#[test]
fn clone_from_another_document_samples_the_layer_it_was_set_on() {
// Document 0: red background, and an empty layer above it, active when the source is set.
let mut s = session(32, 32, 8, "rgb");
paint_layer(&mut s, |_, _| [1.0, 0.0, 0.0, 1.0]);
s.execute("layer.new.layer", json!({})).unwrap();
s.execute("cloneSource.set", json!({"source": [10, 10]})).unwrap();
s.execute("file.new", json!({"width": 32, "height": 32, "depth": 8, "mode": "rgb"})).unwrap();
paint_layer(&mut s, |_, _| [0.0, 0.0, 1.0, 1.0]);
// Current Layer reads the empty layer: nothing to paint. Non-aligned: every stroke starts at
// the source point.
s.execute("paint.cloneStamp", json!({"points": [[20, 20]], "size": 4, "hardness": 100, "sampleLayer": "current", "aligned": false})).unwrap();
assert_eq!(doc_rgba(&s, 1, 20, 20), [0.0, 0.0, 1.0, 1.0]);
// Current & Below and All Layers read the source document's composite down from that layer.
for (sample, at) in [("currentAndBelow", 10), ("all", 24)] {
s.execute("paint.cloneStamp", json!({"points": [[at, 6]], "size": 4, "hardness": 100, "sampleLayer": sample, "aligned": false})).unwrap();
let px = doc_rgba(&s, 1, at, 6);
assert!(px[0] > 0.99 && px[2] < 0.01, "{sample}: {px:?}");
}
// Removing that layer falls back to the source document's active layer.
s.set_active(0);
s.execute("layer.delete", json!({})).unwrap();
s.set_active(1);
s.execute("paint.cloneStamp", json!({"points": [[6, 26]], "size": 4, "hardness": 100, "sampleLayer": "current", "aligned": false})).unwrap();
assert!(doc_rgba(&s, 1, 6, 26)[0] > 0.99);
}
#[test]
fn healing_brush_heals_from_another_document() {
let mut s = two_documents(16, texture, |_, _| [0.4, 0.6, 0.5, 1.0], [20, 20]);
let before = s.active().unwrap().doc.clone();
s.execute("paint.healingBrush", json!({"points": [[30, 24]], "size": 12, "hardness": 100})).unwrap();
let after = s.active().unwrap().doc.clone();
let id = s.active().unwrap().active_layer.unwrap();
let r = Rect::new(26, 20, 34, 28);
let (a, b) = (before.layer(id).unwrap().surface().unwrap().read_region(r), after.layer(id).unwrap().surface().unwrap().read_region(r));
assert_ne!(a, b, "the source document's texture is healed in");
}
#[test]
fn live_clone_from_another_document_matches_the_commit() {
for depth in DEPTHS {
let mut s = two_documents(depth, texture, |_, _| [0.1, 0.2, 0.3, 1.0], [12, 12]);
let params = json!({"points": [[30, 22], [38, 26]], "size": 10, "hardness": 60, "opacity": 80});
let live = LiveRetouch::begin(&s, "paint.cloneStamp", &params).unwrap();
let id = s.active().unwrap().active_layer.unwrap();
let bounds = s.active().unwrap().doc.bounds();
let shown = live.doc.layer(id).unwrap().surface().unwrap().read_region(bounds);
s.execute("paint.cloneStamp", params).unwrap();
let committed = s.active().unwrap().doc.layer(id).unwrap().surface().unwrap().read_region(bounds);
assert_eq!(shown, committed, "depth {depth}");
}
}
#[test]
fn live_clone_rejects_a_source_document_changed_during_the_stroke() {
let mut s = two_documents(8, texture, |_, _| [0.1, 0.2, 0.3, 1.0], [12, 12]);
let params = json!({"points": [[30, 22], [38, 26]], "size": 10, "hardness": 60, "opacity": 80});
let live = LiveRetouch::begin(&s, "paint.cloneStamp", &params).unwrap();
assert!(s.set_active(0));
s.execute("paint.pencil", json!({"points": [[12, 12]], "size": 4, "color": "#ff0000"})).unwrap();
assert!(s.set_active(1));
let error = s.offer_live_retouch(live).unwrap_err();
assert!(error.to_string().contains("source document changed"), "{error}");
let result = s.execute("paint.cloneStamp", params).unwrap();
assert!(result.get("fromLive").is_none(), "the stale live pixels must not be committed");
}
#[test]
fn clone_preview_reads_another_document() {
use crate::presets::clone_source::{Mapping, SourceDoc};
let s = two_documents(8, ramp, |_, _| [0.0, 0.0, 1.0, 1.0], [10, 12]);
let source = SourceDoc { id: s.documents()[0].doc.id, layer: s.documents()[0].active_layer };
let map = Mapping { source: (10.0, 12.0), anchor: (30.0, 30.0), m: [1.0, 0.0, 0.0, 1.0], document: Some(source) };
let buf = clone_preview(&s, Rect::new(30, 30, 31, 31), &map, "current").unwrap();
let want = doc_rgba(&s, 0, 10, 12);
for (a, b) in buf.px[0].iter().zip(want) {
assert!((a - b).abs() < 0.01, "{:?} vs {want:?}", buf.px[0]);
}
}
#[test]
fn clone_source_document_closed_or_invalid_is_an_error() {
let mut s = two_documents(8, ramp, |_, _| [0.0, 0.0, 1.0, 1.0], [10, 12]);
s.execute("file.close", json!({"document": 0})).unwrap();
let before = s.active().unwrap().doc.clone();
for cmd in ["paint.cloneStamp", "paint.healingBrush"] {
let e = s.execute(cmd, json!({"points": [[20, 20]], "size": 4})).unwrap_err();
assert!(e.to_string().contains("closed"), "{cmd}: {e}");
assert!(LiveRetouch::begin(&s, cmd, &json!({"points": [[20, 20]], "size": 4})).is_err());
}
assert_eq!(s.active().unwrap().doc, before, "nothing painted");
assert_eq!(s.presets.clone.active().anchor, None, "a refused stroke pairs nothing");
assert_eq!(s.execute("cloneSource.list", json!({})).unwrap()["sources"][0]["document"], Value::Null);
// Explicit `source`/`offset` params sample the painted document, whatever the slot says.
s.execute("paint.cloneStamp", json!({"points": [[20, 20]], "offset": [4, 0], "size": 4})).unwrap();
// Setting a source in the painted document recovers.
s.execute("cloneSource.set", json!({"source": [5, 5]})).unwrap();
s.execute("paint.cloneStamp", json!({"points": [[20, 20]], "size": 4})).unwrap();
}
#[test]
fn a_copy_opened_after_the_clone_source_document_closed_is_not_the_source() {
// A native copy keeps its document's ID. Opening one after the source document was closed
// must not make the slot read the copy.
let mut s = two_documents(8, ramp, |_, _| [0.0, 0.0, 1.0, 1.0], [10, 12]);
let source = s.documents()[0].doc.id;
let copy = (*s.close(0).unwrap().doc).clone();
let i = s.add_document(copy, None);
assert_eq!(s.documents()[i].doc.id, source, "the copy keeps the closed document's ID");
assert_eq!(s.execute("cloneSource.list", json!({})).unwrap()["sources"][0]["document"], Value::Null);
// Neither in the other document nor in the copy itself does the stroke read the copy.
for painted in [0, i] {
assert!(s.set_active(painted));
let before = s.active().unwrap().doc.clone();
let e = s.execute("paint.cloneStamp", json!({"points": [[20, 20]], "size": 4})).unwrap_err();
assert!(e.to_string().contains("closed"), "document {painted}: {e}");
assert!(LiveRetouch::begin(&s, "paint.cloneStamp", &json!({"points": [[20, 20]], "size": 4})).is_err());
assert_eq!(s.active().unwrap().doc, before, "document {painted}: nothing painted");
}
// Setting a source in the copy makes it the source again.
s.execute("cloneSource.set", json!({"source": [10, 12]})).unwrap();
assert_eq!(s.execute("cloneSource.list", json!({})).unwrap()["sources"][0]["document"], json!(i));
s.execute("paint.cloneStamp", json!({"points": [[20, 20]], "size": 4})).unwrap();
}
#[test]
fn clone_source_set_names_the_source_document() {
let mut s = two_documents(8, ramp, |_, _| [0.0, 0.0, 1.0, 1.0], [0, 0]);
// From document 1, set a source in document 0 by index.
let r = s.execute("cloneSource.set", json!({"source": [10, 12], "document": 0})).unwrap();
assert_eq!(r["document"], json!(0));
assert_eq!(r["layer"], json!(s.documents()[0].active_layer.unwrap().0));
s.execute("paint.cloneStamp", json!({"points": [[30, 20]], "size": 4, "hardness": 100})).unwrap();
let (got, want) = (doc_rgba(&s, 1, 30, 20), doc_rgba(&s, 0, 10, 12));
assert!((got[0] - want[0]).abs() <= tol(8), "{got:?} vs {want:?}");
for bad in [
json!({"source": [1, 1], "document": 2}),
json!({"source": [1, 1], "document": -1}),
json!({"source": [1, 1], "document": "0"}),
json!({"document": 0}),
] {
assert!(s.execute("cloneSource.set", bad.clone()).is_err(), "{bad}");
}
assert_eq!(s.presets.clone.active().source, Some([10.0, 12.0]), "a refused call changes nothing");
}
// ---------------------------------------------------------------------------------------------
// View › Pattern Preview: Clone Stamp and Healing Brush wrap across the canvas edges (#8883)
// ---------------------------------------------------------------------------------------------
+102 -33
View File
@@ -7,7 +7,11 @@
//! anchor (where the stroke started after the source was set) onto the source around the
//! sample point: a 200 % width paints the source twice as wide, a 30° rotation paints it turned
//! 30° counter-clockwise on screen (Photoshop's sense).
//!
//! A slot remembers the document its source was set in, so ⌥-clicking in one open document and
//! painting in another clones across them, as in Photoshop.
use photocraft_doc::{DocId, LayerId};
use photocraft_geom::Rect;
use photocraft_paint::retouch::Region;
use serde::{Deserialize, Serialize};
@@ -19,14 +23,25 @@ use crate::{Result, Session};
pub const SLOTS: usize = 5;
/// A stroke from a slot whose source document was closed.
pub(crate) const SOURCE_CLOSED: &str = "the clone source's document was closed: set a new source (Alt-click, or cloneSource.set)";
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CloneSource {
/// Sample point (document px) set by ⌥-click.
pub source: Option<[f64; 2]>,
/// Destination point paired with `source` (first aligned stroke after setting it).
pub anchor: Option<[f64; 2]>,
/// Layer the source was set on (informational, like the panel's document/layer line).
/// Layer the source was set on: the panel's document/layer line, and what Current Layer and
/// Current & Below sample when the source is in another document.
pub layer: Option<u64>,
/// Document the source was set in. Painting in another open document samples this one.
#[serde(default)]
pub document: Option<DocId>,
/// `document` was closed. Kept apart from the ID, because a document opened later can carry
/// the same one (a native copy keeps its original's), and it must not become the source.
#[serde(default)]
pub document_closed: bool,
/// W and H in percent.
pub scale: [f64; 2],
/// Degrees, counter-clockwise.
@@ -41,7 +56,18 @@ pub struct CloneSource {
impl Default for CloneSource {
fn default() -> Self {
CloneSource { source: None, anchor: None, layer: None, scale: [100.0, 100.0], rotation: 0.0, flip_h: false, flip_v: false, linked: false }
CloneSource {
source: None,
anchor: None,
layer: None,
document: None,
document_closed: false,
scale: [100.0, 100.0],
rotation: 0.0,
flip_h: false,
flip_v: false,
linked: false,
}
}
}
@@ -57,9 +83,22 @@ impl CloneSource {
pub fn offset(&self) -> Option<[f64; 2]> {
Some([self.source?[0] - self.anchor?[0], self.source?[1] - self.anchor?[1]])
}
fn to_json(&self, i: usize) -> Value {
/// The other document a stroke in document `painting` samples: `None` when the source was
/// set in `painting` itself (or before slots remembered their document).
pub fn source_doc(&self, painting: Option<DocId>) -> Option<SourceDoc> {
let id = self.document.filter(|d| Some(*d) != painting)?;
Some(SourceDoc { id, layer: self.layer.map(LayerId) })
}
/// The source document's ID while it is still open: `None` once it was closed, even when a
/// document with the same ID was opened since.
pub fn open_document(&self) -> Option<DocId> {
self.document.filter(|_| !self.document_closed)
}
/// `document` is the source document's index among the open documents (`null` when it was
/// closed or never recorded).
fn to_json(&self, i: usize, document: Option<usize>) -> Value {
json!({
"index": i, "source": self.source, "anchor": self.anchor, "offset": self.offset(), "layer": self.layer,
"index": i, "source": self.source, "anchor": self.anchor, "offset": self.offset(), "layer": self.layer, "document": document,
"width": self.scale[0], "height": self.scale[1], "linked": self.linked, "rotation": self.rotation, "flipH": self.flip_h, "flipV": self.flip_v,
})
}
@@ -95,18 +134,34 @@ impl CloneSources {
pub fn active(&self) -> &CloneSource {
&self.slots[self.active.min(SLOTS - 1)]
}
/// Document `id` is closing: the slots set in it keep their point, but no longer read it or
/// a document opened later with the same ID ([`Session::close`]).
pub fn forget_doc(&mut self, id: DocId) {
for slot in self.slots.iter_mut().filter(|s| s.document == Some(id)) {
slot.document_closed = true;
}
}
pub fn active_mut(&mut self) -> &mut CloneSource {
&mut self.slots[self.active.min(SLOTS - 1)]
}
}
/// Another open document a clone source was set in, and the layer it was set on.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct SourceDoc {
pub id: DocId,
pub layer: Option<LayerId>,
}
/// How a clone stroke samples: destination `d` reads the source at
/// `source + m · (d − anchor)` (`m` row-major 2 × 2).
/// `source + m · (d − anchor)` (`m` row-major 2 × 2), in `document` when the source is in
/// another open document (`None`: the document being painted).
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Mapping {
pub source: (f64, f64),
pub anchor: (f64, f64),
pub m: [f64; 4],
pub document: Option<SourceDoc>,
}
impl Mapping {
@@ -157,18 +212,9 @@ fn pt(p: &Value, k: &str) -> Option<(f64, f64)> {
}
/// Resolve a clone stroke's mapping from its params and the active slot. `first` is the
/// stroke's first point. With `"aligned"` strokes the slot remembers the anchor so later
/// strokes keep sampling relative to the original pairing.
pub fn mapping(s: &mut Session, p: &Value, first: (f64, f64), cmd: &str) -> Result<Mapping> {
let (m, anchor) = resolve(s, p, first, cmd)?;
if let Some(a) = anchor {
s.presets.clone.active_mut().anchor = Some(a);
}
Ok(m)
}
/// [`mapping`] without remembering anything: the mapping, and the anchor an aligned stroke from
/// the slot stores (a live preview resolves the same mapping the commit will).
/// stroke's first point. Remembers nothing: returns the mapping, and the anchor an aligned stroke
/// from the slot stores, so later strokes keep sampling relative to the original pairing (a live
/// preview resolves the same mapping the commit will).
pub fn resolve(s: &Session, p: &Value, first: (f64, f64), cmd: &str) -> Result<(Mapping, Option<[f64; 2]>)> {
let aligned = p.get("aligned").and_then(Value::as_bool).unwrap_or(true);
let slot = s.presets.clone.active().clone();
@@ -186,10 +232,10 @@ pub fn resolve(s: &Session, p: &Value, first: (f64, f64), cmd: &str) -> Result<(
let anchor_param = pt(p, "anchor");
if let Some(off) = pt(p, "offset") {
let a = anchor_param.unwrap_or(first);
return Ok((Mapping { source: (a.0 + off.0, a.1 + off.1), anchor: a, m }, None));
return Ok((Mapping { source: (a.0 + off.0, a.1 + off.1), anchor: a, m, document: None }, None));
}
if let Some(src) = pt(p, "source") {
return Ok((Mapping { source: src, anchor: anchor_param.unwrap_or(first), m }, None));
return Ok((Mapping { source: src, anchor: anchor_param.unwrap_or(first), m, document: None }, None));
}
let Some(src) = slot.source else { return Err(bad(cmd, "missing `source` ([x,y]) or `offset` ([dx,dy]); or set one with cloneSource.set")) };
let src = (src[0], src[1]);
@@ -197,7 +243,11 @@ pub fn resolve(s: &Session, p: &Value, first: (f64, f64), cmd: &str) -> Result<(
(true, Some(a)) => (a[0], a[1]),
_ => first,
};
Ok((Mapping { source: src, anchor, m }, aligned.then_some([anchor.0, anchor.1])))
if slot.document_closed {
return Err(bad(cmd, SOURCE_CLOSED));
}
let document = slot.source_doc(s.active().map(|d| d.doc.id));
Ok((Mapping { source: src, anchor, m, document }, aligned.then_some([anchor.0, anchor.1])))
}
/// The Clone Source overlay's blend mode applied to one pixel: the source `src` over the image
@@ -278,11 +328,17 @@ fn index(s: &Session, p: &Value, cmd: &str) -> Result<usize> {
}
}
/// Slot `i` as JSON, its document given as an index among the open documents.
fn slot_json(s: &Session, i: usize) -> Value {
let slot = &s.presets.clone.slots[i.min(SLOTS - 1)];
let document = slot.open_document().and_then(|id| s.documents().iter().position(|d| d.doc.id == id));
slot.to_json(i, document)
}
fn list(s: &mut Session, _: &Value) -> Result<Value> {
let c = &s.presets.clone;
Ok(
json!({"active": c.active, "sources": c.slots.iter().enumerate().map(|(i, x)| x.to_json(i)).collect::<Vec<_>>(), "overlay": serde_json::to_value(&c.overlay).unwrap_or(Value::Null)}),
)
let sources: Vec<Value> = (0..SLOTS).map(|i| slot_json(s, i)).collect();
Ok(json!({"active": c.active, "sources": sources, "overlay": serde_json::to_value(&c.overlay).unwrap_or(Value::Null)}))
}
fn select(s: &mut Session, p: &Value) -> Result<Value> {
@@ -292,19 +348,32 @@ fn select(s: &mut Session, p: &Value) -> Result<Value> {
return Err(bad(CMD, format!("index {i} out of range (0..{SLOTS})")));
}
s.presets.clone.active = i;
Ok(s.presets.clone.active().to_json(i))
Ok(slot_json(s, i))
}
fn set(s: &mut Session, p: &Value) -> Result<Value> {
const CMD: &str = "cloneSource.set";
let i = index(s, p, CMD)?;
let active_layer = s.active().and_then(|d| d.active_layer).map(|l| l.0);
// The document the sample point is in: the active one (⌥-click), or `document` (an index).
let doc = match p.get("document") {
None => s.active(),
Some(v) => {
if p.get("source").is_none() {
return Err(bad(CMD, "`document` names where a `source` point is: give both"));
}
let n = v.as_u64().ok_or_else(|| bad(CMD, "`document` must be a document index"))?;
Some(usize::try_from(n).ok().and_then(|n| s.documents().get(n)).ok_or_else(|| bad(CMD, format!("no open document {n}")))?)
}
};
let (document, doc_layer) = (doc.map(|d| d.doc.id), doc.and_then(|d| d.active_layer).map(|l| l.0));
let slot = &mut s.presets.clone.slots[i];
if let Some((x, y)) = pt(p, "source") {
// A new sample point re-pairs with the next stroke.
slot.source = Some([x, y]);
slot.anchor = None;
slot.layer = p.get("layer").and_then(Value::as_u64).or(active_layer);
slot.layer = p.get("layer").and_then(Value::as_u64).or(doc_layer);
slot.document = document;
slot.document_closed = false;
}
if let Some((dx, dy)) = pt(p, "offset") {
// Offset X/Y fields: keep the anchor (or the source as anchor) and move the source.
@@ -353,14 +422,14 @@ fn set(s: &mut Session, p: &Value) -> Result<Value> {
if p.get("select").and_then(Value::as_bool).unwrap_or(true) {
s.presets.clone.active = i;
}
Ok(s.presets.clone.slots[i].to_json(i))
Ok(slot_json(s, i))
}
fn reset_transform(s: &mut Session, p: &Value) -> Result<Value> {
let i = index(s, p, "cloneSource.resetTransform")?;
let slot = &mut s.presets.clone.slots[i];
(slot.scale, slot.rotation, slot.flip_h, slot.flip_v) = ([100.0, 100.0], 0.0, false, false);
Ok(slot.to_json(i))
Ok(slot_json(s, i))
}
fn overlay(s: &mut Session, p: &Value) -> Result<Value> {
@@ -397,7 +466,7 @@ pub fn specs() -> Vec<CommandSpec> {
label: "Clone Sources",
menu: &[],
shortcut: None,
params: "{} → {active,sources:[{index,source,anchor,offset,layer,width,height,linked,rotation,flipH,flipV}],overlay}",
params: "{} → {active,sources:[{index,source,anchor,offset,layer,document,width,height,linked,rotation,flipH,flipV}],overlay}",
enabled: always,
run: list,
journal: false,
@@ -417,7 +486,7 @@ pub fn specs() -> Vec<CommandSpec> {
label: "Set Clone Source",
menu: &[],
shortcut: None,
params: r##"{"index":0..4?=active,"source":[x,y]? (⌥-click; re-pairs with the next stroke),"offset":[dx,dy]?,"width":%?,"height":%?|"scale":[w%,h%]?,"linked":bool? (W/H link: a lone width or height scales the other by the same factor),"rotation":deg?,"flipH":bool?,"flipV":bool?,"layer":id?,"clear":bool?,"select":bool=true}"##,
params: r##"{"index":0..4?=active,"source":[x,y]? (⌥-click; re-pairs with the next stroke),"document":index?=active (the open document `source` is in: painting in another document clones from it),"offset":[dx,dy]?,"width":%?,"height":%?|"scale":[w%,h%]?,"linked":bool? (W/H link: a lone width or height scales the other by the same factor),"rotation":deg?,"flipH":bool?,"flipV":bool?,"layer":id?,"clear":bool?,"select":bool=true}"##,
enabled: always,
run: set,
journal: true,
@@ -453,11 +522,11 @@ mod tests {
// Issue repro: a 3e9 source with a rotation makes the mapping a resample,
// so source_rect sees mapped coordinates far outside i32. Must clamp, not
// overflow (debug panic) or wrap (release, inverted rect).
let m = Mapping { source: (3_000_000_000.0, 0.0), anchor: (10.0, 10.0), m: transform_matrix([100.0, 100.0], 45.0, false, false) };
let m = Mapping { source: (3_000_000_000.0, 0.0), anchor: (10.0, 10.0), m: transform_matrix([100.0, 100.0], 45.0, false, false), document: None };
let r = m.source_rect(Rect::new(0, 0, 24, 16));
assert!(r.x0 <= r.x1 && r.y0 <= r.y1, "rect must stay ordered: {r:?}");
// A negative source must clamp the same way.
let m = Mapping { source: (-3_000_000_000.0, 0.0), anchor: (10.0, 10.0), m: transform_matrix([100.0, 100.0], 45.0, false, false) };
let m = Mapping { source: (-3_000_000_000.0, 0.0), anchor: (10.0, 10.0), m: transform_matrix([100.0, 100.0], 45.0, false, false), document: None };
let r = m.source_rect(Rect::new(0, 0, 24, 16));
assert!(r.x0 <= r.x1 && r.y0 <= r.y1, "rect must stay ordered: {r:?}");
}
@@ -487,7 +556,7 @@ mod tests {
#[test]
fn source_rect_normal_case_unchanged() {
let m = Mapping { source: (200.0, 0.0), anchor: (10.0, 10.0), m: [1.0, 0.0, 0.0, 1.0] };
let m = Mapping { source: (200.0, 0.0), anchor: (10.0, 10.0), m: [1.0, 0.0, 0.0, 1.0], document: None };
assert_eq!(m.source_rect(Rect::new(0, 0, 24, 16)), Rect::new(188, -12, 216, 8));
}
}
+1 -2
View File
@@ -817,9 +817,8 @@ fn clone_source_flip_scale_rotation() {
let px = layer_px(&s, 42, 24);
assert!((px[0] - 18.0 / 63.0).abs() < 0.02, "{px:?}");
s.execute("cloneSource.resetTransform", json!({})).unwrap();
s.execute("cloneSource.set", json!({"source": [20, 20], "width": 200, "height": 200})).unwrap();
let mut s2 = clone_doc(16);
s2.presets.clone = s.presets.clone.clone();
s2.execute("cloneSource.set", json!({"source": [20, 20], "width": 200, "height": 200})).unwrap();
s2.execute("paint.cloneStamp", json!({"points": [[40, 24]], "size": 21, "hardness": 100})).unwrap();
// 200 %: 4 px right of the anchor samples 2 px right of the source.
let px = layer_px(&s2, 44, 24);
+1
View File
@@ -215,6 +215,7 @@ impl Session {
self.cancel_jobs_on(id);
self.subject_cache.forget_doc(id);
self.object_finder.forget_doc(id);
self.presets.clone.forget_doc(id);
self.link_missing.retain(|(d, _)| *d != id.0);
self.link_scan = None;
}
+28
View File
@@ -208,6 +208,34 @@ fn alt_click_sets_the_clone_source_and_a_drag_paints_it() {
assert!(px[1] > 0.9 && px[0] < 0.1, "green cloned over red: {px:?}");
}
/// ⌥-click in one open document, then paint in another: the stroke clones from the first, as in
/// Photoshop, rather than from the same point of the document being painted.
#[test]
fn alt_click_in_one_document_clones_into_another() {
let mut app = two_colours();
app.run("file.new", json!({"width": 200, "height": 100, "background": "white"})).unwrap();
app.run("document.activate", json!({"document": 0})).unwrap();
app.sync_views();
let mut h = harness(app);
h.state_mut().ui.tool = Tool::CloneStamp;
h.state_mut().run("tools.setBrush", json!({"brush": {"size": 10, "hardness": 1.0}})).unwrap();
let rev = h.state().session.active().unwrap().revision;
click(&mut h, 150.0, 50.0, Modifiers::ALT);
assert_eq!(h.state().session.active().unwrap().revision, rev, "⌥-click only sets the source");
h.state_mut().run("document.activate", json!({"document": 1})).unwrap();
h.state_mut().sync_views();
let view = h.state().ui.views[0].clone();
h.state_mut().ui.views[1] = view;
h.run_steps(2);
let source = h.state().session.documents()[0].doc.clone();
drag(&mut h, [30.0, 50.0], [70.0, 50.0], Modifiers::NONE);
let app = h.state();
assert_eq!(app.session.active_index(), Some(1));
let px = app.session.active().unwrap().doc.layers[0].surface().unwrap().rgba(50, 50);
assert!(px[1] > 0.9 && px[0] < 0.1 && px[2] < 0.1, "green cloned from the other document over white: {px:?}");
assert_eq!(*app.session.documents()[0].doc, *source, "the source document is only read");
}
#[test]
fn clone_stamp_paints_an_empty_layer_from_the_layers_below() {
// The reported setup: a new empty layer on top, Sample: All Layers (or Current & Below).
+13 -5
View File
@@ -77,7 +77,8 @@ pub(super) fn draw_clone_preview(app: &mut PhotocraftApp, painter: &egui::Painte
return;
}
let slot = app.session.presets.clone.active().clone();
let Some(source) = slot.source else { return };
// A source whose document was closed has nothing to show, whatever has its ID now.
let Some(source) = slot.source.filter(|_| !slot.document_closed) else { return };
let radius = f64::from(app.session.tools.brush.size) / 2.0;
if !radius.is_finite() || radius <= 0.0 || radius > 500.0 || !at.iter().all(|v| v.is_finite() && v.abs() < 1_000_000.0) {
return;
@@ -87,12 +88,19 @@ pub(super) fn draw_clone_preview(app: &mut PhotocraftApp, painter: &egui::Painte
let wrap = tool == Tool::CloneStamp && app.ui.view.pattern_preview;
let stroke_start = app.drag.as_ref().map(|d| d.start);
let anchor = if app.ui.tool_options.clone_aligned { slot.anchor.or(stroke_start) } else { stroke_start }.unwrap_or(at);
let map =
Mapping { source: (source[0], source[1]), anchor: (anchor[0], anchor[1]), m: transform_matrix(slot.scale, slot.rotation, slot.flip_h, slot.flip_v) };
let Some(st) = app.session.active() else { return };
// A source set in another open document is read from it, so its edits redraw the overlay too.
let document = slot.source_doc(Some(st.doc.id));
let source_revision = document.and_then(|d| app.session.documents().iter().find(|o| o.doc.id == d.id)).map(|o| o.revision);
let map = Mapping {
source: (source[0], source[1]),
anchor: (anchor[0], anchor[1]),
m: transform_matrix(slot.scale, slot.rotation, slot.flip_h, slot.flip_v),
document,
};
let (display, display_key) = canvas_display(app, &st.doc, output);
let key = format!(
"{:?}:{}:{:?}:{:?}:{map:?}:{}:{}:{}:{}:{wrap}:{}:{}",
"{:?}:{}:{source_revision:?}:{:?}:{:?}:{map:?}:{}:{}:{}:{}:{wrap}:{}:{}",
st.doc.id,
st.revision,
st.active_layer,
@@ -131,7 +139,7 @@ pub(super) fn draw_clone_preview(app: &mut PhotocraftApp, painter: &egui::Painte
// Darken, Lighten and Difference mix the source with the image under the brush (the
// composite, whatever Sample reads), so Difference turns black where they line up.
if overlay.blend != "normal" {
let here = Mapping { source: (0.0, 0.0), anchor: (0.0, 0.0), m: [1.0, 0.0, 0.0, 1.0] };
let here = Mapping { source: (0.0, 0.0), anchor: (0.0, 0.0), m: [1.0, 0.0, 0.0, 1.0], document: None };
let Ok(under) = photocraft_engine::retouch_cmds::clone_preview_periodic(&app.session, rect, &here, "all", wrap) else {
return;
};
@@ -456,7 +456,7 @@ fn clone_stamp_opacity_and_flow_are_journaled_per_gesture() {
assert_eq!(id, "tools.setBrush");
assert_eq!(params["brush"][field].as_f64().map(|v| v as f32), Some(value));
}
h.state_mut().ui.clone_source = Some([0.0, 0.0]);
crate::retouch_ui::set_source(h.state_mut(), 0.0, 0.0);
let params = crate::retouch_ui::clone_params(h.state()).unwrap();
assert_eq!(params["opacity"], json!(h.state().session.tools.brush.opacity * 100.0));
assert_eq!(params["flow"], json!(h.state().session.tools.brush.flow * 100.0));
@@ -577,12 +577,19 @@ pub fn clone_source_panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
}
});
ui.add_space(4.0);
let src_line =
match (slot.source, slot.layer.and_then(|l| app.session.active().and_then(|d| d.doc.layer(photocraft_doc::LayerId(l)).map(|x| x.name.clone())))) {
(Some(_), Some(l)) => format!("Source: {} : {l}", app.session.active().map(|d| d.doc.name.clone()).unwrap_or_default()),
(Some(_), None) => "Source: set".to_string(),
_ => crate::i18n::fmt(tl!("Source: not set ({key}-click with Clone Stamp)"), &[("key", &crate::shortcuts::pretty("Alt"))]),
};
// The document the source was set in (the active one for slots set before slots remembered it).
let source_doc = match slot.document {
Some(id) => slot.open_document().and_then(|_| app.session.documents().iter().find(|d| d.doc.id == id)),
None => app.session.active(),
};
let src_line = match (slot.source, source_doc) {
(Some(_), None) => tl!("Source: document closed").to_string(),
(Some(_), Some(d)) => match slot.layer.and_then(|l| d.doc.layer(photocraft_doc::LayerId(l))) {
Some(l) => format!("Source: {} : {}", d.doc.name, l.name),
None => "Source: set".to_string(),
},
_ => crate::i18n::fmt(tl!("Source: not set ({key}-click with Clone Stamp)"), &[("key", &crate::shortcuts::pretty("Alt"))]),
};
ui.label(egui::RichText::new(src_line).color(t.text_dim).size(11.0));
ui.add_space(4.0);
let lbl = |ui: &mut egui::Ui, s: &str| {
@@ -683,7 +690,7 @@ pub fn clone_sample_point(app: &PhotocraftApp, at: Option<[f64; 2]>) -> Option<[
let anchor = if app.ui.tool_options.clone_aligned { s.anchor.or(stroking) } else { stroking };
match (anchor, at) {
(Some(a), Some(h)) => {
let m = Mapping { source: (src[0], src[1]), anchor: (a[0], a[1]), m: transform_matrix(s.scale, s.rotation, s.flip_h, s.flip_v) };
let m = Mapping { source: (src[0], src[1]), anchor: (a[0], a[1]), m: transform_matrix(s.scale, s.rotation, s.flip_h, s.flip_v), document: None };
let (x, y) = m.map(h[0], h[1]);
Some([x, y])
}
+9 -8
View File
@@ -41,14 +41,10 @@ pub(crate) fn clone_params(app: &PhotocraftApp) -> Option<Value> {
p["flow"] = json!(app.session.tools.brush.flow * 100.0);
}
// The Clone Source panel's active slot (set by ⌥-click) drives the stroke: the engine keeps
// the aligned pairing and applies the slot's scale/rotation/flip.
let slot = app.session.presets.clone.active().source.is_some();
match (app.ui.clone_offset.filter(|_| o.clone_aligned && !slot), app.ui.clone_source.filter(|_| !slot)) {
_ if slot => {}
(Some(off), _) => p["offset"] = json!(off),
(None, Some(src)) => p["source"] = json!(src),
(None, None) => return None,
}
// the aligned pairing and applies the slot's scale/rotation/flip. An empty slot refuses to
// paint, as with no source at all: `ui.clone_source` / `ui.clone_offset` carry no document,
// so falling back to them would read another document's coordinates from this one's pixels.
app.session.presets.clone.active().source?;
Some(p)
}
@@ -695,10 +691,15 @@ pub fn set_source(app: &mut PhotocraftApp, x: f64, y: f64) {
/// Where the clone source is sampled from, shown only while a Clone Stamp or Healing Brush stroke
/// is painted, as in Photoshop: setting the source (⌥-click) leaves nothing on the canvas (#668).
/// A source in another open document has no point on this canvas.
pub fn source_marker_point(app: &PhotocraftApp) -> Option<[f64; 2]> {
if !matches!(app.active_tool(), Tool::CloneStamp | Tool::Healing) {
return None;
}
let slot = app.session.presets.clone.active();
if slot.document_closed || slot.source_doc(app.session.active().map(|d| d.doc.id)).is_some() {
return None;
}
let at = app.drag.as_ref().filter(|d| matches!(d.tool, Tool::CloneStamp | Tool::Healing)).and_then(|d| d.points.last().map(|p| [p[0], p[1]]))?;
match (crate::preset_panels::clone_sample_point(app, Some(at)), app.ui.clone_offset, app.ui.clone_source) {
(Some(p), ..) => Some(p),
+19 -6
View File
@@ -53,7 +53,7 @@ fn only_clone_stamp_and_healing_brush_wrap_in_pattern_preview() {
let mut app = app();
stripes(&mut app, 8, "pixels");
app.ui.view.pattern_preview = pattern_preview;
app.ui.clone_source = Some([20.0, 30.0]);
crate::retouch_ui::set_source(&mut app, 20.0, 30.0);
app.ui.tool = tool;
let m = egui::Modifiers::NONE;
tool_event(&mut app, ToolEvent::Down { x: 86.0, y: 30.0, pressure: 1.0 }, m);
@@ -75,7 +75,7 @@ fn clone_stamp_in_pattern_preview_wraps_a_dab_across_the_right_edge() {
crate::paint_mouse::sync_tool_brush(&mut app);
// A hard tip, so the wrapped part of the dab is fully painted.
app.run("tools.setBrush", json!({"brush": {"size": 20, "hardness": 1}})).unwrap();
app.ui.clone_source = Some([10.0, 10.0]);
crate::retouch_ui::set_source(&mut app, 10.0, 10.0);
app.ui.view.pattern_preview = pattern_preview;
let modifiers = egui::Modifiers::NONE;
tool_event(&mut app, ToolEvent::Down { x: 98.0, y: 30.0, pressure: 1.0 }, modifiers);
@@ -104,7 +104,7 @@ fn clone_stamp_paints_with_the_brush_hardness() {
app.run("tools.setBrush", json!({"brush": {"size": 24, "hardness": hardness}})).unwrap();
app.run("paint.pencil", json!({"points": [[15, 30]], "size": 40, "color": "#ff0000"})).unwrap();
app.ui.tool = Tool::CloneStamp;
app.ui.clone_source = Some([15.0, 30.0]);
crate::retouch_ui::set_source(&mut app, 15.0, 30.0);
let m = egui::Modifiers::NONE;
tool_event(&mut app, ToolEvent::Down { x: 70.0, y: 30.0, pressure: 1.0 }, m);
tool_event(&mut app, ToolEvent::Up { x: 70.0, y: 30.0 }, m);
@@ -149,7 +149,7 @@ fn clone_stamp_brush_opacity_and_flow_reach_the_painted_pixels() {
app.run("paint.pencil", json!({"points": [[10, 10]], "size": 16, "color": "#ff0000"})).unwrap();
app.run("layer.new.layer", json!({})).unwrap();
app.ui.tool = Tool::CloneStamp;
app.ui.clone_source = Some([10.0, 10.0]);
crate::retouch_ui::set_source(&mut app, 10.0, 10.0);
app.ui.tool_options.clone_sample = "all".into();
app.run("tools.setBrush", json!({"brush": {"opacity": 0.5, "flow": 0.5}})).unwrap();
assert!(finish_stroke(&mut app, Tool::CloneStamp, &[[50.0, 30.0, 1.0]], egui::Modifiers::NONE, false));
@@ -171,7 +171,7 @@ fn healing_brush_heals_in_normal_with_a_mode_outside_its_menu() {
app.ui.tool = tool;
crate::paint_mouse::sync_tool_brush(&mut app);
app.session.tools.brush.mode = photocraft_color::BlendMode::Overlay;
app.ui.clone_source = Some([10.0, 10.0]);
crate::retouch_ui::set_source(&mut app, 10.0, 10.0);
drag(&mut app, tool);
let (_, params) = app.session.journal.last().unwrap();
assert_eq!(params["mode"], want, "{tool:?}");
@@ -192,7 +192,7 @@ fn retouch_mode_reaches_the_command() {
app.ui.tool = tool;
crate::paint_mouse::sync_tool_brush(&mut app);
app.run("tools.setBrush", json!({"brush": {"mode": mode}})).unwrap();
app.ui.clone_source = Some([10.0, 10.0]);
crate::retouch_ui::set_source(&mut app, 10.0, 10.0);
drag(&mut app, tool);
let (id, params) = app.session.journal.last().unwrap();
assert_eq!((id.as_str(), params["mode"].as_str()), (cmd, Some(mode)), "{tool:?}");
@@ -1212,3 +1212,16 @@ fn history_brush_options_bar_shows_source_name() {
h.run_steps(4);
h.get_by_label("The History Brush source was deleted: set a new source in the History panel");
}
/// An empty Clone Source slot refuses to paint, as with no source at all: the ⌥-click point left
/// in `ui.clone_source` carries no document, so it must not be read from another document.
#[test]
fn an_empty_clone_source_slot_refuses_to_paint() {
let mut app = app();
app.ui.tool = Tool::CloneStamp;
crate::retouch_ui::set_source(&mut app, 10.0, 10.0);
assert!(crate::retouch_ui::clone_params(&app).is_some());
app.run("cloneSource.select", json!({"index": 1})).unwrap();
assert!(app.ui.clone_source.is_some(), "the old ⌥-click point is still remembered");
assert!(crate::retouch_ui::clone_params(&app).is_none());
}
+2 -1
View File
@@ -1,6 +1,6 @@
# Brush and painting parity
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-07 · **Change:** minor (Eraser's Erase to History, #10692; no estimate changed; Both Axes on Scatter headers, #3825 partial; Brush Tip Shape Spacing checkbox and percentage share one header, #3825 partial; Angle/Roundness fields left of the Brush Tip Shape widget, labels right-aligned, #3825 partial; the eraser end of the pen switches to the Eraser on Windows with Windows Ink on, #2285; no estimate changed; Art History Brush Opacity on the options bar, #10263; no estimate changed; Shift+right-click menu for every painting tool: Edit Brush… and the tool's own Mode list; Brush Shift+right-click Mode picker and Escape dismissal; Art History Brush row added as partial, 8 of 10 styles, TOOL-213-20, #1610; hard-round built-in presets use 5% spacing to remove stacked-tip outlines and reduce pressure-opacity bands, #8842; Mode for Clone Stamp, Pattern Stamp, History Brush, Healing and Paint Bucket; named, stateful Brush Settings locks and visible keyboard focus; independent Brush Pose tilt-axis overrides; Transfer Wetness/Mix tool applicability; dragged preset tip preview; Hue Jitter amount track; Brush Settings minimum fields follow their Control; checkbox-only rows and non-destructive Smoothing switch; shaped-tip cursor follows the view; Color Replacement is a live toolbar tool; no brush-feel estimate changed; 2026-10-11: Pattern Stamp and Background Eraser draw live, TOOL-213-7) · **Target:** Adobe Photoshop 2026
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-07 · **Change:** minor (Eraser's Erase to History, #10692; no estimate changed; Both Axes on Scatter headers, #3825 partial; Brush Tip Shape Spacing checkbox and percentage share one header, #3825 partial; Angle/Roundness fields left of the Brush Tip Shape widget, labels right-aligned, #3825 partial; the eraser end of the pen switches to the Eraser on Windows with Windows Ink on, #2285; no estimate changed; Art History Brush Opacity on the options bar, #10263; no estimate changed; Clone Stamp and Healing Brush clone from a source set in another open document; Shift+right-click menu for every painting tool: Edit Brush… and the tool's own Mode list; Brush Shift+right-click Mode picker and Escape dismissal; Art History Brush row added as partial, 8 of 10 styles, TOOL-213-20, #1610; hard-round built-in presets use 5% spacing to remove stacked-tip outlines and reduce pressure-opacity bands, #8842; Mode for Clone Stamp, Pattern Stamp, History Brush, Healing and Paint Bucket; named, stateful Brush Settings locks and visible keyboard focus; independent Brush Pose tilt-axis overrides; Transfer Wetness/Mix tool applicability; dragged preset tip preview; Hue Jitter amount track; Brush Settings minimum fields follow their Control; checkbox-only rows and non-destructive Smoothing switch; shaped-tip cursor follows the view; Color Replacement is a live toolbar tool; no brush-feel estimate changed; 2026-10-11: Pattern Stamp and Background Eraser draw live, TOOL-213-7) · **Target:** Adobe Photoshop 2026
Painting is where Photoshop users notice differences first, so it gets its own checklist: the
brush engine (`crates/paint/src/brush.rs`), the Brush Settings UI
@@ -147,4 +147,5 @@ tablets against Photoshop side by side.
| 2026-10-13 | minor | Dragging a brush preset shows its cached tip thumbnail and name in the Brushes panel and preset picker (#4225, partial). No brush-feel estimate changed. |
| 2026-10-23 | minor | Escape also consumes a held right-button release after a rapid second press, so the Brush Mode picker stays dismissed without painting or changing history (#4929). |
| 2026-10-30 | minor | Shift+right-click works for every painting tool as in the reference application: Edit Brush… opens the Brush Preset picker, then the tool's own Mode list from its options bar; Behind and Clear greyed on the Background. Row marked partial for the settings the options bar lacks. No brush-feel estimate changed. |
| 2026-10-30 | minor | Clone Stamp and Healing Brush clone from a source ⌥-clicked in another open document (the slot remembers its document and layer; its colour mode is converted as Paste converts; a closed source document is an error, not a silent sample of the painted one). No brush-feel estimate changed. |
| 2026-11-07 | minor | Eraser's Erase to History in Brush, Pencil and Block modes, with ⌥ at the press reversing it for that stroke; a layer missing from the source state paints from a single-layer state and is refused otherwise (#10692). No brush-feel estimate changed. |
+1 -1
View File
@@ -171,7 +171,7 @@ Corpus floors (`crates/io/tests/it/corpus.rs`): the enforced minimums; the corpu
| TOOL-213-5 | Painting a type/shape/smart/fill layer offers to rasterize; OK converts it and the next click paints | done | [#213](https://github.com/storytold/photocraft/issues/213) | rasterize_prompt.rs: OK rasterizes only, the click that opened the prompt is not replayed (as in Photoshop, #8806), Cancel does nothing; drivable via ui.dialog.confirm |
| TOOL-213-6 | Fill dialog: contents, blend, opacity, preserve transparency; remembered; Shift+Backspace | done | [#213](https://github.com/storytold/photocraft/issues/213) | fill_ui.rs dialog over edit.fill (fill_cmds.rs): all contents, mode, opacity, preserve; remembered in prefs; Shift+F5 / Shift+Backspace |
| TOOL-213-7 | Live stroke preview for every brush-based retouch tool | partial | [#213](https://github.com/storytold/photocraft/issues/213) | Live (canvas.rs strokes_live): Brush, Pencil, Mixer Brush, Eraser, Color Replacement, Blur, Sharpen, Smudge, Dodge, Burn, Sponge, Clone Stamp, Healing Brush, History Brush (#1026, #1040), Pattern Stamp (aligned and Impressionist) and Background Eraser (#3754); the release commits the live stroke's pixels (P32) or, for the retouch tools, the same pixels the live stroke showed (tested equal at 8 and 16 bits). Spot Healing Brush shows the area it heals as a dark overlay and heals on release, as Photoshop does. Mixer Brush uses its incremental transaction and commits the displayed result (#3627) |
| TOOL-213-8 | Clone Source: W/H link, drawn overlay (opacity/blend/clip/auto-hide), Alt target cursor | partial | [#213](https://github.com/storytold/photocraft/issues/213) | Clone Source overlay drawn with opacity, inversion, circular clipping, auto-hide and the Normal/Darken/Lighten/Difference blend against the image under the brush (canvas.rs draw_clone_preview, clone_source::overlay_blend); a shaped tip (sampled bitmap, rotation, roundness) clips the overlay to its outline (brush_cursor::tip_mask, #4372); W/H link (cloneSource.set linked, panel chain button, #3298) |
| TOOL-213-8 | Clone Source: W/H link, drawn overlay (opacity/blend/clip/auto-hide), Alt target cursor | partial | [#213](https://github.com/storytold/photocraft/issues/213) | Clone Source overlay drawn with opacity, inversion, circular clipping, auto-hide and the Normal/Darken/Lighten/Difference blend against the image under the brush (canvas.rs draw_clone_preview, clone_source::overlay_blend); a shaped tip (sampled bitmap, rotation, roundness) clips the overlay to its outline (brush_cursor::tip_mask, #4372); W/H link (cloneSource.set linked, panel chain button, #3298); a source ⌥-clicked in one open document is cloned (Clone Stamp, Healing Brush, the live stroke and the overlay) into another, converted to the painted document's colour mode as Paste converts, from the layer it was set on (cloneSource.set document; retouch_cmds/tests.rs clone_stamp_paints_from_the_document_the_source_was_set_in, ui alt_click_tests.rs alt_click_in_one_document_clones_into_another) |
| TOOL-213-9 | Eyedropper comparison ring (new colour above, current below) while sampling | done | [#213](https://github.com/storytold/photocraft/issues/213) | eyedropper_ring (canvas.rs): the sampled colour on the upper arc, the foreground below, drawn for the Eyedropper and Alt-sampling while the button is held; the Precise-cursor preference keeps the crosshair |
| TOOL-213-10 | Ctrl+Alt drag resizes brush size/hardness with an on-canvas readout | done | [#213](https://github.com/storytold/photocraft/issues/213) | brush_resize.rs (#297, #370): Alt+right-drag, or Control+Option-drag on macOS (Control+Alt everywhere), sets diameter horizontally and hardness vertically, circle plus Diameter/Hardness readout, one coalesced tools.setBrush, no paint or history; 9 tests there |
| TOOL-213-11 | Editable pressure curve, global and per control | done | [#213](https://github.com/storytold/photocraft/issues/213) | Global: Preferences › Tools › Pressure Curve (prefs tools.pressureCurve; applied to every pen sample in ui-egui stylus.rs before any brush; editor pressure_curve_ui.rs with Linear/Soft/Hard presets). Per control: every brush Dynamic has its own curve (paint ResponseCurve, the same monotone cubic; Dynamic.curve, set by tools.setBrush, e.g. shapeDynamics.size.curve) applied to its Fade/Pressure/Tilt/Wheel/Rotation input in dynamics.rs dynamic_value; Brush Settings shows it behind each Control row's curve button (#3294) |
+1 -1
View File
@@ -59,7 +59,7 @@ id = "TOOL-213-8"
target = "Clone Source: W/H link, drawn overlay (opacity/blend/clip/auto-hide), Alt target cursor"
status = "partial"
issue = 213
note = "Clone Source overlay drawn with opacity, inversion, circular clipping, auto-hide and the Normal/Darken/Lighten/Difference blend against the image under the brush (canvas.rs draw_clone_preview, clone_source::overlay_blend); a shaped tip (sampled bitmap, rotation, roundness) clips the overlay to its outline (brush_cursor::tip_mask, #4372); W/H link (cloneSource.set linked, panel chain button, #3298)"
note = "Clone Source overlay drawn with opacity, inversion, circular clipping, auto-hide and the Normal/Darken/Lighten/Difference blend against the image under the brush (canvas.rs draw_clone_preview, clone_source::overlay_blend); a shaped tip (sampled bitmap, rotation, roundness) clips the overlay to its outline (brush_cursor::tip_mask, #4372); W/H link (cloneSource.set linked, panel chain button, #3298); a source ⌥-clicked in one open document is cloned (Clone Stamp, Healing Brush, the live stroke and the overlay) into another, converted to the painted document's colour mode as Paste converts, from the layer it was set on (cloneSource.set document; retouch_cmds/tests.rs clone_stamp_paints_from_the_document_the_source_was_set_in, ui alt_click_tests.rs alt_click_in_one_document_clones_into_another)"
[[item]]
id = "TOOL-213-9"