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
13 changes: 13 additions & 0 deletions crates/engine/src/cmd/lut_profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ fn import(s: &mut Session, p: &Value) -> Result<Value> {
};
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 (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;
}
let slug = crate::presets::slug(&format!("{group}-{display}"));
let mut id = format!("lut:{slug}");
let n = next_suffix.entry(slug.clone()).or_insert(2);
Expand Down
56 changes: 56 additions & 0 deletions crates/engine/src/tests/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,62 @@ 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 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 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 {
c.push_str(&format!("{} {g} {b}\n", r as f32 * red));
}
}
}
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();
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}");
// 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
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]
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

### 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 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

### Filter for unrated photos
Expand Down