LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
LR-IMP-ADD-DIALOG: render import previews when the camera JPEG is too small
tylerphotos6b1fc20053f9
diff --git a/crates/engine/src/import/job.rs b/crates/engine/src/import/job.rsindex 25dc392de..a178035da 100644--- a/crates/engine/src/import/job.rs+++ b/crates/engine/src/import/job.rs@@ -483,7 +483,16 @@ impl Session {(Some(l), MediaKind::Raw) => Some((c.path.clone(), l.clone(), edge)),_ => None,};- Some(crate::media::QuickJob { request_id: 0, photo: id, key, cached: Vec::new(), embedded, small: Some(Box::new(small)) })+ let minimum_embedded_edge = (c.preview_only.is_none() && p.preview_only.is_none()).then_some(render_edge);+ Some(crate::media::QuickJob {+ request_id: 0,+ photo: id,+ key,+ cached: Vec::new(),+ embedded,+ minimum_embedded_edge,+ small: Some(Box::new(small)),+ })}/// Use the system clock for import/edit times (native hosts).@@ -492,3 +501,6 @@ impl Session {self}}++#[cfg(test)]+mod tests;diff --git a/crates/engine/src/import/job/tests.rs b/crates/engine/src/import/job/tests.rsnew file mode 100644index 000000000..82490915b--- /dev/null+++ b/crates/engine/src/import/job/tests.rs@@ -0,0 +1,92 @@+//! Import previews must cover the tile when possible, retaining camera JPEGs as a safe fallback.++use std::sync::{+ Arc,+ atomic::{AtomicUsize, Ordering},+};++use crate::Session;+use crate::import::ImportCandidate;+use crate::media::QuickSource;++/// Synthetic raw, bounded decoder and camera JPEG, with reads counted independently of pixels.+fn fixture(preview_edge: Option<usize>, renderable: bool, preview_only: bool) -> (Session, ImportCandidate, Arc<AtomicUsize>) {+ let mut session = Session::new();+ let reads = Arc::new(AtomicUsize::new(0));+ let count = reads.clone();+ session.media.file_loader = Some(Arc::new(move |_, edge| {+ count.fetch_add(1, Ordering::SeqCst);+ if !renderable {+ return Err("synthetic raw cannot be rendered".into());+ }+ let width = edge.min(1024);+ let height = width * 3 / 4;+ Ok((lightcraft_raster::Rgb32f { width, height, data: vec![[0.1, 0.2, 0.3]; width * height] }, Default::default()))+ }));+ session.media.preview_loader = Some(Arc::new(move |_, requested| {+ let width = preview_edge?.min(requested);+ Some(lightcraft_raster::Rgba8 { width, height: width * 3 / 4, data: vec![[30, 60, 90, 255]; width * (width * 3 / 4)] })+ }));+ let candidate = ImportCandidate {+ path: "synthetic-import.nef".into(),+ name: "synthetic-import.nef".into(),+ format: "NEF".into(),+ kind: lightcraft_catalog::MediaKind::Raw,+ width: 1024,+ height: 768,+ preview_only: preview_only.then(|| "unsupported synthetic raw variant".into()),+ ..Default::default()+ };+ (session, candidate, reads)+}++#[test]+/// A renderable raw fills the requested tile when its embedded JPEG is too small.+fn import_preview_renders_when_the_camera_jpeg_cannot_cover_the_tile() {+ let (mut session, candidate, reads) = fixture(Some(64), true, false);+ let mut job = session.candidate_thumb_job(&candidate, 768, 0).unwrap();+ job.request_id = 42;+ let key = job.key;+ let result = job.run();+ assert_eq!(result.quick, Some(QuickSource::Small));+ let image = result.rendered.unwrap().image;+ assert_eq!((image.width, image.height), (768, 576));+ assert_eq!(reads.load(Ordering::SeqCst), 1);+ assert_eq!((result.request_id, result.key), (42, key));+}++#[test]+/// A sufficient camera JPEG avoids decoding the raw, retaining the fast path.+fn import_preview_keeps_a_camera_jpeg_that_already_covers_the_tile() {+ let (mut session, candidate, reads) = fixture(Some(1024), true, false);+ let result = session.candidate_thumb_job(&candidate, 768, 0).unwrap().run();+ assert_eq!(result.quick, Some(QuickSource::Embedded));+ assert_eq!(result.rendered.unwrap().image.width, 768);+ assert_eq!(reads.load(Ordering::SeqCst), 0);+}++#[test]+/// Preview-only raws never waste a render attempt behind their available camera JPEG.+fn import_preview_only_raw_uses_the_available_camera_jpeg_without_a_render() {+ let (mut session, candidate, reads) = fixture(Some(64), false, true);+ let result = session.candidate_thumb_job(&candidate, 768, 0).unwrap().run();+ assert_eq!(result.quick, Some(QuickSource::Embedded));+ assert_eq!(result.rendered.unwrap().image.width, 64);+ assert_eq!(reads.load(Ordering::SeqCst), 0);+}++#[test]+/// A failed or absent render never discards the usable, if undersized, camera JPEG.+fn import_preview_retains_the_camera_jpeg_if_the_render_fails_or_is_absent() {+ for no_render in [false, true] {+ let (mut session, candidate, reads) = fixture(Some(64), false, false);+ let mut job = session.candidate_thumb_job(&candidate, 768, 0).unwrap();+ if no_render {+ job.small = None;+ }+ let result = job.run();+ assert_eq!(result.quick, Some(QuickSource::Embedded));+ assert_eq!(result.rendered.unwrap().image.width, 64);+ assert_eq!(reads.load(Ordering::SeqCst), usize::from(!no_render));+ }+}diff --git a/crates/engine/src/media/quick.rs b/crates/engine/src/media/quick.rsindex ca399b561..21edb2bed 100644--- a/crates/engine/src/media/quick.rs+++ b/crates/engine/src/media/quick.rs@@ -25,6 +25,10 @@ pub struct QuickJob {pub cached: Vec<(Arc<PreviewCache>, Hash128)>,/// Embedded preview of an unedited raw: (path, loader, max edge).pub embedded: Option<(String, PreviewLoader, usize)>,+ /// Import tiles need this many pixels when a render can provide them. `None` accepts any+ /// camera JPEG immediately (ordinary transient stand-ins and preview-only imports).+ /// An undersized JPEG remains the fallback if the render fails or is unavailable.+ pub minimum_embedded_edge: Option<usize>,/// Last resort: run this thumbnail job.pub small: Option<Box<RenderJob>>,}@@ -72,14 +76,23 @@ impl QuickJob {return done(rendered(Arc::unwrap_or_clone(img)), Some(QuickSource::Cached));}}+ let mut embedded_fallback = None;if let Some((path, loader, edge)) = &self.embedded&& let Some(image) = loader(path, *edge){- return done(rendered(image), Some(QuickSource::Embedded));+ if self.minimum_embedded_edge.is_none_or(|minimum| image.width.max(image.height) >= minimum) {+ return done(rendered(image), Some(QuickSource::Embedded));+ }+ embedded_fallback = Some(image);}if let Some(job) = self.small {let r = job.run();- return RenderResult { request_id, key, quick: Some(QuickSource::Small), ..r };+ if r.rendered.is_ok() || embedded_fallback.is_none() {+ return RenderResult { request_id, key, quick: Some(QuickSource::Small), ..r };+ }+ }+ if let Some(image) = embedded_fallback {+ return done(rendered(image), Some(QuickSource::Embedded));}done(Err("no quick preview".into()), None)}diff --git a/crates/engine/src/media/session.rs b/crates/engine/src/media/session.rsindex b222739fe..ea69c4907 100644--- a/crates/engine/src/media/session.rs+++ b/crates/engine/src/media/session.rs@@ -342,7 +342,7 @@ impl crate::Session {let h = Hasher128::new().str(&content_key(&p)).str("quick").u64(p.develop.hash64()).u64(apply_crop as u64).finish();let key = h.0 as u64;let embedded = self.embedded_of(&p).map(|(path, l)| (path, l, max_edge.clamp(1, SourceLevel::Preview.max_edge())));- Some(QuickJob { request_id: 0, photo: id, key, cached, embedded, small: apply_crop.then(|| Box::new(small)) })+ Some(QuickJob { request_id: 0, photo: id, key, cached, embedded, minimum_embedded_edge: None, small: apply_crop.then(|| Box::new(small)) })}/// A first grid thumbnail for an unedited raw: the cached render for `job` (the real@@ -361,6 +361,7 @@ impl crate::Session {key: job.key,cached: job.cache.clone().into_iter().collect(),embedded: Some((path, l, edge)),+ minimum_embedded_edge: None,small: Some(Box::new(job.clone())),})}diff --git a/crates/engine/src/media/thumbnail_hash_tests.rs b/crates/engine/src/media/thumbnail_hash_tests.rsindex fdbd20f80..3c23e9db9 100644--- a/crates/engine/src/media/thumbnail_hash_tests.rs+++ b/crates/engine/src/media/thumbnail_hash_tests.rs@@ -107,6 +107,7 @@ fn a_render_that_panics_fails_instead_of_never_answering() {key: 9,cached: Vec::new(),embedded: Some(("x.arw".into(), Arc::new(|_: &str, _: usize| -> Option<Rgba8> { panic!("preview reader bug") }), 256)),+ minimum_embedded_edge: None,small: None,};let r = quick.run();diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rsindex caacbc590..c32434569 100644--- a/crates/ui-egui/src/control.rs+++ b/crates/ui-egui/src/control.rs@@ -434,6 +434,9 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context, req: &ControlRequestNone => err("no dialog open"),},"ui.dialog.cancel" => {+ if matches!(app.ui.dialog, Some(crate::state::Dialog::Import { .. })) {+ app.renderer.forget_imports();+ }app.ui.dialog = None;ok(Value::Null)}diff --git a/crates/ui-egui/src/tests/import_thumbnails.rs b/crates/ui-egui/src/tests/import_thumbnails.rsindex ba670cd5e..6a1b0c104 100644--- a/crates/ui-egui/src/tests/import_thumbnails.rs+++ b/crates/ui-egui/src/tests/import_thumbnails.rs@@ -171,16 +171,16 @@ fn import_thumbnail_small_sources_do_not_rebuild_jobs_every_frame() {}}-/// Closing the real review releases large previews through both user-facing dismissal paths.+/// Closing the review releases large previews through the button, Escape and control channel.#[test]-fn import_thumbnail_close_releases_previews_for_cancel_and_escape() {- for escape in [false, true] {+fn import_thumbnail_close_releases_previews_for_all_cancel_paths() {+ for dismissal in ["button", "escape", "control"] {let mut review = Review::new(1.0);assert!(review.h.app.renderer.textures.contains_key(&Slot::Import(0)));- if escape {- review.request("ui.key", json!({"key": "Escape"}));- } else {- review.request("ui.clickWidget", json!({"id": "button:dialogCancel"}));+ match dismissal {+ "escape" => review.request("ui.key", json!({"key": "Escape"})),+ "control" => review.request("ui.dialog.cancel", json!({})),+ _ => review.request("ui.clickWidget", json!({"id": "button:dialogCancel"})),}assert!(review.h.settle(T));assert!(review.h.app.ui.dialog.is_none());diff --git a/docs/control-protocol.md b/docs/control-protocol.mdindex 129726699..22d0723b2 100644--- a/docs/control-protocol.md+++ b/docs/control-protocol.md@@ -320,7 +320,7 @@ library grid's `thumbSize`; resizing keeps the import checkboxes and duplicate mThe shared slider also exposes `sliderValue:importThumbSize` for exact entry and`sliderLabel:importThumbSize` for double-click reset to 116 pt. Up/Down nudges the selectedslider by 1 pt; Return commits typed values and Escape cancels them. Slider and command-labels, including edit/reset feedback, are localized in every shipped catalog. Previews use bounded physical-pixel buckets through 1024 px. A smaller source is tried once per bucket; scrolling releases offscreen textures, queued work and request identities.+labels, including edit/reset feedback, are localized in every shipped catalog. Previews use bounded physical-pixel buckets through 1024 px. A smaller source is tried once per bucket; scrolling releases offscreen textures, queued work and request identities. A renderable raw uses a render when its camera JPEG cannot cover the tile; preview-only raws, unavailable renders and failed renders retain the available camera JPEG.## Headless rendering (no window, no GPU)diff --git a/docs/gaps.md b/docs/gaps.mdindex d9289a63e..fc1a3abd6 100644--- a/docs/gaps.md+++ b/docs/gaps.md@@ -86,7 +86,7 @@ Beta-blocking gaps (B) total **~230–430 h**; with the stability and platform w| Date | Change | Summary ||---|---|---|-| 2026-10-29 | minor | import review: remembered thumbnail size and density-aware previews (#2237, part of #2056); pre-import loupe/keyboard culling remains open; no ranked gap closes |+| 2026-10-29 | minor | Import thumbnails render when the camera JPEG is too small, retaining preview-only/error fallbacks; import review: remembered thumbnail size and density-aware previews (#2237, part of #2056); pre-import loupe/keyboard culling remains open; no ranked gap closes || 2026-10-24 | minor | Gap 28: ⌘⌥⇧C / ⌘⌥⇧V (Ctrl+Alt+Shift+C / V on Windows and Linux) copy and paste metadata; no key leaves the entry; hours unchanged || 2026-10-24 | minor | Gap 30 shrinks: the Info panel's Show Metadata For (Target Photo / Selected Photos, `view.infoSelectedPhotos`) shows the selected photos' shared values and marks fields that differ as Mixed; the All Metadata dialog remains; 1–3 h (was 4–8) || 2026-10-23 | minor | Gap 13: before a Lightroom catalog import the app asks whether it merges into the open library or goes into a new one (opt-out in Settings, #2672); hours unchanged |diff --git a/docs/parity-checklist.md b/docs/parity-checklist.mdindex f8aaaf4a2..b102e754a 100644--- a/docs/parity-checklist.md+++ b/docs/parity-checklist.md@@ -69,7 +69,7 @@ differences and missing bindings are in [ui-parity.md](ui-parity.md#shortcuts).| Id | Feature | Tier | Status | Evidence | Missing / notes ||---|---|---|---|---|---|-| LR-IMP-ADD-DIALOG | Add photos/folders | P0 | ✅ | `cmd:file.addPhotos`, `cmd:view.importThumbSize`, `cmd:library.importPreview`, `cmd:library.import` (`mode`, `album`, `albumName`, `preset`, `keywords`), `crates/ui-egui/src/dialogs/import.rs` | review dialog (Import Photos): the scanned source (a scanned folder is not added to Local), candidate grid with a remembered 80–320 pt thumbnail-size slider (default 116, independent of the library grid), density-aware previews capped at 1024 px and retention limited to nearby cells; tiny sources are tried once per requested size bucket; the pre-import loupe and keyboard culling remain open under #2056; thumbnails and checkboxes (duplicates by path/content marked and unchecked; with several file types, a toggle per type checks or unchecks all of its files, e.g. the raws without the JPEGs beside them, issue #344) filling a resizable window (issue #337), transfer mode (add in place / copy / move, each explained), album (existing/new): the destination picker follows the sidebar folder hierarchy and order, searches full paths, and distinguishes duplicate names by their folder path; folders navigate and smart albums are excluded, with None, New album and album-context preselection retained (#2362; `crates/ui-egui/src/widgets/album_picker.rs`, `crates/ui-egui/src/tests/album_picker.rs`); preset, keywords; the folder scan runs on a background thread, shown in the activity stack with ✕ to cancel (a NAS folder no longer freezes the window); the import itself (probing, sidecars, copying / moving files) runs on a worker thread and its batches join the library between frames, shown in the activity stack with ✕ to cancel; one undo step. Drag-and-drop goes through the same background import. File dialogs list the importable extensions (`lightcraft_engine::import::EXTENSIONS`) in any letter case on Linux, where GTK and the desktop portal match globs case-sensitively (`apps/lightcraft/src/dialog_filter.rs`, issue #342; 0.4.0 hid `.JPG` / `.NEF`, issue #705). The folder scan, Browse Folder, drag-and-drop and the sidecar lookup match extensions in any case (`crates/engine/src/tests/import.rs`) |+| LR-IMP-ADD-DIALOG | Add photos/folders | P0 | ✅ | `cmd:file.addPhotos`, `cmd:view.importThumbSize`, `cmd:library.importPreview`, `cmd:library.import` (`mode`, `album`, `albumName`, `preset`, `keywords`), `crates/ui-egui/src/dialogs/import.rs` | review dialog (Import Photos): the scanned source (a scanned folder is not added to Local), candidate grid with a remembered 80–320 pt thumbnail-size slider (default 116, independent of the library grid), density-aware previews capped at 1024 px and retention limited to nearby cells; tiny sources are tried once per requested size bucket; renderable raws use a sharper render when the camera JPEG is undersized, retaining the JPEG for preview-only raws or an unavailable/failed render; the pre-import loupe and keyboard culling remain open under #2056; thumbnails and checkboxes (duplicates by path/content marked and unchecked; with several file types, a toggle per type checks or unchecks all of its files, e.g. the raws without the JPEGs beside them, issue #344) filling a resizable window (issue #337), transfer mode (add in place / copy / move, each explained), album (existing/new): the destination picker follows the sidebar folder hierarchy and order, searches full paths, and distinguishes duplicate names by their folder path; folders navigate and smart albums are excluded, with None, New album and album-context preselection retained (#2362; `crates/ui-egui/src/widgets/album_picker.rs`, `crates/ui-egui/src/tests/album_picker.rs`); preset, keywords; the folder scan runs on a background thread, shown in the activity stack with ✕ to cancel (a NAS folder no longer freezes the window); the import itself (probing, sidecars, copying / moving files) runs on a worker thread and its batches join the library between frames, shown in the activity stack with ✕ to cancel; one undo step. Drag-and-drop goes through the same background import. File dialogs list the importable extensions (`lightcraft_engine::import::EXTENSIONS`) in any letter case on Linux, where GTK and the desktop portal match globs case-sensitively (`apps/lightcraft/src/dialog_filter.rs`, issue #342; 0.4.0 hid `.JPG` / `.NEF`, issue #705). The folder scan, Browse Folder, drag-and-drop and the sidecar lookup match extensions in any case (`crates/engine/src/tests/import.rs`) || LR-IMP-DRAGDROP | Drop files/folders to import | P0 | ✅ | `crates/ui-egui/src/lib.rs` (dropped files → the import review), `crates/ui-egui/src/drop_overlay.rs`, `crates/ui-egui/src/tests/drop_import.rs` | while files are dragged over the window a veil and a card say what dropping does (review N items for import, import N presets, open the face model; a note to close the open dialog first when one is open); photos and folders open the import review as File ▸ Import does (Settings ▸ Import ▸ Import dropped files without review imports them at once; the web build always does); with no library open on the desktop (the launch list, a library that couldn't open) photos wait for the library opened and presets are refused, and the card says so; a drop while a dialog is open (also in the web build) or while an import is running is refused with a toast, and the card says so; a finished scan waits for an open dialog to close before its review opens; the control channel's `ui.dropFiles` hovers or drops files for scripts; dropping onto a specific album not supported || LR-IMP-DUPES | Skip duplicates by content | P1 | ✅ | `crates/engine/src/import.rs`, `crates/engine/src/tests/import.rs` | || LR-IMP-DEVICE | Import from camera/card | P1 | ✅ | `cmd:library.devices`, `cmd:file.addFromDevice`, `crates/engine/src/devices.rs` | mounted volumes with a DCIM folder (macOS /Volumes, Linux /media and /run/media, Windows drive letters); File → Import from Device → the import review, copying into the library by default; menus serve the last scan and rescan in the background (never blocking a frame; hot-plugs repaint); copies are verified (a new file, synced, checked against the content hash the scan computed — byte compare with the source when there is none, issue #134; a bad copy is removed and reported as failed, never counted as imported; taken names get -1, -2…, never replaced — issue #96, `crates/engine/src/import_move.rs`); no PTP/MTP (cameras that don't mount as a disk); Settings → Import → Cameras and Cards can open the import review when a camera or card is connected (off by default; a card that was already in doesn't ask, and an open dialog or running import is finished first; `crates/ui-egui/src/dialogs/import.rs`) |@@ -799,7 +799,7 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove| Date | Change | Summary ||---|---|---|-| 2026-10-29 | minor | LR-IMP-ADD-DIALOG: remembered import thumbnail size, density-aware bounded previews and one job per candidate/size bucket (#2237, part of #2056); import loupe remains open; counts unchanged |+| 2026-10-29 | minor | LR-IMP-ADD-DIALOG: remembered import thumbnail size, density-aware bounded previews and one job per candidate/size bucket, with sharper raw fallback and the available camera JPEG retained when rendering cannot help (#2237, part of #2056); import loupe remains open; counts unchanged || 2026-10-25 | patch | LR-BEHAV-TITLEBAR: the top bar's title-bar gestures come from craft-window's `title_bar`: a double-click follows the system setting, and a press on a button, the search field or a panel floating over the bar never moves the window; status counts unchanged || 2026-10-24 | minor | KEYC-METADATA, LRC-LIB-KEYWORDS: ⌥0 / ⌥⇧0 (`keyword.nextSet`, `keyword.previousSet`) go to the next / previous keyword set; status counts unchanged (KEYC-METADATA stays 🟡) || 2026-10-24 | minor | KEYC-METADATA: ⌘K / Ctrl+K (`panel.addKeywords`, Add Keywords) shows the Keywords panel, opens Keywording and puts the cursor in the Add keyword box; status counts unchanged (KEYC-METADATA stays 🟡) |