Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

EXR: the ACEScg preference applies to every way of opening a file (#6782) (#6783)

David Mann20c3e95a6bd1
diff --git a/crates/engine/src/exr_cmds.rs b/crates/engine/src/exr_cmds.rs
index 908942d4f..5fbc35531 100644
--- a/crates/engine/src/exr_cmds.rs
+++ b/crates/engine/src/exr_cmds.rs
@@ -52,7 +52,8 @@ fn open_exr_parts(s: &mut Session, p: &Value) -> Result<Value> {
precomp: p.get("precomp").and_then(Value::as_bool).unwrap_or(false),
};
let bytes = read_file(&path)?;
- let r = photocraft_io::exr_parts::import(&stem(&path), &bytes, &sel).map_err(|e| EngineError::Other(format!("{path}: {e}")))?;
+ let mut r = photocraft_io::exr_parts::import(&stem(&path), &bytes, &sel).map_err(|e| EngineError::Other(format!("{path}: {e}")))?;
+ crate::file_cmds::tag_exr_colorspace(s, &path, &mut r.document);
let (i, color) = s.open_document(r.document, Some(path.clone()));
Ok(json!({"document": i, "color": color, "warnings": r.warnings}))
}
@@ -173,6 +174,25 @@ mod tests {
std::fs::remove_dir_all(&dir).unwrap();
}
+ /// File Handling › "Open color-less EXR as ACEScg" applies to Open EXR Parts too.
+ #[test]
+ fn open_exr_parts_honours_the_aces_cg_preference() {
+ let dir = std::env::temp_dir().join(format!("pcraft-exr-aces-{}", std::process::id()));
+ std::fs::create_dir_all(&dir).unwrap();
+ let path = dir.join("aov.exr");
+ write_multipart(&path);
+ let linear = photocraft_cms::Builtin::LinearSrgb.profile().to_bytes();
+ let aces = photocraft_cms::Builtin::AcesCg.profile().to_bytes();
+ for (on, want) in [(false, &linear), (true, &aces)] {
+ let mut s = session();
+ s.prefs.edit(|p| p.file_handling.exr_aces_cg = on);
+ s.execute("file.openExrParts", json!({"path": path.to_str().unwrap(), "part/beauty": true})).unwrap();
+ let doc = &s.active().unwrap().doc;
+ assert_eq!(doc.icc_profile.as_deref().map(|v| v.as_slice()), Some(want.as_slice()), "exr_aces_cg = {on}");
+ }
+ std::fs::remove_dir_all(&dir).unwrap();
+ }
+
#[test]
fn open_exr_parts_refuses_an_empty_selection_and_unknown_names() {
let dir = std::env::temp_dir().join(format!("pcraft-exr-empty-{}", std::process::id()));
diff --git a/crates/engine/src/file_cmds.rs b/crates/engine/src/file_cmds.rs
index 7a86eb0ca..f9230d129 100644
--- a/crates/engine/src/file_cmds.rs
+++ b/crates/engine/src/file_cmds.rs
@@ -497,7 +497,7 @@ fn save_a_copy(s: &mut Session, p: &Value) -> Result<Value> {
/// With File Handling's ACEScg option on, such an EXR opens as ACEScg instead (AP1,
/// linear) — the working space ACES render pipelines write. Only the io default is
/// replaced; an embedded or EXIF-declared profile is kept untouched.
-fn tag_exr_colorspace(s: &Session, name: &str, doc: &mut Document) {
+pub(crate) fn tag_exr_colorspace(s: &Session, name: &str, doc: &mut Document) {
if !name.to_ascii_lowercase().ends_with(".exr") || !s.prefs.get().file_handling.exr_aces_cg {
return;
}
@@ -1806,4 +1806,38 @@ mod aces_exr_tests {
let d = &s.active().unwrap().doc;
assert_eq!(d.icc_profile.as_deref().map(|v| v.as_slice()), Some(aces.as_slice()));
}
+
+ /// The desktop app opens files as background jobs (File > Open, drag-drop, Open Recent):
+ /// the ACEScg preference applies there too, not only to `file.openAs`.
+ #[test]
+ fn exr_aces_cg_preference_applies_to_background_opens() {
+ use crate::jobs::{OpenSource, Started};
+ let image = photocraft_codecs::Image::from_f32(4, 4, photocraft_codecs::ChannelLayout::Rgb, &[0.5; 48]).unwrap();
+ let bytes =
+ std::sync::Arc::new(photocraft_codecs::encode(&image, photocraft_codecs::Format::OpenExr, &photocraft_codecs::EncodeOptions::default()).unwrap());
+ let linear = photocraft_cms::Builtin::LinearSrgb.profile().to_bytes();
+ let aces = photocraft_cms::Builtin::AcesCg.profile().to_bytes();
+ for (on, want) in [(false, &linear), (true, &aces)] {
+ let mut s = Session::new();
+ s.prefs.edit(|p| p.file_handling.exr_aces_cg = on);
+ let v = match s.start_open("shot.exr", OpenSource::Bytes(std::sync::Arc::clone(&bytes))).unwrap() {
+ Started::Job(id) => s.wait_job(id).unwrap(),
+ Started::Done(v) => v,
+ };
+ // ACEScg isn't the working space, so Ask When Opening holds it for the prompt, which
+ // names the ACEScg profile; linear sRGB (io's HDR default) opens without asking.
+ let profile = match v.get("held").and_then(Value::as_u64) {
+ Some(held) => {
+ assert!(on, "{v}");
+ assert!(v["color"]["embedded"].as_str().unwrap().starts_with("ACEScg"), "{v}");
+ s.take_held_open(held).unwrap().0.icc_profile
+ }
+ None => {
+ assert!(v.get("document").is_some(), "{v}");
+ s.active().unwrap().doc.icc_profile.clone()
+ }
+ };
+ assert_eq!(profile.as_deref().map(|v| v.as_slice()), Some(want.as_slice()), "exr_aces_cg = {on}");
+ }
+ }
}
diff --git a/crates/engine/src/jobs.rs b/crates/engine/src/jobs.rs
index 47045a37c..b30e56da3 100644
--- a/crates/engine/src/jobs.rs
+++ b/crates/engine/src/jobs.rs
@@ -509,7 +509,9 @@ impl Session {
warm_layer_bounds(&imported.document, || ctx.check())?;
Ok(imported)
},
- move |s, r: photocraft_io::ImportResult| {
+ move |s, mut r: photocraft_io::ImportResult| {
+ // File Handling's ACEScg option, before the colour prompt looks at the profile.
+ crate::file_cmds::tag_exr_colorspace(s, &name_a, &mut r.document);
// Ask When Opening: held back until the prompt is answered (`take_held_open`). A
// developed raw has no embedded profile to ask about.
let raw = r.warnings.iter().any(|w| w.contains(photocraft_io::raw::DEVELOPED_NOTE));