Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions crates/engine/src/cmd/dcp_profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
fn library_copy(dir: &Path, file: &str) -> Option<PathBuf> {
/// 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<PathBuf> {
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)
}

Expand Down
4 changes: 4 additions & 0 deletions crates/engine/src/cmd/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,10 @@ pub fn specs() -> Vec<CommandSpec> {
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")));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
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);
Expand Down
23 changes: 21 additions & 2 deletions crates/engine/src/cmd/lut_profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,28 @@ fn profiles_dir(s: &Session) -> Option<PathBuf> {
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 {
// 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);
}
Expand Down
5 changes: 3 additions & 2 deletions crates/engine/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
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;
Expand Down
71 changes: 71 additions & 0 deletions crates/engine/src/tests/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,77 @@ 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");
// 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);

// 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();
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]
Expand Down
3 changes: 3 additions & 0 deletions crates/ui-egui/src/tests/edit_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ fn panel(width: f32) -> (Vec<egui::epaint::TextShape>, 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);
Expand Down
3 changes: 3 additions & 0 deletions crates/ui-egui/src/tests/profiles_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ fn panel(width: f32) -> (Vec<egui::epaint::TextShape>, 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();
Expand Down
8 changes: 8 additions & 0 deletions docs/whats-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down