Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Merge PR #1471

Brandon Thomas7f7401713a92
diff --cc crates/engine/src/camera_preview.rs
index 60c0bd556,fb714025c..fe4c1cf1e
--- a/crates/engine/src/camera_preview.rs
+++ b/crates/engine/src/camera_preview.rs
@@@ -2462,52 -2404,36 +2462,82 @@@ mod tests
}
}
+ /// The merged DNG declares the white balance its source shows, also when the look's matrix doesn't keep white
+ /// neutral, as fitted looks often don't, and renders at As Shot as the source does. Real ARW merges declared their
+ /// colour matrix from the look: As Shot about 7000 K / +115 where the ARWs show 4800 K / +8.
+ #[test]
+ fn dng_colour_declares_the_white_balance_the_source_shows() {
+ use crate::files::DngWhite;
+ use lightcraft_raw::color::{as_shot_white_of, camera_transform_of, wb_multipliers};
+ let tags = ColorData::default();
+ let as_shot = [2.5039f32, 1.0, 1.5078];
+ let t = camera_transform_of(&tags, as_shot_white_of(&tags, Some(as_shot)));
+ let mut look = dro_test_look(&std::array::from_fn(|i| 0.005 * 1.2f32.powi(i as i32)), &|x| 0.95 * x / (x + 0.1));
+ look.matrix = Mat3([[1.75, -0.4, -0.2], [-0.2, 1.35, -0.2], [0.05, -0.3, 1.3]]);
+ let tint = look.matrix.apply([1.0; 3]);
+ assert!((tint[0] - tint[1]).abs() > 0.1, "a look that tints white: {tint:?}");
+ let renders_as_shot = |dng: &ColorData| {
+ let r = camera_transform_of(dng, as_shot_white_of(dng, None));
+ assert!(r.wb.iter().zip(t.wb).all(|(a, b)| (a - b).abs() < 1e-4 * b), "{:?} vs {:?}", r.wb, t.wb);
+ let m = look.matrix.mul(&t.matrix);
+ for c in [[0.2, 0.3, 0.1], [0.05, 0.02, 0.4], [0.6, 0.6, 0.6]] {
+ let want = m.apply(std::array::from_fn(|i| c[i] * t.wb[i] as f64)).map(|v| v * t.baseline_exposure.exp2());
+ let got = r.matrix.apply(std::array::from_fn(|i| c[i] * r.wb[i] as f64)).map(|v| v * dng.baseline_exposure.exp2());
+ assert!(want.iter().zip(got).all(|(a, b)| (a - b).abs() < 1e-4), "{c:?}: {want:?} vs {got:?}");
+ }
+ };
+ // a white the source's scale shows (Sony's presets, the relative scale's 6500 K / 0)
+ for xy in [lightcraft_color::cct::temp_tint_to_xy(5600.0, 3.0), lightcraft_color::cct::temp_tint_to_xy(6500.0, 0.0)] {
+ let dng = dng_colour(&tags, &DngWhite::At(xy), &t, Some(&look)).unwrap();
+ let back = as_shot_white_of(&dng, None);
+ assert!((back.x - xy.x).abs() < 1e-6 && (back.y - xy.y).abs() < 1e-6, "as shot {back:?}, shown {xy:?}");
+ renders_as_shot(&dng);
+ }
+ // a camera with measured matrices (the ILCE-7M3): every white read through them, as for the source
+ let camera = lightcraft_raw::spectral::find(Some("SONY"), "ILCE-7M3").expect("a covered camera");
+ let mut model = tags.clone();
+ assert!(camera.fill(&mut model));
+ let shown = lightcraft_raw::spectral::as_shot_white_through(camera, &tags, Some(as_shot)).unwrap();
+ let dng = dng_colour(&tags, &DngWhite::Matrices(Box::new(model.clone())), &t, Some(&look)).unwrap();
+ let back = as_shot_white_of(&dng, None);
+ assert!((back.x - shown.x).abs() < 1e-5 && (back.y - shown.y).abs() < 1e-5, "as shot {back:?}, shown {shown:?}");
+ for w in [Xy::new(0.3127, 0.329), Xy::new(0.4476, 0.4074), Xy::new(0.3457, 0.3585)] {
+ let (a, b) = (wb_multipliers(&model, w), wb_multipliers(&dng, w));
+ assert!(a.iter().zip(b).all(|(a, b)| (a - b).abs() < 1e-6 * a), "{w:?}: {a:?} vs {b:?}");
+ }
+ renders_as_shot(&dng);
+ }
+
+ /// Photo Merge gives a panorama the white balance of its frames' vendor multipliers (issue #1144). A raw without
+ /// colour matrices (CR2, NEF…) is merged with the tags above, whose neutral is that white balance already: taking
+ /// it from the multipliers again leaves the merged DNG rendering as the tags do.
+ #[test]
+ fn a_merges_white_balance_from_the_multipliers_is_the_one_the_starting_colour_tags_have() {
+ use lightcraft_raw::color::{as_shot_white_of, camera_transform_of};
+ for (model, multipliers) in [("Canon EOS 6D Mark II", [2.0, 1.0, 1.5]), ("Canon EOS 600D", [1.9, 1.0, 1.7])] {
+ let mut raw = raw_of(RawFormat::Cr2, "Canon", model, Default::default());
+ raw.wb_multipliers = Some(multipliers);
+ let tags = starting_colour_tags(&mut raw, &[]).expect("tags for a raw without colour matrices");
+ let neutral = tags.as_shot_neutral.expect("the tags carry the as-shot white balance");
+ // the reciprocal of the multipliers, up to the scale a neutral is given in
+ let scale = neutral[1] * multipliers[1] as f64;
+ for i in 0..3 {
+ assert!((neutral[i] * multipliers[i] as f64 - scale).abs() < 1e-3, "{model}: {neutral:?} vs 1 / {multipliers:?}");
+ }
+ let mut merged = lightcraft_merge::FrameColor::Camera(Box::new(tags.clone()));
+ merged.set_as_shot_multipliers(multipliers);
+ let lightcraft_merge::FrameColor::Camera(merged) = merged else { panic!("camera colour") };
+ let (a, b) = (camera_transform_of(&tags, as_shot_white_of(&tags, None)), camera_transform_of(&merged, as_shot_white_of(&merged, None)));
+ for i in 0..3 {
+ assert!((a.wb[i] - b.wb[i]).abs() < 1e-4 * a.wb[i], "{model}: {:?} vs {:?}", a.wb, b.wb);
+ }
+ for (ra, rb) in a.matrix.0.iter().zip(b.matrix.0) {
+ assert!(ra.iter().zip(rb).all(|(x, y)| (x - y).abs() < 1e-4), "{model}: {:?} vs {:?}", a.matrix, b.matrix);
+ }
+ assert_eq!(a.baseline_exposure, b.baseline_exposure);
+ }
+ }
+
/// A look with tone curve `f` at knots `xs` and a colour model and chroma curve to keep.
fn dro_test_look(xs: &[f32; 32], f: &dyn Fn(f32) -> f32) -> CameraLook {
CameraLook {
diff --cc crates/engine/src/merge.rs
index ed61c0509,c190cd489..26c69c63d
--- a/crates/engine/src/merge.rs
+++ b/crates/engine/src/merge.rs
@@@ -190,7 -183,7 +190,8 @@@ impl MergeJob
orientation: r.orientation,
metadata: r.metadata,
baseline_exposure: r.baseline_exposure,
+ lens: Vec::new(),
+ wb_multipliers: r.wb_multipliers,
};
f.orient();
merged.push(f);
diff --cc crates/merge/src/frame.rs
index 9ce00a505,ae91adffe..731f91a14
--- a/crates/merge/src/frame.rs
+++ b/crates/merge/src/frame.rs
@@@ -6,7 -6,7 +6,7 @@@ use lightcraft_geom::Orientation
use lightcraft_meta::Metadata;
use lightcraft_raster::Rgb32f;
use lightcraft_raster::resample::{Filter, fit};
- use lightcraft_raw::{ColorData, Opcode};
-use lightcraft_raw::{ColorData, RawImage};
++use lightcraft_raw::{ColorData, Opcode, RawImage};
use crate::{MergeError, Result};
@@@ -36,10 -51,9 +51,13 @@@ pub struct Frame
pub metadata: Metadata,
/// Raw files: the source's `BaselineExposure` (EV), carried into the output.
pub baseline_exposure: f64,
+ /// Raw files: the lens corrections the source applies (`WarpRectilinear`, `WarpRectilinear2`, `FixVignetteRadial`,
+ /// in order), re-expressed for `image` (the default crop, not yet turned), for the merged DNG to carry. Empty for
+ /// other sources and once [`Frame::orient`] has turned the pixels.
+ pub lens: Vec<Opcode>,
+ /// Raw files: the as-shot white-balance multipliers from the vendor's maker notes (green = 1), for formats such
+ /// as CR2 and NEF that have no `AsShotNeutral` of their own. `None` when the file doesn't say.
+ pub wb_multipliers: Option<[f32; 3]>,
}
impl Frame {
@@@ -57,7 -71,7 +75,8 @@@
orientation: Orientation::Normal,
metadata: Metadata::default(),
baseline_exposure: 0.0,
+ lens: Vec::new(),
+ wb_multipliers: None,
}
}
@@@ -197,7 -185,7 +191,8 @@@ pub fn load_frame_with(bytes: &[u8], ma
orientation: Orientation::from_exif(d.orientation),
metadata,
baseline_exposure: 0.0,
+ lens: Vec::new(),
+ wb_multipliers: None,
};
if orient {
f.orient();
@@@ -205,6 -193,54 +200,67 @@@
Ok(f)
}
+ /// A decoded raw (from `bytes`, which `colour` may read) as a frame: developed to camera RGB, with its colour tags,
+ /// its as-shot white-balance multipliers and its orientation.
+ fn raw_frame(
+ mut raw: RawImage,
+ bytes: &[u8],
+ metadata: Metadata,
+ exposure: Option<f64>,
+ max_edge: Option<usize>,
+ orient: bool,
+ colour: &RawColour,
+ ) -> Result<Frame> {
- // geometric lens corrections stay with the develop settings ("profile corrections")
++ // Lens corrections stay with the develop settings ("profile corrections"): frames are merged uncorrected, and
++ // the output DNG carries the reference frame's corrections, re-expressed for the default crop `develop` keeps.
++ // The DNG 1.6 skip rule is applied here, so no `WarpRectilinear2` is left optional.
++ let (aw, ah) = (raw.active_area.width, raw.active_area.height);
++ let crop = raw.develop_crop(aw, ah);
++ let lens = lightcraft_raw::opcodes::applied_ops(&raw.opcodes.list3)
++ .filter(|op| op.is_lens_correction())
++ .filter_map(|op| op.cropped(aw, ah, crop))
++ .map(|op| match op {
++ Opcode::WarpRectilinear2 { planes, center, reciprocal, .. } => Opcode::WarpRectilinear2 { planes, center, reciprocal, optional: false },
++ op => op,
++ })
++ .collect();
+ raw.opcodes.list3.retain(|op| !op.is_lens_correction());
+ if let Some(color) = colour(&mut raw, bytes) {
+ raw.color = color;
+ }
+ let small = max_edge.is_some_and(|m| m <= 1200);
+ let method = if small { lightcraft_raw::Method::Bilinear } else { lightcraft_raw::Method::Ahd };
+ let mut image = raw.develop(method).map_err(|e| MergeError::Decode(e.to_string()))?;
+ for p in image.data.iter_mut() {
+ *p = p.map(|v| v.max(0.0));
+ }
+ let clip = detect_clip(&image);
+ if let Some(m) = max_edge
+ && image.width.max(image.height) > m
+ {
+ image = fit(&image, m, m, Filter::Box);
+ }
+ let mut f = Frame {
+ image,
+ clip,
+ exposure,
+ raw: true,
+ color: FrameColor::Camera(Box::new(raw.color.clone())),
+ orientation: raw.orientation,
+ metadata: if raw.metadata == Metadata::default() { metadata } else { raw.metadata.clone() },
+ baseline_exposure: raw.color.baseline_exposure,
++ lens,
+ wb_multipliers: raw.wb_multipliers,
+ };
+ if f.exposure.is_none() {
+ f.exposure = exif_exposure(&f.metadata);
+ }
+ if orient {
+ f.orient();
+ }
+ Ok(f)
+ }
+
#[cfg(test)]
mod tests {
use super::*;
diff --cc crates/merge/src/hdr.rs
index 95750ba0b,23f960187..af1d6d25b
--- a/crates/merge/src/hdr.rs
+++ b/crates/merge/src/hdr.rs
@@@ -85,14 -83,11 +85,17 @@@ pub struct HdrResult
pub orientation: lightcraft_geom::Orientation,
pub metadata: lightcraft_meta::Metadata,
pub baseline_exposure: f64,
+ /// The reference frame's lens corrections, for `radiance` ([`Frame::lens`]).
+ pub lens: Vec<lightcraft_raw::Opcode>,
+ /// The inputs' as-shot white-balance multipliers they agree on ([`crate::frame::consensus_multipliers`]), already in
+ /// `color`; kept so merged brackets stitched into a panorama can vote as frames of their own.
+ pub wb_multipliers: Option<[f32; 3]>,
}
+/// Long edge (at most) of the frames the deghost test compares: small moving things (a star at 200 mm) still span a few
+/// pixels there.
+const DEGHOST_EDGE: usize = 2048;
+
#[inline]
fn smoothstep(a: f32, b: f32, x: f32) -> f32 {
let t = ((x - a) / (b - a)).clamp(0.0, 1.0);
@@@ -285,7 -286,7 +294,8 @@@ pub fn merge_hdr(mut frames: Vec<Frame>
orientation: rf.orientation,
metadata: rf.metadata.clone(),
baseline_exposure: rf.baseline_exposure,
+ lens: rf.lens.clone(),
+ wb_multipliers,
})
}
diff --cc crates/merge/src/output.rs
index f8b7e7173,2d966c2aa..b1f439685
--- a/crates/merge/src/output.rs
+++ b/crates/merge/src/output.rs
@@@ -4,12 -4,11 +4,13 @@@
//! - Pixel values are scaled so the brightest pixel sits just below 1.0 (the white level); the
//! scale is carried in `BaselineExposure`, so a default rendering looks like the reference frame.
//! - Raw sources: the reference frame's DNG colour tags (`ColorMatrix*`, `ForwardMatrix*`,
- //! `CameraCalibration*`, `AsShotNeutral`, illuminants) are carried over unchanged — the data is
- //! still camera RGB.
+ //! `CameraCalibration*`, `AsShotNeutral`, illuminants) are carried over — the data is still camera
+ //! RGB. A raw with its white balance only in vendor multipliers (CR2, NEF…) has none of its own: the
+ //! result's `AsShotNeutral` comes from the frames' multipliers ([`FrameColor::set_as_shot_multipliers`]).
//! - Other sources: the "camera" is the file's linear RGB space; `ColorMatrix1` = XYZ(D65) → RGB,
//! `ForwardMatrix1` = RGB → XYZ(D50), `AsShotNeutral` = (1, 1, 1).
+//! - Lens corrections (an HDR merge's: the reference frame's, [`crate::Frame::lens`]) go in `OpcodeList3`, where the
+//! develop settings' profile corrections find them as they do in the sources.
use lightcraft_color::{D50, D65, Mat3, bradford};
use lightcraft_geom::Orientation;
diff --cc crates/merge/src/pano/mod.rs
index 73d19f515,076c0b85e..4211f6503
--- a/crates/merge/src/pano/mod.rs
+++ b/crates/merge/src/pano/mod.rs
@@@ -387,10 -378,9 +392,10 @@@ pub fn stitch(mut frames: Vec<Frame>, o
rms_before,
rms,
fov,
+ native_megapixels: (bx1 - bx0) * (by1 - by0) / 1e6,
focal: f_out,
origin: (ox, oy),
- color: r.color.clone(),
+ color,
metadata: r.metadata.clone(),
raw: r.raw,
baseline_exposure: r.baseline_exposure,
diff --cc crates/merge/tests/white_balance.rs
index 000000000,84474a494..48acff6af
mode 000000,100644..100644
--- a/crates/merge/tests/white_balance.rs
+++ b/crates/merge/tests/white_balance.rs
@@@ -1,0 -1,246 +1,248 @@@
+ //! A panorama or an HDR merge of raw files keeps their as-shot white balance (issue #1144).
+ //!
+ //! CR2, NEF and the like carry their white balance as vendor multipliers, not as DNG tags. The merged DNG has
+ //! to say it as `AsShotNeutral`, or a viewer has no white to start from and shows a colour cast.
+
+ use lightcraft_color::{D50, Xy};
+ use lightcraft_geom::Orientation;
+ use lightcraft_merge::frame::{Frame, FrameColor, consensus_multipliers, detect_clip};
+ use lightcraft_merge::hdr::{HdrOptions, HdrResult, merge_hdr};
+ use lightcraft_merge::output::color_data;
+ use lightcraft_merge::pano::{PanoOptions, PanoResult, Projection, stitch};
+ use lightcraft_merge::{DngSamples, no_progress, write_linear_dng};
+ use lightcraft_meta::Metadata;
+ use lightcraft_raster::Rgb32f;
+ use lightcraft_raw::ColorData;
+
+ type Multipliers = Option<[f32; 3]>;
+
+ /// A camera that sees linear sRGB, with the colour matrices a DNG gives but no white balance of its own, as a raw
+ /// file whose white balance is only in the vendor multipliers would be after the app has worked its colour out.
+ fn camera_without_white_balance() -> ColorData {
+ let srgb = FrameColor::Linear {
+ to_xyz_d50: lightcraft_color::bradford(lightcraft_color::D65, lightcraft_color::D50).mul(&lightcraft_color::SRGB.to_xyz()),
+ };
+ ColorData { as_shot_neutral: None, ..color_data(&srgb) }
+ }
+
+ fn raw_frame(image: Rgb32f, color: &ColorData, wb_multipliers: Multipliers) -> Frame {
+ let clip = detect_clip(&image);
+ Frame {
+ image,
+ clip,
+ exposure: None,
+ raw: true,
+ color: FrameColor::Camera(Box::new(color.clone())),
+ orientation: Orientation::Normal,
+ metadata: Metadata::default(),
+ baseline_exposure: 0.0,
++ lens: Vec::new(),
+ wb_multipliers,
+ }
+ }
+
+ /// Overlapping views of one scene, one frame per entry of `wb`, in order.
+ fn shoot(color: &ColorData, wb: &[Multipliers]) -> Vec<Frame> {
+ let n = wb.len();
+ let yaws: Vec<f64> = (0..n).map(|i| (i as f64 - (n as f64 - 1.0) / 2.0) * 25.0).collect();
+ let views = lightcraft_merge::synth::pano_views(400, 300, 350.0, &yaws).unwrap();
+ views.into_iter().zip(wb).map(|(image, m)| raw_frame(image, color, *m)).collect()
+ }
+
+ fn pano(frames: Vec<Frame>) -> PanoResult {
+ stitch(frames, &PanoOptions { projection: Projection::Cylindrical, ..Default::default() }, &no_progress).unwrap()
+ }
+
+ fn neutral_of(res: &PanoResult) -> Option<[f64; 3]> {
+ match &res.color {
+ FrameColor::Camera(c) => c.as_shot_neutral,
+ FrameColor::Linear { .. } => None,
+ }
+ }
+
+ fn reciprocal(m: [f64; 3]) -> [f64; 3] {
+ m.map(|v| 1.0 / v)
+ }
+
+ fn assert_close(got: [f64; 3], want: [f64; 3], tolerance: f64) {
+ assert!(got.iter().zip(want).all(|(a, b)| (a - b).abs() <= tolerance), "{got:?} vs {want:?}");
+ }
+
+ /// The panorama as a DNG and read back with the repo's own raw reader.
+ fn dng_of(res: &PanoResult) -> lightcraft_raw::RawImage {
- let bytes = write_linear_dng(&res.image, &res.color, Orientation::Normal, &res.metadata, res.baseline_exposure, DngSamples::U16).unwrap();
++ let bytes = write_linear_dng(&res.image, &res.color, Orientation::Normal, &res.metadata, res.baseline_exposure, DngSamples::U16, &[]).unwrap();
+ lightcraft_raw::decode(&bytes).unwrap()
+ }
+
+ const DAYLIGHT: [f32; 3] = [2.0, 1.0, 1.6];
+
+ #[test]
+ fn a_panorama_of_an_odd_number_of_raw_frames_has_their_median_white_balance() {
+ // three frames the camera balanced slightly differently: the middle R/G and the middle B/G, from different frames
+ let wb = [Some([2.1, 1.0, 1.55]), Some([1.9, 1.0, 1.7]), Some(DAYLIGHT)];
+ let res = pano(shoot(&camera_without_white_balance(), &wb));
+ assert_eq!(res.used, [0, 1, 2]);
+ assert_close(neutral_of(&res).expect("an as-shot neutral"), reciprocal([2.0, 1.0, 1.6f32.into()]), 1e-6);
+ let FrameColor::Camera(c) = &res.color else { panic!("camera colour") };
+ assert_eq!(c.as_shot_white_xy, None);
+ }
+
+ #[test]
+ fn a_panorama_of_an_even_number_of_frames_takes_the_mean_of_the_middle_two() {
+ let wb = [Some([1.8, 1.0, 1.9]), Some([2.0, 1.0, 1.6]), Some([2.2, 1.0, 1.5]), Some([2.4, 1.0, 1.4])];
+ let res = pano(shoot(&camera_without_white_balance(), &wb));
+ assert_eq!(res.used.len(), 4);
+ let (r, b) = ((f64::from(2.0f32) + f64::from(2.2f32)) / 2.0, (f64::from(1.6f32) + f64::from(1.5f32)) / 2.0);
+ assert_close(neutral_of(&res).expect("an as-shot neutral"), reciprocal([r, 1.0, b]), 1e-6);
+ // two frames: the mean of both
+ let res = pano(shoot(&camera_without_white_balance(), &[Some([2.0, 1.0, 1.0]), Some([3.0, 1.0, 2.0])]));
+ assert_close(neutral_of(&res).expect("an as-shot neutral"), reciprocal([2.5, 1.0, 1.5]), 1e-6);
+ }
+
+ #[test]
+ fn frames_without_multipliers_do_not_vote() {
+ // one frame of three has none (a DNG, say): the other two decide
+ let wb = [Some([2.0, 1.0, 1.6]), None, Some([2.2, 1.0, 1.4])];
+ let res = pano(shoot(&camera_without_white_balance(), &wb));
+ assert_eq!(res.used.len(), 3);
+ assert_close(neutral_of(&res).expect("an as-shot neutral"), reciprocal([2.1, 1.0, 1.5]), 1e-6);
+ // a first frame without them doesn't hide the others'
+ let wb = [None, Some(DAYLIGHT), Some(DAYLIGHT)];
+ let res = pano(shoot(&camera_without_white_balance(), &wb));
+ assert_close(neutral_of(&res).expect("an as-shot neutral"), reciprocal([2.0, 1.0, 1.6f32.into()]), 1e-6);
+ // unusable values don't count either
+ let wb = [Some([f32::NAN, 1.0, 1.0]), Some(DAYLIGHT), Some([0.0, 1.0, 1.4]), Some([2.0, f32::INFINITY, 1.6]), Some(DAYLIGHT)];
+ let res = pano(shoot(&camera_without_white_balance(), &wb));
+ assert_close(neutral_of(&res).expect("an as-shot neutral"), reciprocal([2.0, 1.0, 1.6f32.into()]), 1e-6);
+ }
+
+ #[test]
+ fn a_frame_outside_the_panorama_does_not_vote() {
+ let color = camera_without_white_balance();
+ let mut frames = shoot(&color, &[Some(DAYLIGHT), Some(DAYLIGHT), Some(DAYLIGHT)]);
+ // four photos of other scenes, balanced very differently: counted, they would be the majority
+ let others = lightcraft_scenes::demo_library().into_iter().filter(|s| s.kind != lightcraft_scenes::Kind::Canyon).take(4);
+ frames.extend(others.map(|scene| raw_frame(scene.render(400, 300), &color, Some([4.0, 1.0, 0.8]))));
+ assert_eq!(frames.len(), 7);
+ let res = pano(frames);
+ assert_eq!(res.used, [0, 1, 2], "the others don't connect");
+ assert_close(neutral_of(&res).expect("an as-shot neutral"), reciprocal([2.0, 1.0, 1.6f32.into()]), 1e-6);
+ }
+
+ #[test]
+ fn without_any_multipliers_the_colour_is_the_first_frames_as_before() {
+ for source in [
+ camera_without_white_balance(),
+ ColorData::default(),
+ ColorData { as_shot_neutral: Some([0.5, 1.0, 0.62]), ..camera_without_white_balance() },
+ ] {
+ let frames = shoot(&source, &[None, None, None]);
+ let first = frames[0].color.clone();
+ let res = pano(frames);
+ assert_eq!(res.color, first);
+ assert_eq!(neutral_of(&res), source.as_shot_neutral);
+ }
+ // a DNG's own AsShotWhiteXY survives when no frame brings multipliers
+ let xy = ColorData { as_shot_white_xy: Some(D50), ..camera_without_white_balance() };
+ assert_eq!(pano(shoot(&xy, &[None, None, None])).color, FrameColor::Camera(Box::new(xy)));
+ }
+
+ #[test]
+ fn the_consensus_replaces_a_neutral_or_white_point_the_first_frame_had() {
+ // a neutral the app worked out for the first frame, and a white point of the source: both give way
+ let had = ColorData { as_shot_neutral: Some([0.9, 1.0, 0.8]), as_shot_white_xy: Some(Xy::new(0.31, 0.33)), ..camera_without_white_balance() };
+ let res = pano(shoot(&had, &[Some(DAYLIGHT), Some(DAYLIGHT), Some(DAYLIGHT)]));
+ assert_close(neutral_of(&res).expect("an as-shot neutral"), reciprocal([2.0, 1.0, 1.6f32.into()]), 1e-6);
+ let FrameColor::Camera(c) = &res.color else { panic!("camera colour") };
+ assert_eq!(c.as_shot_white_xy, None);
+ // everything else of the first frame's colour is as it was
+ assert_eq!(**c, ColorData { as_shot_neutral: c.as_shot_neutral, as_shot_white_xy: None, ..had });
+ }
+
+ #[test]
+ fn the_dng_says_the_median_white_balance_as_as_shot_neutral() {
+ let source = camera_without_white_balance();
+ let wb = [Some([2.1, 1.0, 1.55]), Some([1.9, 1.0, 1.7]), Some(DAYLIGHT)];
+ let frames = shoot(&source, &wb);
+ let median = consensus_multipliers(&frames).unwrap();
+ let res = pano(frames);
+ let raw = dng_of(&res);
+ // AsShotNeutral is the reciprocal of the median multipliers, to the precision of a TIFF rational
+ let got = raw.color.as_shot_neutral.expect("AsShotNeutral in the DNG");
+ assert_close(got, reciprocal(median.map(f64::from)), 2e-6);
+ assert_close(got, [0.5, 1.0, 0.625], 2e-6);
+ assert_eq!(raw.color.as_shot_white_xy, None, "the DNG spec has the two tags exclude each other");
+ // what a viewer starts from: the white and the camera transform the source's multipliers give
+ let want = lightcraft_raw::color::as_shot_white_of(&source, Some(median));
+ let xy = lightcraft_raw::color::as_shot_white_xy(&raw);
+ assert!((xy.x - want.x).abs() < 1e-4 && (xy.y - want.y).abs() < 1e-4, "{xy:?} vs {want:?}");
+ let (got, want) = (lightcraft_raw::color::camera_transform(&raw, xy), lightcraft_raw::color::camera_transform_of(&source, want));
+ assert!(got.wb.iter().zip(want.wb).all(|(a, b)| (a - b).abs() < 1e-3), "{:?} vs {:?}", got.wb, want.wb);
+ // the colour model and the picture are the source's, and the same without the colour matrices
+ assert_eq!(raw.color.forward_matrix[0].is_some(), source.forward_matrix[0].is_some());
+ assert_eq!((raw.width, raw.height, raw.cpp), (res.image.width, res.image.height, 3));
+ let bare = dng_of(&pano(shoot(&ColorData::default(), &wb)));
+ assert_close(bare.color.as_shot_neutral.expect("AsShotNeutral without colour matrices"), [0.5, 1.0, 0.625], 2e-6);
+ }
+
+ #[test]
+ fn without_multipliers_the_dng_has_no_as_shot_neutral_as_before() {
+ let res = pano(shoot(&ColorData::default(), &[None, None, None]));
+ let raw = dng_of(&res);
+ assert_eq!((raw.color.as_shot_neutral, raw.color.as_shot_white_xy), (None, None));
+ }
+
+ /// Exposures `evs` (EV, relative to the view's) of one view, one frame each, with `wb` as their multipliers.
+ fn bracket(color: &ColorData, evs: &[f64], wb: &[Multipliers]) -> Vec<Frame> {
+ let view = lightcraft_merge::synth::pano_views(320, 240, 280.0, &[0.0]).unwrap().remove(0);
+ evs.iter()
+ .zip(wb)
+ .map(|(ev, m)| {
+ let k = 2f32.powf(*ev as f32);
+ let mut frame = raw_frame(view.map(|p| p.map(|v| (v * k).min(1.0))), color, *m);
+ frame.exposure = Some(*ev);
+ frame
+ })
+ .collect()
+ }
+
+ fn hdr(frames: Vec<Frame>) -> HdrResult {
+ merge_hdr(frames, &HdrOptions::default(), &no_progress).unwrap()
+ }
+
+ fn hdr_neutral(res: &HdrResult) -> Option<[f64; 3]> {
+ match &res.color {
+ FrameColor::Camera(c) => c.as_shot_neutral,
+ FrameColor::Linear { .. } => None,
+ }
+ }
+
+ #[test]
+ fn an_hdr_merge_of_raw_frames_has_their_median_white_balance() {
+ let source = camera_without_white_balance();
+ let wb = [Some([2.1, 1.0, 1.55]), Some(DAYLIGHT), Some([1.9, 1.0, 1.7])];
+ let res = hdr(bracket(&source, &[-2.0, 0.0, 2.0], &wb));
+ assert_eq!(res.wb_multipliers, Some(DAYLIGHT));
+ assert_close(hdr_neutral(&res).expect("an as-shot neutral"), reciprocal([2.0, 1.0, 1.6f32.into()]), 1e-6);
+ // the DNG says it, to the precision of a TIFF rational
- let bytes = write_linear_dng(&res.radiance, &res.color, res.orientation, &res.metadata, res.baseline_exposure, DngSamples::Half).unwrap();
++ let bytes =
++ write_linear_dng(&res.radiance, &res.color, res.orientation, &res.metadata, res.baseline_exposure, DngSamples::Half, &res.lens).unwrap();
+ let raw = lightcraft_raw::decode(&bytes).unwrap();
+ assert_close(raw.color.as_shot_neutral.expect("AsShotNeutral in the DNG"), [0.5, 1.0, 0.625], 2e-6);
+ // an even count takes the mean of the middle two; frames without multipliers do not vote
+ let res = hdr(bracket(&source, &[-1.0, 1.0], &[Some([2.0, 1.0, 1.0]), Some([3.0, 1.0, 2.0])]));
+ assert_close(hdr_neutral(&res).expect("an as-shot neutral"), reciprocal([2.5, 1.0, 1.5]), 1e-6);
+ let res = hdr(bracket(&source, &[-2.0, 0.0, 2.0], &[None, Some([2.0, 1.0, 1.6]), Some([f32::NAN, 1.0, 1.0])]));
+ assert_eq!(res.wb_multipliers, Some([2.0, 1.0, 1.6]));
+ assert_close(hdr_neutral(&res).expect("an as-shot neutral"), reciprocal([2.0, 1.0, 1.6f32.into()]), 1e-6);
+ }
+
+ #[test]
+ fn an_hdr_merge_without_multipliers_keeps_the_reference_colour_as_before() {
+ let source = ColorData { as_shot_neutral: Some([0.5, 1.0, 0.62]), ..camera_without_white_balance() };
+ let frames = bracket(&source, &[-2.0, 0.0, 2.0], &[None, None, None]);
+ let reference = frames[1].color.clone();
+ let res = hdr(frames);
+ assert_eq!((res.reference, res.wb_multipliers), (1, None));
+ assert_eq!(res.color, reference);
+ }
diff --cc docs/parity-checklist.md
index ee05a4f55,49c10e79a..7fcf5ac0c
--- a/docs/parity-checklist.md
+++ b/docs/parity-checklist.md
@@@ -1,8 -1,6 +1,8 @@@
# Lightroom parity checklist
- > **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-14 · **Change:** minor (catalog import: persistent result, offline Local promotion and library-switch dismissal; integration batch 35: KEYC-SELECTONLYACTIVE, Select Only Active Photo ⌘⇧D; LR-BEHAV-AUTOSAVE, damaged snapshots repaired on open; LR-EDIT-OPTICS-PROFILE, Nikon Z 6II / Z 8 / Z f in-file distortion; LRC-LIB-CATALOG-IMPORT, WAL-only catalogs open; LR-EXP-DIM, enlargements stop at 512 MP; LR-IMP-CAMERA-COVERAGE, Canon EOS RP CR3 verified; model folder retry) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6
-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-13 · **Change:** minor (LR-MERGE-PANO, LR-MERGE-HDR: a panorama and an HDR merge of raws take their as-shot white balance from the median of their frames (#1144); LR-MERGE-HDR: merges of raws without colour matrices keep their colour (#965); rapid slider entry; LR-PROF-CAMERACOLOR: tone curve from black-and-white camera JPEGs; LR-VIEW-ZOOM, LR-VIEW-COMPARE: Compare and Reference zoom windows; LR-IMP-FORMATS, LR-IMP-CAMERA-COVERAGE: EOS R5 Mark II CR3 decodes; renamed from `parity.md`; Top gaps moved to gaps.md, shortcut notes to ui-parity.md; filesystem history retry/Undo/Redo evidence; renamed from `parity.md`; Top gaps moved to gaps.md, shortcut notes to ui-parity.md) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6
++> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-14 · **Change:** minor (LR-MERGE-PANO, LR-MERGE-HDR: as-shot white balance from the median of the frames (#1144); catalog import: persistent result, offline Local promotion and library-switch dismissal; integration batch 35: KEYC-SELECTONLYACTIVE, Select Only Active Photo ⌘⇧D; LR-BEHAV-AUTOSAVE, damaged snapshots repaired on open; LR-EDIT-OPTICS-PROFILE, Nikon Z 6II / Z 8 / Z f in-file distortion; LRC-LIB-CATALOG-IMPORT, WAL-only catalogs open; LR-EXP-DIM, enlargements stop at 512 MP; LR-IMP-CAMERA-COVERAGE, Canon EOS RP CR3 verified; model folder retry) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-14 · **Change:** minor (integration batch 35: KEYC-SELECTONLYACTIVE, Select Only Active Photo ⌘⇧D; LR-BEHAV-AUTOSAVE, damaged snapshots repaired on open; LR-EDIT-OPTICS-PROFILE, Nikon Z 6II / Z 8 / Z f in-file distortion; LRC-LIB-CATALOG-IMPORT, WAL-only catalogs open; LR-EXP-DIM, enlargements stop at 512 MP; LR-IMP-CAMERA-COVERAGE, Canon EOS RP CR3 verified; model folder retry; LR-IMP-FORMATS: preview-only raws rechecked after an update, #662) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-12 · **Change:** minor (LR-VIEW-ZOOM: full-size slider-drag drafts on the GPU, timed with their frame, issue #330; rapid slider entry; LR-PROF-CAMERACOLOR: tone curve from black-and-white camera JPEGs; LR-VIEW-ZOOM, LR-VIEW-COMPARE: Compare and Reference zoom windows; LR-IMP-FORMATS, LR-IMP-CAMERA-COVERAGE: EOS R5 Mark II CR3 decodes; renamed from `parity.md`; Top gaps moved to gaps.md, shortcut notes to ui-parity.md; filesystem history retry/Undo/Redo evidence; renamed from `parity.md`; Top gaps moved to gaps.md, shortcut notes to ui-parity.md) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6
The measured, row-by-row checklist: one row per Lightroom feature, menu item and shortcut, what we
have and what is missing. It answers *does the feature exist?* (feature breadth). Whether it is good
@@@ -353,10 -347,10 +353,10 @@@ differences and missing bindings are i
| Id | Feature | Tier | Status | Evidence | Missing / notes |
|---|---|---|---|---|---|
- | LR-MERGE-HDR | HDR merge | P2 | 🟡 | `cmd:merge.hdr`, `cmd:dialog.mergeHdr`, `crates/merge/src/frame.rs` (`Frame::lens`), `crates/merge/src/hdr.rs` | auto align, deghost None–High + overlay, auto settings, float DNG, Create Stack; the DNG keeps the reference frame's embedded lens corrections (tested by `hdr_merge_keeps_the_reference_frames_lens_corrections`); raws without colour matrices of their own (CR2, NEF, ARW…) keep the colour they open with, written as DNG tags (`starting_colour_tags`; the look's chroma curve has no tag; panoramas too), issue #965. Tested on real Sony A7R VI brackets (67 MP, 2026-10-14): frames agree with the merged radiance within ~1 % in all channels, exposure steps match EXIF within 0.03 EV. A clipped highlight of the reference that moved in other frames (a star at 200 mm) stays instead of becoming a black hole, and deghost (≤ 2048 px maps) catches a brighter frame's ghost in a dark sky (`a_clipped_star_of_the_reference_is_not_erased_by_frames_where_it_moved`, `deghost_removes_a_bright_frames_ghost_in_a_dark_sky`). 🟡 because: AI Denoise doesn't run on merged DNGs (Bayer only; Lightroom's does), JPEG brackets are treated as linear (no camera response curve), and every frame is held as 32-bit float (~0.86 GB per 67 MP frame, so 7 frames need ~7 GB); gap 29 |
- | LR-MERGE-PANO | Panorama | P2 | ✅ | `cmd:merge.panorama`, `cmd:dialog.mergePanorama` | spherical/cylindrical/perspective + auto, boundary warp, auto crop, fill edges (diffusion), DNG; no lens model / 360° wrap |
-| LR-MERGE-HDR | HDR merge | P2 | ✅ | `cmd:merge.hdr`, `cmd:dialog.mergeHdr` | auto align, deghost None–High + overlay, auto settings, float DNG, Create Stack; JPEG brackets treated as linear; raws without colour matrices of their own (CR2, NEF, ARW…) keep the colour they open with, written as DNG tags (`starting_colour_tags`; the look's chroma curve has no tag; panoramas too), issue #965; the DNG's `AsShotNeutral` is the median of the inputs' vendor white-balance multipliers, issue #1144 |
++| LR-MERGE-HDR | HDR merge | P2 | 🟡 | `cmd:merge.hdr`, `cmd:dialog.mergeHdr`, `crates/merge/src/frame.rs` (`Frame::lens`), `crates/merge/src/hdr.rs` | auto align, deghost None–High + overlay, auto settings, float DNG, Create Stack; the DNG keeps the reference frame's embedded lens corrections (tested by `hdr_merge_keeps_the_reference_frames_lens_corrections`); raws without colour matrices of their own (CR2, NEF, ARW…) keep the colour they open with, written as DNG tags (`starting_colour_tags`; the look's chroma curve has no tag; panoramas too), issue #965; the DNG's `AsShotNeutral` is the median of the inputs' vendor white-balance multipliers, issue #1144. Tested on real Sony A7R VI brackets (67 MP, 2026-10-14): frames agree with the merged radiance within ~1 % in all channels, exposure steps match EXIF within 0.03 EV. A clipped highlight of the reference that moved in other frames (a star at 200 mm) stays instead of becoming a black hole, and deghost (≤ 2048 px maps) catches a brighter frame's ghost in a dark sky (`a_clipped_star_of_the_reference_is_not_erased_by_frames_where_it_moved`, `deghost_removes_a_bright_frames_ghost_in_a_dark_sky`). 🟡 because: AI Denoise doesn't run on merged DNGs (Bayer only; Lightroom's does), JPEG brackets are treated as linear (no camera response curve), and every frame is held as 32-bit float (~0.86 GB per 67 MP frame, so 7 frames need ~7 GB); gap 29 |
+ | LR-MERGE-PANO | Panorama | P2 | ✅ | `cmd:merge.panorama`, `cmd:dialog.mergePanorama` | spherical/cylindrical/perspective + auto, boundary warp, auto crop, fill edges (diffusion), DNG whose `AsShotNeutral` is the median of its frames' as-shot white balance (vendor multipliers for CR2, NEF, ARW…), issue #1144; no lens model / 360° wrap |
| LR-MERGE-HDRPANO | HDR panorama | P2 | ✅ | `cmd:merge.hdrPanorama`, `cmd:dialog.mergeHdrPanorama` | brackets grouped by EXIF |
-| LR-MERGE-HEADLESS | Merge with last settings | P2 | ✅ | `cmd:merge.hdrLast`, `cmd:merge.panoramaLast`, `cmd:merge.hdrPanoramaLast` | no dialog; the options of the last merge of that kind (defaults the first time) |
+| LR-MERGE-HEADLESS | Merge with last settings | P2 | ✅ | `cmd:merge.hdrLast`, `cmd:merge.panoramaLast`, `cmd:merge.hdrPanoramaLast`, `cmd:merge.hdrBatch`, `crates/catalog/src/stacks.rs` (`bracket_sets`) | no dialog; the options of the last merge of that kind (defaults the first time). HDR for Each Bracket Set merges a batch like Lightroom's merge of stacks: one HDR per stack among the photos, then per bracket (photos taken less than a second apart, after the shutter time, at exposures ≥ ½ EV apart; bursts at one exposure are skipped), one after the other in the activity stack (cancelling one stops the rest; a failed set doesn't); CLI `merge hdr-batch FILES…` |
## P. Enhance (ENH)
@@@ -797,26 -789,8 +797,28 @@@ Latin stays upright. Advanced Japanese
| Date | Change | Summary |
|---|---|---|
+ | 2026-10-13 | minor | LR-MERGE-PANO: a panorama's DNG takes its `AsShotNeutral` from the median of its frames' vendor white-balance multipliers (CR2, NEF, ARW…) instead of the first frame's tags, and frames now carry the multipliers (issue #1144); status unchanged (✅) |
-| 2026-10-13 | minor | LR-MERGE-HDR: an HDR merge's DNG takes its `AsShotNeutral` from the median of its inputs' vendor white-balance multipliers instead of the reference frame's tags (issue #1144); status unchanged (✅) |
++| 2026-10-13 | minor | LR-MERGE-HDR: an HDR merge's DNG takes its `AsShotNeutral` from the median of its inputs' vendor white-balance multipliers instead of the reference frame's tags (issue #1144); status unchanged (🟡) |
+| 2026-10-14 | minor | LR-IMP-CAMERA-COVERAGE: 17 uncompressed Olympus and Samsung Adobe models verified on one CC0 file each; status unchanged (🟡) |
+| 2026-10-13 | minor | LR-EDIT-SECTION-SOLO: Solo Mode for Edit sections (Window ▸ Edit Sections, section-header menu, ⌥-click); KEYC-PANELS notes it |
+| 2026-10-14 | minor | LR-MERGE-HDR ✅ → 🟡: tested on real 67 MP Sony brackets; moving clipped highlights (black-hole stars) and dark-sky ghosts fixed, merge memory cut ~25 %; AI Denoise on merged DNGs, JPEG response curves and per-frame memory remain (gap 29). LR-MERGE-HEADLESS, MENU-PHOTO-MERGE: HDR for Each Bracket Set (`merge.hdrBatch`) |
+| 2026-10-15 | patch | LR-VIEW-BEFOREAFTER: side by side and stacked panes share click-zoom animation for whole-frame images, window tiles and input; render requests keep the final target (#1821); status unchanged |
+| 2026-10-14 | patch | LR-META-XMP: automatic sidecar writes that fail (folder offline or read-only) wait and are written again once the files are reachable, with a notice (`cmd:library.retrySidecars`); status unchanged |
+| 2026-10-13 | minor | LR-BEHAV-WINDOW (new, 🟡): the desktop app's window opens at the size it was left at, zoomed / maximized if it was; full screen and the place on the desktop are not remembered |
+| 2026-10-14 | minor | LR-IMP-CAMERA-COVERAGE: Nikon D600, D610 and D5000 NEFs drop the filler and noise columns on the right (a band), and the D600 and D610 measure their white level inside the image (#1627); status unchanged (🟡) |
+| 2026-10-13 | patch | LR-VIEW-COMPARE, LRC-LIB-COMPARE: ⌘/Ctrl- and Shift-clicks on the filmstrip in Compare change the selection as in the grid; the two photos shown stay selected and the active photo is unchanged (#187); statuses unchanged |
+| 2026-10-13 | minor | KEYC-SELECTONLYACTIVE: Edit → Select Only Active Photo (⌘⇧D) lands as a new row; status 🟡 (headless-tested, native macOS menu path unverified) |
+| 2026-10-13 | patch | LRC-LIB-CATALOG-IMPORT: a catalog whose tables are all still in its `-wal` file (main file schema format 0) opens instead of failing as an unsupported schema format; status unchanged |
+| 2026-10-14 | patch | LR-REM-HEAL, LR-REM-CLONE: zero-feather edges preserve exact-radius pixels; zero-opacity regression covers all spot modes and image corners. Statuses and feature counts unchanged. |
+| 2026-10-13 | patch | LR-EXP-DIM: an enlarged export stops at 512 megapixels and is refused when it needs more memory than the computer has, instead of aborting the app; status unchanged |
+| 2026-10-13 | minor | LR-PROF-CAMERACOLOR: bundled ILCA-99M2 profile with its held-out measurement |
+| 2026-10-12 | minor | LR-MASK-EFFECTS (new, ✅): local adjustment (effect / brush) presets: Effect menu, New Effect Preset dialog, Manage window, groups and favorites; imports Lightroom Classic local `.lrtemplate`, Camera Raw local `.xmp`, `.lceffect` and `.zip`. LR-IMP-PROFILES and LR-MASK-SLIDERS notes updated |
+| 2026-10-14 | minor | LR-IMP-CAMERA-COVERAGE: 21 Sony and Leica Adobe models verified on one CC0 file each; status unchanged (🟡) |
+| 2026-10-13 | minor | KEY-HIDEPINS ⬜ → ✅: Tool Overlay (Auto / Always / Selected / Never, `view.toolOverlay`, ⇧H cycles; H stays Remove) for the Remove tool's spot pins and the mask pins (issue #224); LR-MASK-PINS loses its "no Auto mode" note, LR-REM-SPOT-EDIT notes the modes |
+| 2026-10-13 | minor | LR-EDIT-DETAIL-NR, LR-EDIT-DETAIL-CNR: noise-reduction radii in the original's pixels, so previews at any size and smaller exports look like the full-size render scaled down (issue #960); status unchanged |
+| 2026-10-13 | minor | KEYC-RATING: backtick cycles the flag (`photo.cycleFlag`), ⌘↑ / ⌘↓ raise / lower it (`photo.increaseFlag`, `photo.decreaseFlag`); status unchanged (🟡) |
+| 2026-10-13 | patch | LR-MASK-LUMRANGE / LR-MASK-COLORRANGE: range drags keep the grabbed endpoint; colour samples use the render's enabled sections and HDR/SDR settings; regression coverage, status unchanged |
+| 2026-10-13 | minor | LR-IMP-DEVICE: Settings → Import → Cameras and Cards can open the import review when a camera or card is connected; status unchanged (✅) |
| 2026-10-11 | minor | LR-MERGE-HDR: HDR and panorama merges of raws without colour matrices (CR2, NEF, ARW…) write the colour they open with as DNG tags (issue #965); status unchanged |
| 2026-10-12 | minor | LR-META-XMP: Read Metadata from File no longer auto-writes the sidecar it has just read, which added `lc:settings` and hid another app's later `crs:` edits (#934); status unchanged (✅) |
| 2026-10-12 | patch | LR-IMP-CAMERA-COVERAGE: CR2 white level from the active area, not the saturated masked rows above it (issue #1272); status unchanged (🟡) |