Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2ec4add
LR-EDIT-OPTICS-PROFILE: lensfun database downloaded on first run, lib…
OneSlips Oct 22, 2026
030e0ed
LR-EDIT-OPTICS-PROFILE: catalog format 10 for the lens source, snapsh…
OneSlips Oct 26, 2026
5554d78
LR-EDIT-OPTICS-PROFILE: review fixes (desktop library session, stale …
OneSlips Oct 26, 2026
b3b792f
LR-EDIT-OPTICS-PROFILE: merge main (file split)
OneSlips Oct 27, 2026
f7ebead
LR-EDIT-OPTICS-PROFILE: merge main
OneSlips Oct 27, 2026
7a77f72
LR-EDIT-OPTICS-PROFILE: review fixes (CodeRabbit, #3073)
OneSlips Oct 27, 2026
326db68
LR-EDIT-OPTICS-PROFILE: an unlistable lens database folder is an erro…
OneSlips Oct 27, 2026
1d4c53a
Merge remote-tracking branch 'origin/main' into pr/lens-database-down…
OneSlips Oct 27, 2026
f267ddb
LR-EDIT-OPTICS-PROFILE: pinned profiles, whole-folder install, shared…
OneSlips Oct 27, 2026
b7da696
LR-EDIT-OPTICS-PROFILE: review fixes (CodeRabbit, #3073)
OneSlips Oct 27, 2026
bab1e9c
LR-EDIT-OPTICS-PROFILE: look up queued photos as soon as a lookup end…
OneSlips Oct 27, 2026
ef2b209
Merge remote-tracking branch 'origin/main' into pr/lens-database-down…
OneSlips Oct 27, 2026
2cd071c
LR-EDIT-OPTICS-PROFILE: the lens database is offered on first launch …
OneSlips Oct 27, 2026
0fd0ff4
LR-EDIT-OPTICS-PROFILE: a lens database download that can't start kee…
OneSlips Oct 27, 2026
6983520
LR-EDIT-OPTICS-PROFILE: merge main (59a5d00c6, the ui-egui split of #…
OneSlips Oct 28, 2026
3f09c85
LR-EDIT-OPTICS-PROFILE: merge main (integration batch 45)
OneSlips Oct 30, 2026
29443e1
LR-EDIT-OPTICS-PROFILE: merge main (#3430 integration round 3, #3390)
OneSlips Oct 31, 2026
bad1b88
LR-EDIT-OPTICS-PROFILE: a replaced original's missing file correction…
OneSlips Oct 31, 2026
77e6578
LR-EDIT-OPTICS-PROFILE: a database profile is part of the render keys…
OneSlips Oct 31, 2026
0a9707e
LR-EDIT-OPTICS-PROFILE: a decode from before a lens profile change ne…
OneSlips Nov 1, 2026
f3f1831
LR-EDIT-OPTICS-PROFILE: the hover preview follows a new lens profile,…
OneSlips Nov 1, 2026
3698966
LR-EDIT-OPTICS-PROFILE: the lens database folder is held by an operat…
OneSlips Nov 1, 2026
172467b
LR-EDIT-OPTICS-PROFILE: a failed swap keeps the only whole lens datab…
OneSlips Nov 1, 2026
36b2442
Merge remote-tracking branch 'origin/main' into pr-3073
FredApps Nov 4, 2026
9439bf2
Merge remote-tracking branch 'origin/main' into pr-3073
FredApps Nov 4, 2026
0bcc313
Merge remote-tracking branch 'origin/main' into pr-3073
FredApps Nov 4, 2026
9423635
LR-EDIT-OPTICS-PROFILE: merge main (#3550 took catalog format 10; Emb…
FredApps Nov 4, 2026
5da455a
LR-EDIT-OPTICS-PROFILE: merge main (#3144: ILCE-7M3 distortion, kept …
FredApps Nov 4, 2026
86092b3
LR-EDIT-OPTICS-PROFILE: merge main (#2676: unknown crop factors stay …
FredApps Nov 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions apps/lightcraft-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,16 +798,34 @@ fn snapshot(args: &[String]) -> Result<(), String> {
let t0 = Instant::now();
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();
let mut s = 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()
}
None => Session::new().with_fs().with_default_denoise_models().with_system_clock().with_default_face_models().with_default_slide_templates(),
None if files.is_empty() => 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_lens_database()
.with_default_slide_templates(),
};
// a snapshot reads the lens database the desktop app downloaded, but never fetches it (scripts and tests
// stay offline)
session.lens_auto_download = false;
// 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())?;
if !files.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion apps/lightcraft/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ fn open_library_session(in_memory: bool, dir: Option<std::path::PathBuf>, 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();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
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.")));
Expand Down
3 changes: 2 additions & 1 deletion crates/catalog/src/journal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
//! | 7 | Kelvin white balance for raws whose camera has matrices (#730) | `Op::SetAsShotWb`, `WhiteBalance.scale` |
//! | 8 | History cursor: Go to History Step adds no step | `Op::SetHistoryCursor`, `Photo.history_cursor` |
//! | 9 | preview-only recheck | `Photo.preview_checked`, `Op::SetContent.preview_checked` |
//! | 10 | lens database profiles named in the Optics panel | `EmbeddedLens.source` |
//!
//! Rules:
//! - **Bump [`VERSION`]** (and add a row above) in the change that adds an [`Op`] variant or a
Expand All @@ -76,7 +77,7 @@ pub const LOG: &str = "catalog.log";
const FORMAT: &str = "lightcraft-catalog";
/// The catalog format this build writes (and the newest it reads). See the module docs →
/// *Format versions*; bump it whenever an [`Op`] variant or a serialized field is added.
pub const VERSION: u32 = 9;
pub const VERSION: u32 = 10;

/// When [`Journal::wants_snapshot`] says it's time to compact the log.
#[derive(Clone, Copy, Debug)]
Expand Down
3 changes: 2 additions & 1 deletion crates/catalog/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions crates/catalog/src/tests_format_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ fn op_variants_are_versioned() {
Op::SetHistoryCursor { .. } => 8,
}
}
/// v9: `Photo.preview_checked` and `Op::SetContent.preview_checked`.
const NEWEST_FIELDS: u32 = 9;
/// v9: `Photo.preview_checked` and `Op::SetContent.preview_checked`; v10: `EmbeddedLens.source`.
const NEWEST_FIELDS: u32 = 10;
let newest = since(&Op::SetHistoryCursor { id: PhotoId(1), cursor: None });
assert_eq!(newest.max(NEWEST_FIELDS), VERSION, "the newest op's or fields' version must be the current format version");
}
21 changes: 21 additions & 0 deletions crates/develop/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,11 +698,32 @@ impl Default for Optics {
pub struct EmbeddedLens {
pub warp: Option<EmbeddedWarp>,
pub vignette: Option<EmbeddedVignette>,
/// 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<EmbeddedWarpStage>; 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;

Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/cmd/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
164 changes: 164 additions & 0 deletions crates/engine/src/cmd/lens_refresh.rs
Original file line number Diff line number Diff line change
@@ -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<Missing> {
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
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

/// Probe each listed photo's file as Reload would. Doesn't touch the session.
pub fn probe(probe: &FileProbe, list: Vec<Missing>) -> Vec<(Missing, std::result::Result<ProbeInfo, String>)> {
let paths: Vec<String> = 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<ProbeInfo, String>)>) -> Result<Vec<PhotoId>> {
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<PhotoId> = 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()))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
.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<String> {
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<Value> {
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<Vec<PhotoId>> = 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::<Result<_>>()?),
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::<Vec<_>>(), "database": true}))
}

fn download(s: &mut Session, _: &Value) -> Result<Value> {
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<Value> {
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<CommandSpec> {
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
),
]
}
2 changes: 2 additions & 0 deletions crates/engine/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
8 changes: 8 additions & 0 deletions crates/engine/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading
Loading