diff --git a/apps/photocraft/src/main.rs b/apps/photocraft/src/main.rs index 265f977697..a75915d270 100644 --- a/apps/photocraft/src/main.rs +++ b/apps/photocraft/src/main.rs @@ -703,7 +703,7 @@ fn main() -> eframe::Result { let session = Session::new(); // Before the first pass: the one install of the craft runtime must see every pass from // the first (R71); the app then runs on that context. - PhotocraftApp::setup_window(&cc.egui_ctx, Default::default(), decision); + PhotocraftApp::setup_window(&cc.egui_ctx, Default::default(), decision, services::config_dir().as_deref()); let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), session, services); app.open_suite(&cc.egui_ctx); app.min_frame_ms = uncapped.then_some(1000.0 / 240.0); diff --git a/crates/ui-egui/src/app/framework.rs b/crates/ui-egui/src/app/framework.rs index d6cd27967d..bfa6c349ae 100644 --- a/crates/ui-egui/src/app/framework.rs +++ b/crates/ui-egui/src/app/framework.rs @@ -45,10 +45,26 @@ use crate::i18n; use crate::state::Tool; use crate::theme::AppTheme; -/// Installs the runtime on `ctx` with `fonts` and the root window's decided `frame` (`None` where -/// the platform decides none), unless it is there already (`setup_window` again for the same -/// context). Only `theme::install_runtime` calls it. -pub(crate) fn install(ctx: &egui::Context, fonts: &UiFonts<'_>, frame: Option) { +/// The store the dialogs that open their own window (RAW Develop, Vanishing Point) keep their size and place in: +/// `window.json` in the settings folder `settings`. Without a settings folder (tests, the web) there is none, and those +/// windows open at their default size each time. +pub(crate) fn placement_store(settings: Option<&std::path::Path>) -> Option>> { + #[cfg(not(target_arch = "wasm32"))] + { + settings.map(|dir| Arc::new(Mutex::new(craft::window::restore::Store::at(&dir.join(craft::window::restore::FILE_NAME))))) + } + #[cfg(target_arch = "wasm32")] + { + let _ = settings; + None + } +} + +/// Installs the runtime on `ctx` with `fonts`, the root window's decided `frame` (`None` where +/// the platform decides none) and the window placement store of the settings folder `settings` +/// ([`placement_store`]), unless it is there already (`setup_window` again for the same context). +/// Only `theme::install_runtime` calls it. +pub(crate) fn install(ctx: &egui::Context, fonts: &UiFonts<'_>, frame: Option, settings: Option<&std::path::Path>) { // The wheel zooms with the canvas's own keys and scrolls sideways with Shift or Command, as // PhotoCraft's input always has. let wheel = WheelModifiers::new(egui::Modifiers::NONE, egui::Modifiers::SHIFT | egui::Modifiers::COMMAND); @@ -60,6 +76,10 @@ pub(crate) fn install(ctx: &egui::Context, fonts: &UiFonts<'_>, frame: Option egui::FullOutput { let ctx = app.ctx().clone(); - install(&ctx, &UiFonts::new(&craft::ui::fonts::I18nScripts), None); + install(&ctx, &UiFonts::new(&craft::ui::fonts::I18nScripts), None, None); ctx.run_ui(input, |ui| embed::logic(ui.ctx(), || crate::discard_ui::close_decision(app))) } @@ -864,6 +884,26 @@ pub(crate) fn keys_pass(app: &mut PhotocraftApp, ctx: &egui::Context, input: egu mod tests { use super::*; + /// The dialogs' own windows keep their place in the settings folder's `window.json` and find it there on the next + /// launch; without a settings folder nothing is kept (#17012). + #[test] + fn dialog_windows_keep_their_placement_in_the_settings_folder() { + use craft::window::restore::FILE_NAME; + let dir = tempfile::tempdir().unwrap(); + let key = "craft_imaging.raw_develop.window"; + let placement = craft::behavior::placement::Placement::new([1400.0, 900.0], 1.25); + let store = placement_store(Some(dir.path())).expect("a settings folder has a placement store"); + { + let mut store = store.lock().unwrap(); + store.set(key, &placement); + store.save().unwrap(); + } + assert!(dir.path().join(FILE_NAME).is_file()); + let reopened = placement_store(Some(dir.path())).unwrap(); + assert_eq!(reopened.lock().unwrap().get(key).map(|p| p.normal.size), Some([1400.0, 900.0]), "the next launch reads it"); + assert!(placement_store(None).is_none()); + } + fn table(n: i64) -> toml::Table { let mut t = toml::Table::new(); t.insert("n".into(), toml::Value::Integer(n)); diff --git a/crates/ui-egui/src/app/prefs.rs b/crates/ui-egui/src/app/prefs.rs index 264e3af91a..ef4e331070 100644 --- a/crates/ui-egui/src/app/prefs.rs +++ b/crates/ui-egui/src/app/prefs.rs @@ -70,19 +70,20 @@ impl PhotocraftApp { /// (and again for a replacement Context) before the first `run_ui` so the very first frame /// renders; otherwise `logic` does it and the first frame is skipped. pub fn setup_context(ctx: &egui::Context, theme: theme::AppTheme) { - Self::setup(ctx, theme, None); + Self::setup(ctx, theme, None, None); } /// [`setup_context`](Self::setup_context) for a window whose frame the platform decided - /// (`decision`): the runtime installs the frame's look with the fonts. - pub fn setup_window(ctx: &egui::Context, theme: theme::AppTheme, decision: craft::window::policy::Decision) { - Self::setup(ctx, theme, Some(decision)); + /// (`decision`): the runtime installs the frame's look with the fonts, and the dialogs that + /// open their own window keep their size and place in the settings folder `settings`. + pub fn setup_window(ctx: &egui::Context, theme: theme::AppTheme, decision: craft::window::policy::Decision, settings: Option<&std::path::Path>) { + Self::setup(ctx, theme, Some(decision), settings); } /// The one setup both entry points run. - fn setup(ctx: &egui::Context, theme: theme::AppTheme, frame: Option) { + fn setup(ctx: &egui::Context, theme: theme::AppTheme, frame: Option, settings: Option<&std::path::Path>) { crate::icons::register(); - theme::install_runtime(ctx, frame); + theme::install_runtime(ctx, frame, settings); egui_extras::install_image_loaders(ctx); theme::apply(ctx, &theme); // egui's own ⌘+ / ⌘- / ⌘0 scale the whole interface; PhotoCraft zooms the canvas instead diff --git a/crates/ui-egui/src/canvas/document_window_title_tests.rs b/crates/ui-egui/src/canvas/document_window_title_tests.rs index 67ab197a56..acd4edb0b2 100644 --- a/crates/ui-egui/src/canvas/document_window_title_tests.rs +++ b/crates/ui-egui/src/canvas/document_window_title_tests.rs @@ -102,7 +102,7 @@ fn desktop() -> (Harness<'static, App>, Rc>) { let frame = Frame::Integrated(Captions { family: CaptionFamily::Windows, layout: craft::window::Layout::default() }); let desktop = Desktop { kind: DesktopKind::Other, ssd: None, gtk_theme: None, icon_theme: None }; let decision = Decision { frame, overridden: None, desktop }; - PhotocraftApp::setup_window(&cc.egui_ctx, crate::theme::AppTheme::pro(), decision); + PhotocraftApp::setup_window(&cc.egui_ctx, crate::theme::AppTheme::pro(), decision, None); cc.egui_ctx.set_embed_viewports(false); let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), photocraft_engine::Session::new(), crate::Services::default()); app.background_jobs = false; diff --git a/crates/ui-egui/src/dialogs/camera_raw_detail_ui.rs b/crates/ui-egui/src/dialogs/camera_raw_detail_ui.rs index 7ac61692ed..8d19d52535 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_detail_ui.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_detail_ui.rs @@ -1,5 +1,7 @@ //! Full-resolution refinement of Camera Raw's interactive proxy. Native work is off the -//! UI thread; only one revision runs at a time, and obsolete results never replace new edits. +//! UI thread; only one develop runs at a time, and obsolete results never replace new edits. +//! The source asks for the develop it wants ([`DetailPreview::want`]); the after picture collects +//! it each pass ([`DetailPreview::refresh`]) and shows it once it is the wanted one. use craft::imaging::raw::RawDevelopSettings as CameraRaw; use craft::imaging::scopes::ClippingMask; #[cfg(test)] @@ -9,7 +11,6 @@ use egui::{Color32, ColorImage, Context}; use photocraft_algo::camera_raw::DevelopInputs; use photocraft_geom::Rect as PixelRect; use photocraft_raster::Surface; -#[cfg(test)] use std::sync::mpsc::TryRecvError; use std::sync::{ Arc, @@ -26,6 +27,15 @@ pub(crate) enum Coverage { type DetailResult = Result<(u64, Surface), String>; +/// The develop the source last asked for: its order (the source's develop counter, which changes +/// with every settings change, unlike the request's revision) and what it runs with. +struct Wanted { + order: u64, + params: CameraRaw, + inputs: DevelopInputs, + ctx: Context, +} + pub(crate) struct DetailPreview { source: Surface, /// The open-time dialog's camera tone curve: Shadows, Highlights, Clarity, Texture and Dehaze @@ -40,7 +50,12 @@ pub(crate) struct DetailPreview { failed_revision: Option, /// The clipping mask of `result`'s area, made on first ask and kept with its revision. mask: Option<(u64, Arc)>, - /// Whether `result` is the develop of the revision [`Self::refine`] last ran for. + /// The develop of the settings in force; kept while the view needs none, so zooming back in + /// does not develop the same settings again. + wanted: Option, + /// Whether the view shows more pixels than the proxy has, so the wanted develop is shown. + active: bool, + /// Whether `result` is the wanted develop, so the after picture shows it. pub(crate) ready: bool, } @@ -63,6 +78,8 @@ impl DetailPreview { error: None, failed_revision: None, mask: None, + wanted: None, + active: false, ready: false, } } @@ -71,28 +88,67 @@ impl DetailPreview { self.pending.is_some() } - #[cfg(test)] - pub(crate) fn poll(&mut self, revision: u64) { - let Some((requested_revision, rx)) = &self.pending else { return }; - let requested_revision = *requested_revision; + /// Asks for the develop `order` of `params`: it starts once the running one is done, and the + /// after picture shows it once it lands. The same settings keep the develop already wanted: the + /// workspace asks again for every pan and zoom, and the refinement covers the whole area. + pub(crate) fn want(&mut self, ctx: &Context, order: u64, params: &CameraRaw, inputs: &DevelopInputs) { + if !self.wanted.as_ref().is_some_and(|w| w.params == *params && w.inputs == *inputs) { + self.wanted = Some(Wanted { order, params: params.clone(), inputs: *inputs, ctx: ctx.clone() }); + } + self.active = true; + self.refresh(); + } + + /// The view needs no refinement: the after picture shows the proxy, and nothing new starts. + pub(crate) fn unwant(&mut self) { + self.active = false; + self.ready = false; + } + + /// The order of the develop `result` holds, for the after picture's revision. + pub(crate) fn shown(&self) -> Option { + self.result.as_ref().filter(|_| self.ready).map(|(order, _)| *order) + } + + /// Collects a finished develop, starts the wanted one when none runs and it is not there yet, + /// and says whether the result is the wanted develop. + pub(crate) fn refresh(&mut self) { + self.poll(); + let wanted = self.wanted.as_ref().map(|w| w.order); + self.ready = self.active && wanted.is_some() && self.result.as_ref().map(|(order, _)| *order) == wanted; + if !self.active || self.ready || self.pending.is_some() { + return; + } + if let Some(Wanted { order, params, inputs, ctx }) = self.wanted.take() { + self.request(&ctx, order, ¶ms, &inputs); + self.wanted = Some(Wanted { order, params, inputs, ctx }); + } + } + + /// Takes a finished develop off the worker: kept when it is the wanted one, dropped when the + /// settings moved on while it ran. A failure of the wanted develop is reported and not retried. + fn poll(&mut self) { + let Some((requested, rx)) = &self.pending else { return }; + let requested = *requested; let result = match rx.try_recv() { Ok(result) => result, Err(TryRecvError::Empty) => return, Err(TryRecvError::Disconnected) => Err("RAW Develop detail preview worker stopped".into()), }; self.pending = None; + let wanted = self.wanted.as_ref().map(|w| w.order); match result { - Ok((r, surface)) if r == revision => { - self.result = Some((r, surface)); + Ok((order, surface)) if Some(order) == wanted => { + self.result = Some((order, surface)); self.mask = None; self.error = None; } - Ok(_) => {} // A parameter changed while the worker was developing this revision. + Ok(_) => {} // A setting changed while the worker was developing this one. Err(e) => { - if requested_revision == revision { + if Some(requested) == wanted { self.error = Some(e); } - self.failed_revision = Some(requested_revision); + self.failed_revision = Some(requested); } } } @@ -164,39 +220,19 @@ impl DetailPreview { } /// Writes the refined develop of `region` (document pixels) into `out`, one texel per `factor` - /// pixels each way, as the canvas shows it (sRGBA, premultiplied); transparent where the - /// region leaves the refined area. `false` when there is nothing to serve (not refined for the - /// current revision, or the part is larger than 16 MP), and the caller then reads the proxy. - /// Only the asked part is converted, never the whole image. + /// pixels each way, as the canvas shows it (sRGBA, premultiplied): each texel the average of its + /// block, transparent where the block leaves the refined area. `false` when the refinement is not + /// the wanted develop, and the caller then reads the proxy. Only `out`'s texels are converted, so + /// a view of the whole image at Fit is served as well as a 1:1 crop. pub(crate) fn read(&self, region: RasterRect, factor: u32, display: &photocraft_engine::display_color::CanvasDisplay, out: &mut ColorImage) -> bool { let Some((_, surface)) = self.result.as_ref().filter(|_| self.ready) else { return false }; - let want = PixelRect::new(region.x0, region.y0, region.x1, region.y1).intersect(&self.area); - if want.width() as u64 * want.height() as u64 > 16_777_216 { - return false; - } - out.pixels.fill(Color32::TRANSPARENT); - if want.is_empty() { - return true; - } - let src = crop_image(surface, want, display); - let factor = i64::from(factor.max(1)); - let (out_w, out_h) = (out.size[0], out.size[1]); - let src_w = src.size[0]; - for oy in 0..out_h { - let y = i64::from(region.y0) + oy as i64 * factor; - if y < i64::from(want.y0) || y >= i64::from(want.y1) { - continue; - } - for ox in 0..out_w { - let x = i64::from(region.x0) + ox as i64 * factor; - if x < i64::from(want.x0) || x >= i64::from(want.x1) { - continue; - } - let from = (y - i64::from(want.y0)) as usize * src_w + (x - i64::from(want.x0)) as usize; - if let (Some(o), Some(s)) = (out.pixels.get_mut(oy * out_w + ox), src.pixels.get(from)) { - *o = *s; - } - } + let [out_w, out_h] = out.size; + let area = self.area; + let image = display_image(PixelRect::new(0, 0, out_w as i32, out_h as i32), display, |texels, px| { + block_averages(surface, area, region, factor, texels, px); + }); + if image.size == out.size { + out.pixels = image.pixels; } true } @@ -336,7 +372,55 @@ fn develop(source: &Surface, curve: Option<&[[f32; 2]]>, area: PixelRect, params /// parallel threshold (16K pixels), and small enough that a band's float scratch is 1 MiB. const CROP_BAND_PIXELS: usize = 64 * 1024; -/// The visible pixels of `surface`, as the canvas shows them. +/// The texels `texels` (one per `factor` pixels each way from `region`'s origin) of `surface`'s +/// `area` into `out`, straight RGBA: each the alpha-weighted average of the pixels of its block that +/// lie in `area`, transparent where none does. Reads the area's rows once per band. +fn block_averages(surface: &Surface, area: PixelRect, region: RasterRect, factor: u32, texels: PixelRect, out: &mut [[f32; 4]]) { + let f = i64::from(factor.max(1)); + let tw = texels.width() as usize; + out.fill([0.0; 4]); + if tw == 0 { + return; + } + // Document columns of the texel row, clipped to the area. + let x0 = (i64::from(region.x0) + i64::from(texels.x0) * f).max(i64::from(area.x0)); + let x1 = (i64::from(region.x0) + i64::from(texels.x1) * f).min(i64::from(area.x1)); + if x1 <= x0 { + return; + } + let (Ok(x0), Ok(x1)) = (i32::try_from(x0), i32::try_from(x1)) else { return }; + let mut row = vec![[0.0f32; 4]; (x1 - x0) as usize]; + let mut sums = vec![[0.0f32; 5]; tw]; + for (ty, texel_row) in (texels.y0..texels.y1).zip(out.chunks_exact_mut(tw)) { + sums.fill([0.0; 5]); + let top = i64::from(region.y0) + i64::from(ty) * f; + let (y0, y1) = (top.max(i64::from(area.y0)), (top + f).min(i64::from(area.y1))); + for y in y0..y1 { + let Ok(y) = i32::try_from(y) else { continue }; + surface.read_rgba_into(PixelRect::new(x0, y, x1, y + 1), &mut row); + for (i, p) in row.iter().enumerate() { + let x = i64::from(x0) + i as i64; + let column = (x - i64::from(region.x0)) / f - i64::from(texels.x0); + if let Some(sum) = usize::try_from(column).ok().and_then(|c| sums.get_mut(c)) { + let a = p[3]; + sum[0] += p[0] * a; + sum[1] += p[1] * a; + sum[2] += p[2] * a; + sum[3] += a; + sum[4] += 1.0; + } + } + } + for (o, sum) in texel_row.iter_mut().zip(&sums) { + if sum[4] > 0.0 && sum[3] > 0.0 { + *o = [sum[0] / sum[3], sum[1] / sum[3], sum[2] / sum[3], sum[3] / sum[4]]; + } + } + } +} + +/// The visible pixels of `surface`, as the canvas shows them: the tests' whole-area reference for [`display_image`]. +#[cfg(test)] fn crop_image(surface: &Surface, area: PixelRect, display: &photocraft_engine::display_color::CanvasDisplay) -> ColorImage { display_image(area, display, |rect, out| surface.read_rgba_into(rect, out)) } @@ -453,23 +537,84 @@ mod tests { fn stale_refinements_and_failed_old_revisions_do_not_replace_new_settings() { let source = Surface::with_default(PixelFormat::RGBA8, &[0.2, 0.4, 0.6, 1.0]); let mut preview = DetailPreview::new(source.clone(), PixelRect::new(0, 0, 16, 16), Coverage::None); + preview.wanted = Some(Wanted { order: 2, params: CameraRaw::default(), inputs: inputs(), ctx: Context::default() }); + preview.active = true; let (tx, rx) = std::sync::mpsc::channel(); preview.pending = Some((1, rx)); tx.send(Ok((1, source.clone()))).unwrap(); - preview.poll(2); + preview.poll(); assert!(preview.result.is_none()); assert!(!preview.pending()); let (tx, rx) = std::sync::mpsc::channel(); preview.pending = Some((1, rx)); tx.send(Err("old failure".into())).unwrap(); - preview.poll(2); + preview.poll(); assert_eq!(preview.failed_revision, Some(1), "a failure must not suppress the new revision"); + assert!(preview.error.is_none(), "an old failure is not the wanted develop's"); let (tx, rx) = std::sync::mpsc::channel(); preview.pending = Some((2, rx)); tx.send(Ok((2, source))).unwrap(); - preview.poll(2); + preview.refresh(); assert_eq!(preview.result.as_ref().map(|(r, _)| *r), Some(2)); + assert!(preview.ready && preview.shown() == Some(2), "the wanted develop is shown"); assert!(preview.error.is_none()); + preview.unwant(); + assert!(!preview.ready && preview.shown().is_none(), "a view the proxy serves shows the proxy"); + // Zoomed in again with the same settings: the develop that landed is shown, none starts. + preview.want(&Context::default(), 9, &CameraRaw::default(), &inputs()); + assert!(preview.shown() == Some(2) && !preview.pending(), "the same settings are not developed again"); + } + + /// The refinement is collected outside tests too (#17012): asked for, it lands and is shown, and the + /// develop of newer settings replaces it. + #[test] + fn a_wanted_develop_lands_and_follows_newer_settings() { + let area = PixelRect::new(0, 0, 8, 4); + let source = Surface::with_default(PixelFormat::RGBA8, &[0.25, 0.25, 0.25, 1.0]); + let mut preview = DetailPreview::new(source, area, Coverage::None); + let ctx = Context::default(); + let wait = |preview: &mut DetailPreview, order: u64| { + for _ in 0..3000 { + preview.refresh(); + if preview.shown() == Some(order) { + return; + } + std::thread::sleep(std::time::Duration::from_millis(2)); + } + panic!("the develop {order} never landed: pending {}, error {:?}", preview.pending(), preview.error); + }; + preview.want(&ctx, 1, &exposure_only(0.0), &inputs()); + wait(&mut preview, 1); + let first = preview.result.as_ref().unwrap().1.rgba(3, 2); + // A pan asks again with the same settings: the landed develop stays shown, nothing is developed again. + preview.want(&ctx, 7, &exposure_only(0.0), &inputs()); + assert!(preview.shown() == Some(1) && !preview.pending(), "the same settings are not developed again"); + preview.want(&ctx, 2, &exposure_only(1.0), &inputs()); + assert!(!preview.ready, "the old develop is not shown for new settings"); + wait(&mut preview, 2); + let second = preview.result.as_ref().unwrap().1.rgba(3, 2); + assert!(second[0] > first[0] + 0.1, "the newer settings are developed: {second:?} after {first:?}"); + } + + /// A reduced read averages each texel's block, so a view of the whole refined image (Fit) reads it too. + #[test] + fn a_reduced_read_averages_blocks_and_leaves_the_outside_transparent() { + let area = PixelRect::new(0, 0, 4, 2); + let mut source = Surface::new(PixelFormat::RGBA8); + let values: Vec = (0..8).flat_map(|i| if i % 2 == 0 { [1.0, 1.0, 1.0, 1.0] } else { [0.0, 0.0, 0.0, 1.0] }).collect(); + source.write_region(area, &values); + let mut doc = photocraft_doc::Document::new("test", photocraft_geom::Size::new(4, 2), photocraft_doc::ColorMode::Rgb, photocraft_doc::SampleType::U8); + doc.icc_profile = Some(craft::cms::Builtin::Srgb.profile().to_bytes()); + let display = photocraft_engine::color_cmds::ColorState::default().canvas_display(&doc).unwrap(); + let mut preview = DetailPreview::new(source.clone(), area, Coverage::None); + preview.result = Some((1, source)); + preview.ready = true; + let mut out = ColorImage::new([3, 1], vec![Color32::RED; 3]); + assert!(preview.read(RasterRect::new(0, 0, 6, 2), 2, &display, &mut out)); + let grey = out.pixels[0]; + assert!(grey.r() > 110 && grey.r() < 150 && grey.a() == 255, "white and black average to mid grey: {grey:?}"); + assert_eq!(out.pixels[1], grey); + assert_eq!(out.pixels[2], Color32::TRANSPARENT, "past the refined area"); } #[test] diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui.rs b/crates/ui-egui/src/dialogs/camera_raw_ui.rs index f2f40b7020..25c8e947e6 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui.rs @@ -125,7 +125,10 @@ impl RasterSource for AfterRaster { } fn revision(&self) -> Revision { - Revision::of(&(RasterSource::revision(&*self.picture), self.detail().ready)) + // The canvas asks every pass: a refinement that landed since is collected here. + let mut detail = self.detail(); + detail.refresh(); + Revision::of(&(RasterSource::revision(&*self.picture), detail.shown())) } fn damage(&self, since: Revision) -> Option { @@ -316,12 +319,18 @@ impl RawDevelopSource for PcRawSource { } fn develop(&self, request: &RawPreviewRequest) -> Job { - if self.needs_detail(request) { - self.detail.lock().unwrap_or_else(std::sync::PoisonError::into_inner).request(&self.ctx, request.revision, &request.settings, &self.inputs); - } // The request's revision only counts source changes; the develops of one source are told apart by this order, so - // an older job that finishes after a newer one does not replace its result. + // an older job that finishes after a newer one does not replace its result, and the refinement follows the + // settings. let order = self.issued.fetch_add(1, Ordering::Relaxed) + 1; + { + let mut detail = self.detail.lock().unwrap_or_else(std::sync::PoisonError::into_inner); + if self.needs_detail(request) { + detail.want(&self.ctx, order, &request.settings, &self.inputs); + } else { + detail.unwant(); + } + } let job = self.proxy_job(&request.settings); let settings = request.settings.clone(); let picture = self.after.picture.clone(); @@ -503,7 +512,8 @@ pub(crate) fn describe(app: &PhotocraftApp) -> Value { "samples": h.samples, "transparent": h.transparent, "invalid": h.invalid, "underflow": h.underflow, "overflow": h.overflow, "shadows": h.shadows, "highlights": h.highlights}) }); - let detail = source.detail.lock().unwrap_or_else(std::sync::PoisonError::into_inner); + let mut detail = source.detail.lock().unwrap_or_else(std::sync::PoisonError::into_inner); + detail.refresh(); let mut result = json!({ "layer": session.layer.0, "params": serde_json::to_value(hosted.workspace().session()).unwrap_or(Value::Null), diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs b/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs index 63a6bf88af..9565992409 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs @@ -4,6 +4,7 @@ use craft::host::{PickKind, Picked, ScriptedFiles}; use craft::imaging::raw::RawDevelopSettings as CameraRaw; use craft::imaging::ui::raw_develop::RawDevelopWorkspace; use craft::ui::dialog::HostedWorkspace; +use egui::Color32; use photocraft_geom::Rect; use serde_json::{Value, json}; @@ -144,6 +145,59 @@ fn histogram_follows_preview_and_view_changes_do_not_render_or_edit() { assert!((pixel[0] - 128.0 / 255.0).abs() < 0.0001); } +/// Develops the open dialog's source with `settings` at 100%, as the workspace asks when its view shows more pixels than +/// the proxy has, and runs frames until the after picture shows the full-resolution develop. +fn refine_at_full_size(app: &mut PhotocraftApp, settings: CameraRaw) { + let request = RawPreviewRequest::new(1, settings, None, craft::ui::canvas::PixelRect::new(0, 0, 400, 200), 1.0); + drop(session(app).source.develop(&request)); + for _ in 0..3000 { + frame(app); + if describe(app)["previewApproximate"] == false { + return; + } + std::thread::sleep(std::time::Duration::from_millis(5)); + } + let d = describe(app); + panic!("the full-resolution preview never showed: pending {} error {}", d["detailPending"], d["detailError"]); +} + +/// The after picture's pixels of columns 8..14 of row 0 at 100%. +fn after_row(app: &PhotocraftApp) -> Vec { + let mut out = ColorImage::filled([6, 1], Color32::TRANSPARENT); + session(app).source.after().read(craft::ui::canvas::PixelRect::new(8, 0, 14, 1), 1, &mut out); + out.pixels +} + +/// A layer larger than the proxy: once the view shows more pixels than the proxy has, the visible part is developed at +/// full resolution and replaces the proxy, and newer settings are developed again (#17012). Before, nothing collected +/// the refinement, so the preview stayed the proxy scaled up: pixelated. +#[test] +fn the_full_resolution_preview_replaces_the_proxy_and_follows_the_settings() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + let ctx = app.ctx().clone(); + app.run("file.new", json!({"width": 2400, "height": 1200})).unwrap(); + app.run("layer.new.layer", json!({})).unwrap(); + app.run("edit.fill", json!({"color": "#808080"})).unwrap(); + // One black column: the proxy averages it with its grey neighbours. + app.run("select.rect", json!({"x": 10, "y": 0, "width": 1, "height": 1200})).unwrap(); + app.run("edit.fill", json!({"color": "#000000"})).unwrap(); + app.run("select.deselect", json!({})).unwrap(); + open(&mut app, &ctx).unwrap(); + settle(&mut app); + let proxy = describe(&app)["proxy"].clone(); + assert!(proxy[0].as_u64().unwrap() < 2400, "the dialog develops a proxy: {proxy}"); + refine_at_full_size(&mut app, CameraRaw::default()); + let row = after_row(&app); + assert_eq!(row[2], Color32::BLACK, "the 1-pixel column is sharp: {row:?}"); + assert_eq!(row[3], Color32::from_gray(0x80), "{row:?}"); + let mut brighter = CameraRaw::default(); + brighter.exposure = 1.0; + refine_at_full_size(&mut app, brighter); + let row = after_row(&app); + assert!(row[3].r() > 0x90, "the refinement follows the new settings: {row:?}"); + menu(&mut app, &ctx, "filter.cameraRaw", &json!({"ui": {"cancel": true}})).unwrap().unwrap(); +} + /// A layer with tonal variation, a selection over part of it and the dialog open on it. fn worker_app() -> (Box, egui::Context) { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); diff --git a/crates/ui-egui/src/panels/title_bar/tests.rs b/crates/ui-egui/src/panels/title_bar/tests.rs index 173fb778c0..de19f43351 100644 --- a/crates/ui-egui/src/panels/title_bar/tests.rs +++ b/crates/ui-egui/src/panels/title_bar/tests.rs @@ -17,7 +17,7 @@ fn integrated_app(size: egui::Vec2, pixels_per_point: f32, setup: impl FnOnce(&m let mut h = Harness::builder().with_size(size).with_pixels_per_point(pixels_per_point).with_max_steps(64).build_eframe(move |cc| { let desktop = Desktop::detect(Backend::X11); let decision = decide(Os::Windows, Runtime::Native, Backend::X11, &desktop, WindowKind::Main, TitleBarPref::Integrated, None); - PhotocraftApp::setup_window(&cc.egui_ctx, Default::default(), decision); + PhotocraftApp::setup_window(&cc.egui_ctx, Default::default(), decision, None); let mut session = photocraft_engine::Session::new(); session.edit_prefs(|p| p.general.auto_show_home_screen = false); let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), session, crate::Services::default()); diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rs index 1d1a1386c9..62d3e8be19 100644 --- a/crates/ui-egui/src/theme.rs +++ b/crates/ui-egui/src/theme.rs @@ -997,13 +997,14 @@ fn ui_fonts(ctx: &egui::Context, ui_language: &str) -> UiFonts<'static> { crate::served_fonts::append_loaded(ctx, fonts, ui_language) } -/// Installs the craft runtime on `ctx` with the font stack (see [`install_fonts`]) and the root +/// Installs the craft runtime on `ctx` with the font stack (see [`install_fonts`]), the root /// window's `frame` decision (`None` where the platform has none, as on the web; the frame is part -/// of this install, never set afterwards). It runs once, from `PhotocraftApp::setup_window` or +/// of this install, never set afterwards) and the settings folder `settings` its windows' placement +/// is saved in (`None`: not saved). It runs once, from `PhotocraftApp::setup_window` or /// `setup_context`, when the window or headless context is created. -pub fn install_runtime(ctx: &egui::Context, frame: Option) { +pub fn install_runtime(ctx: &egui::Context, frame: Option, settings: Option<&std::path::Path>) { let fonts = ui_fonts(ctx, crate::i18n::current().code()); - crate::app::framework::install(ctx, &fonts, frame); + crate::app::framework::install(ctx, &fonts, frame, settings); install_font_stack(ctx, &fonts); }