diff --git a/apps/lightcraft-cli/src/main.rs b/apps/lightcraft-cli/src/main.rs index c1f9d258c6..e8bad66a4b 100644 --- a/apps/lightcraft-cli/src/main.rs +++ b/apps/lightcraft-cli/src/main.rs @@ -799,14 +799,14 @@ fn snapshot(args: &[String]) -> Result<(), String> { let mut session = match &library { Some(dir) => { let mut s = - Session::new().with_fs().with_default_denoise_models().with_system_clock().with_default_face_models().with_default_slide_templates(); + Session::new().with_fs().with_default_denoise_models().with_system_clock().with_default_face_models().with_default_lens_database().with_default_slide_templates(); s.open_library(dir, false).map_err(|e| library_error(dir, e))?; s } None if files.is_empty() => { - Session::with_demo().with_fs().with_default_denoise_models().with_system_clock().with_default_face_models().with_default_slide_templates() + Session::with_demo().with_fs().with_default_denoise_models().with_system_clock().with_default_face_models().with_default_lens_database().with_default_slide_templates() } - None => Session::new().with_fs().with_default_denoise_models().with_system_clock().with_default_face_models().with_default_slide_templates(), + None => Session::new().with_fs().with_default_denoise_models().with_system_clock().with_default_face_models().with_default_lens_database().with_default_slide_templates(), }; // Apply compute policy before imports or the first scripted query can discover an adapter. session.execute("app.gpu", &json!({"enabled": false})).map_err(|e| e.to_string())?; diff --git a/apps/lightcraft/src/main.rs b/apps/lightcraft/src/main.rs index 868112a97f..982c89a1f2 100644 --- a/apps/lightcraft/src/main.rs +++ b/apps/lightcraft/src/main.rs @@ -777,7 +777,7 @@ fn open_library_session(in_memory: bool, dir: Option, seed_d if in_memory { return (if seed_demo { Session::with_demo() } else { Session::new() }.with_fs().with_default_denoise_models().with_system_clock(), None); } - let unopened = || Session::new().with_fs().with_default_denoise_models().with_system_clock(); + let unopened = || Session::new().with_fs().with_default_denoise_models().with_default_lens_database().with_system_clock(); let Some(dir) = dir else { log::warn!("no library location (set --library or LIGHTCRAFT_LIBRARY)"); return (unopened(), Some(LibraryProblem::new("", "There is no home folder to keep the library in. Choose a folder for it."))); diff --git a/crates/catalog/src/tests.rs b/crates/catalog/src/tests.rs index 579175086e..708ab57468 100644 --- a/crates/catalog/src/tests.rs +++ b/crates/catalog/src/tests.rs @@ -564,7 +564,8 @@ fn set_embedded_lens_is_undoable_and_journaled() { photo: Box::new(Photo::new(a, Source::File { path: "/x.rw2".into() }, "x.rw2", "RW2", 4000, 3000, "2026-10-06T00:00:00")), }) .unwrap(); - let lens = lightcraft_develop::EmbeddedLens { warp: Some(Default::default()), vignette: None, stages: Default::default() }; + let lens = + lightcraft_develop::EmbeddedLens { warp: Some(Default::default()), vignette: None, stages: Default::default(), source: Default::default() }; let op = Op::SetEmbeddedLens { id: a, lens: Some(Box::new(lens)) }; let op: Op = serde_json::from_str(&serde_json::to_string(&op).unwrap()).unwrap(); let inv = c.apply(op).unwrap(); diff --git a/crates/develop/src/settings.rs b/crates/develop/src/settings.rs index a40f094c25..a1e122f68a 100644 --- a/crates/develop/src/settings.rs +++ b/crates/develop/src/settings.rs @@ -698,11 +698,32 @@ impl Default for Optics { pub struct EmbeddedLens { pub warp: Option, pub vignette: Option, + /// Where the correction came from: the file itself, or a lens database looked up by the + /// lens named in the file (what the Optics panel says is loaded). + #[serde(skip_serializing_if = "LensSource::is_file")] + pub source: LensSource, /// A DNG 1.6 `WarpRectilinear2` chain (up to [`WARP_STAGES`] stages, in `OpcodeList3` order; each stage warps /// the result of the one before it). When any is set, `warp` is `None`: the chain holds every warp opcode. pub stages: [Option; WARP_STAGES], } +/// Where an [`EmbeddedLens`] came from. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum LensSource { + /// The file's own correction (DNG opcodes, a camera's correction a raw reader converts). + #[default] + File, + /// A profile from a lensfun-format lens database, matched by the lens named in the file. + Database, +} + +impl LensSource { + pub fn is_file(&self) -> bool { + *self == LensSource::File + } +} + /// Most warp stages an [`EmbeddedLens`] chain keeps. pub const WARP_STAGES: usize = 3; diff --git a/crates/engine/src/cmd/convert.rs b/crates/engine/src/cmd/convert.rs index 0871e43528..24b4165278 100644 --- a/crates/engine/src/cmd/convert.rs +++ b/crates/engine/src/cmd/convert.rs @@ -456,6 +456,7 @@ mod tests { warp: Some(lightcraft_develop::EmbeddedWarp { planes: [[1.0, -0.1, 0.03, 0.0, 0.0, 0.0]; 3], ..Default::default() }), vignette: None, stages: Default::default(), + source: Default::default(), } } fn old_rw2() -> lightcraft_catalog::Photo { diff --git a/crates/engine/src/cmd/lens_refresh.rs b/crates/engine/src/cmd/lens_refresh.rs new file mode 100644 index 0000000000..720edad8a2 --- /dev/null +++ b/crates/engine/src/cmd/lens_refresh.rs @@ -0,0 +1,164 @@ +//! Lens profiles looked up again when the lens database appears or changes. A photo's lens data is +//! stored when it is imported ([`Photo::embedded_lens`]), so photos imported before the database was there say "no +//! profile" until something reads their file again. When the database arrives (the first-run download) or is updated, +//! and when "Enable Lens Corrections" is ticked on a photo without a profile, every library raw that has no profile +//! but whose lens the database knows by name is probed again and gets what Reload from Disk would give it: the +//! profile, and the correction switched on where its settings are still what import gave it (an edited photo keeps +//! its settings). +//! +//! Split like [`super::recheck`] so the app probes on a worker thread: [`missing`] lists what to probe (no +//! file-system calls), [`probe`] reads the files without the session, [`apply`] applies the results as LightCraft's +//! own bookkeeping (journaled, not an undo step). Agents and tests use `library.refreshLensProfiles`. + +use lightcraft_catalog::{Catalog, Op, Photo, PhotoId}; +use serde_json::{Value, json}; + +use super::{CommandSpec, always, bad, cmd}; +use crate::media::{FileProbe, ProbeInfo}; +use crate::{Result, Session}; + +/// A photo to probe again, and its file when listed (a result for a photo moved meanwhile is dropped). +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Missing { + pub id: PhotoId, + pub path: String, +} + +/// Library raws with a file, no lens profile and a lens the database `db` knows by name (`ids`: only these; virtual +/// copies follow the photo they were copied from). No file-system calls. +pub fn missing(cat: &Catalog, db: &lightcraft_lensdb::LensDb, ids: Option<&[PhotoId]>) -> Vec { + cat.photos() + .filter(|p| ids.is_none_or(|ids| ids.contains(&p.id) || p.copy_of.is_some_and(|c| ids.contains(&c)))) + .map(|p| p.copy_of.and_then(|c| cat.photo(c)).map_or(&**p, |orig| &**orig)) + .filter(|p| p.develops_raw() && p.embedded_lens.is_none() && !p.meta.lens.trim().is_empty()) + .filter(|p| crate::lens_profiles::profile_name(db, &p.meta.camera, &p.meta.lens).is_some()) + .filter_map(|p| crate::cmd::missing::checked_path(p).map(|path| Missing { id: p.id, path: path.to_string() })) + .fold(Vec::new(), |mut v, m| { + if !v.contains(&m) { + v.push(m); + } + v + }) +} + +/// Probe each listed photo's file as Reload would. Doesn't touch the session. +pub fn probe(probe: &FileProbe, list: Vec) -> Vec<(Missing, std::result::Result)> { + let paths: Vec = list.iter().map(|x| x.path.clone()).collect(); + list.into_iter().zip(crate::import::probe_with(probe, &paths)).collect() +} + +/// Apply [`probe`]'s results: each photo and its virtual copies get the lens data their file gives now, in one batch +/// that is journaled but isn't an undo step. Returns the photos that gained a profile. +pub fn apply(s: &mut Session, results: Vec<(Missing, std::result::Result)>) -> Result> { + let mut ops = Vec::new(); + let mut found = Vec::new(); + for (item, info) in results { + let Ok(info) = info else { continue }; + if info.embedded_lens.is_none() { + continue; + } + let family: Vec = s + .catalog + .photos() + .filter(|p| p.id == item.id || p.copy_of == Some(item.id)) + .filter(|p| p.id != item.id || crate::cmd::missing::checked_path(p) == Some(item.path.as_str())) + .map(|p| p.id) + .collect(); + for id in family { + if let Some(p) = s.catalog.photo(id) { + let mine = crate::cmd::convert::lens_ops(id, p, &info); + if !mine.is_empty() { + ops.extend(mine); + found.push(id); + } + } + } + } + if !ops.is_empty() { + s.apply_system(Op::Batch { ops })?; + } + for id in &found { + s.media.forget(*id); + } + Ok(found) +} + +/// Why a photo has no lens profile, in words for the Optics panel: `None` when it has one. +pub fn no_profile_reason(p: &Photo) -> Option { + if p.embedded_lens.is_some() { + return None; + } + let lens = p.meta.lens.trim(); + Some(if lens.is_empty() { "This file names no lens.".to_string() } else { format!("No lens profile found for {lens}.") }) +} + +fn refresh(s: &mut Session, p: &Value) -> Result { + const C: &str = "library.refreshLensProfiles"; + let fp = super::recheck::file_probe(s).ok_or_else(|| bad(C, "this session has no file access"))?; + let ids: Option> = match p.get("ids") { + None | Some(Value::Null) => None, + Some(Value::Array(a)) => Some(a.iter().map(|v| v.as_u64().map(PhotoId).ok_or_else(|| bad(C, "ids are photo ids"))).collect::>()?), + Some(_) => return Err(bad(C, "ids is a list of photo ids")), + }; + let Some(db) = crate::lens_profiles::database() else { + return Ok(json!({"checked": 0, "found": [], "database": false})); + }; + let listed = missing(&s.catalog, &db, ids.as_deref()); + let n = listed.len(); + let found = apply(s, probe(&fp, listed))?; + Ok(json!({"checked": n, "found": found.iter().map(|i| i.0).collect::>(), "database": true})) +} + +fn download(s: &mut Session, _: &Value) -> Result { + const C: &str = "lens.downloadDatabase"; + let dir = crate::lensfun_download::default_dir().ok_or_else(|| bad(C, "this session has no data folder"))?; + let activity = s.activity.clone(); + s.lensfun.start(&dir, crate::lensfun_download::mirrors(), crate::lensfun_download::FILES, &activity).map_err(|e| bad(C, e))?; + Ok(json!({"started": true, "dir": dir.to_string_lossy()})) +} + +fn status(s: &mut Session, _: &Value) -> Result { + use crate::lensfun_download::State; + let state = match s.lensfun.state() { + State::Idle => json!({"state": "idle"}), + State::Running { bytes, total } => json!({"state": "running", "bytes": bytes, "total": total}), + State::Done { files } => json!({"state": "done", "files": files}), + State::Failed(e) => json!({"state": "failed", "error": e}), + State::Cancelled => json!({"state": "cancelled"}), + }; + let dir = crate::lens_profiles::dir(); + let lenses = crate::lens_profiles::database().map_or(0, |db| db.lenses.len()); + Ok(json!({"download": state, "dir": dir.map(|d| d.to_string_lossy().to_string()), "lenses": lenses})) +} + +pub fn specs() -> Vec { + vec![ + cmd!( + "library.refreshLensProfiles", + "Look Up Lens Profiles Again", + [], + None, + "{ids?: [photo ids]} — library raws without a lens profile whose lens the lens database knows are read again and get their profile (the correction is switched on where the photo's settings are still as imported); the app does this by itself when the database arrives or changes and when Enable Lens Corrections is ticked; not an undo step → {checked, found: [ids], database: bool}", + always, + refresh + ), + cmd!( + "lens.downloadDatabase", + "Download the Lens Database", + [], + None, + "{} — fetch lensfun's lens database (CC BY-SA 3.0, pinned to one commit, checked file by file) into the app's data folder in the background, with an activity row; the desktop app does this by itself on first run. LIGHTCRAFT_LENSFUN_URL lists other places to fetch the same files from → {started, dir}", + always, + download + ), + cmd!( + "lens.databaseStatus", + "Lens Database Status", + [], + None, + "{} → {download: {state: idle|running|done|failed|cancelled, …}, dir, lenses (in the database in use)}", + always, + status + ), + ] +} diff --git a/crates/engine/src/cmd/mod.rs b/crates/engine/src/cmd/mod.rs index 9b8dc3dbd2..dbaa43ff72 100644 --- a/crates/engine/src/cmd/mod.rs +++ b/crates/engine/src/cmd/mod.rs @@ -22,6 +22,7 @@ pub mod filters; mod focus; pub mod geocode; pub mod keywords; +pub mod lens_refresh; pub mod library; pub mod lut_profiles; pub mod manage; @@ -168,6 +169,7 @@ pub fn command_specs() -> &'static [CommandSpec] { v.extend(browse::specs()); v.extend(missing::specs()); v.extend(recheck::specs()); + v.extend(lens_refresh::specs()); v.extend(sync::specs()); v.extend(metadata::specs()); v.extend(geocode::specs()); diff --git a/crates/engine/src/config.rs b/crates/engine/src/config.rs index b3ded1fbd7..3088b6f119 100644 --- a/crates/engine/src/config.rs +++ b/crates/engine/src/config.rs @@ -146,6 +146,14 @@ impl Session { self } + /// Read lens profiles from the app's own copy of the lens database ([`crate::lensfun_download::default_dir`], + /// unless `LIGHTCRAFT_LENSFUN_DIR` names another), and let the host fetch it by itself when it is missing. + pub fn with_default_lens_database(mut self) -> Self { + crate::lens_profiles::use_dir(crate::lensfun_download::default_dir()); + self.lens_auto_download = true; + self + } + /// Keep denoise models in the shared default folder ([`default_denoise_models_dir`]). pub fn with_default_denoise_models(mut self) -> Self { self.set_denoise_models_dir(default_denoise_models_dir()); diff --git a/crates/engine/src/lens_profiles.rs b/crates/engine/src/lens_profiles.rs index 6e7f28120f..43aec88915 100644 --- a/crates/engine/src/lens_profiles.rs +++ b/crates/engine/src/lens_profiles.rs @@ -1,38 +1,92 @@ -//! Lens profile corrections from a lens database the user supplies ([`lightcraft_lensdb`]). +//! Lens profile corrections from a lens database ([`lightcraft_lensdb`]). //! //! When a raw carries no lens correction of its own (DNG opcodes, or a camera correction a raw reader converts, -//! [`crate::files::embedded_lens`]), the lens named in its EXIF is looked up in a lensfun-format database: the -//! directory in `LIGHTCRAFT_LENSFUN_DIR` (e.g. lensfun's `data/db`, CC-BY-SA, which is never bundled with the app). -//! The profile is converted to the same [`lightcraft_develop::EmbeddedLens`] form, so "Enable Profile Corrections", its -//! amount sliders, the GPU path and DNG export treat both alike. Without the variable nothing changes. -use std::path::PathBuf; -use std::sync::OnceLock; +//! [`crate::files::embedded_lens`]), the lens named in its EXIF is looked up in a lensfun-format database. The +//! database is lensfun's `data/db` (CC BY-SA 3.0): never bundled with the app, it is downloaded at run time into the +//! app's data folder ([`crate::lensfun_download`], which the desktop app starts by itself on first run), or it is the +//! directory in `LIGHTCRAFT_LENSFUN_DIR` (which wins). The profile is converted to the same +//! [`lightcraft_develop::EmbeddedLens`] form (marked [`LensSource::Database`]), so "Enable Profile Corrections", its +//! amount sliders, the GPU path and DNG export treat both alike. Without a database nothing changes. +use std::path::{Path, PathBuf}; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::{Arc, PoisonError, RwLock}; -use lightcraft_develop::EmbeddedLens; +use lightcraft_develop::{EmbeddedLens, LensSource}; use lightcraft_lensdb::{LensDb, Shot}; /// The environment variable naming the lens database directory. pub const ENV: &str = "LIGHTCRAFT_LENSFUN_DIR"; -/// The configured database, read once per process; `None` when none is configured or it holds no lenses. -pub fn database() -> Option<&'static LensDb> { - static DB: OnceLock> = OnceLock::new(); - DB.get_or_init(|| { - let dir = PathBuf::from(std::env::var_os(ENV)?); - match LensDb::load_dir(&dir) { - Ok((db, errors)) => { - for (file, e) in errors { - log::warn!("lens database: skipped {file}: {e}"); - } - (!db.lenses.is_empty()).then_some(db) - } - Err(e) => { - log::warn!("{e}"); - None +/// The database folder a host set up ([`use_dir`]), read when `LIGHTCRAFT_LENSFUN_DIR` is not set. +static HOST_DIR: RwLock> = RwLock::new(None); +/// The loaded database and the folder it was read from (`None` inside: nothing usable there). +static LOADED: RwLock>)>> = RwLock::new(None); +/// Bumped whenever the database in use changes ([`reload`]): photos looked up before may now find a profile. +static GENERATION: AtomicU64 = AtomicU64::new(0); + +/// Use `dir` (the app's downloaded lensfun data, [`crate::lensfun_download::default_dir`]) when +/// `LIGHTCRAFT_LENSFUN_DIR` is not set. Hosts with a file system call it; tests and sessions that don't stay +/// without a database. +pub fn use_dir(dir: Option) { + *HOST_DIR.write().unwrap_or_else(PoisonError::into_inner) = dir; + reload(); +} + +/// Read the database again (after a download or an update): the next lookup sees the new data. +pub fn reload() { + *LOADED.write().unwrap_or_else(PoisonError::into_inner) = None; + GENERATION.fetch_add(1, Ordering::Relaxed); +} + +/// Changes whenever the database in use may have changed. +pub fn generation() -> u64 { + GENERATION.load(Ordering::Relaxed) +} + +/// The folder the database is read from: `LIGHTCRAFT_LENSFUN_DIR`, else the host's ([`use_dir`]). +pub fn dir() -> Option { + std::env::var_os(ENV).filter(|v| !v.is_empty()).map(PathBuf::from).or_else(|| HOST_DIR.read().unwrap_or_else(PoisonError::into_inner).clone()) +} + +/// The database in use, read once per folder (and again after [`reload`]); `None` when none is configured, the +/// folder is missing or it holds no lenses. +pub fn database() -> Option> { + let dir = dir()?; + if let Some((d, db)) = LOADED.read().unwrap_or_else(PoisonError::into_inner).as_ref() + && *d == dir + { + return db.clone(); + } + let db = load(&dir); + *LOADED.write().unwrap_or_else(PoisonError::into_inner) = Some((dir, db.clone())); + db +} + +fn load(dir: &Path) -> Option> { + if !dir.is_dir() { + return None; + } + match LensDb::load_dir(dir) { + Ok((db, errors)) => { + for (file, e) in errors { + log::warn!("lens database: skipped {file}: {e}"); } + (!db.lenses.is_empty()).then(|| Arc::new(db)) } - }) - .as_ref() + Err(e) => { + log::warn!("{e}"); + None + } + } +} + +/// The database's name for the lens a photo's file calls `lens` (taken with `camera`, the make and model as the +/// library shows them): "Canon EF 70-200mm f/2.8L IS II USM". `None` without a database or a match. +pub fn profile_name(db: &LensDb, camera: &str, lens: &str) -> Option { + let cam = camera.split_once(' ').and_then(|(make, model)| db.find_camera(make, model).or_else(|| db.find_camera(make, camera))); + let p = db.find_lens(None, lens, cam)?; + let model = p.models.first()?; + Some(if model.to_lowercase().starts_with(&p.maker.to_lowercase()) || p.maker.is_empty() { model.clone() } else { format!("{} {model}", p.maker) }) } /// The database profile for a photo with metadata `m`, for its `w × h` (unoriented, default-cropped) image, @@ -52,7 +106,7 @@ pub fn lookup(db: &LensDb, m: &lightcraft_meta::Metadata, w: f64, h: f64, orient let crop = frame_crop_factor(camera.map(|c| c.crop_factor), focal, m.focal_length_35mm); let shot = Shot { focal, aperture: m.f_number, distance: None, crop_factor: crop, width: w, height: h }; let corr = lens.correction(&shot)?; - Some(lightcraft_pipeline::optics::reorient_lens(&corr, orientation, w, h)) + Some(EmbeddedLens { source: LensSource::Database, ..lightcraft_pipeline::optics::reorient_lens(&corr, orientation, w, h) }) } /// The crop factor of the recorded frame, which scales the profile's radii: the body's (`camera`), else what the @@ -73,7 +127,7 @@ pub fn for_raw(raw: &lightcraft_raw::RawInfo, meta: impl FnOnce() -> lightcraft_ crate::files::embedded_lens(raw).or_else(|| { let db = database()?; let (w, h) = raw.developed_size(); - lookup(db, &meta(), w as f64, h as f64, raw.orientation) + lookup(&db, &meta(), w as f64, h as f64, raw.orientation) }) } @@ -107,6 +161,9 @@ mod tests { let db = LensDb::parse(DB).unwrap(); let lens = lookup(&db, &meta(), 6000.0, 4000.0, Orientation::Normal).unwrap(); assert!(lens.warp.is_some() && lens.vignette.is_some()); + assert_eq!(lens.source, LensSource::Database, "the Optics panel says where it came from"); + assert_eq!(profile_name(&db, "Testcam TC-1", "18-55mm F3.5-5.6").as_deref(), Some("Testcam 18-55mm f/3.5-5.6")); + assert_eq!(profile_name(&db, "Testcam TC-1", "70-200mm F4"), None); let rotated = lookup(&db, &meta(), 6000.0, 4000.0, Orientation::Rotate90).unwrap(); assert_eq!(rotated.warp.unwrap().center, lightcraft_geom::Point::new(0.5, 0.5)); // no lens name, no focal length, an unknown lens: nothing @@ -164,7 +221,7 @@ mod tests { }; let at = |crop: f64, w: f64, h: f64| { let shot = Shot { focal: 70.0, aperture: Some(2.8), distance: None, crop_factor: Some(crop), width: w, height: h }; - db.lenses[0].correction(&shot).unwrap() + EmbeddedLens { source: LensSource::Database, ..db.lenses[0].correction(&shot).unwrap() } }; let aps_c = lookup(&db, &m(Some(105.0)), 5616.0, 3744.0, Orientation::Normal).unwrap(); assert_eq!(aps_c, at(1.5, 5616.0, 3744.0)); diff --git a/crates/engine/src/lensfun_download.rs b/crates/engine/src/lensfun_download.rs new file mode 100644 index 0000000000..00e03bbdf5 --- /dev/null +++ b/crates/engine/src/lensfun_download.rs @@ -0,0 +1,387 @@ +//! The lensfun lens database, downloaded by itself on first run (zero setup). +//! +//! lensfun's `data/db` (CC BY-SA 3.0, ) is data, never bundled with LightCraft and +//! never committed to its repository: the desktop app fetches it at run time into its data folder +//! ([`default_dir`]), with a row in the activity stack, and [`crate::lens_profiles`] reads it from there. The files are +//! pinned to one lensfun commit ([`COMMIT`]) by name, size and SHA-256 ([`FILES`]), so whatever mirror serves them +//! ([`URL_ENV`] lists others, e.g. a copy on LightCraft's own server), what arrives is exactly that commit's data or +//! it is thrown away. A new pin in a later build replaces the folder's files once ([`installed`] compares the pin). +//! +//! The transfer is [`lightcraft_fetch`] (pure-Rust HTTPS, resume, size and hash checks) on a background thread; the +//! files land in a staging folder first and move into place only when all of them are verified, so the database is +//! never a mix of two versions. Failure is a message, never a panic. + +use std::path::{Path, PathBuf}; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Arc, Mutex, PoisonError}; + +use crate::activity::{Activity, Cancel, TaskHandle, Unit}; + +/// The lensfun commit the files are pinned to (2026-10-08). +pub const COMMIT: &str = "43f9e001ab66c4fcdd4f400463f13b72f94b2288"; +/// Where the files are fetched from by default: lensfun's repository at [`COMMIT`]. +pub const DEFAULT_MIRROR: &str = "https://raw.githubusercontent.com/lensfun/lensfun/43f9e001ab66c4fcdd4f400463f13b72f94b2288/data/db"; +/// Other places to fetch the same files from, tried first (base URLs separated by commas or spaces). +pub const URL_ENV: &str = "LIGHTCRAFT_LENSFUN_URL"; +/// The file written once every database file is in place: the pin it holds says which data the folder has. +pub const MARKER: &str = "SOURCE.txt"; +/// The folder inside the database folder where files wait until all have arrived. +const STAGING: &str = ".download"; +/// Largest database file accepted (the biggest is under 1 MB). +const MAX_FILE: u64 = 8 << 20; + +/// The database files at [`COMMIT`]: name, size in bytes, SHA-256. +pub const FILES: &[(&str, u64, &str)] = &[ + ("6x6.xml", 29550, "ca13c2756b32d728675372695c072517a0e38af5eff2ecd3e17599dee7fc58b3"), + ("actioncams.xml", 17188, "79a5da0322574b95690464444c9d9ba1da0e1f827da44fd6bff120a0ec10e4b4"), + ("compact-canon.xml", 247046, "bae47e4b3a0f8852641038ae2dcca5b28ed7965e65ca795fd676f9de857c4670"), + ("compact-casio.xml", 6889, "ab35433879c4574ef8f97cd4e3d114d7ff8db4e7279da9d502fc9e911b51ee27"), + ("compact-fujifilm.xml", 67954, "58af9ebef2410c428ae2c5d01003d2247330d47d918823e63522b4d897a997d1"), + ("compact-kodak.xml", 2091, "377018ccd74f58e966b37a11e5a8689be4268153bebece9f1f2a0dbfa8234845"), + ("compact-konica-minolta.xml", 13349, "832a7473951ab625e10c48af6cf60f89b57280016d45729e2584cf9e41ad3cc7"), + ("compact-leica.xml", 9113, "8e4676679377576dc19e7900ce86fc69b0248ea1d4538aa22ee1ee09431a3be3"), + ("compact-nikon.xml", 40003, "5393bdb8223e13d21b85818e96571e97c035470b49b0452dfcedc2e1ff512d3b"), + ("compact-olympus.xml", 34454, "7637d469ad54a02ebce9492a9aa9424a2ff1ec07b0398158076f762fdc08389b"), + ("compact-panasonic.xml", 70621, "f191fc2a5d49fb50c06f4c399ee8c1a83a05f93a0efaecd352ec5c1479b8e60b"), + ("compact-pentax.xml", 6689, "596fae3edaadcf2d90ae930fc1bec42597ca0b2bd11842e686e1b915f3736390"), + ("compact-ricoh.xml", 18424, "46df96ebc367d5170cb6b7dfc3742093f0ad946264518fc5488573ba052f29d7"), + ("compact-samsung.xml", 13875, "36e3a778046d56385c387d48474cd32a89a5da94d99e640b5ce716ce747f898d"), + ("compact-sigma.xml", 2395, "0ddc265e3e580da05dcd4664d1b9c2464838d74dd02519c826520950c8f1759e"), + ("compact-sony.xml", 126229, "be146388b4f6f7bf0d73394e20386ce6ccef3559ab39f1268ba3c14aaef03207"), + ("contax.xml", 1696, "5eba12e6fd4913470afb6fe25fee47a263084b6cec830297273909872f47669a"), + ("generic.xml", 5416, "cd572d4110981546b2c4cd296c2ff16755b30063fa136d8b06ad2ca13ab4c59f"), + ("mil-canon.xml", 247994, "2de8e9467a6af6f83cc9da834d3d3b94d1aaf54519f60c68ac6bc02780a77516"), + ("mil-fujifilm.xml", 210586, "64586336153b948fe2325f6c46679149a4e3c114a70bee4bd1de88721cb4de72"), + ("mil-hasselblad.xml", 1048, "13e1fa55d36c2ed7d22964c21ce6c21d887bfe4506e840e425da1ce4157c3756"), + ("mil-leica.xml", 11663, "c691037e2e0743388473c2a0545e340462c412b7e3b57e451f4f9c89dde2388a"), + ("mil-nikon.xml", 178941, "dcae5ec2e505411a7f00b6b8dd03825e55620403b558b156be15e9ddfbeaf159"), + ("mil-olympus.xml", 147123, "989a3d88ef07a286efc2755df214792fdf71d60366932a1b369a77ad39cf2abb"), + ("mil-panasonic.xml", 299264, "eb5f01f33e65721f3900786d5970c7e220dd042aaa56968be33c009a358ff3c5"), + ("mil-pentax.xml", 1385, "675a94f52794868ad9f1d79e17b7128783c34b3db23e9eac346c5963812a16e5"), + ("mil-samsung.xml", 13007, "10130e9e125e0882a16fd3033cfed0175e9c14cb7d35e630cdb94736f27e5dc3"), + ("mil-samyang.xml", 25990, "ae3bf262f12facdc6f81b837cf6d36fdde2a930d2bfb0918d5abaa47fcfea3ab"), + ("mil-sigma.xml", 126080, "5f39b232efba5c208e5a98d8afe92cb2eee879213322d47827fcc6f0dc3a06f9"), + ("mil-sony.xml", 274541, "f9f7e5d7461ac58f76eb55dcc5b211f2e9a451402ddb4a9ecb12d1e4dc04f2b8"), + ("mil-tamron.xml", 106950, "2f0c9c4dfb9b0419ba0fac2e618bc251c2e71e068b6e09a23d7994b0ff62db0a"), + ("mil-tokina.xml", 1014, "addb27bd82b0d729644b9da1342f92401f63cc5945309ed17f38f4b7af1649e3"), + ("mil-zeiss.xml", 19171, "ef8a238904fc9ea6fdb6171863dfd70cd94814af19ecd8c31ee000ca1864589d"), + ("misc.xml", 176039, "2000a347d9dc37d908ea5b56c760de5b2b4ab475857959ae2e901c31339b01bb"), + ("om-system.xml", 35344, "a53a627e6ba79fbabb0fa7552ce2b6e56e206425d2eaf0e8ccdb6b8c40c20755"), + ("rf-leica.xml", 6712, "f93636e1980ad308d1873cc3ac078cdc77c0d529d777cd45c5c8d0e4781981e3"), + ("slr-canon.xml", 780353, "5244e6df8f2522f829c57e2073313ce31a624e9ed9605310fe43613b9d588c99"), + ("slr-hasselblad.xml", 642, "97602c467699904bf101179ea2fa24f05f3e1879250498a6ba306cd95a3b7a6b"), + ("slr-konica-minolta.xml", 47170, "5639ca94f121f609247c2c120b65830b3ef7784db6ecfa7e8eb3d29ff5046c1b"), + ("slr-leica.xml", 432, "c5e74cb511712e99ed60a066e85c842fea58f693c5039c3819485619f5293d0e"), + ("slr-nikon.xml", 550157, "5e591e8b1032203cce4c822f1da3d49524a78e7d71c594ea5a4533f2e57aacdf"), + ("slr-olympus.xml", 116602, "f7693b6779edd8ed10d7dc23113669255bfa4987cea7db0e843f7f5f2bbbe615"), + ("slr-panasonic.xml", 419, "cd79acb49d9ce5f2a4cecc572b3e117f03da380bed2dcbfd52327192d8ce2381"), + ("slr-pentax.xml", 209552, "2fba773e41a1cfb70f0c85efdab6d78944bf80ddf89bc2035ef6db39da352f29"), + ("slr-ricoh.xml", 2869, "c835798136a53535fdf4f81312ac9aad0ea3de3ef732c183d8cc4d2f432011d9"), + ("slr-samsung.xml", 1110, "dc0a29e424ff96e4316ddeb76126fa6f6c73a8836905a3e1f56f0c493826148f"), + ("slr-samyang.xml", 16811, "fb1585bea91f5f59e1fae8811dd76c92252ee5d52e3647df2aff4695048443b5"), + ("slr-schneider.xml", 5890, "de607cfe4ba6e7debc61e282ce39b72825c07601572e14af2bc9108ba67faf81"), + ("slr-sigma.xml", 444640, "f55f41c144fbb72e3c51d2dfef40e918930d37db1b4150bd02bd746406c036d2"), + ("slr-soligor.xml", 573, "1aba0aab19bce87ea86175b6551cb5306a512eb54be1698b89991b86008f6a04"), + ("slr-sony.xml", 88865, "e5ca7f532afe23ff380bf2f9e5458f687bed603355d73a254d85c4e692942fdc"), + ("slr-tamron.xml", 201992, "c62090789cebe6bbb663111c6e97beeb1111852bb735088e29cf8782df4bab45"), + ("slr-tokina.xml", 91977, "b1213eda81a613bc3976340398c6b8ce8b7dc29423476fc565d5f8e5cf612ecf"), + ("slr-ussr.xml", 19024, "1fd6acc8a8f40373379bea2899ffd96fc34b22d9b044d0474dabd4c89af44efb"), + ("slr-vivitar.xml", 2157, "c5c67e3fe38e8fa19044acadc7730047690435f66aac563f55ffe04997a88111"), + ("slr-zeiss.xml", 14957, "49aa211a41fd5fe391d26af5fa65bdf9428d60863ffff15d3916fa1c520dc101"), +]; + +/// The app's own copy of the database: `/lensfun`. +pub fn default_dir() -> Option { + crate::config::config_dir().map(|d| d.join("lensfun")) +} + +/// The folder holds the pinned data ([`MARKER`] names [`COMMIT`]). +pub fn installed(dir: &Path) -> bool { + std::fs::read_to_string(dir.join(MARKER)).is_ok_and(|s| s.contains(COMMIT)) +} + +/// The mirrors to try, in order: [`URL_ENV`]'s, then lensfun's own ([`DEFAULT_MIRROR`]). +pub fn mirrors() -> Vec { + #[cfg(not(target_arch = "wasm32"))] + { + lightcraft_fetch::mirrors(std::env::var(URL_ENV).ok().as_deref(), None, &[DEFAULT_MIRROR]) + } + #[cfg(target_arch = "wasm32")] + { + Vec::new() + } +} + +/// Where the download stands. +#[derive(Clone, Debug, PartialEq, Eq, Default)] +pub enum State { + /// Not started this session. + #[default] + Idle, + Running { + bytes: u64, + total: u64, + }, + /// In place and loaded: `files` database files. + Done { + files: usize, + }, + Failed(String), + Cancelled, +} + +struct Shared { + state: Mutex, + cancel: Arc, + task: Option, +} + +impl Shared { + fn set(&self, s: State) { + if let (State::Running { bytes, total }, Some(task)) = (&s, &self.task) { + task.progress(*bytes, *total); + } + *self.state.lock().unwrap_or_else(PoisonError::into_inner) = s; + } + + fn get(&self) -> State { + self.state.lock().unwrap_or_else(PoisonError::into_inner).clone() + } +} + +/// The session's lens database download. +#[derive(Default)] +pub struct Download { + job: Option>, +} + +/// One pinned file: name, size in bytes, SHA-256. +pub type Pin = (&'static str, u64, &'static str); + +impl Download { + pub fn state(&self) -> State { + self.job.as_ref().map_or(State::Idle, |j| j.get()) + } + + pub fn running(&self) -> bool { + matches!(self.state(), State::Running { .. }) + } + + /// Fetch `files` from `mirrors` into `dir` on a background thread, shown in the activity stack until it ends + /// (its ✕ stops it). Started once at a time; when it ends the database is read again + /// ([`crate::lens_profiles::reload`]). + pub fn start(&mut self, dir: &Path, mirrors: Vec, files: &'static [Pin], activity: &Activity) -> Result<(), String> { + if self.running() { + return Err("the lens database is already downloading".into()); + } + if mirrors.is_empty() { + return Err("no download location is configured for the lens database".into()); + } + let cancel = Arc::new(AtomicBool::new(false)); + let task = activity.start("download", "Downloading the lens database", Cancel::Flag(cancel.clone())); + task.set_unit(Unit::Bytes); + task.detail("lensfun (CC BY-SA 3.0)"); + let total = files.iter().map(|f| f.1).fold(0u64, u64::saturating_add); + task.progress(0, total); + let shared = Arc::new(Shared { state: Mutex::new(State::Running { bytes: 0, total }), cancel, task: Some(task.handle()) }); + let worker = shared.clone(); + let dir = dir.to_path_buf(); + std::thread::Builder::new() + .name("lens-database-download".into()) + .spawn(move || { + // the row goes when the thread ends, however it ends + let _task = task; + let outcome = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| run(&dir, &mirrors, files, &worker))); + if outcome.is_err() { + worker.set(State::Failed("the lens database download stopped unexpectedly".into())); + } + }) + .map_err(|e| format!("could not start the lens database download: {e}"))?; + self.job = Some(shared); + Ok(()) + } +} + +impl Drop for Download { + /// Quitting while it runs stops it (the staged files stay for the next try to resume). + fn drop(&mut self) { + if let Some(j) = &self.job { + j.cancel.store(true, Ordering::Relaxed); + } + } +} + +/// The whole job: fetch and check every file into the staging folder, then move them into `dir`, write the marker +/// and read the database again. Always ends in a final [`State`]. +fn run(dir: &Path, mirrors: &[String], files: &[Pin], shared: &Shared) { + match fetch_all(dir, mirrors, files, shared) { + Ok(n) => { + crate::lens_profiles::reload(); + shared.set(State::Done { files: n }); + } + Err(e) if shared.cancel.load(Ordering::Relaxed) => { + log::info!("lens database download stopped: {e}"); + shared.set(State::Cancelled); + } + Err(e) => { + log::warn!("lens database download: {e}"); + shared.set(State::Failed(e)); + } + } +} + +#[cfg(not(target_arch = "wasm32"))] +fn fetch_all(dir: &Path, mirrors: &[String], files: &[Pin], shared: &Shared) -> Result { + let staging = dir.join(STAGING); + std::fs::create_dir_all(&staging).map_err(|e| format!("could not create {}: {e}", staging.display()))?; + let specs: Vec> = + files.iter().map(|(name, size, sha)| lightcraft_fetch::FileSpec { name, size: Some(*size), sha256: Some(sha), max: MAX_FILE }).collect(); + let total = files.iter().map(|f| f.1).fold(0u64, u64::saturating_add); + lightcraft_fetch::download(&specs, mirrors, &staging, &lightcraft_fetch::Options::default(), &shared.cancel, &mut |p| { + shared.set(State::Running { bytes: p.done.min(total), total }); + }) + .map_err(|e| match e { + lightcraft_fetch::DownloadError::AllMirrorsFailed { errors, .. } => { + let detail: String = errors.join("; ").chars().take(300).collect(); + format!("could not download the lens database ({detail}): check the internet connection; LightCraft tries again next time it starts") + } + other => other.to_string(), + })?; + // every file is here and checked: into place, then the marker that says so + let _ = std::fs::remove_file(dir.join(MARKER)); + for (name, _, _) in files { + std::fs::rename(staging.join(name), dir.join(name)).map_err(|e| format!("could not move {name} into {}: {e}", dir.display()))?; + } + let _ = std::fs::remove_dir_all(&staging); + let readme = format!( + "lensfun lens database (data/db), commit {COMMIT}\nfrom https://github.com/lensfun/lensfun, downloaded by LightCraft.\n\ + Licence: Creative Commons Attribution-ShareAlike 3.0 (https://creativecommons.org/licenses/by-sa/3.0/), by the lensfun contributors.\n\ + Data only, read by LightCraft at run time; not part of LightCraft.\n" + ); + std::fs::write(dir.join(MARKER), readme).map_err(|e| format!("could not write {}: {e}", dir.join(MARKER).display()))?; + Ok(files.len()) +} + +#[cfg(target_arch = "wasm32")] +fn fetch_all(_: &Path, _: &[String], _: &[Pin], _: &Shared) -> Result { + Err("the web build downloads no lens database".into()) +} + +#[cfg(all(test, not(target_arch = "wasm32")))] +mod tests { + use super::*; + use std::io::{BufRead, BufReader, Write}; + use std::net::TcpListener; + use std::time::Duration; + + fn scratch(name: &str) -> PathBuf { + let d = std::env::temp_dir().join(format!("lc-lensfun-{name}-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&d); + std::fs::create_dir_all(&d).unwrap(); + d + } + + /// A local server answering `GET /db/` with that file's body (404 otherwise). + fn serve(files: Vec<(&'static str, Vec)>) -> String { + let l = TcpListener::bind("127.0.0.1:0").unwrap(); + let base = format!("http://{}/db", l.local_addr().unwrap()); + std::thread::spawn(move || { + for mut s in l.incoming().flatten() { + let mut r = BufReader::new(s.try_clone().unwrap()); + let mut first = String::new(); + let _ = r.read_line(&mut first); + loop { + let mut line = String::new(); + if r.read_line(&mut line).unwrap_or(0) == 0 || line.trim().is_empty() { + break; + } + } + let path = first.split_whitespace().nth(1).unwrap_or_default().to_string(); + match files.iter().find(|(n, _)| path == format!("/db/{n}")) { + Some((_, body)) => { + let _ = s.write_all(format!("HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n", body.len()).as_bytes()); + let _ = s.write_all(body); + } + None => { + let _ = s.write_all(b"HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"); + } + } + } + }); + base + } + + fn wait(what: &str, done: impl Fn() -> bool) { + let t = std::time::Instant::now(); + while !done() { + assert!(t.elapsed() < Duration::from_secs(20), "{what}"); + std::thread::sleep(Duration::from_millis(10)); + } + } + + const LENS: &str = r#"TestcamTestcam 50mm f/1.8T1 + "#; + const CAMERA: &str = + r#"TestcamTC-1T1"#; + + fn sha(s: &str) -> &'static str { + Box::leak(lightcraft_faces::hash::sha256_hex(s.as_bytes()).into_boxed_str()) + } + + fn pins() -> &'static [Pin] { + Box::leak(vec![("lenses.xml", LENS.len() as u64, sha(LENS)), ("cameras.xml", CAMERA.len() as u64, sha(CAMERA))].into_boxed_slice()) + } + + /// Every pinned file lands in the folder with the marker, the activity row shows the download until it ends, + /// and the database reads. + #[test] + fn downloads_checks_and_installs_the_pinned_files() { + let dir = scratch("ok"); + let base = serve(vec![("lenses.xml", LENS.as_bytes().to_vec()), ("cameras.xml", CAMERA.as_bytes().to_vec())]); + let activity = Activity::default(); + let mut d = Download::default(); + assert!(!installed(&dir)); + d.start(&dir, vec![base], pins(), &activity).unwrap(); + let rows = activity.list(); + assert!(rows.iter().any(|r| r.kind == "download" && r.label == "Downloading the lens database" && r.cancellable), "{rows:?}"); + wait("the download never ended", || !d.running()); + assert_eq!(d.state(), State::Done { files: 2 }); + assert!(installed(&dir), "the marker names the pinned commit"); + assert!(!dir.join(STAGING).exists(), "the staging folder is gone"); + let (db, errors) = lightcraft_lensdb::LensDb::load_dir(&dir).unwrap(); + assert!(errors.is_empty() && db.lenses.len() == 1 && db.cameras.len() == 1); + wait("the row stayed", || activity.list().is_empty()); + let _ = std::fs::remove_dir_all(&dir); + } + + /// A file that is not the pinned one (another commit, a hostile mirror) is refused and nothing is installed. + #[test] + fn a_file_that_is_not_the_pinned_one_installs_nothing() { + let dir = scratch("bad"); + let base = serve(vec![("lenses.xml", LENS.replace("0.01", "0.02").into_bytes()), ("cameras.xml", CAMERA.as_bytes().to_vec())]); + let mut d = Download::default(); + d.start(&dir, vec![base], pins(), &Activity::default()).unwrap(); + wait("the download never ended", || !d.running()); + assert!(matches!(d.state(), State::Failed(_)), "{:?}", d.state()); + assert!(!installed(&dir) && !dir.join("cameras.xml").exists(), "nothing moved into place"); + // no mirror at all is an error, not a thread + assert!(Download::default().start(&dir, Vec::new(), pins(), &Activity::default()).is_err()); + let _ = std::fs::remove_dir_all(&dir); + } + + /// The pinned list is lensfun's whole `data/db` at the commit: unique XML names, sane sizes, hex hashes. + #[test] + fn the_pins_are_well_formed() { + assert_eq!(FILES.len(), 56); + let mut names: Vec<&str> = FILES.iter().map(|f| f.0).collect(); + names.sort_unstable(); + names.dedup(); + assert_eq!(names.len(), FILES.len()); + for (name, size, sha) in FILES { + assert!(name.ends_with(".xml") && !name.contains(['/', '\\']), "{name}"); + assert!(*size > 0 && *size < MAX_FILE, "{name}"); + assert!(sha.len() == 64 && sha.bytes().all(|b| b.is_ascii_hexdigit()), "{name}"); + } + assert!(DEFAULT_MIRROR.contains(COMMIT)); + } +} diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index ff2b972c0a..3f1d786406 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -46,6 +46,7 @@ pub mod guard; pub mod import; mod import_move; pub mod lens_profiles; +pub mod lensfun_download; pub mod library; mod lightroom_archive; pub mod lightroom_catalog; @@ -284,6 +285,10 @@ pub struct Session { pub face_models_dir: Option, /// Face model downloads started this session (the staged files wait in `/.downloads`). pub face_downloads: face_download::Downloads, + /// The lens database download ([`lensfun_download`]). + pub lensfun: lensfun_download::Download, + /// The host fetches the lens database by itself when it is missing ([`Session::with_default_lens_database`]). + pub lens_auto_download: bool, /// Reverse geocoding: the parsed place names and their download (`metadata.*PlaceNames`). pub place_names: cmd::geocode::PlaceNames, /// The user's own list of models to download (`catalog.json` in the models folder), as last read. @@ -476,6 +481,8 @@ impl Session { denoise: Default::default(), face_models_dir: None, face_downloads: Default::default(), + lensfun: Default::default(), + lens_auto_download: false, place_names: Default::default(), face_catalog: Default::default(), #[cfg(not(target_arch = "wasm32"))] @@ -1406,6 +1413,8 @@ mod tests_import_move; #[cfg(test)] mod tests_keyword_list; #[cfg(test)] +mod tests_lens_refresh; +#[cfg(test)] mod tests_libops; #[cfg(test)] mod tests_library; diff --git a/crates/engine/src/tests_lens_refresh.rs b/crates/engine/src/tests_lens_refresh.rs new file mode 100644 index 0000000000..b502f58157 --- /dev/null +++ b/crates/engine/src/tests_lens_refresh.rs @@ -0,0 +1,120 @@ +//! Lens profiles stay per lens. Presets, Copy / Paste and Sync carry "Enable Lens Corrections" and +//! its amounts, never a profile: each photo keeps the one found for its own lens. And photos imported before the lens +//! database was there get their profile when it arrives (`cmd::lens_refresh`). + +use std::sync::Arc; + +use lightcraft_catalog::{MediaKind, Op, Photo, PhotoId, Source}; +use lightcraft_develop::{EmbeddedLens, EmbeddedWarp, LensSource}; +use serde_json::json; + +use crate::Session; + +fn lens(k: f64) -> EmbeddedLens { + EmbeddedLens { + warp: Some(EmbeddedWarp { planes: [[1.0, k, 0.0, 0.0, 0.0, 0.0]; 3], radius: 0.6, ..Default::default() }), + source: LensSource::Database, + ..Default::default() + } +} + +fn lens_of(s: &Session, id: PhotoId) -> Option { + s.catalog.photo(id).and_then(|p| p.embedded_lens) +} + +/// Two demo photos "taken with different lenses". +fn two_lenses() -> (Session, PhotoId, PhotoId) { + let mut s = Session::with_demo(); + let ids: Vec = s.visible().iter().copied().take(2).collect(); + let (a, b) = (ids[0], ids[1]); + s.catalog.apply(Op::SetEmbeddedLens { id: a, lens: Some(Box::new(lens(-0.05))) }).unwrap(); + s.catalog.apply(Op::SetEmbeddedLens { id: b, lens: Some(Box::new(lens(0.03))) }).unwrap(); + s.execute("library.select", &json!({"ids": [a.0]})).unwrap(); + s.execute("develop.merge", &json!({"settings": {"optics": {"lens_profile": true}}, "label": "Lens Corrections"})).unwrap(); + s.execute("develop.set", &json!({"values": {"optics.profileDistortion": 60}})).unwrap(); + (s, a, b) +} + +fn carried(s: &Session, id: PhotoId) { + let d = s.develop_of(id).unwrap(); + assert!(d.optics.lens_profile, "the switch travels"); + assert_eq!(d.optics.profile_distortion, 60.0, "the amount travels"); +} + +#[test] +fn copy_paste_carries_the_switch_and_amounts_never_the_profile() { + let (mut s, a, b) = two_lenses(); + s.execute("develop.copy", &json!({})).unwrap(); + s.execute("develop.paste", &json!({"ids": [b.0]})).unwrap(); + carried(&s, b); + assert_eq!(lens_of(&s, b), Some(lens(0.03)), "b keeps its own lens's profile"); + assert_eq!(lens_of(&s, a), Some(lens(-0.05))); +} + +#[test] +fn sync_and_presets_keep_each_photos_own_profile() { + let (mut s, a, b) = two_lenses(); + s.execute("library.select", &json!({"ids": [a.0, b.0], "active": a.0})).unwrap(); + s.execute("develop.sync", &json!({})).unwrap(); + carried(&s, b); + assert_eq!(lens_of(&s, b), Some(lens(0.03))); + // a preset made on a's settings, applied to b + let pid = s.execute("preset.create", &json!({"name": "Optics", "groups": ["optics"]})).unwrap()["id"].as_str().unwrap().to_string(); + s.execute("library.select", &json!({"ids": [b.0]})).unwrap(); + s.execute("develop.merge", &json!({"settings": {"optics": {"lens_profile": false}}, "label": "Lens Corrections"})).unwrap(); + s.execute("preset.apply", &json!({"id": pid})).unwrap(); + carried(&s, b); + assert_eq!(lens_of(&s, b), Some(lens(0.03)), "a preset never brings another lens's profile"); + assert_eq!(lens_of(&s, a), Some(lens(-0.05))); +} + +/// A raw in a library folder, as an older import left it: no lens data. +fn raw(id: u64, lens_name: &str, edited: bool) -> Photo { + let mut p = + Photo::new(PhotoId(id), Source::File { path: format!("/photos/{id}.cr3") }, &format!("{id}.cr3"), "CR3", 600, 400, "2026-10-01T00:00:00"); + p.kind = MediaKind::Raw; + p.meta.camera = "Testcam TC-1".into(); + p.meta.lens = lens_name.into(); + if edited { + let mut d = (*p.develop).clone(); + d.light.exposure = 0.5; + p.develop = Arc::new(d); + p.edited = Some("2026-10-02T00:00:00".into()); + } + p +} + +const DB: &str = r#" + TestcamTC-1T1 + TestcamTestcam 50mm f/1.8T1 + "#; + +/// When the database arrives, the library's raws whose lens it knows get their profile; untouched photos get the +/// correction switched on as import would, edited ones keep their settings; lenses it doesn't know are not probed. +#[test] +fn photos_get_their_profile_when_the_database_arrives() { + let mut s = Session::new(); + for p in [raw(1, "50mm F1.8", false), raw(2, "50mm F1.8", true), raw(3, "300mm F4", false), raw(4, "", false)] { + s.catalog.apply(Op::AddPhoto { photo: Box::new(p) }).unwrap(); + } + let db = lightcraft_lensdb::LensDb::parse(DB).unwrap(); + let listed = crate::cmd::lens_refresh::missing(&s.catalog, &db, None); + assert_eq!(listed.iter().map(|m| m.id.0).collect::>(), [1, 2], "only lenses the database knows"); + assert_eq!(crate::cmd::lens_refresh::missing(&s.catalog, &db, Some(&[PhotoId(2)])).len(), 1, "or only the photos asked for"); + // what the files give when read again + let results = listed.into_iter().map(|m| (m, Ok(crate::media::ProbeInfo { embedded_lens: Some(lens(-0.01)), ..Default::default() }))).collect(); + let found = crate::cmd::lens_refresh::apply(&mut s, results).unwrap(); + assert_eq!(found, [PhotoId(1), PhotoId(2)]); + let p = |id: u64| s.catalog.photo(PhotoId(id)).unwrap().clone(); + assert!(p(1).embedded_lens.is_some() && p(1).develop.optics.lens_profile, "untouched: on, as import would"); + assert!(p(2).embedded_lens.is_some() && !p(2).develop.optics.lens_profile, "edited: its settings stay"); + assert!(p(3).embedded_lens.is_none()); + assert!(s.undo.is_empty(), "bookkeeping, not an undo step"); + // the Optics panel's words + assert_eq!(crate::cmd::lens_refresh::no_profile_reason(&p(3)).as_deref(), Some("No lens profile found for 300mm F4.")); + assert_eq!(crate::cmd::lens_refresh::no_profile_reason(&p(4)).as_deref(), Some("This file names no lens.")); + assert_eq!(crate::cmd::lens_refresh::no_profile_reason(&p(1)), None); + // without file access the command says so instead of clearing anything + assert!(s.execute("library.refreshLensProfiles", &json!({})).is_err()); + assert!(s.execute("library.refreshLensProfiles", &json!({"ids": "x"})).is_err()); +} diff --git a/crates/gpu/src/render.rs b/crates/gpu/src/render.rs index 64990db0e1..cb47f18db7 100644 --- a/crates/gpu/src/render.rs +++ b/crates/gpu/src/render.rs @@ -1104,6 +1104,7 @@ mod tests { }), vignette: None, stages: Default::default(), + source: Default::default(), }; let mut s = DevelopSettings::default(); s.optics.lens_profile = true; diff --git a/crates/gpu/tests/it/equivalence.rs b/crates/gpu/tests/it/equivalence.rs index 6a8169b301..fe055d3757 100644 --- a/crates/gpu/tests/it/equivalence.rs +++ b/crates/gpu/tests/it/equivalence.rs @@ -553,6 +553,7 @@ fn embedded_lens_perspective_edges_match() { }), vignette: Some(EmbeddedVignette { k: [0.4, -0.1, 0.02, 0.0, 0.0], center: Point::new(0.5, 0.5), radius: 0.6 }), stages: Default::default(), + source: Default::default(), }; let info = SourceInfo { lens: Some(lens), ..raw }; let mut s = DevelopSettings::default(); diff --git a/crates/pipeline/src/optics.rs b/crates/pipeline/src/optics.rs index 31e8d1351b..462c8c649c 100644 --- a/crates/pipeline/src/optics.rs +++ b/crates/pipeline/src/optics.rs @@ -375,7 +375,7 @@ pub fn reorient_lens(lens: &EmbeddedLens, o: Orientation, w: f64, h: f64) -> Emb EmbeddedWarpStage { planes, center: map_pt(st.center), radius: st.radius * long_ratio, reciprocal: st.reciprocal } }) }); - EmbeddedLens { warp, vignette, stages } + EmbeddedLens { warp, vignette, stages, source: lens.source } } // ------------------------------------------------------------------------------------------ lateral CA diff --git a/crates/ui-egui/locales/cs-formats.json b/crates/ui-egui/locales/cs-formats.json index 1eb882f09d..f79aee3fb1 100644 --- a/crates/ui-egui/locales/cs-formats.json +++ b/crates/ui-egui/locales/cs-formats.json @@ -305,5 +305,8 @@ "Could not read {name}: {e}": "Soubor {name} se nepodařilo přečíst: {e}", "Added {n} photo{}": "Přidáno fotografií: {n}{:.0}", "Where should the Lightroom catalog “{catalog}” go?": "Kam má jít katalog Lightroomu „{catalog}“?", - "Merge into the open library “{library}” ({count} photo{})": "Sloučit s otevřenou knihovnou „{library}“ (fotografie: {count}{:.0})" + "Merge into the open library “{library}” ({count} photo{})": "Sloučit s otevřenou knihovnou „{library}“ (fotografie: {count}{:.0})", + "Profile: {} (lens database)": "Profil: {} (databáze objektivů)", + "No lens profile found for {}.": "Pro {} nebyl nalezen profil objektivu.", + "{n} photos got their lens profile": "Profil objektivu získaly fotky: {n}" } diff --git a/crates/ui-egui/locales/cs.json b/crates/ui-egui/locales/cs.json index 52ca94a524..58362cd1ca 100644 --- a/crates/ui-egui/locales/cs.json +++ b/crates/ui-egui/locales/cs.json @@ -2408,5 +2408,11 @@ "Import dropped files without review": "Importovat přetažené soubory bez kontroly", "An import is running": "Import už běží", "An import is running. Drop photos when it has finished": "Import už běží. Fotky přetáhněte, až skončí", - "Finish Lightroom catalog import before adding photos": "Dokončete import katalogu Lightroom, než přidáte fotky" + "Finish Lightroom catalog import before adding photos": "Dokončete import katalogu Lightroom, než přidáte fotky", + "Profile: from the file (the camera's own correction)": "Profil: ze souboru (vlastní korekce fotoaparátu)", + "Downloading the lens database…": "Stahuje se databáze objektivů…", + "This file names no lens.": "Tento soubor neuvádí žádný objektiv.", + "1 photo got its lens profile": "1 fotka získala profil objektivu", + "Looking up lens profiles": "Hledání profilů objektivů", + "Downloading the lens database": "Stahování databáze objektivů" } diff --git a/crates/ui-egui/locales/de-formats.json b/crates/ui-egui/locales/de-formats.json index 79390f1364..77a30016fc 100644 --- a/crates/ui-egui/locales/de-formats.json +++ b/crates/ui-egui/locales/de-formats.json @@ -305,5 +305,8 @@ "Could not read {name}: {e}": "{name} konnte nicht gelesen werden: {e}", "Added {n} photo{}": "{n} Foto{} hinzugefügt", "Where should the Lightroom catalog “{catalog}” go?": "Wohin soll der Lightroom-Katalog „{catalog}“?", - "Merge into the open library “{library}” ({count} photo{})": "Mit der geöffneten Bibliothek „{library}“ zusammenführen ({count} Foto{})" + "Merge into the open library “{library}” ({count} photo{})": "Mit der geöffneten Bibliothek „{library}“ zusammenführen ({count} Foto{})", + "Profile: {} (lens database)": "Profil: {} (Objektivdatenbank)", + "No lens profile found for {}.": "Kein Objektivprofil für {} gefunden.", + "{n} photos got their lens profile": "{n} Fotos haben ihr Objektivprofil erhalten" } diff --git a/crates/ui-egui/locales/de.json b/crates/ui-egui/locales/de.json index e2205db782..a02b0ad59d 100644 --- a/crates/ui-egui/locales/de.json +++ b/crates/ui-egui/locales/de.json @@ -3440,5 +3440,11 @@ "Import dropped files without review": "Abgelegte Dateien ohne Prüfung importieren", "An import is running": "Ein Import läuft", "An import is running. Drop photos when it has finished": "Ein Import läuft. Lege die Fotos ab, wenn er fertig ist", - "Finish Lightroom catalog import before adding photos": "Schließe den Import des Lightroom-Katalogs ab, bevor du Fotos hinzufügst" + "Finish Lightroom catalog import before adding photos": "Schließe den Import des Lightroom-Katalogs ab, bevor du Fotos hinzufügst", + "Profile: from the file (the camera's own correction)": "Profil: aus der Datei (Korrektur der Kamera)", + "Downloading the lens database…": "Objektivdatenbank wird geladen…", + "This file names no lens.": "Diese Datei nennt kein Objektiv.", + "1 photo got its lens profile": "1 Foto hat sein Objektivprofil erhalten", + "Looking up lens profiles": "Objektivprofile werden gesucht", + "Downloading the lens database": "Objektivdatenbank wird geladen" } diff --git a/crates/ui-egui/locales/es-formats.json b/crates/ui-egui/locales/es-formats.json index 33e5f52fc6..90015d5291 100644 --- a/crates/ui-egui/locales/es-formats.json +++ b/crates/ui-egui/locales/es-formats.json @@ -305,5 +305,8 @@ "Could not read {name}: {e}": "No se pudo leer {name}: {e}", "Added {n} photo{}": "{n} foto{0} añadida{0}", "Where should the Lightroom catalog “{catalog}” go?": "¿Dónde debe ir el catálogo de Lightroom “{catalog}”?", - "Merge into the open library “{library}” ({count} photo{})": "Combinar con la biblioteca abierta “{library}” ({count} foto{})" + "Merge into the open library “{library}” ({count} photo{})": "Combinar con la biblioteca abierta “{library}” ({count} foto{})", + "Profile: {} (lens database)": "Perfil: {} (base de datos de objetivos)", + "No lens profile found for {}.": "No se encontró un perfil de objetivo para {}.", + "{n} photos got their lens profile": "{n} fotos recibieron su perfil de objetivo" } diff --git a/crates/ui-egui/locales/es.json b/crates/ui-egui/locales/es.json index 888af077ff..5152a8f518 100644 --- a/crates/ui-egui/locales/es.json +++ b/crates/ui-egui/locales/es.json @@ -2358,5 +2358,11 @@ "Import dropped files without review": "Importar los archivos soltados sin revisión", "An import is running": "Hay una importación en curso", "An import is running. Drop photos when it has finished": "Hay una importación en curso. Suelta las fotos cuando termine", - "Finish Lightroom catalog import before adding photos": "Termina la importación del catálogo de Lightroom antes de añadir fotos" + "Finish Lightroom catalog import before adding photos": "Termina la importación del catálogo de Lightroom antes de añadir fotos", + "Profile: from the file (the camera's own correction)": "Perfil: del archivo (corrección de la propia cámara)", + "Downloading the lens database…": "Descargando la base de datos de objetivos…", + "This file names no lens.": "Este archivo no indica ningún objetivo.", + "1 photo got its lens profile": "1 foto recibió su perfil de objetivo", + "Looking up lens profiles": "Buscando perfiles de objetivo", + "Downloading the lens database": "Descargando la base de datos de objetivos" } diff --git a/crates/ui-egui/locales/fr-formats.json b/crates/ui-egui/locales/fr-formats.json index 294273781e..2b0ee74bbd 100644 --- a/crates/ui-egui/locales/fr-formats.json +++ b/crates/ui-egui/locales/fr-formats.json @@ -305,5 +305,8 @@ "Could not read {name}: {e}": "Impossible de lire {name} : {e}", "Added {n} photo{}": "{n} photo{} ajoutée(s)", "Where should the Lightroom catalog “{catalog}” go?": "Où importer le catalogue Lightroom « {catalog} » ?", - "Merge into the open library “{library}” ({count} photo{})": "Fusionner avec la bibliothèque ouverte « {library} » ({count} photo{})" + "Merge into the open library “{library}” ({count} photo{})": "Fusionner avec la bibliothèque ouverte « {library} » ({count} photo{})", + "Profile: {} (lens database)": "Profil : {} (base de données d'objectifs)", + "No lens profile found for {}.": "Aucun profil d'objectif trouvé pour {}.", + "{n} photos got their lens profile": "{n} photos ont reçu leur profil d'objectif" } diff --git a/crates/ui-egui/locales/fr.json b/crates/ui-egui/locales/fr.json index 3278d6ccda..1d1a999a88 100644 --- a/crates/ui-egui/locales/fr.json +++ b/crates/ui-egui/locales/fr.json @@ -2390,5 +2390,11 @@ "Checking recent libraries": "Vérification des bibliothèques récentes", "The photos are imported once a library is open": "Les photos seront importées dès qu'une bibliothèque sera ouverte", "Open a library first, then drop the presets again": "Ouvrez d'abord une bibliothèque, puis déposez à nouveau les préréglages", - "This library couldn't be checked:": "Impossible de vérifier cette bibliothèque :" + "This library couldn't be checked:": "Impossible de vérifier cette bibliothèque :", + "Profile: from the file (the camera's own correction)": "Profil : du fichier (correction de l'appareil)", + "Downloading the lens database…": "Téléchargement de la base de données d'objectifs…", + "This file names no lens.": "Ce fichier n'indique aucun objectif.", + "1 photo got its lens profile": "1 photo a reçu son profil d'objectif", + "Looking up lens profiles": "Recherche des profils d'objectif", + "Downloading the lens database": "Téléchargement de la base de données d'objectifs" } diff --git a/crates/ui-egui/locales/it-formats.json b/crates/ui-egui/locales/it-formats.json index 7efae90e94..600df15c07 100644 --- a/crates/ui-egui/locales/it-formats.json +++ b/crates/ui-egui/locales/it-formats.json @@ -305,5 +305,8 @@ "Could not read {name}: {e}": "Impossibile leggere {name}: {e}", "Added {n} photo{}": "Foto aggiunte: {n}{:.0}", "Where should the Lightroom catalog “{catalog}” go?": "Dove importare il catalogo Lightroom “{catalog}”?", - "Merge into the open library “{library}” ({count} photo{})": "Unisci alla libreria aperta “{library}” (foto: {count}{:.0})" + "Merge into the open library “{library}” ({count} photo{})": "Unisci alla libreria aperta “{library}” (foto: {count}{:.0})", + "Profile: {} (lens database)": "Profilo: {} (database degli obiettivi)", + "No lens profile found for {}.": "Nessun profilo obiettivo trovato per {}.", + "{n} photos got their lens profile": "{n} foto hanno ricevuto il profilo dell'obiettivo" } diff --git a/crates/ui-egui/locales/it.json b/crates/ui-egui/locales/it.json index e159fd47d1..14419b86b8 100644 --- a/crates/ui-egui/locales/it.json +++ b/crates/ui-egui/locales/it.json @@ -2361,5 +2361,11 @@ "Import dropped files without review": "Importa i file rilasciati senza revisione", "An import is running": "Un'importazione è in corso", "An import is running. Drop photos when it has finished": "Un'importazione è in corso. Trascina le foto quando è finita", - "Finish Lightroom catalog import before adding photos": "Termina l'importazione del catalogo Lightroom prima di aggiungere foto" + "Finish Lightroom catalog import before adding photos": "Termina l'importazione del catalogo Lightroom prima di aggiungere foto", + "Profile: from the file (the camera's own correction)": "Profilo: dal file (correzione della fotocamera)", + "Downloading the lens database…": "Download del database degli obiettivi…", + "This file names no lens.": "Questo file non indica alcun obiettivo.", + "1 photo got its lens profile": "1 foto ha ricevuto il profilo dell'obiettivo", + "Looking up lens profiles": "Ricerca dei profili degli obiettivi", + "Downloading the lens database": "Download del database degli obiettivi" } diff --git a/crates/ui-egui/locales/ja-formats.json b/crates/ui-egui/locales/ja-formats.json index 99c14bf16d..dfe3de7b00 100644 --- a/crates/ui-egui/locales/ja-formats.json +++ b/crates/ui-egui/locales/ja-formats.json @@ -305,5 +305,8 @@ "Could not read {name}: {e}": "{name} を読み取れませんでした: {e}", "Added {n} photo{}": "{n}枚を追加しました{:.0}", "Where should the Lightroom catalog “{catalog}” go?": "Lightroom カタログ「{catalog}」をどこに読み込みますか?", - "Merge into the open library “{library}” ({count} photo{})": "開いているライブラリ「{library}」に統合(写真{count}枚){:.0}" + "Merge into the open library “{library}” ({count} photo{})": "開いているライブラリ「{library}」に統合(写真{count}枚){:.0}", + "Profile: {} (lens database)": "プロファイル: {}(レンズデータベース)", + "No lens profile found for {}.": "{} のレンズプロファイルが見つかりません。", + "{n} photos got their lens profile": "{n} 枚の写真にレンズプロファイルが適用されました" } diff --git a/crates/ui-egui/locales/ja.json b/crates/ui-egui/locales/ja.json index e1834555bd..d7670e1c45 100644 --- a/crates/ui-egui/locales/ja.json +++ b/crates/ui-egui/locales/ja.json @@ -2356,5 +2356,11 @@ "Import dropped files without review": "ドロップしたファイルを確認せずに読み込む", "An import is running": "読み込み中です", "An import is running. Drop photos when it has finished": "読み込み中です。完了してから写真をドロップしてください", - "Finish Lightroom catalog import before adding photos": "写真を追加する前に Lightroom カタログの読み込みを完了してください" + "Finish Lightroom catalog import before adding photos": "写真を追加する前に Lightroom カタログの読み込みを完了してください", + "Profile: from the file (the camera's own correction)": "プロファイル: ファイル内(カメラ自身の補正)", + "Downloading the lens database…": "レンズデータベースをダウンロード中…", + "This file names no lens.": "このファイルにはレンズ名がありません。", + "1 photo got its lens profile": "1 枚の写真にレンズプロファイルが適用されました", + "Looking up lens profiles": "レンズプロファイルを検索中", + "Downloading the lens database": "レンズデータベースをダウンロード中" } diff --git a/crates/ui-egui/locales/ka-formats.json b/crates/ui-egui/locales/ka-formats.json index 4603682618..bacd85c73c 100644 --- a/crates/ui-egui/locales/ka-formats.json +++ b/crates/ui-egui/locales/ka-formats.json @@ -305,5 +305,8 @@ "Could not read {name}: {e}": "ვერ წაიკითხა {name}: {e}", "Added {n} photo{}": "დაემატა ფოტო: {n}{:.0}", "Where should the Lightroom catalog “{catalog}” go?": "სად გადავიტანოთ Lightroom-ის კატალოგი „{catalog}“?", - "Merge into the open library “{library}” ({count} photo{})": "გაერთიანება ღია ბიბლიოთეკასთან „{library}“ (ფოტოები: {count}){:.0}" + "Merge into the open library “{library}” ({count} photo{})": "გაერთიანება ღია ბიბლიოთეკასთან „{library}“ (ფოტოები: {count}){:.0}", + "Profile: {} (lens database)": "პროფილი: {} (ობიექტივების ბაზა)", + "No lens profile found for {}.": "{}-ისთვის ობიექტივის პროფილი ვერ მოიძებნა.", + "{n} photos got their lens profile": "ობიექტივის პროფილი მიიღო {n} ფოტომ" } diff --git a/crates/ui-egui/locales/ka.json b/crates/ui-egui/locales/ka.json index 32c4077001..646b6eb6cd 100644 --- a/crates/ui-egui/locales/ka.json +++ b/crates/ui-egui/locales/ka.json @@ -2734,5 +2734,11 @@ "Import dropped files without review": "ჩაგდებული ფაილების იმპორტი გადახედვის გარეშე", "An import is running": "იმპორტი მიმდინარეობს", "An import is running. Drop photos when it has finished": "იმპორტი მიმდინარეობს. ფოტოები ჩააგდეთ, როცა დასრულდება", - "Finish Lightroom catalog import before adding photos": "ფოტოების დამატებამდე დაასრულეთ Lightroom-ის კატალოგის იმპორტი" + "Finish Lightroom catalog import before adding photos": "ფოტოების დამატებამდე დაასრულეთ Lightroom-ის კატალოგის იმპორტი", + "Profile: from the file (the camera's own correction)": "პროფილი: ფაილიდან (კამერის საკუთარი კორექცია)", + "Downloading the lens database…": "ობიექტივების ბაზა იტვირთება…", + "This file names no lens.": "ამ ფაილში ობიექტივი არ არის მითითებული.", + "1 photo got its lens profile": "1 ფოტომ მიიღო ობიექტივის პროფილი", + "Looking up lens profiles": "ობიექტივის პროფილების ძიება", + "Downloading the lens database": "ობიექტივების ბაზის ჩამოტვირთვა" } diff --git a/crates/ui-egui/locales/pl-formats.json b/crates/ui-egui/locales/pl-formats.json index 20c7f840d6..d312f8e6ba 100644 --- a/crates/ui-egui/locales/pl-formats.json +++ b/crates/ui-egui/locales/pl-formats.json @@ -305,5 +305,8 @@ "Added {n} photo{}": "Dodano zdjęcia: {n}{:.0}", "Inside: {names}": "Wewnątrz: {names}", "Where should the Lightroom catalog “{catalog}” go?": "Dokąd zaimportować katalog Lightroom „{catalog}”?", - "Merge into the open library “{library}” ({count} photo{})": "Scal z otwartą biblioteką „{library}” (zdjęcia: {count}){:.0}" + "Merge into the open library “{library}” ({count} photo{})": "Scal z otwartą biblioteką „{library}” (zdjęcia: {count}){:.0}", + "Profile: {} (lens database)": "Profil: {} (baza obiektywów)", + "No lens profile found for {}.": "Nie znaleziono profilu obiektywu dla {}.", + "{n} photos got their lens profile": "Profil obiektywu otrzymały zdjęcia: {n}" } diff --git a/crates/ui-egui/locales/pl.json b/crates/ui-egui/locales/pl.json index adac22e62a..dedb38a14a 100644 --- a/crates/ui-egui/locales/pl.json +++ b/crates/ui-egui/locales/pl.json @@ -2283,5 +2283,11 @@ "Import dropped files without review": "Importuj upuszczone pliki bez przeglądu", "An import is running": "Import jest w toku", "An import is running. Drop photos when it has finished": "Import jest w toku. Upuść zdjęcia, gdy się zakończy", - "Finish Lightroom catalog import before adding photos": "Zakończ import katalogu Lightrooma, zanim dodasz zdjęcia" + "Finish Lightroom catalog import before adding photos": "Zakończ import katalogu Lightrooma, zanim dodasz zdjęcia", + "Profile: from the file (the camera's own correction)": "Profil: z pliku (korekcja aparatu)", + "Downloading the lens database…": "Pobieranie bazy obiektywów…", + "This file names no lens.": "Ten plik nie podaje obiektywu.", + "1 photo got its lens profile": "1 zdjęcie otrzymało profil obiektywu", + "Looking up lens profiles": "Wyszukiwanie profili obiektywów", + "Downloading the lens database": "Pobieranie bazy obiektywów" } diff --git a/crates/ui-egui/locales/pt-br-formats.json b/crates/ui-egui/locales/pt-br-formats.json index f17f2c0fd4..9a8f1144ef 100644 --- a/crates/ui-egui/locales/pt-br-formats.json +++ b/crates/ui-egui/locales/pt-br-formats.json @@ -305,5 +305,8 @@ "Could not read {name}: {e}": "Não foi possível ler {name}: {e}", "Added {n} photo{}": "{n} foto{0} adicionada{0}", "Where should the Lightroom catalog “{catalog}” go?": "Para onde vai o catálogo do Lightroom “{catalog}”?", - "Merge into the open library “{library}” ({count} photo{})": "Mesclar na biblioteca aberta “{library}” ({count} foto{})" + "Merge into the open library “{library}” ({count} photo{})": "Mesclar na biblioteca aberta “{library}” ({count} foto{})", + "Profile: {} (lens database)": "Perfil: {} (banco de dados de lentes)", + "No lens profile found for {}.": "Nenhum perfil de lente encontrado para {}.", + "{n} photos got their lens profile": "{n} fotos receberam o perfil da lente" } diff --git a/crates/ui-egui/locales/pt-br.json b/crates/ui-egui/locales/pt-br.json index e84fb7615b..ea8ecbb986 100644 --- a/crates/ui-egui/locales/pt-br.json +++ b/crates/ui-egui/locales/pt-br.json @@ -2202,5 +2202,11 @@ "Import dropped files without review": "Importar arquivos soltos sem revisão", "An import is running": "Uma importação está em andamento", "An import is running. Drop photos when it has finished": "Uma importação está em andamento. Solte as fotos quando ela terminar", - "Finish Lightroom catalog import before adding photos": "Conclua a importação do catálogo do Lightroom antes de adicionar fotos" + "Finish Lightroom catalog import before adding photos": "Conclua a importação do catálogo do Lightroom antes de adicionar fotos", + "Profile: from the file (the camera's own correction)": "Perfil: do arquivo (correção da própria câmera)", + "Downloading the lens database…": "Baixando o banco de dados de lentes…", + "This file names no lens.": "Este arquivo não indica nenhuma lente.", + "1 photo got its lens profile": "1 foto recebeu o perfil da lente", + "Looking up lens profiles": "Procurando perfis de lente", + "Downloading the lens database": "Baixando o banco de dados de lentes" } diff --git a/crates/ui-egui/locales/ru-formats.json b/crates/ui-egui/locales/ru-formats.json index 76b7af4276..060eabbf8e 100644 --- a/crates/ui-egui/locales/ru-formats.json +++ b/crates/ui-egui/locales/ru-formats.json @@ -305,5 +305,8 @@ "Could not read {name}: {e}": "Не удалось прочитать {name}: {e}", "Added {n} photo{}": "Добавлено фото: {n}{:.0}", "Where should the Lightroom catalog “{catalog}” go?": "Куда импортировать каталог Lightroom «{catalog}»?", - "Merge into the open library “{library}” ({count} photo{})": "Объединить с открытой библиотекой «{library}» (фото: {count}){:.0}" + "Merge into the open library “{library}” ({count} photo{})": "Объединить с открытой библиотекой «{library}» (фото: {count}){:.0}", + "Profile: {} (lens database)": "Профиль: {} (база объективов)", + "No lens profile found for {}.": "Профиль объектива для {} не найден.", + "{n} photos got their lens profile": "Профиль объектива получили фото: {n}" } diff --git a/crates/ui-egui/locales/ru.json b/crates/ui-egui/locales/ru.json index 306804df04..ec340f98e8 100644 --- a/crates/ui-egui/locales/ru.json +++ b/crates/ui-egui/locales/ru.json @@ -2349,5 +2349,11 @@ "Import dropped files without review": "Импортировать перетащенные файлы без проверки", "An import is running": "Импорт уже выполняется", "An import is running. Drop photos when it has finished": "Импорт уже выполняется. Перетащите фото, когда он закончится", - "Finish Lightroom catalog import before adding photos": "Завершите импорт каталога Lightroom, прежде чем добавлять фото" + "Finish Lightroom catalog import before adding photos": "Завершите импорт каталога Lightroom, прежде чем добавлять фото", + "Profile: from the file (the camera's own correction)": "Профиль: из файла (коррекция самой камеры)", + "Downloading the lens database…": "Загружается база объективов…", + "This file names no lens.": "В этом файле не указан объектив.", + "1 photo got its lens profile": "1 фото получило профиль объектива", + "Looking up lens profiles": "Поиск профилей объективов", + "Downloading the lens database": "Загрузка базы объективов" } diff --git a/crates/ui-egui/locales/uk-formats.json b/crates/ui-egui/locales/uk-formats.json index 36022ac1a2..9e1b31144e 100644 --- a/crates/ui-egui/locales/uk-formats.json +++ b/crates/ui-egui/locales/uk-formats.json @@ -305,5 +305,8 @@ "Could not read {name}: {e}": "Не вдалося прочитати {name}: {e}", "Added {n} photo{}": "Додано фото: {n}{:.0}", "Where should the Lightroom catalog “{catalog}” go?": "Куди імпортувати каталог Lightroom «{catalog}»?", - "Merge into the open library “{library}” ({count} photo{})": "Об’єднати з відкритою бібліотекою «{library}» (фото: {count}){:.0}" + "Merge into the open library “{library}” ({count} photo{})": "Об’єднати з відкритою бібліотекою «{library}» (фото: {count}){:.0}", + "Profile: {} (lens database)": "Профіль: {} (база об'єктивів)", + "No lens profile found for {}.": "Профіль об'єктива для {} не знайдено.", + "{n} photos got their lens profile": "Профіль об'єктива отримали фото: {n}" } diff --git a/crates/ui-egui/locales/uk.json b/crates/ui-egui/locales/uk.json index ee694ed4fe..a43ffbd1f4 100644 --- a/crates/ui-egui/locales/uk.json +++ b/crates/ui-egui/locales/uk.json @@ -2354,5 +2354,11 @@ "Import dropped files without review": "Імпортувати перетягнуті файли без перегляду", "An import is running": "Імпорт уже виконується", "An import is running. Drop photos when it has finished": "Імпорт уже виконується. Перетягніть фото, коли він завершиться", - "Finish Lightroom catalog import before adding photos": "Завершіть імпорт каталогу Lightroom, перш ніж додавати фото" + "Finish Lightroom catalog import before adding photos": "Завершіть імпорт каталогу Lightroom, перш ніж додавати фото", + "Profile: from the file (the camera's own correction)": "Профіль: з файлу (корекція самої камери)", + "Downloading the lens database…": "Завантажується база об'єктивів…", + "This file names no lens.": "У цьому файлі не вказано об'єктив.", + "1 photo got its lens profile": "1 фото отримало профіль об'єктива", + "Looking up lens profiles": "Пошук профілів об'єктивів", + "Downloading the lens database": "Завантаження бази об'єктивів" } diff --git a/crates/ui-egui/locales/zh-hans-formats.json b/crates/ui-egui/locales/zh-hans-formats.json index 7406c39b86..d5e6145ffa 100644 --- a/crates/ui-egui/locales/zh-hans-formats.json +++ b/crates/ui-egui/locales/zh-hans-formats.json @@ -305,5 +305,8 @@ "Could not read {name}: {e}": "无法读取 {name}:{e}", "Added {n} photo{}": "已添加 {n} 张照片{:.0}", "Where should the Lightroom catalog “{catalog}” go?": "Lightroom 目录“{catalog}”要导入到哪里?", - "Merge into the open library “{library}” ({count} photo{})": "合并到当前打开的图库“{library}”({count} 张照片){:.0}" + "Merge into the open library “{library}” ({count} photo{})": "合并到当前打开的图库“{library}”({count} 张照片){:.0}", + "Profile: {} (lens database)": "配置文件:{}(镜头数据库)", + "No lens profile found for {}.": "未找到 {} 的镜头配置文件。", + "{n} photos got their lens profile": "{n} 张照片获得了镜头配置文件" } diff --git a/crates/ui-egui/locales/zh-hans.json b/crates/ui-egui/locales/zh-hans.json index 270af8a625..5bd3b0805e 100644 --- a/crates/ui-egui/locales/zh-hans.json +++ b/crates/ui-egui/locales/zh-hans.json @@ -2200,5 +2200,11 @@ "Import dropped files without review": "不经检查直接导入拖入的文件", "An import is running": "正在导入", "An import is running. Drop photos when it has finished": "正在导入。导入完成后再拖放照片", - "Finish Lightroom catalog import before adding photos": "添加照片前,请先完成 Lightroom 目录的导入" + "Finish Lightroom catalog import before adding photos": "添加照片前,请先完成 Lightroom 目录的导入", + "Profile: from the file (the camera's own correction)": "配置文件:来自文件(相机自身的校正)", + "Downloading the lens database…": "正在下载镜头数据库…", + "This file names no lens.": "此文件未注明镜头。", + "1 photo got its lens profile": "1 张照片获得了镜头配置文件", + "Looking up lens profiles": "正在查找镜头配置文件", + "Downloading the lens database": "正在下载镜头数据库" } diff --git a/crates/ui-egui/locales/zh-hant-formats.json b/crates/ui-egui/locales/zh-hant-formats.json index d5c4eb279a..6aff8bca77 100644 --- a/crates/ui-egui/locales/zh-hant-formats.json +++ b/crates/ui-egui/locales/zh-hant-formats.json @@ -305,5 +305,8 @@ "Could not read {name}: {e}": "無法讀取 {name}:{e}", "Added {n} photo{}": "已加入 {n} 張照片{:.0}", "Where should the Lightroom catalog “{catalog}” go?": "Lightroom 目錄「{catalog}」要匯入到哪裡?", - "Merge into the open library “{library}” ({count} photo{})": "合併到目前開啟的照片庫「{library}」({count} 張照片){:.0}" + "Merge into the open library “{library}” ({count} photo{})": "合併到目前開啟的照片庫「{library}」({count} 張照片){:.0}", + "Profile: {} (lens database)": "設定檔:{}(鏡頭資料庫)", + "No lens profile found for {}.": "找不到 {} 的鏡頭設定檔。", + "{n} photos got their lens profile": "{n} 張照片取得了鏡頭設定檔" } diff --git a/crates/ui-egui/locales/zh-hant.json b/crates/ui-egui/locales/zh-hant.json index 0408e23ec8..ddba21e479 100644 --- a/crates/ui-egui/locales/zh-hant.json +++ b/crates/ui-egui/locales/zh-hant.json @@ -2157,5 +2157,11 @@ "Import dropped files without review": "不經檢查直接匯入拖放的檔案", "An import is running": "正在匯入", "An import is running. Drop photos when it has finished": "正在匯入。匯入完成後再拖放照片", - "Finish Lightroom catalog import before adding photos": "新增照片前,請先完成 Lightroom 目錄的匯入" + "Finish Lightroom catalog import before adding photos": "新增照片前,請先完成 Lightroom 目錄的匯入", + "Profile: from the file (the camera's own correction)": "設定檔:來自檔案(相機本身的校正)", + "Downloading the lens database…": "正在下載鏡頭資料庫…", + "This file names no lens.": "此檔案未註明鏡頭。", + "1 photo got its lens profile": "1 張照片取得了鏡頭設定檔", + "Looking up lens profiles": "正在查找鏡頭設定檔", + "Downloading the lens database": "正在下載鏡頭資料庫" } diff --git a/crates/ui-egui/src/lens_db.rs b/crates/ui-egui/src/lens_db.rs new file mode 100644 index 0000000000..f828dacb69 --- /dev/null +++ b/crates/ui-egui/src/lens_db.rs @@ -0,0 +1,141 @@ +//! The lens database without setup: on first run the app fetches lensfun's database by itself +//! (`lightcraft_engine::lensfun_download`, an activity row while it runs), and whenever the database in use changes +//! (it arrived, a newer pin replaced it) or Enable Lens Corrections is ticked on a photo without a profile, the +//! library's raws that have none are looked up again on a worker thread (`lightcraft_engine::cmd::lens_refresh`). + +use lightcraft_engine::cmd::{lens_refresh, recheck}; +use lightcraft_engine::{lens_profiles, lensfun_download}; + +use crate::LightcraftApp; + +/// The activity stack's label while files are read for their lens. +pub const LABEL: &str = "Looking up lens profiles"; + +/// Called every frame. +pub fn tick(app: &mut LightcraftApp) { + start_download(app); + refresh(app); +} + +/// Once per run, when the host asked for the app's own copy and it is missing (or from an older pin). +fn start_download(app: &mut LightcraftApp) { + if app.ui.lens_download_checked || !app.session.lens_auto_download { + return; + } + app.ui.lens_download_checked = true; + // a folder of the user's own (LIGHTCRAFT_LENSFUN_DIR) is never replaced + if std::env::var_os(lens_profiles::ENV).is_some_and(|v| !v.is_empty()) { + return; + } + let Some(dir) = lensfun_download::default_dir() else { return }; + if lensfun_download::installed(&dir) { + return; + } + let activity = app.session.activity.clone(); + if let Err(e) = app.session.lensfun.start(&dir, lensfun_download::mirrors(), lensfun_download::FILES, &activity) { + log::warn!("lens database: {e}"); + } +} + +/// Look the library's raws up again when the database changed, the library changed, or photos asked for it. +fn refresh(app: &mut LightcraftApp) { + let key = (app.session.library_generation(), lens_profiles::generation()); + let asked = std::mem::take(&mut app.ui.lens_lookup_ids); + if app.ui.lens_refreshed == Some(key) && asked.is_empty() { + return; + } + // (a lookup already under way finishes first; what was asked meanwhile waits for the next frame) + if app.tasks.is_running(LABEL) { + app.ui.lens_lookup_ids.extend(asked); + return; + } + let ids = (app.ui.lens_refreshed == Some(key)).then_some(asked); + app.ui.lens_refreshed = Some(key); + let Some(probe) = recheck::file_probe(&app.session) else { return }; + let Some(db) = lens_profiles::database() else { return }; + let listed = lens_refresh::missing(&app.session.catalog, &db, ids.as_deref()); + if listed.is_empty() { + return; + } + let library = key.0; + let work = move || lens_refresh::probe(&probe, listed); + let done = move |app: &mut LightcraftApp, ctx: &egui::Context, results| { + if app.session.library_generation() != library { + return; + } + match lens_refresh::apply(&mut app.session, results) { + Ok(found) if found.len() == 1 => app.toast(ctx, crate::i18n::tr("1 photo got its lens profile")), + Ok(found) if found.len() > 1 => app.toast(ctx, crate::i18n::tr_format!("{n} photos got their lens profile", n = found.len())), + Ok(_) => {} + Err(e) => log::warn!("lens profile lookup: {e}"), + } + }; + if let Err(e) = crate::tasks::spawn(app, LABEL, Some("lensLookup"), work, done) { + log::warn!("{e}"); + } +} + +/// The database's name for a lens, remembered per lens and database (the panel asks every frame; a search scores +/// every lens in the database). +fn database_name(camera: &str, lens: &str) -> Option { + type Key = (String, String, u64); + thread_local! { + static LAST: std::cell::RefCell)>> = const { std::cell::RefCell::new(None) }; + } + let key = (camera.to_string(), lens.to_string(), lens_profiles::generation()); + LAST.with(|last| { + if let Some((k, name)) = last.borrow().as_ref() + && *k == key + { + return name.clone(); + } + let name = lens_profiles::database().and_then(|db| lens_profiles::profile_name(&db, camera, lens)); + *last.borrow_mut() = Some((key, name.clone())); + name + }) +} + +/// What the Optics panel says about photo `p`'s lens profile: which one is loaded and from where, or why there is +/// none. +pub fn readout(app: &LightcraftApp, p: &lightcraft_catalog::Photo) -> String { + use lightcraft_develop::LensSource; + match p.embedded_lens.map(|l| l.source) { + Some(LensSource::File) => crate::i18n::tr("Profile: from the file (the camera's own correction)").to_string(), + Some(LensSource::Database) => { + let name = database_name(&p.meta.camera, &p.meta.lens).unwrap_or_else(|| p.meta.lens.trim().to_string()); + crate::i18n::tr_format!("Profile: {} (lens database)", name) + } + None if app.session.lensfun.running() => crate::i18n::tr("Downloading the lens database…").to_string(), + None => match lens_refresh::no_profile_reason(p) { + Some(r) if p.meta.lens.trim().is_empty() => crate::i18n::tr(&r).to_string(), + Some(_) => crate::i18n::tr_format!("No lens profile found for {}.", p.meta.lens.trim()), + None => String::new(), + }, + } +} + +#[cfg(test)] +mod tests { + use crate::{LightcraftApp, Services}; + use lightcraft_develop::{EmbeddedLens, LensSource}; + + /// The Optics panel says which profile is loaded and from where, or why there is none. + #[test] + fn the_optics_readout_names_the_profile_or_the_lens_without_one() { + let app = LightcraftApp::new(lightcraft_engine::Session::with_demo(), Services { png: None, ..Default::default() }); + let id = app.session.active().expect("a photo"); + let mut p = (**app.session.catalog.photo(id).expect("the photo")).clone(); + p.meta.lens = "EF35mm f/1.4L II USM".into(); + p.embedded_lens = None; + assert_eq!(super::readout(&app, &p), "No lens profile found for EF35mm f/1.4L II USM."); + p.meta.lens.clear(); + assert_eq!(super::readout(&app, &p), "This file names no lens."); + p.embedded_lens = Some(EmbeddedLens::default()); + assert_eq!(super::readout(&app, &p), "Profile: from the file (the camera's own correction)"); + p.meta.lens = "EF70-200mm f/2.8L IS II USM".into(); + p.embedded_lens = Some(EmbeddedLens { source: LensSource::Database, ..Default::default() }); + // the database's name for it, or the file's own without a database (LIGHTCRAFT_LENSFUN_DIR may be set) + let r = super::readout(&app, &p); + assert!(r.starts_with("Profile: ") && r.contains("70-200mm f/2.8L IS II USM") && r.ends_with(" (lens database)"), "{r}"); + } +} diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index e53989fca9..9f78d63f47 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -23,6 +23,7 @@ pub mod headless; pub mod i18n; pub mod icons; pub mod import; +pub mod lens_db; pub mod lightroom_destination; pub mod lightroom_import; pub mod links; @@ -1970,6 +1971,7 @@ impl LightcraftApp { } lightroom_import::tick(self, ctx); recheck::tick(self); + lens_db::tick(self); tasks::poll(self, ctx); updates_ui::tick(self, ctx); self.preview_build_status(ctx); diff --git a/crates/ui-egui/src/panels/edit.rs b/crates/ui-egui/src/panels/edit.rs index 10542e4432..d82de05dad 100644 --- a/crates/ui-egui/src/panels/edit.rs +++ b/crates/ui-egui/src/panels/edit.rs @@ -374,12 +374,23 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId) { } let mut lp = d.optics.lens_profile; if ui.checkbox(&mut lp, crate::i18n::tr("Enable Lens Corrections")).changed() { - let _ = app.run("develop.merge", json!({"settings": {"optics": {"lens_profile": lp}}, "label": "Lens Corrections"})); + let ok = app.run("develop.merge", json!({"settings": {"optics": {"lens_profile": lp}}, "label": "Lens Corrections"})).is_ok(); + // ticked on photos without a profile: look their lenses up again (a database that arrived + // since they were imported may know them now) + if ok && lp { + let without: Vec<_> = std::iter::once(id) + .chain(app.session.selection.ids.iter().copied()) + .filter(|t| app.session.catalog.photo(*t).is_some_and(|p| p.embedded_lens.is_none())) + .collect(); + app.ui.lens_lookup_ids.extend(without); + } } - if lp && !has_lens { - ui.label( - egui::RichText::new(crate::i18n::tr("No lens data embedded in this file.")).size(11.0).color(Tokens::get(ui.ctx()).text_dim), - ); + if lp && let Some(p) = app.session.catalog.photo(id).cloned() { + let text = crate::lens_db::readout(app, &p); + if !text.is_empty() { + let r = ui.label(egui::RichText::new(text).size(11.0).color(Tokens::get(ui.ctx()).text_dim)); + crate::widgets::register(ui, "optics:lensProfile", r.rect); + } } }); if d.optics.lens_profile { diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 310cac90ab..9011f85771 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -1099,6 +1099,15 @@ pub struct UiState { /// (`crate::recheck`). #[serde(skip)] pub rechecked_library: Option, + /// The first-run lens database download was considered this run (`crate::lens_db`). + #[serde(skip)] + pub lens_download_checked: bool, + /// The library and lens database generation whose raws were last looked up for a lens profile. + #[serde(skip)] + pub lens_refreshed: Option<(u64, u64)>, + /// Photos to look up for a lens profile on the next frame (Enable Lens Corrections ticked without one). + #[serde(skip)] + pub lens_lookup_ids: Vec, #[serde(skip)] pub status: String, #[serde(skip)] @@ -1618,6 +1627,9 @@ impl Default for UiState { #[cfg(test)] find_missing_test_delay: None, rechecked_library: None, + lens_download_checked: false, + lens_refreshed: None, + lens_lookup_ids: Vec::new(), status: String::new(), dialog: None, print: Default::default(), diff --git a/docs/gaps.md b/docs/gaps.md index 42d9d437b6..c2f0e4c18d 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -1,6 +1,6 @@ # Gaps: where LightCraft falls short of Lightroom -> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-24 · **Change:** minor (gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 551 models verified; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF) +> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-27 · **Change:** minor (gap 8: lensfun's lens database downloaded on first run, looked up for the library; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 551 models verified; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF) Every known shortfall, one entry each, ranked by user impact (how many Lightroom users hit it, and how hard it blocks them), then by effort. **Agents pick work from the top** (the first entry nobody is @@ -22,7 +22,7 @@ Hours are Opus 5.5 agent wall-clock hours (see [target-app-parity.md](target-app | 5 B | **AI masks: Subject, Sky, People, Background, Landscape** are heuristics; Object / Describe run SAM 3 but its download has no mirror configured | `crates/segment`; ai-masks.md; MASK rows 67% | masking is how most Lightroom users edit today | 40–70 + model decision | [target-app-parity](target-app-parity.md#ai) | | 6 B | **Compressed ORF** (every Olympus / OM body since ~2008) | measured: 66 of 78 Olympus / OM models preview-only; `orf.rs` refuses; OM bucket 3% of photographers, 3% of them fully work | +2.6 points; best gain per hour of any raw gap (~0.2) | 8–15 | [raw-parity](raw-parity.md#compressed-orf-a-clean-room-starting-point) (the two Olympus patents that describe the method) | | 7 | **Nikon High Efficiency NEF** (HE / HE★ on Z 8, Z 9, Z 6III, Z f, Z50II, Z5II when set to HE) | named and preview only (#193); needs a pure-Rust JPEG XS decoder | +1.1 points (only shots taken in HE; lossless works on the same bodies); low gain per hour (~0.04), so not a beta blocker | 20–40 | [raw-parity](raw-parity.md) | -| 8 B | **No lens profile database** (LR-EDIT-OPTICS-PROFILE): only DNG opcodes, RW2 in-file distortion, Sony ILCE-7RM4A, full-frame ILCE-7CR distortion (Auto only) and ILCE-7RM6 distortion (`docs/sony-ilce7rm6-lens-corrections.md`) and Nikon Z 6II / Z 8 / Z f distortion (`docs/nikon-lens-corrections.md`) | Adobe ships 3,635 lens profiles; we never use them | distortion / vignetting correction is a default step for many | 40–80 + calibration shots | [raw-parity](raw-parity.md#lens-profiles) | +| 8 B | **Lens profiles: lensfun only, no picker, no own calibration** (LR-EDIT-OPTICS-PROFILE): the desktop app downloads lensfun's database (CC BY-SA 3.0, pinned, never bundled) by itself on first run and looks every raw up by its lens ([lens-profiles.md](lens-profiles.md)), but those profiles are not validated against Lightroom, there is no profile picker (in the file / lens database / own calibration) and no calibration wizard; in-file corrections: DNG opcodes, RW2 in-file distortion, Sony ILCE-7RM4A, full-frame ILCE-7CR distortion (Auto only) and ILCE-7RM6 distortion (`docs/sony-ilce7rm6-lens-corrections.md`) and Nikon Z 6II / Z 8 / Z f distortion (`docs/nikon-lens-corrections.md`) | Adobe ships 3,635 lens profiles; we never use them | distortion / vignetting correction is a default step for many | 40–80 + calibration shots | [raw-parity](raw-parity.md#lens-profiles) | | 9 B | **Tests don't run in CI on macOS or Windows**: Linux x64 runs `cargo xtask ci` on every PR and push to main (`.github/workflows/ci.yml`) and FreeBSD runs `cargo test`; the others build packages | `.github/workflows/` (ci, freebsd, packaging-lint, release, windows-arm64); the linux-riscv64 release job added in 0.6.0 (#844) runs only `lightcraft-cli --version` under QEMU; macOS / Windows jobs: #1148 | regressions in `cfg(target_os)` code reach macOS and Windows users | 6–12 | [target-app-parity](target-app-parity.md#by-dimension) | | 10 B | **Per-model verification thin, plus cheap per-body decode fixes**: 551 of 1,446 Adobe models verified (38%), ~85% of photographers on a verified body; Nikon 5 bodies verified, Canon 34, Leica 14 (the Q3 by a recorded check of 38 private DNGs). Cheap fixes: Z 6II packed 14-bit NEF (#769, PR #671), Sony A100 regression (#702); F828 SRF now discovered and imported as preview-only, sensor decoding still missing, DSLR-A200…A390 / A850 12-bit ARW (#535) | measured: [raw/coverage.tsv](raw/coverage.tsv) | per-body bugs (levels, crops, WB) surface only from users | 25–45 | [raw-parity](raw-parity.md#by-maker-measured) | | 11 | **Enhance: Raw Details, Super Resolution; AI denoise without shippable weights or X-Trans** | ENH rows 0%; denoise Bayer only, RawNIND weights GPL and opt-in | Fujifilm users get no AI denoise; nobody gets it out of the box | 30–60 + model decision | [raw-parity](raw-parity.md#demosaic-levels-crops-and-lens-metadata) | @@ -84,6 +84,7 @@ Beta-blocking gaps (B) total **~230–430 h**; with the stability and platform w | Date | Change | Summary | |---|---|---| +| 2026-10-27 | minor | Gap 8 shrinks: the desktop app downloads lensfun's lens database (CC BY-SA, pinned) by itself on first run and looks the library's raws up when it arrives; validation, a profile picker and own calibration remain | | 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/lens-profiles.md b/docs/lens-profiles.md index 13d1b2b7a7..80739f47f1 100644 --- a/docs/lens-profiles.md +++ b/docs/lens-profiles.md @@ -1,18 +1,33 @@ # Lens profiles from a lens database Raws that carry no lens correction of their own (DNG `OpcodeList3`, or a camera correction a raw reader converts, -see [sony-lens-corrections.md](sony-lens-corrections.md) and [nikon-lens-corrections.md](nikon-lens-corrections.md)) can be corrected from a **lens database in the lensfun -XML format** that you supply. The app does not ship any lens database: lensfun's data is licensed CC-BY-SA 3.0 and -stays a separate download. Adobe LCP profiles are never used. +see [sony-lens-corrections.md](sony-lens-corrections.md) and [nikon-lens-corrections.md](nikon-lens-corrections.md)) are corrected from a **lens database in the lensfun +XML format**. The app does not ship any lens database: lensfun's data is licensed CC BY-SA 3.0 and is downloaded at +run time, never bundled and never committed. Adobe LCP profiles are never used. -## Setup +## Setup: none -1. Get the lensfun database (the `data/db/*.xml` files of , or the copy a Linux - distribution installs under `/usr/share/lensfun/version_1/`). -2. Point `LIGHTCRAFT_LENSFUN_DIR` at that directory and start the app (or the CLI). +1. On first run the desktop app downloads lensfun's `data/db` (56 XML files, about 5 MB) into its data folder + (`/lensfun`, beside the face and denoise models; see `crates/engine/src/config.rs`), with a row in + the activity stack (its ✕ stops it; the next start resumes). The files are pinned to one lensfun commit by name, + size and SHA-256 (`crates/engine/src/lensfun_download.rs`); a file that differs is thrown away. A later build with + a newer pin replaces them once. `SOURCE.txt` in the folder names the commit and the licence. +2. By default the files come from lensfun's GitHub repository at the pinned commit. `LIGHTCRAFT_LENSFUN_URL` lists + other places serving the same files (base URLs, tried first), e.g. a copy on LightCraft's own server. +3. `LIGHTCRAFT_LENSFUN_DIR` points at a database of your own instead (lensfun's `data/db`, or a Linux + distribution's `/usr/share/lensfun/version_1/`); then nothing is downloaded. -Files are read once per process. Invalid files are skipped with a warning in the log. Without the variable nothing -changes. +When the database arrives (or changes), every library raw without a profile whose lens it knows is read again in the +background and gets its profile; a photo still as imported gets the correction switched on, as import would, and an +edited one keeps its settings. Ticking **Enable Lens Corrections** on a photo without a profile looks it up again +too. `library.refreshLensProfiles`, `lens.downloadDatabase` and `lens.databaseStatus` do the same for agents. + +The Optics panel says which profile is loaded: "Profile: from the file", "Profile: (lens database)", or +"No lens profile found for ". A profile is never copied between photos: presets, Copy / Paste, Sync and Auto +Sync carry Enable Lens Corrections and its amounts, and each photo keeps the profile of its own lens +(`crates/engine/src/tests_lens_refresh.rs`). + +Files are read once per folder and again after a download. Invalid files are skipped with a warning in the log. ## What is applied @@ -50,5 +65,6 @@ the image centre (lensfun's `
` offsets are not read). - Only raws: rendered images (JPEG, HEIF, TIFF) are often already corrected in camera. - The focus distance is not read from maker notes yet: vignetting uses the farthest calibrated distance. -- No manual make / model picker yet; matching is automatic. +- No manual make / model picker and no choice between sources (in the file, lens database, an own calibration) + yet; matching is automatic, the file's own correction wins. - Not yet validated against real photos and another renderer; the tests use synthetic profiles and grids. diff --git a/docs/parity-checklist.md b/docs/parity-checklist.md index afbed8675e..8bc456ad4a 100644 --- a/docs/parity-checklist.md +++ b/docs/parity-checklist.md @@ -1,6 +1,6 @@ # Lightroom parity checklist -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (LR-BEHAV-TITLEBAR: a double-click follows the system setting, and a panel over the bar keeps the window still; KEYC-METADATA, LRC-LIB-KEYWORDS: ⌥0 / ⌥⇧0 go to the next / previous keyword set; LRC-DEV-HISTOGRAM-DRAG: the histogram's five tonal zones — hover for the value, drag to adjust the Basic control the press locked, double-click to reset; LR-VIEW-HISTOGRAM note updated; MENU-BAR: on macOS a menu item that yields its key to a focused text field or to shortcut recording really lets it go; LR-MERGE-HDR / LR-MERGE-PANO: Lanczos-3 warps; LR-IMP-LOCAL: browsing from the sidebar records the folder; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LR-IMP-ADD-DIALOG: hierarchical import album destination reconciled with main, #2362; KEY-SLIDER-NUDGE: vertical wheel nudges need a click or drag in the row; leaving it disarms them; LR-EDIT-OPTICS-PROFILE: Fujifilm nine-knot lens tables read at the plain radius; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LRC-LIB-LIBFOLDERS, LR-BEHAV-BG-TASKS: Synchronize Folder's scan shows its folder listing and stops it on ✕; LRC-LIB-LIBFOLDERS: Synchronize Folder says a folder is up to date; LR-LIB-STACK: filmstrip stack badge click; LRC-LIB-REFVIEW / CATALOG-SWITCH: Escape preserves edits; catalog-local pins; deleted and malformed references refused; LRC-LIB-COMPARE: the Info panel labels the active photo while culling, #2398; KEYC-RATING: `\` shows / hides the Filter Bar in the grids; LR-VIEW-PHOTOGRID: the grid reads only the photos an import batch or an edit touched, not the whole list; earlier: LRC-PRINT-PAGE: Print Page Options; LR-META-XMP: fewer false unimported-XMP warnings; KEYC-METADATA: ⌘K / Ctrl+K Add Keywords; LRC-DEV-HISTOGRAM-DRAG: the histogram's five tonal zones — hover for the value, drag to adjust the Basic control the press locked, double-click to reset; LR-VIEW-HISTOGRAM note updated; MENU-BAR: on macOS a menu item that yields its key to a focused text field or to shortcut recording really lets it go; LR-MERGE-HDR / LR-MERGE-PANO: Lanczos-3 warps; LR-IMP-LOCAL: browsing from the sidebar records the folder; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LR-IMP-ADD-DIALOG: hierarchical import album destination reconciled with main, #2362; KEY-SLIDER-NUDGE: vertical wheel nudges need a click or drag in the row; leaving it disarms them; LR-EDIT-OPTICS-PROFILE: Fujifilm nine-knot lens tables read at the plain radius; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LRC-LIB-LIBFOLDERS, LR-BEHAV-BG-TASKS: Synchronize Folder's scan shows its folder listing and stops it on ✕; LRC-LIB-LIBFOLDERS: Synchronize Folder says a folder is up to date; LR-LIB-STACK: filmstrip stack badge click; LRC-LIB-REFVIEW / CATALOG-SWITCH: Escape preserves edits; catalog-local pins; deleted and malformed references refused; LRC-LIB-COMPARE: the Info panel labels the active photo while culling, #2398; KEYC-RATING: `\` shows / hides the Filter Bar in the grids; LR-VIEW-PHOTOGRID: the grid reads only the photos an import batch or an edit touched, not the whole list; earlier: LRC-PRINT-PAGE: Print Page Options; LR-META-XMP: fewer false unimported-XMP warnings) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-27 · **Change:** minor (LR-EDIT-OPTICS-PROFILE: lensfun downloaded by itself on first run, profiles looked up for the library, the Optics panel names the profile; profiles never travel between lenses; LR-BEHAV-TITLEBAR: a double-click follows the system setting, and a panel over the bar keeps the window still; KEYC-METADATA, LRC-LIB-KEYWORDS: ⌥0 / ⌥⇧0 go to the next / previous keyword set; LRC-DEV-HISTOGRAM-DRAG: the histogram's five tonal zones — hover for the value, drag to adjust the Basic control the press locked, double-click to reset; LR-VIEW-HISTOGRAM note updated; MENU-BAR: on macOS a menu item that yields its key to a focused text field or to shortcut recording really lets it go; LR-MERGE-HDR / LR-MERGE-PANO: Lanczos-3 warps; LR-IMP-LOCAL: browsing from the sidebar records the folder; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LR-IMP-ADD-DIALOG: hierarchical import album destination reconciled with main, #2362; KEY-SLIDER-NUDGE: vertical wheel nudges need a click or drag in the row; leaving it disarms them; LR-EDIT-OPTICS-PROFILE: Fujifilm nine-knot lens tables read at the plain radius; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LRC-LIB-LIBFOLDERS, LR-BEHAV-BG-TASKS: Synchronize Folder's scan shows its folder listing and stops it on ✕; LRC-LIB-LIBFOLDERS: Synchronize Folder says a folder is up to date; LR-LIB-STACK: filmstrip stack badge click; LRC-LIB-REFVIEW / CATALOG-SWITCH: Escape preserves edits; catalog-local pins; deleted and malformed references refused; LRC-LIB-COMPARE: the Info panel labels the active photo while culling, #2398; KEYC-RATING: `\` shows / hides the Filter Bar in the grids; LR-VIEW-PHOTOGRID: the grid reads only the photos an import batch or an edit touched, not the whole list; earlier: LRC-PRINT-PAGE: Print Page Options; LR-META-XMP: fewer false unimported-XMP warnings; KEYC-METADATA: ⌘K / Ctrl+K Add Keywords; LRC-DEV-HISTOGRAM-DRAG: the histogram's five tonal zones — hover for the value, drag to adjust the Basic control the press locked, double-click to reset; LR-VIEW-HISTOGRAM note updated; MENU-BAR: on macOS a menu item that yields its key to a focused text field or to shortcut recording really lets it go; LR-MERGE-HDR / LR-MERGE-PANO: Lanczos-3 warps; LR-IMP-LOCAL: browsing from the sidebar records the folder; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LR-IMP-ADD-DIALOG: hierarchical import album destination reconciled with main, #2362; KEY-SLIDER-NUDGE: vertical wheel nudges need a click or drag in the row; leaving it disarms them; LR-EDIT-OPTICS-PROFILE: Fujifilm nine-knot lens tables read at the plain radius; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LRC-LIB-LIBFOLDERS, LR-BEHAV-BG-TASKS: Synchronize Folder's scan shows its folder listing and stops it on ✕; LRC-LIB-LIBFOLDERS: Synchronize Folder says a folder is up to date; LR-LIB-STACK: filmstrip stack badge click; LRC-LIB-REFVIEW / CATALOG-SWITCH: Escape preserves edits; catalog-local pins; deleted and malformed references refused; LRC-LIB-COMPARE: the Info panel labels the active photo while culling, #2398; KEYC-RATING: `\` shows / hides the Filter Bar in the grids; LR-VIEW-PHOTOGRID: the grid reads only the photos an import batch or an edit touched, not the whole list; earlier: LRC-PRINT-PAGE: Print Page Options; LR-META-XMP: fewer false unimported-XMP warnings) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6 The measured, row-by-row checklist: one row per Lightroom feature, menu item and shortcut, what we have and what is missing. It answers *does the feature exist?* (feature breadth). Whether it is good @@ -212,7 +212,7 @@ differences and missing bindings are in [ui-parity.md](ui-parity.md#shortcuts). | LR-EDIT-DETAIL-SUPERRES | Super resolution | P2 | ⬜ | | | | LR-EDIT-DETAIL-AISHARPEN | AI sharpen | OOS | 🚫 | | | | LR-EDIT-OPTICS-CA | Remove chromatic aberration | P1 | ✅ | `crates/ui-egui/src/panels/edit.rs` (checkbox), `ctl:optics.caRed`, `ctl:optics.caBlue` | | -| LR-EDIT-OPTICS-PROFILE | Lens profile corrections | P1 | 🟡 | `ctl:optics.profileDistortion`, `ctl:optics.profileVignetting`, `crates/pipeline/src/optics.rs`, `crates/raw/src/vendor/rw2.rs`, `crates/raw/src/vendor/raf_lens.rs`, `crates/engine/src/crs.rs` | uses corrections embedded in the file: DNG `WarpRectilinear` / `WarpRectilinear2` (opcode 14, DNG 1.6: degree-14 radial polynomial, valid-radius clamp, reciprocal option, applied in list order with the spec's skip rule for a `WarpRectilinear` after an optional one, so Pixel DNGs' two-stage warp is corrected; up to 3 chained stages, sampled on the CPU because the polynomials need `f64`; issue #635) / `FixVignetteRadial`, and the camera's own distortion correction in Panasonic / Leica RW2 / RWL files (tag `0x0119`, read as the equivalent `WarpRectilinear`; on 79 photos from 13 bodies and 11 lenses the corrected render lines up with the camera JPEG within 0.75 px at 1440 px at the corners, from up to 13 % of the half diagonal uncorrected; issue #256); an imported preset's `LensProfileEnable=0` leaves them on, as Lightroom applies built-in corrections regardless (inferred); Sony ILCE-7RM4A Bayer ARW raw-IFD distortion tables (`0x7037`, 16-sample layout, native 3:2 framing) use the same warp path, enabled for the independently validated ILCE-7RM4A with FE 24–105 and FE 200–600 lenses, and ILCE-7CR full-frame Bayer 3:2 files with correction Auto or forced Auto (a separate corrected-radius conversion validated against camera JPEGs with FE 24-50mm, FE 16-25mm and FE 50mm lenses); A7CR Off, APS-C, aspect crops and lossless M/S remain uncorrected; ILCE-7RM6 verified against the camera JPEG on 54 photos with three lenses (`docs/sony-ilce7rm6-lens-corrections.md`); other Sony models remain uncorrected (see `docs/sony-lens-corrections.md`); Nikon NEF distortion from NikonNEFInfo (`0xc7d5`: polynomial, frame-filling zoom and the optical-centre offset left by in-body stabilisation; `crates/raw/src/vendor/nef_lens.rs`, `docs/nikon-lens-corrections.md`) for the Z 6II, Z 8 and Z f, full-frame image area only: F-mount lenses on the FTZ match the camera JPEG within 0.2 px median, Z lenses within 0.5–1.5 px except the 24-70 f/4's wide end, where the camera applies a further correction that is not in the readable data (7 px median at 24 mm, from 16 px / 106 px p95 uncorrected); Fujifilm RAF raw-IFD tables (`0xf00b` distortion, `0xf010` vignetting; `crates/raw/src/vendor/raf_lens.rs`, `docs/fuji-lens-corrections.md`) become a `WarpRectilinear` with the camera's frame-filling zoom and a `FixVignetteRadial` gain for 59 body models with sample files checked against the camera JPEG (the table indexed by the source radius with last knot at the corner; on 67 body/lens combinations the corrected render's radial shape error against the camera JPEG falls from a median of 0.72 % to 0.05 % of the half diagonal, largest 0.42 %, and the vignetting gain of the JPEG tracks the table at a median correlation of 0.987); files whose table scale is not the recorded image's half diagonal (X-S20, X-T30 III, X-M5, X-T5 crops) and six unmatched bodies stay uncorrected; Fujifilm's lateral CA table (`0xf00f`) is real but is not applied, because our demosaic already registers the planes and the stored shift over-corrects; vignetting and lateral CA data of Olympus raws not read yet; Sony ARW shading, lateral CA and distortion tables (raw IFD `0x7031`–`0x7037`, with the encrypted `SR2SubIFD` copies as a checked fallback) are decoded with their camera settings, provenance and framing evidence for every body that records them (`crates/raw/src/lens_metadata.rs`), but only the ILCE-7RM4A, ILCE-7RM6 and ILCE-7CR use the separate distortion conversions above; Sony shading and CA semantics are not validated beyond the ILCE-7RM6's (lateral CA off) (`docs/sony-lens-corrections.md`); Reload from Disk reads the file's lens data for photos catalogued without it and turns the correction on for those still at import settings (issue #314); lens-profile database: a lensfun-format XML database in `LIGHTCRAFT_LENSFUN_DIR` (none is bundled) supplies distortion (poly3 / poly5 / PTLens), TCA and vignetting for lenses it lists (`crates/lensdb`, `crates/engine/src/lens_profiles.rs`, `docs/lens-profiles.md`); raws that name no lens model (Nikon DSLRs: maker-note lens specification only) look it up by a name built from the specification (`24-70mm f/2.8`) and take only a profile named exactly that; no settings switch or bundled database yet | +| LR-EDIT-OPTICS-PROFILE | Lens profile corrections | P1 | 🟡 | `ctl:optics.profileDistortion`, `ctl:optics.profileVignetting`, `crates/pipeline/src/optics.rs`, `crates/raw/src/vendor/rw2.rs`, `crates/raw/src/vendor/raf_lens.rs`, `crates/engine/src/crs.rs` | uses corrections embedded in the file: DNG `WarpRectilinear` / `WarpRectilinear2` (opcode 14, DNG 1.6: degree-14 radial polynomial, valid-radius clamp, reciprocal option, applied in list order with the spec's skip rule for a `WarpRectilinear` after an optional one, so Pixel DNGs' two-stage warp is corrected; up to 3 chained stages, sampled on the CPU because the polynomials need `f64`; issue #635) / `FixVignetteRadial`, and the camera's own distortion correction in Panasonic / Leica RW2 / RWL files (tag `0x0119`, read as the equivalent `WarpRectilinear`; on 79 photos from 13 bodies and 11 lenses the corrected render lines up with the camera JPEG within 0.75 px at 1440 px at the corners, from up to 13 % of the half diagonal uncorrected; issue #256); an imported preset's `LensProfileEnable=0` leaves them on, as Lightroom applies built-in corrections regardless (inferred); Sony ILCE-7RM4A Bayer ARW raw-IFD distortion tables (`0x7037`, 16-sample layout, native 3:2 framing) use the same warp path, enabled for the independently validated ILCE-7RM4A with FE 24–105 and FE 200–600 lenses, and ILCE-7CR full-frame Bayer 3:2 files with correction Auto or forced Auto (a separate corrected-radius conversion validated against camera JPEGs with FE 24-50mm, FE 16-25mm and FE 50mm lenses); A7CR Off, APS-C, aspect crops and lossless M/S remain uncorrected; ILCE-7RM6 verified against the camera JPEG on 54 photos with three lenses (`docs/sony-ilce7rm6-lens-corrections.md`); other Sony models remain uncorrected (see `docs/sony-lens-corrections.md`); Nikon NEF distortion from NikonNEFInfo (`0xc7d5`: polynomial, frame-filling zoom and the optical-centre offset left by in-body stabilisation; `crates/raw/src/vendor/nef_lens.rs`, `docs/nikon-lens-corrections.md`) for the Z 6II, Z 8 and Z f, full-frame image area only: F-mount lenses on the FTZ match the camera JPEG within 0.2 px median, Z lenses within 0.5–1.5 px except the 24-70 f/4's wide end, where the camera applies a further correction that is not in the readable data (7 px median at 24 mm, from 16 px / 106 px p95 uncorrected); Fujifilm RAF raw-IFD tables (`0xf00b` distortion, `0xf010` vignetting; `crates/raw/src/vendor/raf_lens.rs`, `docs/fuji-lens-corrections.md`) become a `WarpRectilinear` with the camera's frame-filling zoom and a `FixVignetteRadial` gain for 59 body models with sample files checked against the camera JPEG (the table indexed by the source radius with last knot at the corner; on 67 body/lens combinations the corrected render's radial shape error against the camera JPEG falls from a median of 0.72 % to 0.05 % of the half diagonal, largest 0.42 %, and the vignetting gain of the JPEG tracks the table at a median correlation of 0.987); files whose table scale is not the recorded image's half diagonal (X-S20, X-T30 III, X-M5, X-T5 crops) and six unmatched bodies stay uncorrected; Fujifilm's lateral CA table (`0xf00f`) is real but is not applied, because our demosaic already registers the planes and the stored shift over-corrects; vignetting and lateral CA data of Olympus raws not read yet; Sony ARW shading, lateral CA and distortion tables (raw IFD `0x7031`–`0x7037`, with the encrypted `SR2SubIFD` copies as a checked fallback) are decoded with their camera settings, provenance and framing evidence for every body that records them (`crates/raw/src/lens_metadata.rs`), but only the ILCE-7RM4A, ILCE-7RM6 and ILCE-7CR use the separate distortion conversions above; Sony shading and CA semantics are not validated beyond the ILCE-7RM6's (lateral CA off) (`docs/sony-lens-corrections.md`); Reload from Disk reads the file's lens data for photos catalogued without it and turns the correction on for those still at import settings (issue #314); lens-profile database: a lensfun-format XML database in `LIGHTCRAFT_LENSFUN_DIR` (none is bundled) supplies distortion (poly3 / poly5 / PTLens), TCA and vignetting for lenses it lists (`crates/lensdb`, `crates/engine/src/lens_profiles.rs`, `docs/lens-profiles.md`); raws that name no lens model (Nikon DSLRs: maker-note lens specification only) look it up by a name built from the specification (`24-70mm f/2.8`) and take only a profile named exactly that; lens database: the desktop app downloads lensfun's `data/db` (CC BY-SA 3.0, pinned by commit, size and SHA-256, never bundled; `cmd:lens.downloadDatabase`, `crates/engine/src/lensfun_download.rs`) on first run with an activity row, and when it arrives every library raw whose lens it knows is looked up again in the background (`cmd:library.refreshLensProfiles`, `crates/engine/src/cmd/lens_refresh.rs`), as is a photo whose Enable Lens Corrections is ticked; the Optics panel names the loaded profile and its source, or says "No lens profile found for " (`crates/ui-egui/src/lens_db.rs`); presets, Copy / Paste and Sync carry only the switch and amounts, never a profile (`crates/engine/src/tests_lens_refresh.rs`); no source picker or own calibration yet | ) | LR-EDIT-OPTICS-DEFRINGE | Defringe | P1 | ✅ | `ctl:optics.defringe*` | no fringe eyedropper | | LR-EDIT-OPTICS-MANUAL | Manual distortion / vignetting | P1 | ✅ | `ctl:optics.distortion`, `ctl:optics.vignetting`, `ctl:optics.vignettingMidpoint` | | @@ -799,6 +799,7 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove | Date | Change | Summary | |---|---|---| +| 2026-10-27 | minor | LR-EDIT-OPTICS-PROFILE: lensfun's database downloaded by itself on first run (pinned, CC BY-SA, never bundled), the library looked up when it arrives or Enable Lens Corrections is ticked, the Optics panel names the profile or the lens without one; status 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 🟡) |