mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
select-mask: bind the preview's base cache to the document revision
A preview job still running when the document changed stored its base selection back, and the next preview reused it for the new pixels. BaseCache now records its revision and compute reuses it only on a match. Also describe TOOL-214-1 as the full-window workspace.
This commit is contained in:
1 parent
eda6e71835
commit
3450ca20bc
4 files changed
+37
-5
No files matched your search
@@ -346,6 +346,8 @@ struct Gesture {
|
||||
#[derive(Clone)]
|
||||
struct BaseCache {
|
||||
k: u32,
|
||||
/// The document revision the base was computed from.
|
||||
revision: u64,
|
||||
edits: Vec<Value>,
|
||||
base: Option<Surface>,
|
||||
}
|
||||
@@ -1105,16 +1107,16 @@ fn compute(job: Job, cancel: Option<&photocraft_engine::jobs::JobCtx>) -> Result
|
||||
select_mask_edits::parse(&json!({ "edits": list })).map_err(|e| e.to_string())
|
||||
};
|
||||
// With no edits yet, the selection Select and Mask starts from is where the first one starts.
|
||||
let mut cache = BaseCache { k, edits: Vec::new(), base: start() };
|
||||
let mut cache = BaseCache { k, revision: job.revision, edits: Vec::new(), base: start() };
|
||||
if !job.edits.is_empty() || job.extra.is_some() {
|
||||
// The selection after the edits already applied, when they still lead the list.
|
||||
let (from, done) = match job.cache.filter(|c| c.k == k && job.edits.starts_with(&c.edits)) {
|
||||
let (from, done) = match job.cache.filter(|c| c.k == k && c.revision == job.revision && job.edits.starts_with(&c.edits)) {
|
||||
Some(c) => (c.base, c.edits.len()),
|
||||
None => (start(), 0),
|
||||
};
|
||||
let rest = scaled(job.edits.get(done..).unwrap_or_default())?;
|
||||
let base = select_mask_edits::apply(&doc, layer, from, &rest);
|
||||
cache = BaseCache { k, edits: job.edits.clone(), base: base.clone() };
|
||||
cache = BaseCache { k, revision: job.revision, edits: job.edits.clone(), base: base.clone() };
|
||||
let base = match &job.extra {
|
||||
Some(e) => select_mask_edits::apply(&doc, layer, base, &scaled(std::slice::from_ref(e))?),
|
||||
None => base,
|
||||
|
||||
@@ -349,6 +349,36 @@ fn the_preview_reuses_the_edits_it_applied() {
|
||||
assert_eq!(ws(&app).preview.cache.as_ref().map(|c| c.edits.len()), Some(1));
|
||||
}
|
||||
|
||||
/// The selection the edits made on an older document is not reused: a Quick Selection stroke
|
||||
/// on a repainted image previews what OK would commit.
|
||||
#[test]
|
||||
fn the_preview_recomputes_the_edits_after_the_document_changes() {
|
||||
let warm = |app: &mut PhotocraftApp| {
|
||||
app.session
|
||||
.edit("paint", |doc, _| {
|
||||
doc.layers[0].surface_mut().unwrap().fill_rect(Rect::new(0, 0, 160, 100), &[0.85, 0.55, 0.25, 1.0]);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
};
|
||||
let stroke = json!({"stroke": {"points": [[120.0, 50.0], [130.0, 50.0]]}});
|
||||
let mut app = app_with_selection();
|
||||
open(&mut app).unwrap();
|
||||
ui(&mut app, stroke.clone());
|
||||
let two_tone = selected(&mut app);
|
||||
// The pixels change under the workspace (a control-channel command) before it redraws.
|
||||
warm(&mut app);
|
||||
let after = selected(&mut app);
|
||||
let mut fresh = app_with_selection();
|
||||
warm(&mut fresh);
|
||||
open(&mut fresh).unwrap();
|
||||
ui(&mut fresh, stroke);
|
||||
let expected = selected(&mut fresh);
|
||||
assert_ne!(two_tone, expected, "the repaint changes what the stroke selects");
|
||||
assert_eq!(after, expected);
|
||||
assert_eq!(ws(&app).preview.cache.as_ref().map(|c| c.revision), app.session.active().map(|s| s.revision));
|
||||
}
|
||||
|
||||
/// Sends `key` with `modifiers` through the workspace's key handling.
|
||||
fn press(app: &mut PhotocraftApp, ctx: &egui::Context, key: Key, modifiers: Modifiers) {
|
||||
let ev = egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers };
|
||||
|
||||
+1
-1
@@ -153,7 +153,7 @@ Corpus floors (`crates/io/tests/it/corpus.rs`): the enforced minimums; the corpu
|
||||
| TOOL-213-13 | Brush regression tests: no seams, hard edge, zero-scatter defaults, ABR never black | done | [#213](https://github.com/storytold/photocraft/issues/213) | Seam, hard-edge and zero-scatter tests in brush_tests.rs; ABR tip colour test in abr_map/tests.rs |
|
||||
| TOOL-213-14 | Tablet: no OS arrow cursor over the canvas on macOS, Windows and Linux | partial | [#213](https://github.com/storytold/photocraft/issues/213) | Brush tools set CursorIcon::None (canvas.rs:1259-1275); not verified per OS |
|
||||
| TOOL-213-18 | Pattern Stamp tool: sibling of Clone Stamp in the S flyout | done | [#213](https://github.com/storytold/photocraft/issues/213) | Tool::PatternStamp in the S group; paint.patternStamp stamps the Patterns-panel tile with Aligned and Impressionist (an approximation: it jitters each dab's tile phase, not Photoshop's smeared impressionist look); engine tests cover depths, seams, hostile input |
|
||||
| TOOL-214-1 | Select and Mask workspace: view modes, Refine Edge brush, 6 outputs | partial | [#214](https://github.com/storytold/photocraft/issues/214) | select.refineEdge dialog with a live preview in Photoshop's view modes: Onion Skin, Marching Ants, Overlay, On Black, On White, Black & White, On Layers, per-view Opacity, Show Edge (J), Show Original (P), F cycles, X shows the image (select_mask_view.rs, #1754); Refine Edge Brush (R, size, Expand Detection Area / Restore Original Edge, Alt swaps) paints select.refineEdge refineStrokes, estimated by colour-line matting (matting/brush.rs, #2972); outputs Selection, Layer Mask, New Layer, New Layer with Mask, New Document, New Document with Mask (#2998); Photoshop's workspace (select_mask_ui.rs, #7069, #8148): options bar, tools Quick Selection W, Refine Edge Brush R, Brush B, Object Selection W, Lasso and Polygonal Lasso L, Hand H, Zoom Z, Properties with Remember Settings, View Mode (Real-Time Refinement, High Quality Preview, Overlay colour and Indicates), Refine Mode, Edge Detection, Global Refinements with Clear Selection and Invert, Output Settings; the tools run as select.refineEdge edits; Ctrl+Z per edit; no Refine Hair (#2671), Object Aware (#2788) or Presets |
|
||||
| TOOL-214-1 | Select and Mask workspace: view modes, Refine Edge brush, 6 outputs | partial | [#214](https://github.com/storytold/photocraft/issues/214) | Photoshop's full-window Select and Mask workspace (select_mask_ui.rs, #7069, #8148); OK applies select.refineEdge. Live preview in Photoshop's view modes: Onion Skin, Marching Ants, Overlay, On Black, On White, Black & White, On Layers, per-view Opacity, Show Edge (J), Show Original (P), F cycles, X shows the image (select_mask_view.rs, #1754); Refine Edge Brush (R, size, Expand Detection Area / Restore Original Edge, Alt swaps) paints select.refineEdge refineStrokes, estimated by colour-line matting (matting/brush.rs, #2972); outputs Selection, Layer Mask, New Layer, New Layer with Mask, New Document, New Document with Mask (#2998); the workspace has the options bar, tools Quick Selection W, Refine Edge Brush R, Brush B, Object Selection W, Lasso and Polygonal Lasso L, Hand H, Zoom Z, Properties with Remember Settings, View Mode (Real-Time Refinement, High Quality Preview, Overlay colour and Indicates), Refine Mode, Edge Detection, Global Refinements with Clear Selection and Invert, Output Settings; the tools run as select.refineEdge edits; Ctrl+Z per edit; no Refine Hair (#2671), Object Aware (#2788) or Presets |
|
||||
| TOOL-214-2 | Marquee: Shift square, Alt from centre, live W x H readout | done | [#214](https://github.com/storytold/photocraft/issues/214) | canvas.rs marquee_corners: Shift square or circle, Alt from the centre, live W x H readout beside the cursor (marquee_readout); marquee_tests.rs |
|
||||
| TOOL-214-3 | Color Range test: Sampled Colors at Fuzziness 0 selects the exact match only | done | [#214](https://github.com/storytold/photocraft/issues/214) | color_range_fuzziness_zero_selects_exact_match_only in selection_cmds.rs asserts exact match is selected and 1-level-off pixels are rejected at fuzziness 0; tonal presets covered in color_range_presets |
|
||||
| TOOL-214-4 | Move tool: box-select layers, Auto-Select hover outline, double-click fit, drag to a tab | partial | [#214](https://github.com/storytold/photocraft/issues/214) | Auto-Select hover outline (Preferences › Tools › Show Highlight on Rollover, #2834) and box-select layers from an empty spot (move_box.rs:59, layer.selectInRect, #2844) done; dragging layers with the Move tool (or from the Layers panel) onto another document's tab copies them there (layer_transfer.rs:162, layer.copyToDocument, #589/#851); double-click fit and dragging a selection's pixels to another document open |
|
||||
|
||||
@@ -115,7 +115,7 @@ id = "TOOL-214-1"
|
||||
target = "Select and Mask workspace: view modes, Refine Edge brush, 6 outputs"
|
||||
status = "partial"
|
||||
issue = 214
|
||||
note = "select.refineEdge dialog with a live preview in Photoshop's view modes: Onion Skin, Marching Ants, Overlay, On Black, On White, Black & White, On Layers, per-view Opacity, Show Edge (J), Show Original (P), F cycles, X shows the image (select_mask_view.rs, #1754); Refine Edge Brush (R, size, Expand Detection Area / Restore Original Edge, Alt swaps) paints select.refineEdge refineStrokes, estimated by colour-line matting (matting/brush.rs, #2972); outputs Selection, Layer Mask, New Layer, New Layer with Mask, New Document, New Document with Mask (#2998); Photoshop's workspace (select_mask_ui.rs, #7069, #8148): options bar, tools Quick Selection W, Refine Edge Brush R, Brush B, Object Selection W, Lasso and Polygonal Lasso L, Hand H, Zoom Z, Properties with Remember Settings, View Mode (Real-Time Refinement, High Quality Preview, Overlay colour and Indicates), Refine Mode, Edge Detection, Global Refinements with Clear Selection and Invert, Output Settings; the tools run as select.refineEdge edits; Ctrl+Z per edit; no Refine Hair (#2671), Object Aware (#2788) or Presets"
|
||||
note = "Photoshop's full-window Select and Mask workspace (select_mask_ui.rs, #7069, #8148); OK applies select.refineEdge. Live preview in Photoshop's view modes: Onion Skin, Marching Ants, Overlay, On Black, On White, Black & White, On Layers, per-view Opacity, Show Edge (J), Show Original (P), F cycles, X shows the image (select_mask_view.rs, #1754); Refine Edge Brush (R, size, Expand Detection Area / Restore Original Edge, Alt swaps) paints select.refineEdge refineStrokes, estimated by colour-line matting (matting/brush.rs, #2972); outputs Selection, Layer Mask, New Layer, New Layer with Mask, New Document, New Document with Mask (#2998); the workspace has the options bar, tools Quick Selection W, Refine Edge Brush R, Brush B, Object Selection W, Lasso and Polygonal Lasso L, Hand H, Zoom Z, Properties with Remember Settings, View Mode (Real-Time Refinement, High Quality Preview, Overlay colour and Indicates), Refine Mode, Edge Detection, Global Refinements with Clear Selection and Invert, Output Settings; the tools run as select.refineEdge edits; Ctrl+Z per edit; no Refine Hair (#2671), Object Aware (#2788) or Presets"
|
||||
|
||||
[[item]]
|
||||
id = "TOOL-214-2"
|
||||
|
||||
Reference in new issue
Block a user