PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Improve zoomed Liquify preview detail (#2715)
Elvis33LE094d0776d141
diff --git a/crates/algo/src/liquify.rs b/crates/algo/src/liquify.rsindex adda53973..fd0e9e0df 100644--- a/crates/algo/src/liquify.rs+++ b/crates/algo/src/liquify.rs@@ -680,6 +680,8 @@ pub struct ProxyImage {pub px: Vec<[f32; 4]>,}+const MAX_FULL_RES_SOURCE_PIXELS: usize = 8 * 1024 * 1024;+impl ProxyImage {/// Box-downsamples `src` over `bounds` so the longer side is at most `max_side`.pub fn new(src: &Surface, bounds: Rect, max_side: usize) -> Self {@@ -760,6 +762,130 @@ impl ProxyImage {rows.chunks_mut(self.w).enumerate().for_each(|(i, line)| row(y0 + i, line));}+ /// Renders a document-pixel-resolution preview for `region` into the corresponding part of+ /// `out`, whose dimensions cover `bounds`. Source reads are limited to the dirty region plus+ /// the displacement range that can affect it, so zoomed-in brush updates do not flatten the+ /// whole layer. `source_scratch` is reused by the caller between updates.+ pub fn render_full_resolution(+ src: &Surface,+ field: &LiquifyField,+ bounds: Rect,+ region: Rect,+ out: &mut [[u8; 4]],+ source_scratch: &mut Vec<[f32; 4]>,+ ) -> bool {+ let bounds = bounds.intersect(&field.bounds);+ let region = region.intersect(&bounds);+ let (width, height) = (bounds.width() as usize, bounds.height() as usize);+ let Some(out_len) = width.checked_mul(height) else { return false };+ if region.is_empty() || out.len() != out_len || width == 0 || height == 0 {+ return false;+ }++ // Bilinear field interpolation is a convex combination of its surrounding nodes. The+ // extrema of those nodes therefore bound every source sample in this output rectangle.+ let (mut min_dx, mut min_dy, mut max_dx, mut max_dy) = (f32::INFINITY, f32::INFINITY, f32::NEG_INFINITY, f32::NEG_INFINITY);+ let (gx0, gy0) = field.to_grid(f64::from(region.x0) + 0.5, f64::from(region.y0) + 0.5);+ let (gx1, gy1) = field.to_grid(f64::from(region.x1) - 0.5, f64::from(region.y1) - 0.5);+ let (i0, j0) = (gx0.floor().max(0.0) as usize, gy0.floor().max(0.0) as usize);+ let (i1, j1) = (gx1.ceil().max(0.0) as usize, gy1.ceil().max(0.0) as usize);+ for j in j0..=j1.min(field.h.saturating_sub(1)) {+ for i in i0..=i1.min(field.w.saturating_sub(1)) {+ let Some(v) = j.checked_mul(field.w).and_then(|row| row.checked_add(i)).and_then(|idx| field.d.get(idx)) else { continue };+ min_dx = min_dx.min(v[0]);+ min_dy = min_dy.min(v[1]);+ max_dx = max_dx.max(v[0]);+ max_dy = max_dy.max(v[1]);+ }+ }+ if !min_dx.is_finite() || !min_dy.is_finite() || !max_dx.is_finite() || !max_dy.is_finite() {+ return false;+ }++ // Source coordinates are pixel centres. Add one sample on each side for bilinear+ // interpolation, then clamp to the document just as the regular proxy renderer does.+ let x0 = (f64::from(region.x0) + f64::from(min_dx)).floor() - 1.0;+ let y0 = (f64::from(region.y0) + f64::from(min_dy)).floor() - 1.0;+ let x1 = (f64::from(region.x1 - 1) + f64::from(max_dx)).ceil() + 2.0;+ let y1 = (f64::from(region.y1 - 1) + f64::from(max_dy)).ceil() + 2.0;+ let canvas = field.bounds;+ let src_rect = Rect::new(+ x0.max(f64::from(canvas.x0)).min(f64::from(canvas.x1)) as i32,+ y0.max(f64::from(canvas.y0)).min(f64::from(canvas.y1)) as i32,+ x1.max(f64::from(canvas.x0)).min(f64::from(canvas.x1)) as i32,+ y1.max(f64::from(canvas.y0)).min(f64::from(canvas.y1)) as i32,+ );+ if src_rect.is_empty() {+ return false;+ }+ let (sw, sh) = (src_rect.width() as usize, src_rect.height() as usize);+ let Some(source_len) = sw.checked_mul(sh) else { return false };+ if source_len > MAX_FULL_RES_SOURCE_PIXELS {+ return false;+ }+ if source_scratch.try_reserve(source_len.saturating_sub(source_scratch.len())).is_err() {+ return false;+ }+ source_scratch.resize(source_len, [0.0; 4]);+ src.read_rgba_into(src_rect, source_scratch);+ if !src.format().alpha {+ for pixel in source_scratch.iter_mut() {+ pixel[3] = 1.0;+ }+ }+ for pixel in source_scratch.iter_mut() {+ let alpha = pixel[3];+ pixel[0] *= alpha;+ pixel[1] *= alpha;+ pixel[2] *= alpha;+ }++ let x0 = (region.x0 - bounds.x0) as usize;+ let x1 = (region.x1 - bounds.x0) as usize;+ let y0 = (region.y0 - bounds.y0) as usize;+ let y1 = (region.y1 - bounds.y0) as usize;+ let source_at = |x: f64, y: f64| -> [f32; 4] {+ let fx = (x - 0.5).clamp(f64::from(canvas.x0), f64::from(canvas.x1 - 1));+ let fy = (y - 0.5).clamp(f64::from(canvas.y0), f64::from(canvas.y1 - 1));+ let ix = fx.floor();+ let iy = fy.floor();+ let (tx, ty) = ((fx - ix) as f32, (fy - iy) as f32);+ let sx0 = (ix as i32).clamp(src_rect.x0, src_rect.x1 - 1);+ let sy0 = (iy as i32).clamp(src_rect.y0, src_rect.y1 - 1);+ let sx1 = (sx0 + 1).min(src_rect.x1 - 1);+ let sy1 = (sy0 + 1).min(src_rect.y1 - 1);+ let at = |sx: i32, sy: i32| -> [f32; 4] {+ let ox = (sx - src_rect.x0) as usize;+ let oy = (sy - src_rect.y0) as usize;+ source_scratch.get(oy * sw + ox).copied().unwrap_or([0.0; 4])+ };+ let (a, b, c, d) = (at(sx0, sy0), at(sx1, sy0), at(sx0, sy1), at(sx1, sy1));+ std::array::from_fn(|channel| (a[channel] * (1.0 - tx) + b[channel] * tx) * (1.0 - ty) + (c[channel] * (1.0 - tx) + d[channel] * tx) * ty)+ };+ let render_rows = |first_y: usize, rows: &mut [[u8; 4]]| {+ for (offset, row) in rows.chunks_mut(width).enumerate() {+ let y = bounds.y0 + (first_y + offset) as i32;+ let Some(dest) = row.get_mut(x0..x1) else { continue };+ for (offset_x, pixel) in dest.iter_mut().enumerate() {+ let x = bounds.x0 + (x0 + offset_x) as i32;+ let p = [f64::from(x) + 0.5, f64::from(y) + 0.5];+ let d = field.sample(p[0], p[1]);+ let rgba = source_at(p[0] + d[0], p[1] + d[1]);+ *pixel = rgba.map(|v| (v.clamp(0.0, 1.0) * 255.0 + 0.5) as u8);+ }+ }+ };+ let Some(rows) = out.get_mut(y0 * width..y1 * width) else { return false };+ #[cfg(not(target_arch = "wasm32"))]+ if (x1 - x0).saturating_mul(y1 - y0) > 150_000 {+ use rayon::prelude::*;+ rows.par_chunks_mut(width).enumerate().for_each(|(offset, line)| render_rows(y0 + offset, line));+ return true;+ }+ rows.chunks_mut(width).enumerate().for_each(|(offset, line)| render_rows(y0 + offset, line));+ true+ }+/// The proxy pixel rectangle covering document rect `r`.pub fn proxy_rect(&self, r: Rect) -> [usize; 4] {let s = self.scale;@@ -955,6 +1081,34 @@ mod tests {}}+ #[test]+ fn full_resolution_preview_matches_the_unit_scale_proxy_and_partial_updates() {+ let canvas = Rect::new(0, 0, 96, 64);+ for sample_type in [SampleType::U8, SampleType::U16, SampleType::F32] {+ let source = sample(sample_type);+ let mut stroke = LiquifyStroke::new(LiquifyTool::ForwardWarp, 32.0);+ stroke.points = vec![vec![38.0, 30.0, 1.0], vec![52.0, 34.0, 0.8]];+ let mut field = LiquifyField::from_strokes(canvas, 2.0, &[stroke]);++ let proxy = ProxyImage::new(&source, canvas, 96);+ assert_eq!(proxy.scale, 1.0);+ let mut want = vec![[0; 4]; proxy.w * proxy.h];+ proxy.render(&field, [0, 0, proxy.w, proxy.h], &mut want);++ let mut got = vec![[0; 4]; proxy.w * proxy.h];+ let mut scratch = Vec::new();+ assert!(ProxyImage::render_full_resolution(&source, &field, canvas, canvas, &mut got, &mut scratch));+ assert_eq!(got, want, "full-resolution render at {sample_type:?}");++ let mut more = LiquifyStroke::new(LiquifyTool::Bloat, 16.0);+ more.points = vec![vec![43.0, 32.0, 1.0]];+ let dirty = field.apply_stroke(&more);+ proxy.render(&field, proxy.proxy_rect(dirty), &mut want);+ assert!(ProxyImage::render_full_resolution(&source, &field, canvas, dirty, &mut got, &mut scratch));+ assert_eq!(got, want, "partial update at {sample_type:?}");+ }+ }+#[test]fn forward_warp_displaces_along_the_stroke_and_reconstruct_restores() {let mut s = LiquifyStroke::new(LiquifyTool::ForwardWarp, 40.0);diff --git a/crates/ui-egui/examples/perf_scenarios.rs b/crates/ui-egui/examples/perf_scenarios.rsindex 0a2558d7b..1b7125847 100644--- a/crates/ui-egui/examples/perf_scenarios.rs+++ b/crates/ui-egui/examples/perf_scenarios.rs@@ -16,7 +16,11 @@use std::time::Instant;use eframe::egui_wgpu::RenderState;+use photocraft_algo::liquify::{LiquifyField, LiquifyStroke, LiquifyTool, ProxyImage, auto_cell};+use photocraft_color::{ColorMode, PixelFormat, SampleType};use photocraft_engine::Session;+use photocraft_geom::Rect;+use photocraft_raster::Surface;use photocraft_testkit::perf::{RssSampler, report, row, write_report};use photocraft_ui_egui::gpu_canvas::GpuCanvas;use serde_json::{Value, json};@@ -861,6 +865,7 @@ fn algorithm_scenarios(b: &mut Bench, sz: &Sizes) {Err(e) => b.errors.push((names[0].into(), e)),}}+ liquify_preview_scenario(b);let cmyk = "brush dab on A4 300 ppi CMYK + refresh";if b.wanted(cmyk) {let (w, h) = sz.a4;@@ -923,3 +928,74 @@ fn algorithm_scenarios(b: &mut Bench, sz: &Sizes) {});}}++/// A source-resolution Liquify brush update on the visible part of a 3500×2200 layer.+/// Reports the old whole-document proxy cost alongside the full-resolution cropped update.+fn liquify_preview_scenario(b: &mut Bench) {+ let name = "Liquify 800 px brush on 3500x2200 at full resolution";+ if !b.wanted(name) {+ return;+ }+ let canvas = Rect::new(0, 0, 3500, 2200);+ let view = Rect::new(1150, 700, 2350, 1500);+ let source = Surface::with_default(PixelFormat::new(ColorMode::Rgb, SampleType::U8, true), &[0.32, 0.48, 0.64, 1.0]);+ let proxy = ProxyImage::new(&source, canvas, 1600);+ let mut low_out = vec![[0u8; 4]; proxy.w * proxy.h];+ let (vw, vh) = (view.width() as usize, view.height() as usize);+ let mut full_out = vec![[0u8; 4]; vw * vh];+ let mut source_scratch = Vec::new();+ let mut stroke = LiquifyStroke::new(LiquifyTool::ForwardWarp, 800.0);+ stroke.density = 100.0;+ stroke.points = vec![vec![1470.0, 1100.0, 1.0], vec![1530.0, 1100.0, 1.0]];+ let base = LiquifyField::new(canvas, auto_cell(canvas));+ let update = |field: &mut LiquifyField, out: &mut [[u8; 4]], scratch: &mut Vec<[f32; 4]>, full_res: bool| -> Res<f64> {+ let t = Instant::now();+ let dirty = field.stroke_segment(&stroke, [1470.0, 1100.0, 1.0], [1530.0, 1100.0, 1.0]);+ let ok = if full_res {+ ProxyImage::render_full_resolution(&source, field, view, dirty, out, scratch)+ } else {+ proxy.render(field, proxy.proxy_rect(dirty), out);+ true+ };+ if !ok {+ return Err("full-resolution preview could not allocate or render its visible region".into());+ }+ Ok(ms(t))+ };++ // Warm both paths, then compare identical field updates. The old renderer shades a downsampled+ // proxy; the new one produces one source pixel per preview texel at 100% zoom.+ let mut warm_low = base.clone();+ let _ = update(&mut warm_low, &mut low_out, &mut source_scratch, false);+ let mut warm_full = base.clone();+ let warm = update(&mut warm_full, &mut full_out, &mut source_scratch, true);+ if let Err(e) = warm {+ return b.errors.push((name.into(), e));+ }++ let mut low_samples = Vec::new();+ let mut samples = Vec::new();+ b.current = Some(name.into());+ b.sampler.reset();+ for _ in 0..b.reps.clamp(1, 5) {+ let mut field = base.clone();+ match update(&mut field, &mut low_out, &mut source_scratch, false) {+ Ok(t) => low_samples.push(t),+ Err(e) => return b.errors.push((name.into(), e)),+ }+ let mut field = base.clone();+ match update(&mut field, &mut full_out, &mut source_scratch, true) {+ Ok(t) => samples.push(t),+ Err(e) => return b.errors.push((name.into(), e)),+ }+ }+ let low_sorted = {+ let mut v = low_samples.clone();+ v.sort_by(f64::total_cmp);+ v+ };+ if let Some(median) = low_sorted.get(low_sorted.len() / 2) {+ println!(" existing 1600 px proxy update p50 {median:.2} ms (lower-resolution output)");+ }+ b.record(name, &Session::new(), &samples, Ok(()));+}diff --git a/crates/ui-egui/src/liquify_ui.rs b/crates/ui-egui/src/liquify_ui.rsindex f1b13fe4c..3e3a33e8a 100644--- a/crates/ui-egui/src/liquify_ui.rs+++ b/crates/ui-egui/src/liquify_ui.rs@@ -12,6 +12,7 @@ use egui::{Align2, Color32, FontId, Pos2, Rect as ERect, Sense, Stroke, TextureHuse photocraft_algo::liquify::{LiquifyField, LiquifyStroke, LiquifyTool, ProxyImage, auto_cell};use photocraft_doc::LayerId;use photocraft_geom::Rect;+use photocraft_raster::Surface;use serde_json::{Value, json};use crate::PhotocraftApp;@@ -21,6 +22,7 @@ use crate::widgets;/// Longest side of the preview proxy (px).const PROXY_SIDE: usize = 1600;+const MAX_VIEW_PREVIEW_PIXELS: usize = 8 * 1024 * 1024;const LEFT_W: f32 = 48.0;const RIGHT_W: f32 = 292.0;const REDO_STACK_LIMIT: usize = 100;@@ -130,10 +132,17 @@ pub struct LiquifyDialog {/// The lasso polygon being drawn (document px) and whether it thaws (Alt held at pointer-down).lasso: Option<(bool, Vec<[f64; 2]>)>,proxy: ProxyImage,+ source: Surface,out: Vec<[u8; 4]>,tex: Option<TextureHandle>,/// Proxy pixels to re-render and upload (x0, y0, x1, y1).dirty: Option<[usize; 4]>,+ /// Document-pixel preview used above 100% zoom.+ view_bounds: Option<Rect>,+ view_out: Vec<[u8; 4]>,+ view_source_scratch: Vec<[f32; 4]>,+ view_tex: Option<TextureHandle>,+ view_dirty: Option<Rect>,backdrop: Option<TextureHandle>,mask_tex: Option<TextureHandle>,mask_dirty: bool,@@ -145,6 +154,8 @@ pub struct LiquifyDialog {last_dab: f64,/// Last dab + proxy update time (ms), shown in the footer.pub dab_ms: f64,+ /// CPU time spent refreshing the zoomed-in source-resolution preview.+ pub preview_ms: f64,}fn union(a: Option<[usize; 4]>, b: [usize; 4]) -> Option<[usize; 4]> {@@ -157,6 +168,16 @@ fn union(a: Option<[usize; 4]>, b: [usize; 4]) -> Option<[usize; 4]> {})}+fn union_rect(a: Option<Rect>, b: Rect) -> Option<Rect> {+ if b.is_empty() {+ return a;+ }+ Some(match a {+ Some(a) => Rect::new(a.x0.min(b.x0), a.y0.min(b.y0), a.x1.max(b.x1), a.y1.max(b.y1)),+ None => b,+ })+}+impl LiquifyDialog {pub fn describe(&self) -> Value {json!({@@ -169,6 +190,8 @@ impl LiquifyDialog {"maxDisplacement": self.field.max_displacement(),"proxy": [self.proxy.w, self.proxy.h],"dabMs": self.dab_ms,+ "fullResolutionPreview": self.view_bounds.is_some(),+ "previewMs": self.preview_ms,})}@@ -190,6 +213,7 @@ impl LiquifyDialog {return;}self.dirty = union(self.dirty, self.proxy.proxy_rect(doc_rect));+ self.view_dirty = union_rect(self.view_dirty, doc_rect);self.mask_dirty |= mask;}@@ -302,6 +326,87 @@ impl LiquifyDialog {}}+ /// Builds or updates the visible source-resolution viewport. At ordinary zoom the whole-layer+ /// proxy remains cheaper; above 100%, a full-resolution crop is enough to fill the preview.+ fn update_view_preview(&mut self, ctx: &egui::Context, area: ERect) {+ if self.zoom <= 1.0 {+ return;+ }+ let half_w = f64::from(area.width() / self.zoom) * 0.5;+ let half_h = f64::from(area.height() / self.zoom) * 0.5;+ let clamp_x = |x: f64| x.max(f64::from(self.canvas.x0)).min(f64::from(self.canvas.x1)) as i32;+ let clamp_y = |y: f64| y.max(f64::from(self.canvas.y0)).min(f64::from(self.canvas.y1)) as i32;+ let bounds = Rect::new(+ clamp_x((self.center[0] - half_w).floor()),+ clamp_y((self.center[1] - half_h).floor()),+ clamp_x((self.center[0] + half_w).ceil()),+ clamp_y((self.center[1] + half_h).ceil()),+ );+ if bounds.is_empty() {+ self.view_bounds = None;+ self.view_tex = None;+ self.view_dirty = None;+ return;+ }+ let (w, h) = (bounds.width() as usize, bounds.height() as usize);+ let Some(len) = w.checked_mul(h).filter(|n| *n <= MAX_VIEW_PREVIEW_PIXELS) else {+ self.view_bounds = None;+ self.view_tex = None;+ self.view_dirty = None;+ return;+ };+ if self.view_bounds != Some(bounds) || self.view_out.len() != len {+ if self.view_out.try_reserve(len.saturating_sub(self.view_out.len())).is_err() {+ self.view_bounds = None;+ self.view_tex = None;+ self.view_dirty = None;+ return;+ }+ self.view_out.resize(len, [0; 4]);+ self.view_bounds = Some(bounds);+ self.view_tex = None;+ self.view_dirty = Some(bounds);+ }+ let Some(dirty) = self.view_dirty.take().map(|r| r.intersect(&bounds)) else { return };+ if dirty.is_empty() {+ return;+ }+ let started = crate::gpu_canvas::now_ms();+ let rendered = ProxyImage::render_full_resolution(&self.source, &self.field, bounds, dirty, &mut self.view_out, &mut self.view_source_scratch);+ if !rendered {+ self.view_bounds = None;+ self.view_tex = None;+ self.preview_ms = crate::gpu_canvas::now_ms() - started;+ return;+ }+ let x0 = (dirty.x0 - bounds.x0) as usize;+ let y0 = (dirty.y0 - bounds.y0) as usize;+ let x1 = (dirty.x1 - bounds.x0) as usize;+ let y1 = (dirty.y1 - bounds.y0) as usize;+ let mut pixels = Vec::with_capacity((x1 - x0) * (y1 - y0));+ for y in y0..y1 {+ if let Some(row) = self.view_out.get(y * w + x0..y * w + x1) {+ pixels.extend(row.iter().map(|p| Color32::from_rgba_premultiplied(p[0], p[1], p[2], p[3])));+ }+ }+ let image = egui::ColorImage::new([x1 - x0, y1 - y0], pixels);+ match &mut self.view_tex {+ Some(tex) => tex.set_partial([x0, y0], image, egui::TextureOptions::NEAREST),+ None => {+ // A new viewport always starts dirty over its full bounds.+ self.view_tex = Some(ctx.load_texture(+ "liquify-detail",+ {+ let pixels = self.view_out.iter().map(|p| Color32::from_rgba_premultiplied(p[0], p[1], p[2], p[3])).collect();+ egui::ColorImage::new([w, h], pixels)+ },+ egui::TextureOptions::NEAREST,+ ));+ }+ }+ self.preview_ms = crate::gpu_canvas::now_ms() - started;+ }+fn upload(&mut self, ctx: &egui::Context) {let (w, h) = (self.proxy.w, self.proxy.h);match (&mut self.tex, self.dirty.take()) {@@ -358,9 +463,15 @@ pub fn open(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), String>cur: None,lasso: None,proxy,+ source: surf,out,tex: None,dirty: None,+ view_bounds: None,+ view_out: Vec::new(),+ view_source_scratch: Vec::new(),+ view_tex: None,+ view_dirty: None,backdrop: None,mask_tex: None,mask_dirty: true,@@ -370,6 +481,7 @@ pub fn open(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), String>hover: None,last_dab: 0.0,dab_ms: 0.0,+ preview_ms: 0.0,};// A sensible starting brush (about a tenth of the image), then the settings last used, so// Liquify opens as it was left (#418). Saved values are clamped; a bad one is skipped.@@ -682,9 +794,15 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {}widgets::hairline(ui);ui.label(- egui::RichText::new(format!("{} stroke(s) · field {} px/node · dab {:.2} ms", d.strokes.len(), d.cell, d.dab_ms))- .color(t.text_faint)- .size(11.0),+ egui::RichText::new(format!(+ "{} stroke(s) · field {} px/node · dab {:.2} ms · preview {:.2} ms",+ d.strokes.len(),+ d.cell,+ d.dab_ms,+ d.preview_ms+ ))+ .color(t.text_faint)+ .size(11.0),);});// Footer buttons.@@ -715,14 +833,13 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {&& let Some(hp) = resp.hover_pos(){let before = to_doc(d, area, hp);- // Liquify's own preview zoom, not the canvas (`zoom_levels` doesn't apply): the- // preview is a proxy of at most PROXY_SIDE px, so past 3200 % it would only magnify- // proxy pixels further.+ // Liquify's own preview zoom, not the canvas (`zoom_levels` doesn't apply).d.zoom = (d.zoom * (scroll / 200.0).exp()).clamp(0.01, 32.0);let after = to_doc(d, area, hp);d.center = [d.center[0] + before[0] - after[0], d.center[1] + before[1] - after[1]];}}+ d.update_view_preview(ctx, area);let img = ERect::from_min_max(to_screen(d, area, [f64::from(d.canvas.x0), f64::from(d.canvas.y0)]),to_screen(d, area, [f64::from(d.canvas.x1), f64::from(d.canvas.y1)]),@@ -735,11 +852,23 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {{clip.image(b.id(), img, uv, Color32::from_white_alpha((d.opts.backdrop_opacity / 100.0 * 255.0) as u8));}- // The proxy covers whole proxy pixels, a little past the canvas edge.- let pr =- ERect::from_min_max(img.min, img.min + vec2(d.proxy.w as f32 * d.proxy.scale as f32 * d.zoom, d.proxy.h as f32 * d.proxy.scale as f32 * d.zoom));- if let Some(tex) = &d.tex {- clip.image(tex.id(), pr, uv, Color32::WHITE);+ if d.zoom > 1.0+ && let (Some(bounds), Some(tex)) = (d.view_bounds, &d.view_tex)+ {+ let detail = ERect::from_min_max(+ to_screen(d, area, [f64::from(bounds.x0), f64::from(bounds.y0)]),+ to_screen(d, area, [f64::from(bounds.x1), f64::from(bounds.y1)]),+ );+ clip.image(tex.id(), detail, uv, Color32::WHITE);+ } else {+ // The proxy covers whole proxy pixels, a little past the canvas edge.+ let pr = ERect::from_min_max(+ img.min,+ img.min + vec2(d.proxy.w as f32 * d.proxy.scale as f32 * d.zoom, d.proxy.h as f32 * d.proxy.scale as f32 * d.zoom),+ );+ if let Some(tex) = &d.tex {+ clip.image(tex.id(), pr, uv, Color32::WHITE);+ }}if d.opts.show_mask&& let Some(m) = &d.mask_tex@@ -901,6 +1030,30 @@ mod tests {app}+ #[test]+ fn zoomed_liquify_preview_uses_only_the_visible_full_resolution_crop() {+ let ctx = egui::Context::default();+ let mut app = app_with_layer();+ open(&mut app, &ctx).unwrap();+ let d = app.distort.liquify.as_mut().unwrap();+ d.zoom = 2.0;+ d.center = [60.0, 40.0];+ d.update_view_preview(&ctx, ERect::from_min_size(pos2(0.0, 0.0), vec2(60.0, 40.0)));+ assert_eq!(d.view_bounds, Some(Rect::new(45, 30, 75, 50)));+ assert_eq!(d.view_out.len(), 30 * 20, "one preview texel per document pixel");+ assert!(d.view_tex.is_some());++ let before = d.view_out.clone();+ let mut stroke = LiquifyStroke::new(LiquifyTool::ForwardWarp, 24.0);+ stroke.points = vec![vec![50.0, 40.0, 1.0], vec![58.0, 40.0, 1.0]];+ let dirty = d.field.stroke_segment(&stroke, [50.0, 40.0, 1.0], [58.0, 40.0, 1.0]);+ d.mark(dirty, false);+ d.render_dirty();+ d.update_view_preview(&ctx, ERect::from_min_size(pos2(0.0, 0.0), vec2(60.0, 40.0)));+ assert_ne!(d.view_out, before, "a brush update refreshes the visible source-resolution crop");+ assert!(d.preview_ms.is_finite());+ }+/// #418: the brush settings survive Cancel, OK and Esc, and come back the next time Liquify/// opens (also after a restart: they live in the preferences).#[test]diff --git a/docs/scorecard.md b/docs/scorecard.mdindex 363583723..a1e456fbd 100644--- a/docs/scorecard.md+++ b/docs/scorecard.md@@ -6,7 +6,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js| Area | Done | Partial | Missing | Key numbers ||---|---:|---:|---:|---|-| [Performance](#performance) | 3 | 22 | 22 | 56 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 16 not run, 6 not measurable yet (baseline 2026-10-05) |+| [Performance](#performance) | 3 | 22 | 22 | 56 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 17 not run, 5 not measurable yet (baseline 2026-10-05) || [File compatibility](#file-compatibility) | 5 | 11 | 11 | io corpus: oracle ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 236/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 133/256, round trip ≥ 258/256 || [Tools](#tools) | 21 | 17 | 4 | || [Workspace and UI](#workspace-and-ui) | 6 | 7 | 10 | settings that do nothing: 37 of 152 (target 0) |@@ -53,6 +53,7 @@ Baseline: 2026-10-05, commit `f5d2bcb54a`, Apple M4 Pro (48 GB), GPU Apple M4 Pr| P27 | Select › Modify › Feather on 24 MP (radius 50) | ≤ 100 ms p95 | 122 | 357 | 360 | 1.1 GB | – | over budget (target not met yet) | [#211](https://github.com/storytold/photocraft/issues/211) || P28 | Content-Aware Scale 24 MP (to 90 % width) | ≤ 3000 ms p95 | 954192 | 954192 | 954192 | 2.1 GB | – | over budget (target not met yet) | [#211](https://github.com/storytold/photocraft/issues/211) || P29 | Select Subject on 24 MP, repeated | ≤ 100 ms p95 | 559 | 693 | 693 | 1.4 GB | – | over budget (target not met yet) | [#211](https://github.com/storytold/photocraft/issues/211) |+| P30 | Liquify 800 px brush on 3500×2200 at full resolution | ≤ 1 ms per update | – | – | – | – | – | not run | [#211](https://github.com/storytold/photocraft/issues/211) || P31 | Camera Raw exposure change (proxy) | ≤ 10 ms | – | – | – | – | – | not run | [#211](https://github.com/storytold/photocraft/issues/211) || P32 | Brush release on a long stroke | ≤ 16 ms (no hitch at mouse-up) | – | – | – | – | – | not run | [#211](https://github.com/storytold/photocraft/issues/211) || P33 | Brush dab on A4 300 ppi CMYK (dab to screen) | ≤ 6 ms p95 | 34.7 | 235 | 235 | 775 MB | 87 MB | over budget (target not met yet) | [#211](https://github.com/storytold/photocraft/issues/211) |@@ -82,7 +83,6 @@ Baseline: 2026-10-05, commit `f5d2bcb54a`, Apple M4 Pro (48 GB), GPU Apple M4 Pr| P15 | Zoom / pan frame time on a 15000×10000 16-bit document | ≤ 16 ms per frame | no headless canvas frame harness yet (zoom and pan sample the GPU texture in the egui paint callback) | [#209](https://github.com/storytold/photocraft/issues/209) || P20 | Open a 2 GB PSD / 4–5 GB PSB | opens with progress, editable, never blank | opens run in the background with progress (#210), but there are no generated large-file fixtures yet (#216) | [#210](https://github.com/storytold/photocraft/issues/210) || P23 | Warp / Puppet / Perspective preview at 4K | ≤ 16 ms per frame, commit in the background | the previews run inside the UI tools; no headless frame harness, no background commit | [#210](https://github.com/storytold/photocraft/issues/210) |-| P30 | Liquify 800 px brush on 3500×2200 at full resolution | ≤ 1 ms per update | the Liquify proxy is capped at 1600 px and the stroke path lives in the UI tool | [#211](https://github.com/storytold/photocraft/issues/211) || P34 | Brush preview memory, small dab on an 8K viewport | ≤ 2 MiB | the live brush preview buffers are UI-side; no headless counter yet | [#211](https://github.com/storytold/photocraft/issues/211) || P35 | Marquee drag on 24 MP with Alt/Shift | ≤ 17 ms p95 | Shift/Alt marquee modifiers don't exist yet (#208) and the drag preview is UI-side | [#211](https://github.com/storytold/photocraft/issues/211) |diff --git a/docs/target-app-parity.md b/docs/target-app-parity.mdindex 5f1430699..023ac15ee 100644--- a/docs/target-app-parity.md+++ b/docs/target-app-parity.md@@ -435,7 +435,7 @@ filled bar. This extends UI reachability and does not claim Photoshop-authored s| Painting | Brush model and Brush Settings panel near Photoshop; .abr/.grd import; persistent presets; pen pressure/tilt on Windows, web, macOS and X11 | medium | Native Wayland pen input open (#79; a pen opens the window through Xwayland meanwhile); X11 pressure confirmed by a user, macOS not yet verified on tablet hardware. || Text / typography | Engine works; caret placement and size editing fixed; OpenType features, text-on-path editing, composer parity partial | medium-low | Measure with the Photoshop-authored set. || Colour management | Colour-managed canvas (document → monitor), embedded CMYK profiles, linear EXR/HDR, 16-bit float canvas | medium-high | Monitor profile follows only at launch. |-| Performance | 14k+ px on the GPU at ~⅓ the memory; adjustment preview 285 ms → 4–9 ms; font-size edits 297 ms → 4.6 ms; 2026-10-07: 30 MP TIFF open (banded, parallel strip/tile decode) Deflate 345 → 32 ms, LZW 428 → 43 ms, BigTIFF and every IFD readable; 2026-10-09: 4.2 MP Indexed Color, 256 colours, full-resolution CPU preview p50 3018 → 1061 ms (Ryzen AI 7 350, three measured runs; GPU upload excluded) | medium-high on rasters | Complex layout documents still laggy (#125/#128); >16384 px GPU tiling in progress (#49). Native Indexed Color previews run on one background worker with stale-result rejection; large palettes can still take about a second to compute. Web previews remain synchronous. |+| Performance | 14k+ px on the GPU at ~⅓ the memory; adjustment preview 285 ms → 4–9 ms; font-size edits 297 ms → 4.6 ms; 2026-10-07: 30 MP TIFF open (banded, parallel strip/tile decode) Deflate 345 → 32 ms, LZW 428 → 43 ms, BigTIFF and every IFD readable; 2026-10-09: 4.2 MP Indexed Color, 256 colours, full-resolution CPU preview p50 3018 → 1061 ms (Ryzen AI 7 350, three measured runs; GPU upload excluded); 2026-10-10: Liquify 3500×2200, 800 px brush, visible 1:1 crop 3.20 → 3.63 ms p50 (5 runs) while refreshing ~9× as many pixels | medium-high on rasters | Complex layout documents still laggy (#125/#128); >16384 px GPU tiling in progress (#49). Liquify now displays source-resolution detail above 100% zoom; its ≤1 ms update target is not met (3.73 ms p95 on a Windows run; GPU upload excluded). Native Indexed Color previews run on one background worker with stale-result rejection; large palettes can still take about a second to compute. Web previews remain synchronous. || Stability | Never-crash lint series, crash guard, `panic_hunt` fuzzing in the gate | medium-high | No field crash data yet. || Camera RAW | DNG, CR2, Sony ARW (lossless + compressed), Nikon NEF (lossless + lossy compressed), RW2, uncompressed ORF; 2026-10-09: uncompressed Fujifilm RAF, Bayer and X-Trans (edge-directed X-Trans demosaic; 26 MP X-Trans develop 306 ms on 12 cores) | medium | CR3, compressed RAF, Nikon "lossy after split" and calibrated colour for non-DNG cameras (no Fuji colour calibration: neutral fallback) still open (#50). || AI / generative | none | ~0% | Deferred by decision (#41). |diff --git a/perf/budgets.toml b/perf/budgets.tomlindex 2747ac1bc..d91bc9f8a 100644--- a/perf/budgets.toml+++ b/perf/budgets.toml@@ -358,7 +358,10 @@ id = "P30"title = "Liquify 800 px brush on 3500×2200 at full resolution"issue = 211target = "≤ 1 ms per update"-not_measurable = "the Liquify proxy is capped at 1600 px and the stroke path lives in the UI tool"+bench = "perf_scenarios"+row = "Liquify 800 px brush on 3500x2200 at full resolution"+budget_ms = 1+enforce = false # visible source-resolution rendering is measurable; target remains aspirational[[scenario]]id = "P31"