Skip to content

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

Merge PR #7417: Camera Raw: choose the demosaic method when a raw opens

aiongga77b078589ff
diff --cc crates/engine/src/jobs.rs
index 9ea1a2413,34c4d24ba..5a89d0721
--- a/crates/engine/src/jobs.rs
+++ b/crates/engine/src/jobs.rs
@@@ -531,23 -532,14 +539,23 @@@ impl Session
};
ctx.check()?;
ctx.progress(0.02, "Decoding");
- let imported = ctx
- .stage(0.02, 0.95, "Decoding", |ctl| photocraft_io::import_with_svg_group_depth_and_interrupt(&name_w, &bytes, max_svg_group_depth, ctl))
- .map_err(|e| match e {
+ let imported = ctx.stage(0.02, 0.95, "Decoding", |ctl| photocraft_io::import_with_options_and_interrupt(&name_w, &bytes, &opts, ctl)).map_err(
+ |e| match e {
photocraft_io::IoError::Cancelled => EngineError::Cancelled,
e => EngineError::Other(e.to_string()),
- })?;
+ },
+ )?;
ctx.progress(0.95, "Preparing layers");
warm_layer_bounds(&imported.document, || ctx.check())?;
+ // Type layers need the shared text engine, whose first use waits for the
+ // installed-font scan started at launch (minutes on some machines). Wait here,
+ // so the shell's missing-font check after the open finds it ready instead of
+ // freezing the window (#7332).
+ if crate::type_extra_cmds::has_type_layers(&imported.document) {
+ ctx.progress(0.97, "Loading fonts");
+ let _ = photocraft_text::shared();
+ ctx.check()?;
+ }
Ok(imported)
},
move |s, mut r: photocraft_io::ImportResult| {
diff --cc crates/io/src/lib.rs
index d71a5d716,8290ea6d1..024d704b0
--- a/crates/io/src/lib.rs
+++ b/crates/io/src/lib.rs
@@@ -325,25 -328,7 +350,25 @@@ pub fn import_with_options_and_interrup
Ok(r)
}
+fn import_psd(name: &str, bytes: &[u8], ctl: &photocraft_raster::Interrupt) -> Result<ImportResult, IoError> {
+ // A merged image the import reads is decoded with the parse: a ZIP one is inflated once.
+ let (file, merged) = PsdFile::from_bytes_and_merged_recovering(
+ bytes,
+ |f| psd_import::check_group_depth(f).is_ok() && psd_import::merged_needed(f),
+ psd_import::can_recover_layers,
+ )?;
+ // Nesting past the document model's cap could never be saved; reject the file with the
+ // actionable limit.
+ psd_import::check_group_depth(&file)?;
+ ctl.check().map_err(|_| IoError::Cancelled)?;
+ ctl.progress(0.05);
+ let (mut document, warnings) = psd_import::psd_to_document_decoded(&file, ctl, merged).ok_or(IoError::Cancelled)?;
+ document.name = name.to_string();
+ text_import::prepare(&mut document);
+ Ok(ImportResult { document, warnings, source_read_only: false, preview_only: false })
+}
+
- fn import_stages(name: &str, bytes: &[u8], ctl: &photocraft_raster::Interrupt, max_group_depth: usize) -> Result<ImportResult, IoError> {
+ fn import_stages(name: &str, bytes: &[u8], ctl: &photocraft_raster::Interrupt, opts: &ImportOptions) -> Result<ImportResult, IoError> {
// A declared native extension must reach its loader so malformed bundles retain format errors.
if has_extension(name, photocraft_format::EXTENSION) || photocraft_format::is_pcraft(bytes) {
let document = photocraft_format::load_from_bytes(bytes)?;
@@@ -377,16 -366,11 +402,16 @@@
return pdn::import(name, bytes, ctl);
}
if raw::is_raw(bytes) {
- return raw::import_raw(name, bytes);
+ return raw::import_raw_demosaic(name, bytes, opts.demosaic);
}
if is_svg_input(name, bytes) {
- return svg::import_svg_with_group_depth(name, bytes, max_group_depth);
+ return svg::import_svg_with_group_depth(name, bytes, opts.max_group_depth);
}
+ // A `.psd`/`.psb`/`.psdt` with no raster signature keeps the PSD error instead of
+ // `codec: unrecognized image format` (#5258). Magic already returned above.
+ if is_psd_input(name, bytes) {
+ return import_psd(name, bytes, ctl);
+ }
flat::import_flat(name, bytes)
}
diff --cc crates/io/src/raw.rs
index 5ce761b52,a74c8a9ea..420b3f2cf
--- a/crates/io/src/raw.rs
+++ b/crates/io/src/raw.rs
@@@ -110,8 -112,8 +112,8 @@@ pub fn import_raw_tuned(name: &str, byt
.filter(|(_, v)| *v != 0.0)
.map(|(k, v)| format!(", {k} {v:+.0}"))
.collect::<String>();
- let summary = format!("developed in Camera Raw (exposure {:+.2} EV{tone}, {wb})", tuning.exposure);
+ let summary = format!("developed in Camera Raw (exposure {:+.2} EV{tone}, {wb}, {} demosaic)", tuning.exposure, tuning.demosaic.id());
- Ok((developed_document(name, format, dev, &summary)?, wb_applied))
+ Ok((developed_document(name, bytes, format, dev, &summary)?, wb_applied))
}
/// The tone curve `bytes` develop with by default: the fitted look's for a file without colour