Skip to content

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

Camera Raw open: the dialog starts from the demosaic method the open developed with

Unemars6c7425343637
diff --git a/crates/io/src/raw.rs b/crates/io/src/raw.rs
index f03c503c9..456669aa4 100644
--- a/crates/io/src/raw.rs
+++ b/crates/io/src/raw.rs
@@ -253,6 +253,16 @@ fn develop_fitted(bytes: &[u8], opts: &DevelopOptions) -> Result<photocraft_raw:
/// a preview fallback): what the open-time Camera Raw dialog looks for.
pub const DEVELOPED_NOTE: &str = "developed with default settings";
+/// The demosaic method a default open developed with, read back from its [`DEVELOPED_NOTE`]
+/// warning: the open-time dialog starts from it, whatever the preference says by the time the
+/// (background) open lands.
+pub fn developed_demosaic(warnings: &[String]) -> Option<Demosaic> {
+ let note = warnings.iter().find(|w| w.contains(DEVELOPED_NOTE))?;
+ let after = &note[note.find(DEVELOPED_NOTE)? + DEVELOPED_NOTE.len()..];
+ let id = after.trim_start().strip_prefix('(')?.split(" demosaic").next()?;
+ Demosaic::from_id(id)
+}
+
/// Develops a raw file with explicit settings. Without `opts.camera_look`, a file without
/// colour calibration gets one fitted to its embedded JPEG when that clearly helps.
pub fn import_raw_with(name: &str, bytes: &[u8], opts: &DevelopOptions) -> Result<ImportResult, IoError> {
@@ -285,6 +295,14 @@ pub fn import_raw_with(name: &str, bytes: &[u8], opts: &DevelopOptions) -> Resul
mod tests {
use super::*;
+ #[test]
+ fn the_developed_note_says_which_demosaic_method_was_used() {
+ let note = format!("NEF: {DEVELOPED_NOTE} (mhc demosaic, as-shot white balance) into 16-bit ProPhoto RGB");
+ assert_eq!(developed_demosaic(&["unrelated".to_string(), note]), Some(Demosaic::Mhc));
+ assert_eq!(developed_demosaic(&[format!("{DEVELOPED_NOTE} (amaze demosaic)")]), None);
+ assert_eq!(developed_demosaic(&["opened the embedded preview".to_string()]), None);
+ }
+
#[test]
fn camera_names_drop_a_repeated_make() {
assert_eq!(camera_name(Some("Canon"), Some("Canon EOS 80D")), "Canon EOS 80D");
diff --git a/crates/ui-egui/src/camera_raw_ui.rs b/crates/ui-egui/src/camera_raw_ui.rs
index 869f4ba2c..b7b6f1e24 100644
--- a/crates/ui-egui/src/camera_raw_ui.rs
+++ b/crates/ui-egui/src/camera_raw_ui.rs
@@ -223,11 +223,13 @@ pub fn without_develop_note(warnings: &[String]) -> Vec<String> {
warnings.iter().filter(|w| !w.contains(photocraft_io::raw::DEVELOPED_NOTE)).cloned().collect()
}
-/// Queues the open-time dialog for the active document (shown on the next frame).
-pub fn queue_open_dialog(app: &mut PhotocraftApp, name: &str, path: Option<&str>, bytes: Option<&[u8]>) {
+/// Queues the open-time dialog for the active document (shown on the next frame). `warnings`
+/// are the import's: its note says which demosaic method the open developed with.
+pub fn queue_open_dialog(app: &mut PhotocraftApp, name: &str, path: Option<&str>, bytes: Option<&[u8]>, warnings: &[String]) {
if let Some(st) = app.session.active() {
- // The open developed it with the preference's method (`jobs::import_options`).
- let method = app.session.prefs().raw_defaults.demosaic.method();
+ // The method the open actually used (`jobs::import_options` at the job's start), from its
+ // note: the preference may have changed while a background open ran.
+ let method = photocraft_io::raw::developed_demosaic(warnings).unwrap_or_else(|| app.session.prefs().raw_defaults.demosaic.method());
app.pending_raw_open = Some(RawOpen {
document: st.doc.id,
name: name.to_string(),
@@ -1617,6 +1619,16 @@ mod tests {
// Only the open-time dialog has the choice.
menu(&mut app, &ctx, "filter.cameraRaw", &json!({})).unwrap().unwrap();
assert!(menu(&mut app, &ctx, "filter.cameraRaw", &json!({"ui": {"demosaic": "ahd"}})).unwrap().is_err());
+
+ // The preference may change while a background open runs: the dialog starts from the
+ // method the open developed with (its note), not from the newer preference.
+ let warnings = app.open_bytes("IMG_0004.dng", &dng).unwrap();
+ app.pending_raw_open.take();
+ app.run("prefs.set", json!({"path": "rawDefaults.demosaic", "value": "ahd"})).unwrap();
+ queue_open_dialog(&mut app, "IMG_0004.dng", None, Some(&dng), &warnings);
+ let raw = app.pending_raw_open.take().unwrap();
+ use photocraft_io::raw::Demosaic;
+ assert_eq!((raw.developed_with, raw.demosaic), (Demosaic::Bilinear, Demosaic::Bilinear));
}
#[test]
diff --git a/crates/ui-egui/src/jobs_ui.rs b/crates/ui-egui/src/jobs_ui.rs
index 29da41d48..41dc41dfd 100644
--- a/crates/ui-egui/src/jobs_ui.rs
+++ b/crates/ui-egui/src/jobs_ui.rs
@@ -582,7 +582,7 @@ pub(crate) fn after_open(app: &mut PhotocraftApp, name: &str, path: Option<&str>
app.ui.status_error = false;
// A raw opens in Camera Raw first; the dialog says how it was developed.
if crate::camera_raw_ui::wants_open_dialog(app, warnings) {
- crate::camera_raw_ui::queue_open_dialog(app, name, path, bytes);
+ crate::camera_raw_ui::queue_open_dialog(app, name, path, bytes, warnings);
notices::io_warnings(app, &opened, &crate::camera_raw_ui::without_develop_note(warnings));
} else {
notices::io_warnings(app, &opened, warnings);