Skip to content

Commit a9ed271

Browse files
committed
LR-EDIT-OPTICS-PROFILE: merge main (storytold#3073: lensfun database offer; docs)
2 parents c5771ae + 79e900c commit a9ed271

70 files changed

Lines changed: 2651 additions & 81 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/lightcraft-cli/src/main.rs‎

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ fn merge(args: &[String]) -> Result<(), String> {
434434
}
435435
i += 1;
436436
}
437-
let mut s = Session::new().with_fs().with_default_denoise_models().with_system_clock();
437+
let mut s = file_session();
438438
let paths = expand_paths(&files);
439439
let r = s.execute("library.import", &json!({"paths": paths})).map_err(|e| e.to_string())?;
440440
let mut ids: Vec<u64> = r["imported"].as_array().map(|a| a.iter().filter_map(Value::as_u64).collect()).unwrap_or_default();
@@ -712,6 +712,12 @@ fn read_settings(p: &str) -> Result<SettingsFile, String> {
712712
}
713713
}
714714

715+
/// The session `render` and `merge` develop files in: with the lens database the desktop app downloaded, when it is
716+
/// there (never fetched from here: scripts and tests stay offline).
717+
fn file_session() -> Session {
718+
Session::new().with_fs().with_default_denoise_models().with_system_clock().with_default_lens_database()
719+
}
720+
715721
fn render(args: &[String]) -> Result<(), String> {
716722
let mut input = None;
717723
let mut output = None;
@@ -750,7 +756,7 @@ fn render(args: &[String]) -> Result<(), String> {
750756
}
751757
let input = input.ok_or("render: missing input file")?;
752758
let output = output.ok_or("render: missing -o OUTPUT")?;
753-
let mut s = Session::new().with_fs().with_default_denoise_models().with_system_clock();
759+
let mut s = file_session();
754760
let abs = expand_paths(std::slice::from_ref(&input));
755761
let r = s.execute("library.import", &json!({"paths": abs})).map_err(|e| e.to_string())?;
756762
let id = r["imported"][0].as_u64().ok_or_else(|| format!("{input}: not a readable photo"))?;
@@ -845,15 +851,30 @@ fn snapshot(args: &[String]) -> Result<(), String> {
845851
let t0 = Instant::now();
846852
let mut session = match &library {
847853
Some(dir) => {
848-
let mut s =
849-
Session::new().with_fs().with_default_denoise_models().with_system_clock().with_default_face_models().with_default_slide_templates();
854+
let mut s = Session::new()
855+
.with_fs()
856+
.with_default_denoise_models()
857+
.with_system_clock()
858+
.with_default_face_models()
859+
.with_default_lens_database()
860+
.with_default_slide_templates();
850861
s.open_library(dir, false).map_err(|e| library_error(dir, e))?;
851862
s
852863
}
853-
None if files.is_empty() => {
854-
Session::with_demo().with_fs().with_default_denoise_models().with_system_clock().with_default_face_models().with_default_slide_templates()
855-
}
856-
None => Session::new().with_fs().with_default_denoise_models().with_system_clock().with_default_face_models().with_default_slide_templates(),
864+
None if files.is_empty() => Session::with_demo()
865+
.with_fs()
866+
.with_default_denoise_models()
867+
.with_system_clock()
868+
.with_default_face_models()
869+
.with_default_lens_database()
870+
.with_default_slide_templates(),
871+
None => Session::new()
872+
.with_fs()
873+
.with_default_denoise_models()
874+
.with_system_clock()
875+
.with_default_face_models()
876+
.with_default_lens_database()
877+
.with_default_slide_templates(),
857878
};
858879
// Apply compute policy before imports or the first scripted query can discover an adapter.
859880
session.execute("app.gpu", &json!({"enabled": false})).map_err(|e| e.to_string())?;
@@ -1107,6 +1128,18 @@ mod raw_files_tests {
11071128
}
11081129
}
11091130

1131+
#[cfg(test)]
1132+
mod tests {
1133+
/// `render` and `merge` read the lens database the desktop app downloaded, as the desktop does (the same raw
1134+
/// gets the same profile everywhere), but never fetch it.
1135+
#[test]
1136+
fn render_reads_the_downloaded_lens_database() {
1137+
let s = super::file_session();
1138+
assert_eq!(lightcraft_engine::lens_profiles::host_dir(), lightcraft_engine::lensfun_download::default_dir());
1139+
assert!(!s.lens_auto_download, "selecting it is not permission to download it");
1140+
}
1141+
}
1142+
11101143
#[cfg(test)]
11111144
mod import_target_tests {
11121145
use super::{import_and_select, import_targets, json};

‎apps/lightcraft/src/session.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ pub(crate) fn open_session(in_memory: bool, launch: &Launch, seed_demo: bool) ->
255255
Launch::Ask => (Session::new().with_fs().with_default_denoise_models().with_system_clock(), None),
256256
Launch::Open { dir, remembered, .. } => open_library_session(in_memory, dir.clone(), *remembered, seed_demo),
257257
};
258+
// lens profiles from the app's own lensfun copy, offered on the first launch (not for a throwaway session)
259+
if !in_memory {
260+
s = s.with_default_lens_database().with_lens_auto_download();
261+
}
258262
s.face_models_dir = lightcraft_engine::config::default_face_models_dir();
259263
s.slide_templates_dir = lightcraft_engine::config::config_dir().map(|d| d.join(lightcraft_engine::slide_template::DIR_NAME));
260264
// Control requests are answered on the UI thread: Add to Apple Photos must not wait there

‎crates/catalog/src/journal.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
//! | 8 | History cursor: Go to History Step adds no step | `Op::SetHistoryCursor`, `Photo.history_cursor` |
5454
//! | 9 | preview-only recheck | `Photo.preview_checked`, `Op::SetContent.preview_checked` |
5555
//! | 10 | masks stay on the photo under lens corrections, Upright and Transform | `Mask.on_photo` (develop settings) |
56+
//! | 11 | lens database profiles named in the Optics panel | `EmbeddedLens.source` |
5657
//!
5758
//! Rules:
5859
//! - **Bump [`VERSION`]** (and add a row above) in the change that adds an [`Op`] variant or a
@@ -77,7 +78,7 @@ pub const LOG: &str = "catalog.log";
7778
const FORMAT: &str = "lightcraft-catalog";
7879
/// The catalog format this build writes (and the newest it reads). See the module docs →
7980
/// *Format versions*; bump it whenever an [`Op`] variant or a serialized field is added.
80-
pub const VERSION: u32 = 10;
81+
pub const VERSION: u32 = 11;
8182

8283
/// When [`Journal::wants_snapshot`] says it's time to compact the log.
8384
#[derive(Clone, Copy, Debug)]

‎crates/catalog/src/tests.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@ fn set_embedded_lens_is_undoable_and_journaled() {
636636
photo: Box::new(Photo::new(a, Source::File { path: "/x.rw2".into() }, "x.rw2", "RW2", 4000, 3000, "2026-10-06T00:00:00")),
637637
})
638638
.unwrap();
639-
let lens = lightcraft_develop::EmbeddedLens { warp: Some(Default::default()), vignette: None, stages: Default::default() };
639+
let lens =
640+
lightcraft_develop::EmbeddedLens { warp: Some(Default::default()), vignette: None, stages: Default::default(), source: Default::default() };
640641
let op = Op::SetEmbeddedLens { id: a, lens: Some(Box::new(lens)) };
641642
let op: Op = serde_json::from_str(&serde_json::to_string(&op).unwrap()).unwrap();
642643
let inv = c.apply(op).unwrap();

