Repository navigation
LR-PROF-IMPORT: import the user's own DNG camera profiles (.dcp) #1063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
366b1d2
LR-PROF-IMPORT: import the user's own DNG camera profiles (.dcp)
OneSlips 1ecfb7b
Merge upstream main into pr/dcp-camera-profiles
OneSlips 4a5ef6f
LR-PROF-IMPORT: build against upstream main (kelvin_presets, 3-arg lo…
OneSlips ba03cfe
LR-PROF-IMPORT: hover previews and browser thumbnails develop the hov…
OneSlips d1cfbc7
Merge upstream main into pr/dcp-camera-profiles
OneSlips c8c9904
LR-PROF-IMPORT: build against upstream main (face-tile test loader an…
OneSlips 50044cd
Merge upstream main into pr/dcp-camera-profiles
OneSlips 96e46fc
CI: the catalog's staging-link test module is Unix-only (unused impor…
OneSlips d1313b7
CI: same-folder export test expects the '/'-joined subfolder (failed …
OneSlips af265c5
CI: folder-drop tests build widget ids with the Folders tree's '/' pa…
OneSlips cb20494
LR-PROF-IMPORT: rustfmt after merging main
OneSlips a38bb76
LR-PROF-IMPORT: merge origin/main
OneSlips f911c7d
LR-PROF-IMPORT: a real D750 camera profile as a pinned test corpus, c…
OneSlips 0d17a38
LR-PROF-IMPORT: a single .dcp file is a camera profile only, not also…
OneSlips 2128b3f
LR-PROF-IMPORT: merge origin/main
OneSlips 49f2ec4
LR-PROF-IMPORT: merge origin/main (31ee2643, round-2 integration)
OneSlips af38d04
LR-PROF-IMPORT: review fixes for imported camera profiles
OneSlips 4ef025d
LR-PROF-IMPORT: merge origin/main (23e18128, release 0.13.0)
OneSlips 7d616d6
LR-PROF-IMPORT: merge origin/main (98702b5c, integration batch 43)
OneSlips 4694624
LR-PROF-IMPORT: smart previews without the camera profile, current-pr…
OneSlips 91f08f4
Merge remote-tracking branch 'origin/main' into pr/dcp-camera-profiles
OneSlips 42c414d
LR-PROF-IMPORT: the Before side decodes with its own camera profile; …
OneSlips a3c82f9
LR-PROF-IMPORT: a cached smart preview stands in while the original i…
OneSlips a670d64
LR-PROF-IMPORT: merge origin/main (31ec62cd)
OneSlips c94484c
Merge remote-tracking branch 'origin/main' into pr/dcp-camera-profiles
OneSlips 865c914
Merge remote-tracking branch 'origin/main' into pr/dcp-camera-profiles
OneSlips 7dac66e
LR-PROF-IMPORT: deleting a camera profile removes the library's copy …
OneSlips c739b7b
LR-PROF-IMPORT: deleting a camera profile never follows `..` out of t…
OneSlips 3c16bcd
LR-PROF-IMPORT: merge main (upstream file split)
OneSlips d7eb0ef
LR-PROF-IMPORT: both tone fits of a DNG see its lens opcodes; no side…
OneSlips 5a3d647
LR-PROF-IMPORT: a hover preview's key carries the camera profile file…
OneSlips c29f618
LR-PROF-IMPORT: merge main (59a5d00c6, the ui-egui split and clippy s…
OneSlips 3e19238
LR-PROF-IMPORT: merge main (e381c1ae6, Release 0.15.0)
OneSlips 3bca86f
LR-PROF-IMPORT: merge main (e2d18b5fb, flatpak network access #3269)
OneSlips e68f7bb
LR-PROF-IMPORT: merge main (integration batch 45)
OneSlips 4a30283
Merge remote-tracking branch 'origin/main' into pr/dcp-camera-profiles
OneSlips 32d3a7e
LR-PROF-IMPORT: unusable camera profiles not offered; file's WB scale…
OneSlips 46c9d82
Merge remote-tracking branch 'origin/main' into pr/dcp-camera-profiles
OneSlips e074555
LR-PROF-IMPORT: one Camera Profiles group; the web loader keeps a raw…
OneSlips b9937f7
LR-PROF-IMPORT: camera profile files are read at most to the 64 MiB l…
OneSlips 408636a
LR-PROF-IMPORT: a test that a hostile hue/saturation map header in a …
OneSlips 3cb0d3b
Merge main; cache keys keep both the camera profile and the lens profile
FredApps a864aad
Docs: parity checklist keeps both sides of the merge
FredApps b295a55
LR-PROF-IMPORT: tests added on main take the file loader's camera-pro…
FredApps 04b7054
Merge main; tracker docs keep both sides
FredApps 9b049d0
Merge remote-tracking branch 'origin/main' into HEAD
FredApps 9f8b3f5
Merge main; a thumbnail test takes the file loader's camera-profile a…
FredApps ed7508f
Docs: one camera colour row, with main's notes and the import note
FredApps d696b8a
Merge remote-tracking branch 'origin/main' into HEAD
FredApps 1261048
Merge main; cache keys hold the process, camera profile and lens
FredApps 32a9b05
Process key tests take the profile salt argument
FredApps File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| //! Imported camera profiles: the user's own DNG Camera Profiles (`.dcp`), chosen like any other | ||
| //! profile (`develop.profile {id: "dcp:…"}`). Unlike the built-in looks and LUT profiles, which | ||
| //! work on developed colour, a camera profile replaces the raw file's colour model when it is | ||
| //! decoded (its matrices and hue/saturation map; see [`lightcraft_raw::dcp`]), so the photo's | ||
| //! source is decoded again when it changes. Other photos (JPEG, TIFF…) ignore it. | ||
| //! | ||
| //! A library on disk keeps a copy of each file in its `Profiles/` folder; the list lives in the | ||
| //! library's prefs and the profiles are parsed again when the library opens. | ||
|
|
||
| use std::path::{Path, PathBuf}; | ||
| use std::sync::Arc; | ||
|
|
||
| use lightcraft_raw::dcp::DcpProfile; | ||
| use serde_json::{Value, json}; | ||
|
|
||
| use super::{CommandSpec, always, bad, cmd, str_param}; | ||
| use crate::{Result, Session}; | ||
|
|
||
| /// Profile id prefix of imported camera profiles. | ||
| pub const DCP_PREFIX: &str = "dcp:"; | ||
| /// Profile browser group of imported camera profiles. | ||
| pub const DCP_GROUP: &str = "Camera Profiles"; | ||
|
|
||
| /// One imported camera profile. | ||
| #[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct DcpEntry { | ||
| /// `dcp:<slug>`. | ||
| pub id: String, | ||
| /// `ProfileName`, else the file name. | ||
| pub name: String, | ||
| /// The camera it was made for (`UniqueCameraModel`). | ||
| #[serde(default)] | ||
| pub camera_model: String, | ||
| /// The `.dcp` file (the library's copy when there is a library on disk). | ||
| pub file: String, | ||
| } | ||
|
|
||
| /// Is `id` an imported camera profile id? | ||
| pub fn is_dcp_id(id: &str) -> bool { | ||
| id.starts_with(DCP_PREFIX) | ||
| } | ||
|
|
||
| fn profiles_dir(s: &Session) -> Option<PathBuf> { | ||
| s.library.as_ref().filter(|l| l.on_disk).map(|l| l.dir.join("Profiles")) | ||
| } | ||
|
|
||
| /// Parse every imported camera profile again and hand them to the decoder (missing or damaged | ||
| /// files are skipped: photos using them develop with the file's own colour). | ||
| pub fn register_all(s: &mut Session) { | ||
| let loaded: Vec<(String, Arc<DcpProfile>)> = s | ||
| .dcp_profiles | ||
| .iter() | ||
| .filter_map(|p| std::fs::read(&p.file).ok().and_then(|b| lightcraft_raw::dcp::parse_dcp(&b).ok()).map(|d| (p.id.clone(), Arc::new(d)))) | ||
| .collect(); | ||
| s.media.camera_profiles = loaded.into_iter().collect(); | ||
| } | ||
|
|
||
| /// `.dcp` files under `paths` (folders searched). | ||
| pub fn dcp_files(paths: &[String]) -> Vec<PathBuf> { | ||
| let is_dcp = |f: &Path| f.extension().is_some_and(|x| x.eq_ignore_ascii_case("dcp")); | ||
| let mut out = Vec::new(); | ||
| for p in paths { | ||
| let path = Path::new(p); | ||
| if path.is_dir() { | ||
| out.extend(crate::walk::files_in(path, None, crate::walk::Limits::default(), is_dcp).files); | ||
| } else if is_dcp(path) { | ||
| out.push(path.to_path_buf()); | ||
| } | ||
| } | ||
| out | ||
| } | ||
|
|
||
| /// Import the `.dcp` files under `paths` → (imported `[{id, name, cameraModel}]`, failed `[[file, error]]`). | ||
| /// A profile already imported (same name, camera and bytes) is not added twice. | ||
| pub fn import_files(s: &mut Session, paths: &[String]) -> Result<(Vec<Value>, Vec<Value>)> { | ||
| const C: &str = "profile.import"; | ||
| let dir = profiles_dir(s); | ||
| if let Some(d) = &dir { | ||
| std::fs::create_dir_all(d).map_err(|e| bad(C, format!("{}: {e}", d.display())))?; | ||
| } | ||
| let (mut imported, mut failed) = (Vec::new(), Vec::new()); | ||
| for f in dcp_files(paths) { | ||
| let shown = f.display().to_string(); | ||
| let bytes = match std::fs::read(&f) { | ||
| Ok(b) => b, | ||
| Err(e) => { | ||
| failed.push(json!([shown, e.to_string()])); | ||
| continue; | ||
| } | ||
| }; | ||
| let profile = match lightcraft_raw::dcp::parse_dcp(&bytes) { | ||
| Ok(p) => p, | ||
| Err(e) => { | ||
| failed.push(json!([shown, e.to_string()])); | ||
| continue; | ||
| } | ||
| }; | ||
| let stem = f.file_stem().map(|n| n.to_string_lossy().to_string()).unwrap_or_else(|| "Camera Profile".into()); | ||
| let name = if profile.name.trim().is_empty() { stem.clone() } else { profile.name.trim().to_string() }; | ||
| // the same profile imported again: keep the one there is | ||
| let same = s | ||
| .dcp_profiles | ||
| .iter() | ||
| .find(|p| p.name == name && p.camera_model == profile.camera_model && std::fs::read(&p.file).is_ok_and(|b| b == bytes)); | ||
| if let Some(p) = same { | ||
| imported.push(json!({"id": p.id, "name": p.name, "cameraModel": p.camera_model, "existing": true})); | ||
| continue; | ||
| } | ||
| // (the file name keeps profiles with the same ProfileName apart, e.g. per-body copies) | ||
| let slug = crate::presets::slug(&format!("{}-{stem}", profile.camera_model)); | ||
| let mut id = format!("{DCP_PREFIX}{slug}"); | ||
| let mut n = 2; | ||
| while s.dcp_profiles.iter().any(|x| x.id == id) { | ||
| id = format!("{DCP_PREFIX}{slug}-{n}"); | ||
| n += 1; | ||
| } | ||
| let file = match &dir { | ||
| Some(d) => { | ||
| let to = d.join(format!("{}.dcp", id.trim_start_matches(DCP_PREFIX))); | ||
| std::fs::write(&to, &bytes).map_err(|e| bad(C, format!("{}: {e}", to.display())))?; | ||
| to.to_string_lossy().to_string() | ||
| } | ||
| // no library on disk: remember the original (the in-memory session ends with the app) | ||
| None => f.to_string_lossy().to_string(), | ||
| }; | ||
| s.media.camera_profiles.insert(id.clone(), Arc::new(profile.clone())); | ||
| s.dcp_profiles.push(DcpEntry { id: id.clone(), name: name.clone(), camera_model: profile.camera_model.clone(), file }); | ||
| imported.push(json!({"id": id, "name": name, "cameraModel": profile.camera_model})); | ||
| } | ||
| Ok((imported, failed)) | ||
| } | ||
|
|
||
| fn delete(s: &mut Session, p: &Value) -> Result<Value> { | ||
| const C: &str = "profile.deleteCamera"; | ||
| let id = str_param(p, "id").ok_or_else(|| bad(C, "missing id"))?.to_string(); | ||
| let Some(i) = s.dcp_profiles.iter().position(|x| x.id == id) else { | ||
| return Err(bad(C, format!("no imported camera profile `{id}`"))); | ||
| }; | ||
| let entry = s.dcp_profiles.remove(i); | ||
| s.media.camera_profiles.remove(&id); | ||
| // the library's copy goes; a file outside the library is the user's and stays | ||
| if let Some(d) = profiles_dir(s) | ||
| && Path::new(&entry.file).starts_with(&d) | ||
| { | ||
| let _ = std::fs::remove_file(&entry.file); | ||
| } | ||
| s.profile_favorites.retain(|f| f != &id); | ||
| s.profile_recent.retain(|f| f != &id); | ||
| s.save_prefs()?; | ||
| Ok(json!({"deleted": id})) | ||
| } | ||
|
|
||
| pub fn specs() -> Vec<CommandSpec> { | ||
| vec![ | ||
| cmd!( | ||
| query "profiles.camera", | ||
| "Imported Camera Profiles", | ||
| [], | ||
| None, | ||
| "{} → {profiles: [{id, name, cameraModel, file}]}: the imported .dcp camera profiles (use with develop.profile)", | ||
| always, | ||
| |s, _| Ok(json!({"profiles": s.dcp_profiles})) | ||
| ), | ||
| cmd!( | ||
| "profile.deleteCamera", | ||
| "Delete Imported Camera Profile", | ||
| [], | ||
| None, | ||
| "{id: dcp:…} — photos using it develop with their file's own colour again", | ||
| always, | ||
| delete | ||
| ), | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.