From a573052a1845ce362e0840efc18d6c5fbd7303e1 Mon Sep 17 00:00:00 2001 From: anthonyessaye Date: Mon, 30 Nov 2026 02:40:48 +0200 Subject: [PATCH 1/3] profile.import returns the LUT profile already there on a repeat import (#4901) Importing a .cube whose title, group and table match an imported LUT profile returns that profile ("existing": true), as camera profiles do, instead of adding a second entry and a second copy in Profiles/. A changed table under the same title is still a new profile. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/lut_profiles.rs | 7 ++++ crates/engine/src/tests/import.rs | 49 +++++++++++++++++++++++++++ docs/whats-new.md | 8 +++++ 3 files changed, 64 insertions(+) diff --git a/crates/engine/src/cmd/lut_profiles.rs b/crates/engine/src/cmd/lut_profiles.rs index 50cb1223007..f4c1150352c 100644 --- a/crates/engine/src/cmd/lut_profiles.rs +++ b/crates/engine/src/cmd/lut_profiles.rs @@ -117,6 +117,13 @@ fn import(s: &mut Session, p: &Value) -> Result { }; let display = lut.title.clone().filter(|t| !t.trim().is_empty()).unwrap_or_else(|| name.clone()); let group = super::super::preset_import::group_from_dir(&group.unwrap_or_default()).unwrap_or_else(|| "Imported".into()); + // the same LUT imported again (title, group and table): keep the one there is + let same = + s.lut_profiles.iter().find(|p| p.name == display && p.group == group && lightcraft_pipeline::lut::get(&p.id).is_some_and(|l| *l == lut)); + if let Some(p) = same { + imported.push(json!({"id": p.id, "name": p.name, "group": p.group, "existing": true})); + continue; + } let slug = crate::presets::slug(&format!("{group}-{display}")); let mut id = format!("lut:{slug}"); let n = next_suffix.entry(slug.clone()).or_insert(2); diff --git a/crates/engine/src/tests/import.rs b/crates/engine/src/tests/import.rs index 3b65dbae9a3..b2f134236b9 100644 --- a/crates/engine/src/tests/import.rs +++ b/crates/engine/src/tests/import.rs @@ -1748,6 +1748,55 @@ fn cube_import_without_a_library_leaves_no_temp_copy() { let _ = std::fs::remove_dir_all(&src); } +/// Importing a LUT that is already imported (same title, group and table) returns the profile +/// there is, with no second entry or copy (#4901); a changed table under the same title is a new +/// profile. +#[test] +fn cube_imported_twice_is_one_profile() { + let src = temp_dir("cubetwice"); + let lib = temp_dir("cubetwicelib"); + let cube = |red: f32| { + let mut c = String::from("TITLE \"Twice Test\"\nLUT_3D_SIZE 2\n"); + for b in 0..2 { + for g in 0..2 { + for r in 0..2 { + c.push_str(&format!("{} {g} {b}\n", r as f32 * red)); + } + } + } + c + }; + std::fs::create_dir_all(src.join("Twice Looks")).unwrap(); + std::fs::write(src.join("Twice Looks/look.cube"), cube(1.0)).unwrap(); + let mut s = Session::new().with_fs(); + s.open_library(&lib, true).unwrap(); + let import = |s: &mut Session| s.execute("profile.import", &json!({"paths": [src.join("Twice Looks").to_string_lossy()]})).unwrap(); + let copies = || { + std::fs::read_dir(lib.join("Profiles")) + .unwrap() + .filter(|e| e.as_ref().is_ok_and(|e| e.path().extension().is_some_and(|x| x == "cube"))) + .count() + }; + let first = import(&mut s); + let id = first["imported"][0]["id"].as_str().unwrap().to_string(); + let again = import(&mut s); + assert_eq!(again["imported"][0]["id"], id.as_str(), "the profile there is: {again}"); + assert_eq!(again["imported"][0]["existing"], true, "{again}"); + assert_eq!(s.lut_profiles.len(), 1, "one entry: {:?}", s.lut_profiles); + assert_eq!(copies(), 1, "one copy in Profiles/"); + // a different table under the same title and group is another profile + std::fs::write(src.join("Twice Looks/look.cube"), cube(0.5)).unwrap(); + let changed = import(&mut s); + let other = changed["imported"][0]["id"].as_str().unwrap().to_string(); + assert_ne!(other, id, "{changed}"); + assert_eq!((s.lut_profiles.len(), copies()), (2, 2)); + drop(s); + lightcraft_pipeline::lut::unregister(&id); + lightcraft_pipeline::lut::unregister(&other); + let _ = std::fs::remove_dir_all(&src); + let _ = std::fs::remove_dir_all(&lib); +} + /// Folder rename / move on disk: files and sidecars go along, the photos are relinked and /// still render; clashes and moving into itself are refused. #[test] diff --git a/docs/whats-new.md b/docs/whats-new.md index fdc89055fb6..1afdb3106a6 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 + +### Importing a LUT profile again keeps the one there is +- Importing a `.cube` profile that was already imported added it a second time, with a second copy in the library's + Profiles folder and a second entry of the same name in the profile browser. The same LUT (same title, group and + table) now returns the profile already there, as camera profiles do; a changed table under the same title is still + imported as a new profile (#4901). + ## 2026-10-31 ### Filter for unrated photos From 71075ad9509f926894837cb5104bef2ee005c43e Mon Sep 17 00:00:00 2001 From: anthonyessaye Date: Mon, 30 Nov 2026 10:44:32 +0200 Subject: [PATCH 2/3] LUT import: match the table, not the TITLE metadata (#4901) The profile's name already stands for the title, so a file without a TITLE line, named like the title, with the same table in the same group is the same LUT and returns the profile there is. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/lut_profiles.rs | 12 +++++++++--- crates/engine/src/tests/import.rs | 17 ++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/lut_profiles.rs b/crates/engine/src/cmd/lut_profiles.rs index f4c1150352c..2fe5b33069f 100644 --- a/crates/engine/src/cmd/lut_profiles.rs +++ b/crates/engine/src/cmd/lut_profiles.rs @@ -117,9 +117,15 @@ fn import(s: &mut Session, p: &Value) -> Result { }; let display = lut.title.clone().filter(|t| !t.trim().is_empty()).unwrap_or_else(|| name.clone()); let group = super::super::preset_import::group_from_dir(&group.unwrap_or_default()).unwrap_or_else(|| "Imported".into()); - // the same LUT imported again (title, group and table): keep the one there is - let same = - s.lut_profiles.iter().find(|p| p.name == display && p.group == group && lightcraft_pipeline::lut::get(&p.id).is_some_and(|l| *l == lut)); + // the same LUT imported again (name, group and table): keep the one there is. The name already + // stands for the title, so a file without a TITLE line, named like it, is the same LUT + let same_table = |l: &lightcraft_pipeline::lut::Lut3d| { + l.size == lut.size && l.data == lut.data && l.domain_min == lut.domain_min && l.domain_max == lut.domain_max + }; + let same = s + .lut_profiles + .iter() + .find(|p| p.name == display && p.group == group && lightcraft_pipeline::lut::get(&p.id).is_some_and(|l| same_table(&l))); if let Some(p) = same { imported.push(json!({"id": p.id, "name": p.name, "group": p.group, "existing": true})); continue; diff --git a/crates/engine/src/tests/import.rs b/crates/engine/src/tests/import.rs index b2f134236b9..97d2daae583 100644 --- a/crates/engine/src/tests/import.rs +++ b/crates/engine/src/tests/import.rs @@ -1748,15 +1748,15 @@ fn cube_import_without_a_library_leaves_no_temp_copy() { let _ = std::fs::remove_dir_all(&src); } -/// Importing a LUT that is already imported (same title, group and table) returns the profile -/// there is, with no second entry or copy (#4901); a changed table under the same title is a new -/// profile. +/// Importing a LUT that is already imported (same name, group and table) returns the profile +/// there is, with no second entry or copy (#4901), also from a file without a TITLE line named +/// like the title; a changed table under the same title is a new profile. #[test] fn cube_imported_twice_is_one_profile() { let src = temp_dir("cubetwice"); let lib = temp_dir("cubetwicelib"); - let cube = |red: f32| { - let mut c = String::from("TITLE \"Twice Test\"\nLUT_3D_SIZE 2\n"); + let untitled = |red: f32| { + let mut c = String::from("LUT_3D_SIZE 2\n"); for b in 0..2 { for g in 0..2 { for r in 0..2 { @@ -1766,6 +1766,7 @@ fn cube_imported_twice_is_one_profile() { } c }; + let cube = |red: f32| format!("TITLE \"Twice Test\"\n{}", untitled(red)); std::fs::create_dir_all(src.join("Twice Looks")).unwrap(); std::fs::write(src.join("Twice Looks/look.cube"), cube(1.0)).unwrap(); let mut s = Session::new().with_fs(); @@ -1782,6 +1783,12 @@ fn cube_imported_twice_is_one_profile() { let again = import(&mut s); assert_eq!(again["imported"][0]["id"], id.as_str(), "the profile there is: {again}"); assert_eq!(again["imported"][0]["existing"], true, "{again}"); + // the same table in a file without a TITLE line, named like the title, in a folder of the same name + let bare = src.join("bare/Twice Looks"); + std::fs::create_dir_all(&bare).unwrap(); + std::fs::write(bare.join("Twice Test.cube"), untitled(1.0)).unwrap(); + let r = s.execute("profile.import", &json!({"paths": [bare.to_string_lossy()]})).unwrap(); + assert_eq!(r["imported"][0]["id"], id.as_str(), "the profile there is: {r}"); assert_eq!(s.lut_profiles.len(), 1, "one entry: {:?}", s.lut_profiles); assert_eq!(copies(), 1, "one copy in Profiles/"); // a different table under the same title and group is another profile From 8645e6740083bac250f16382be87db6cb10c6d64 Mon Sep 17 00:00:00 2001 From: anthonyessaye Date: Tue, 1 Dec 2026 18:19:44 +0200 Subject: [PATCH 3/3] What's New: LUT import matches the profile name, not the TITLE (#4901) Co-Authored-By: Claude Opus 5.5 --- docs/whats-new.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/whats-new.md b/docs/whats-new.md index 1afdb3106a6..5d880c3f143 100644 --- a/docs/whats-new.md +++ b/docs/whats-new.md @@ -18,9 +18,9 @@ ### Importing a LUT profile again keeps the one there is - Importing a `.cube` profile that was already imported added it a second time, with a second copy in the library's - Profiles folder and a second entry of the same name in the profile browser. The same LUT (same title, group and - table) now returns the profile already there, as camera profiles do; a changed table under the same title is still - imported as a new profile (#4901). + Profiles folder and a second entry of the same name in the profile browser. The same LUT (same profile name, group + and table) now returns the profile already there, as camera profiles do; a changed table under the same name is + still imported as a new profile (#4901). ## 2026-10-31