‎crates/catalog/src/tests_format_version.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ fn op_variants_are_versioned() {
238238
Op::SetHistoryCursor { .. } => 8,
239239
}
240240
}
241-
/// v10: `Mask.on_photo` (v9: `Photo.preview_checked` and `Op::SetContent.preview_checked`).
242-
const NEWEST_FIELDS: u32 = 10;
241+
/// v11: `EmbeddedLens.source` (v10: `Mask.on_photo`; v9: `Photo.preview_checked` and `Op::SetContent.preview_checked`).
242+
const NEWEST_FIELDS: u32 = 11;
243243
let newest = since(&Op::SetHistoryCursor { id: PhotoId(1), cursor: None });
244244
assert_eq!(newest.max(NEWEST_FIELDS), VERSION, "the newest op's or fields' version must be the current format version");
245245
}

‎crates/develop/src/settings.rs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,32 @@ impl Default for Optics {
699699
pub struct EmbeddedLens {
700700
pub warp: Option<EmbeddedWarp>,
701701
pub vignette: Option<EmbeddedVignette>,
702+
/// Where the correction came from: the file itself, or a lens database looked up by the
703+
/// lens named in the file (what the Optics panel says is loaded).
704+
#[serde(skip_serializing_if = "LensSource::is_file")]
705+
pub source: LensSource,
702706
/// A DNG 1.6 `WarpRectilinear2` chain (up to [`WARP_STAGES`] stages, in `OpcodeList3` order; each stage warps
703707
/// the result of the one before it). When any is set, `warp` is `None`: the chain holds every warp opcode.
704708
pub stages: [Option<EmbeddedWarpStage>; WARP_STAGES],
705709
}
706710

711+
/// Where an [`EmbeddedLens`] came from.
712+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
713+
#[serde(rename_all = "camelCase")]
714+
pub enum LensSource {
715+
/// The file's own correction (DNG opcodes, a camera's correction a raw reader converts).
716+
#[default]
717+
File,
718+
/// A profile from a lensfun-format lens database, matched by the lens named in the file.
719+
Database,
720+
}
721+
722+
impl LensSource {
723+
pub fn is_file(&self) -> bool {
724+
*self == LensSource::File
725+
}
726+
}
727+
707728
/// Most warp stages an [`EmbeddedLens`] chain keeps.
708729
pub const WARP_STAGES: usize = 3;
709730

‎crates/engine/src/cmd.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub mod filters;
2222
mod focus;
2323
pub mod geocode;
2424
pub mod keywords;
25+
pub mod lens_refresh;
2526
pub mod library;
2627
pub mod lut_profiles;
2728
pub mod manage;
@@ -168,6 +169,7 @@ pub fn command_specs() -> &'static [CommandSpec] {
168169
v.extend(browse::specs());
169170
v.extend(missing::specs());
170171
v.extend(recheck::specs());
172+
v.extend(lens_refresh::specs());
171173
v.extend(sync::specs());
172174
v.extend(metadata::specs());
173175
v.extend(geocode::specs());

‎crates/engine/src/cmd/convert.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ mod tests {
456456
warp: Some(lightcraft_develop::EmbeddedWarp { planes: [[1.0, -0.1, 0.03, 0.0, 0.0, 0.0]; 3], ..Default::default() }),
457457
vignette: None,
458458
stages: Default::default(),
459+
source: Default::default(),
459460
}
460461
}
461462
fn old_rw2() -> lightcraft_catalog::Photo {

0 commit comments

Comments
 (0)