From 9afdf48c7814b6f90ad403c229f41b2c9c8e7d73 Mon Sep 17 00:00:00 2001 From: anthonyessaye Date: Mon, 30 Nov 2026 19:35:14 +0200 Subject: [PATCH 1/3] LUT profiles are found in a moved library; an unloaded one is refused (#4902) Opening a library now looks for each imported LUT's copy in that library's Profiles folder, as camera profiles already do, and updates the saved path, so a moved or restored library keeps its LUTs. develop.profile refuses an imported LUT that couldn't be loaded instead of rendering the photo with no profile. The two ui-egui layout tests that apply an imported LUT with no file now register an identity LUT under its id first. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/dcp_profiles.rs | 2 +- crates/engine/src/cmd/develop.rs | 4 ++ crates/engine/src/cmd/lut_profiles.rs | 16 +++++- crates/engine/src/library.rs | 5 +- crates/engine/src/tests/import.rs | 61 +++++++++++++++++++++ crates/ui-egui/src/tests/edit_layout.rs | 3 + crates/ui-egui/src/tests/profiles_layout.rs | 3 + docs/whats-new.md | 8 +++ 8 files changed, 97 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/cmd/dcp_profiles.rs b/crates/engine/src/cmd/dcp_profiles.rs index a7c6d4c02cf..be80e4b7ce4 100644 --- a/crates/engine/src/cmd/dcp_profiles.rs +++ b/crates/engine/src/cmd/dcp_profiles.rs @@ -71,7 +71,7 @@ pub fn register_all(s: &mut Session, profiles: Option<&Path>) { /// The copy of saved profile file `file` in the open library's profiles folder `dir`, when it is there under the /// same name and `file` is not already it. -fn library_copy(dir: &Path, file: &str) -> Option { +pub(super) fn library_copy(dir: &Path, file: &str) -> Option { let saved = Path::new(file); let here = dir.join(saved.file_name()?); (here != saved && here.is_file()).then_some(here) diff --git a/crates/engine/src/cmd/develop.rs b/crates/engine/src/cmd/develop.rs index 4821e6fcd15..d1514c99ea0 100644 --- a/crates/engine/src/cmd/develop.rs +++ b/crates/engine/src/cmd/develop.rs @@ -798,6 +798,10 @@ pub fn specs() -> Vec { if crate::cmd::dcp_profiles::is_dcp_id(&id) && !s.media.camera_profiles.contains_key(&id) { return Err(bad("develop.profile", format!("camera profile `{id}` can't be used: its file is missing or damaged"))); } + // the same for an imported LUT that couldn't be loaded: the photo would render with no profile + if s.lut_profiles.iter().any(|x| x.id == id) && lightcraft_pipeline::lut::get(&id).is_none() { + return Err(bad("develop.profile", format!("LUT profile `{id}` can't be used: its file is missing or damaged"))); + } edit(s, "develop.profile", "Profile", |d| { d.profile.id = id.clone(); d.profile.amount = f64_or(p, "amount", d.profile.amount).clamp(0.0, 200.0); diff --git a/crates/engine/src/cmd/lut_profiles.rs b/crates/engine/src/cmd/lut_profiles.rs index 50cb1223007..af1d5e9016e 100644 --- a/crates/engine/src/cmd/lut_profiles.rs +++ b/crates/engine/src/cmd/lut_profiles.rs @@ -25,8 +25,20 @@ fn profiles_dir(s: &Session) -> Option { s.library.as_ref().filter(|l| l.on_disk).map(|l| l.dir.join("Profiles")) } -/// Register every imported profile's LUT with the pipeline (missing files are skipped). -pub fn register_all(s: &Session) { +/// Register every imported profile's LUT with the pipeline (missing or damaged files are skipped: the profile is not +/// accepted by `develop.profile` until its file is back; the entry is kept). +/// +/// A library's own copies are found in `profiles`, the `Profiles/` folder of the library being opened (`None`: not on +/// disk), wherever the saved path points: a library moved or restored elsewhere keeps its LUTs (the saved path is +/// updated), as camera profiles do. +pub fn register_all(s: &mut Session, profiles: Option<&Path>) { + if let Some(dir) = profiles { + for p in &mut s.lut_profiles { + if let Some(here) = super::dcp_profiles::library_copy(dir, &p.file) { + p.file = here.to_string_lossy().to_string(); + } + } + } for p in &s.lut_profiles { if let Some(l) = std::fs::read_to_string(&p.file).ok().and_then(|t| lightcraft_pipeline::lut::Lut3d::parse_cube(&t).ok()) { lightcraft_pipeline::lut::register(&p.id, l); diff --git a/crates/engine/src/library.rs b/crates/engine/src/library.rs index effc5d5e42d..4e3e8fa2a66 100644 --- a/crates/engine/src/library.rs +++ b/crates/engine/src/library.rs @@ -678,10 +678,11 @@ impl Session { self.mask_effects = prefs.mask_effects; self.mask_tool_effects = prefs.mask_tool_effects; self.label_sets = prefs.label_sets; + let profiles = on_disk.then(|| dir.join("Profiles")); self.lut_profiles = prefs.lut_profiles; - crate::cmd::lut_profiles::register_all(self); + crate::cmd::lut_profiles::register_all(self, profiles.as_deref()); self.dcp_profiles = prefs.dcp_profiles; - crate::cmd::dcp_profiles::register_all(self, on_disk.then(|| dir.join("Profiles")).as_deref()); + crate::cmd::dcp_profiles::register_all(self, profiles.as_deref()); self.keyword_sets = prefs.keyword_sets; self.keyword_set = prefs.keyword_set; self.recent_keywords = prefs.recent_keywords; diff --git a/crates/engine/src/tests/import.rs b/crates/engine/src/tests/import.rs index 3b65dbae9a3..1e162195e4b 100644 --- a/crates/engine/src/tests/import.rs +++ b/crates/engine/src/tests/import.rs @@ -1720,6 +1720,67 @@ fn cube_luts_become_profiles() { let _ = std::fs::remove_dir_all(&lib); } +/// A library moved to another folder keeps its imported LUTs: they are found in its own Profiles +/// folder and still render (#4902). A LUT whose file is gone is kept in the list but refused by +/// `develop.profile`, instead of rendering as no profile. +#[test] +fn cube_profiles_follow_a_moved_library() { + let src = temp_dir("cubemovesrc"); + let old = temp_dir("cubemovelib"); + let new = old.with_extension("moved"); + let _ = std::fs::remove_dir_all(&new); + let mut cube = String::from("TITLE \"Move Test\"\nLUT_3D_SIZE 2\n"); + for b in 0..2 { + for g in 0..2 { + for r in 0..2 { + // red up, blue down + cube.push_str(&format!("{} {g} {}\n", (r as f32 * 0.6 + 0.4), b as f32 * 0.25)); + } + } + } + std::fs::create_dir_all(src.join("Move Looks")).unwrap(); + std::fs::write(src.join("Move Looks/move.cube"), &cube).unwrap(); + let mut s = Session::new().with_fs(); + s.open_library(&old, true).unwrap(); + let r = s.execute("profile.import", &json!({"paths": [src.to_string_lossy()]})).unwrap(); + let id = r["imported"][0]["id"].as_str().unwrap().to_string(); + let photo = s.catalog.photos().next().unwrap().id; + s.execute("library.select", &json!({"ids": [photo.0]})).unwrap(); + s.execute("develop.profile", &json!({"id": id, "amount": 100})).unwrap(); + s.persist().unwrap(); + s.close_library().unwrap(); + drop(s); + // a new process: nothing registered until the library is opened + lightcraft_pipeline::lut::unregister(&id); + std::fs::rename(&old, &new).unwrap(); + + let mut s = Session::new().with_fs(); + s.open_library(&new, false).unwrap(); + assert!(lightcraft_pipeline::lut::get(&id).is_some(), "the LUT is found in the moved library"); + let file = s.lut_profiles.iter().find(|p| p.id == id).map(|p| PathBuf::from(&p.file)).unwrap(); + assert!(file.starts_with(&new), "the saved path follows the library: {}", file.display()); + s.execute("library.select", &json!({"ids": [photo.0]})).unwrap(); + let looked = s.render_now(photo, 48, 32).unwrap().image; + s.execute("develop.profile", &json!({"id": id, "amount": 0})).unwrap(); + let plain = s.render_now(photo, 48, 32).unwrap().image; + assert_ne!(looked.data, plain.data, "the photo still renders with its LUT"); + s.close_library().unwrap(); + drop(s); + + // the copy is gone: the entry stays, but choosing it is refused rather than rendering as no profile + lightcraft_pipeline::lut::unregister(&id); + std::fs::remove_file(&file).unwrap(); + let mut s = Session::new().with_fs(); + s.open_library(&new, false).unwrap(); + assert!(s.lut_profiles.iter().any(|p| p.id == id), "the entry is kept"); + s.execute("library.select", &json!({"ids": [photo.0]})).unwrap(); + let err = s.execute("develop.profile", &json!({"id": id})).unwrap_err(); + assert!(err.to_string().contains("missing or damaged"), "{err}"); + drop(s); + let _ = std::fs::remove_dir_all(&src); + let _ = std::fs::remove_dir_all(&new); +} + /// Without a library on disk an imported LUT lives only in this session: no copy of it is /// left in the temp folder (#1952). #[test] diff --git a/crates/ui-egui/src/tests/edit_layout.rs b/crates/ui-egui/src/tests/edit_layout.rs index 4d1a1826d83..8188f70af1a 100644 --- a/crates/ui-egui/src/tests/edit_layout.rs +++ b/crates/ui-egui/src/tests/edit_layout.rs @@ -26,6 +26,9 @@ fn panel(width: f32) -> (Vec, Vec<(String, Rect)>) { group: "Film Stocks".into(), file: String::new(), }); + // its LUT, loaded (`develop.profile` refuses an imported LUT it couldn't load): an identity table + let identity = lightcraft_pipeline::lut::Lut3d::parse_cube("LUT_3D_SIZE 2\n0 0 0\n1 0 0\n0 1 0\n1 1 0\n0 0 1\n1 0 1\n0 1 1\n1 1 1\n").unwrap(); + lightcraft_pipeline::lut::register(LONG_ID, identity); app.run("develop.profile", json!({"id": LONG_ID})).unwrap(); let photo = app.session.active().unwrap(); let drawn = draw(&mut app, photo, width); diff --git a/crates/ui-egui/src/tests/profiles_layout.rs b/crates/ui-egui/src/tests/profiles_layout.rs index ccc521151d5..046d514454d 100644 --- a/crates/ui-egui/src/tests/profiles_layout.rs +++ b/crates/ui-egui/src/tests/profiles_layout.rs @@ -24,6 +24,9 @@ fn panel(width: f32) -> (Vec, Vec<(String, Rect)>) { group: "Film Stocks".into(), file: String::new(), }); + // its LUT, loaded (`develop.profile` refuses an imported LUT it couldn't load): an identity table + let identity = lightcraft_pipeline::lut::Lut3d::parse_cube("LUT_3D_SIZE 2\n0 0 0\n1 0 0\n0 1 0\n1 1 0\n0 0 1\n1 0 1\n0 1 1\n1 1 1\n").unwrap(); + lightcraft_pipeline::lut::register(LONG_ID, identity); app.run("develop.profile", json!({"id": LONG_ID})).unwrap(); let photo = app.session.active().unwrap(); let ctx = egui::Context::default(); diff --git a/docs/whats-new.md b/docs/whats-new.md index fdc89055fb6..60c0057f452 100644 --- a/docs/whats-new.md +++ b/docs/whats-new.md @@ -14,6 +14,14 @@ three quarters, where it used to cover 90 % and more, and a slow stroke covers the same as a fast one (issue #4045). New photos (and Reset) get it; photos you already edited keep their brushes until Photo ▸ Update to Current Process. +## 2026-12-01 + +### LUT profiles move with their library +- A library moved or restored to another folder lost its imported LUT profiles without a word: they were still listed + and set on their photos, but every render came out as if no profile were set. They are now found in the moved + library's Profiles folder, as camera profiles already were. A LUT profile whose file is gone stays in the list, and + choosing it says the file is missing instead of quietly rendering with no profile (#4902). + ## 2026-10-31 ### Filter for unrated photos From d38f3576dcb2e6c3ee00a620c816ebccc1671885 Mon Sep 17 00:00:00 2001 From: anthonyessaye Date: Mon, 30 Nov 2026 20:15:44 +0200 Subject: [PATCH 2/3] LUT profiles: a reopened library doesn't keep a LUT loaded before (#4902) The LUT registry outlives a library, so register_all now clears each imported LUT's registration before reading its file: a file that is gone leaves the profile unloaded (and refused by develop.profile) also when the library is opened again in the same session. Entries without a file (imported with no library on disk) keep their registration. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/lut_profiles.rs | 7 +++++++ crates/engine/src/tests/import.rs | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/lut_profiles.rs b/crates/engine/src/cmd/lut_profiles.rs index af1d5e9016e..b99c60126a1 100644 --- a/crates/engine/src/cmd/lut_profiles.rs +++ b/crates/engine/src/cmd/lut_profiles.rs @@ -40,6 +40,13 @@ pub fn register_all(s: &mut Session, profiles: Option<&Path>) { } } for p in &s.lut_profiles { + // an entry without a file (imported with no library on disk) has only its registration + if p.file.is_empty() { + continue; + } + // the registry outlives a library: a LUT loaded under this id before (this library opened earlier in the + // session, or another one) goes first, so a file that can't be read leaves the profile unloaded + lightcraft_pipeline::lut::unregister(&p.id); if let Some(l) = std::fs::read_to_string(&p.file).ok().and_then(|t| lightcraft_pipeline::lut::Lut3d::parse_cube(&t).ok()) { lightcraft_pipeline::lut::register(&p.id, l); } diff --git a/crates/engine/src/tests/import.rs b/crates/engine/src/tests/import.rs index 1e162195e4b..c62fa2a822d 100644 --- a/crates/engine/src/tests/import.rs +++ b/crates/engine/src/tests/import.rs @@ -1767,8 +1767,8 @@ fn cube_profiles_follow_a_moved_library() { s.close_library().unwrap(); drop(s); - // the copy is gone: the entry stays, but choosing it is refused rather than rendering as no profile - lightcraft_pipeline::lut::unregister(&id); + // the copy is gone, and the library is opened again in the same process (the LUT loaded above is still in the + // registry): the entry stays, but choosing it is refused rather than rendering with what was loaded before std::fs::remove_file(&file).unwrap(); let mut s = Session::new().with_fs(); s.open_library(&new, false).unwrap(); From d6ff105743f44db32eeabc1e6f0e09f6bf947caf Mon Sep 17 00:00:00 2001 From: anthonyessaye Date: Wed, 2 Dec 2026 19:35:48 +0200 Subject: [PATCH 3/3] LUT and camera profiles: find the copy of a path saved on Windows or another system (CodeRabbit, #4902) Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/dcp_profiles.rs | 5 +++-- crates/engine/src/tests/import.rs | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/dcp_profiles.rs b/crates/engine/src/cmd/dcp_profiles.rs index be80e4b7ce4..74c77e25acc 100644 --- a/crates/engine/src/cmd/dcp_profiles.rs +++ b/crates/engine/src/cmd/dcp_profiles.rs @@ -70,10 +70,11 @@ pub fn register_all(s: &mut Session, profiles: Option<&Path>) { } /// The copy of saved profile file `file` in the open library's profiles folder `dir`, when it is there under the -/// same name and `file` is not already it. +/// same name and `file` is not already it. The name is the part after the last `/` or `\`: a library made on Windows +/// keeps Windows paths, whose `\` isn't a separator to `Path` on macOS or Linux (the copies' own names hold neither). pub(super) fn library_copy(dir: &Path, file: &str) -> Option { let saved = Path::new(file); - let here = dir.join(saved.file_name()?); + let here = dir.join(Path::new(file.rsplit(['/', '\\']).next()?).file_name()?); (here != saved && here.is_file()).then_some(here) } diff --git a/crates/engine/src/tests/import.rs b/crates/engine/src/tests/import.rs index c62fa2a822d..5524403219d 100644 --- a/crates/engine/src/tests/import.rs +++ b/crates/engine/src/tests/import.rs @@ -1764,6 +1764,16 @@ fn cube_profiles_follow_a_moved_library() { s.execute("develop.profile", &json!({"id": id, "amount": 0})).unwrap(); let plain = s.render_now(photo, 48, 32).unwrap().image; assert_ne!(looked.data, plain.data, "the photo still renders with its LUT"); + // a path saved on Windows or on macOS / Linux: the copy is found under its name on either + let name = file.file_name().unwrap().to_string_lossy().to_string(); + for saved in [format!(r"C:\Old\Lib\Profiles\{name}"), format!("/old/lib/Profiles/{name}")] { + s.lut_profiles.iter_mut().find(|p| p.id == id).unwrap().file = saved.clone(); + s.save_prefs().unwrap(); + s.close_library().unwrap(); + lightcraft_pipeline::lut::unregister(&id); + s.open_library(&new, false).unwrap(); + assert!(lightcraft_pipeline::lut::get(&id).is_some(), "the LUT saved as {saved} is found"); + } s.close_library().unwrap(); drop(s);