LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge main into geometry/optics branch (embedded lens + XMP sidecar import, ProbeInfo fields)
Brandon Thomas8cbdece6f2ac
diff --cc crates/engine/src/files.rsindex 5645341e1,eaa29a66b..c4dfa0772--- a/crates/engine/src/files.rs+++ b/crates/engine/src/files.rs@@@ -92,7 -44,25 +92,26 @@@ pub fn probe_bytes(name: &str, bytes: &let m = lightcraft_meta::extract(bytes);let (meta, captured) = meta_of(&m);if lightcraft_raw::probe(bytes).is_some() {- let raw = lightcraft_raw::decode(bytes).map_err(|e| e.to_string())?;+ let raw = match lightcraft_raw::decode(bytes) {+ Ok(r) => r,+ Err(lightcraft_raw::RawError::Unsupported(why)) => {+ // a raw variant we can't decode yet: describe it from its embedded preview+ let (w, h) = embedded_preview_size(bytes).ok_or(format!("unsupported raw ({why}) without an embedded preview"))?;+ return Ok(ProbeInfo {+ width: w,+ height: h,+ format: ext_upper(name),+ kind: MediaKind::Raw,+ file_size: bytes.len() as u64,+ captured,+ meta,+ as_shot_wb: None,+ content_hash,++ ..Default::default()+ });+ }+ Err(e) => return Err(e.to_string()),+ };let (mut w, mut h) = (raw.crop.width.max(1) as u32, raw.crop.height.max(1) as u32);if w <= 1 || h <= 1 {(w, h) = (raw.active_area.width as u32, raw.active_area.height as u32);@@@ -141,17 -110,21 +161,25 @@@meta,as_shot_wb: None,content_hash,+ embedded_lens: None,+ xmp: None,})}/// Decode a file into a linear Rec.2020 image no larger than `max_edge`, oriented.pub fn load_bytes(bytes: &[u8], max_edge: usize) -> Result<(Rgb32f, SourceInfo), String> {if lightcraft_raw::probe(bytes).is_some() {- let mut raw = lightcraft_raw::decode(bytes).map_err(|e| e.to_string())?;- let raw = match lightcraft_raw::decode(bytes) {++ let mut raw = match lightcraft_raw::decode(bytes) {+ Ok(r) => r,+ Err(lightcraft_raw::RawError::Unsupported(why)) => {+ // show the camera's embedded JPEG (rendered, not raw) until the variant is supported+ return load_embedded_preview(bytes, max_edge).ok_or(format!("unsupported raw ({why}) without an embedded preview"));+ }+ Err(e) => return Err(e.to_string()),+ };+ // Embedded lens corrections are applied by the pipeline ("Enable Profile Corrections"), not baked in.+ let lens = embedded_lens(&raw);+ raw.opcodes.list3.retain(|op| !is_lens_opcode(op));let method = if max_edge <= 600 { lightcraft_raw::Method::Bilinear } else { lightcraft_raw::Method::Ahd };let mut img = raw.develop(method).map_err(|e| e.to_string())?;let xy = lightcraft_raw::color::as_shot_white_xy(&raw);diff --cc crates/engine/src/import.rsindex f02028555,315e5290e..3aac02034--- a/crates/engine/src/import.rs+++ b/crates/engine/src/import.rs@@@ -219,11 -223,20 +223,25 @@@ pub fn import(s: &mut Session, paths: &if let Some((t, tint)) = info.as_shot_wb {p.develop = std::sync::Arc::new(lightcraft_develop::DevelopSettings::for_raw(t, tint));}+ p.embedded_lens = info.embedded_lens;+ if p.embedded_lens.is_some() {+ // built-in (file-embedded) lens corrections are on by default, like the camera intended+ std::sync::Arc::make_mut(&mut p.develop).optics.lens_profile = true;+ }+ let raw = p.kind == lightcraft_catalog::MediaKind::Raw;+ let packet = crate::sidecar::find_sidecar(&path, s.xmp.naming)+ .and_then(|f| std::fs::read_to_string(f).ok())+ .or_else(|| info.xmp.clone().filter(|_| raw));+ if let Some(x) = packet {+ match crate::sidecar::parse_sidecar(&x, raw) {+ Ok(sc) if sc != crate::sidecar::SidecarData::default() => {+ crate::sidecar::merge_into(&mut p, &sc, &now);+ report.sidecars += 1;+ }+ Ok(_) => {}+ Err(e) => log::warn!("import {path}: XMP: {e}"),+ }+ }report.imported.push(id.0);ops.push(Op::AddPhoto { photo: Box::new(p) });}diff --cc crates/engine/src/media.rsindex 7c3285283,4d6f4cba3..b4a4f6e6a--- a/crates/engine/src/media.rs+++ b/crates/engine/src/media.rs@@@ -305,8 -301,8 +305,10 @@@ pub struct ProbeInfopub as_shot_wb: Option<(f64, f64)>,/// Hash of the file's bytes (hex), for duplicate detection.pub content_hash: Option<String>,+ /// Lens corrections embedded in the file (DNG opcodes).+ pub embedded_lens: Option<lightcraft_develop::EmbeddedLens>,+ /// The file's embedded XMP packet (raw/DNG files), for develop settings stored inside the file.+ pub xmp: Option<String>,}pub type FileProbe = Arc<dyn Fn(&str) -> Result<ProbeInfo, String> + Send + Sync>;