Repository navigation
LR-MERGE-HDR: merges of raws without colour matrices keep their colour (#965) - #1123
Conversation
storytold#965) Photo Merge decoded each raw itself and wrote the reference frame's own colour tags into the merged DNG. A CR2 (and NEF, ARW and the other raws whose colour is fitted from the camera JPEG) has none, so an HDR merge of CR2s rendered with no camera colour: green and about 16 L* dark. `lightcraft_merge::load_frame_with` takes the raw's colour tags from the caller, and the engine passes `starting_colour_tags`: the colour the raw opens with (`starting_colour`) as DNG tags. That is one forward matrix with a colour matrix and AsShotNeutral that agree with it at the as-shot white, the look's hue/sat table as ProfileHueSatMap and its tone curve as ProfileToneCurve. Raws with their own matrices (DNG) keep their tags. The look's chroma curve has no DNG tag and is left out. On two CC0 CR2s (EOS 550D, 40D) an HDR merge of three copies against the photo alone: mean CIE76 dE 26.15 -> 1.07 and 22.89 -> 0.47. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I tested 090553d against main 76b5377 through the CPU CLI. Files were the EOS 2000D CR2 linked in issue 853 and used by issue 965, saved as canon-2000d.CR2, and public CC0 Sony ILCE-7M2 sample 851, saved as pixls-851.ARW. Each test merged three copies, with distinct trailing markers to pass import deduplication. All source renders and embedded JPEG bytes matched within each set. With Auto Settings off, Canon HDR mean delta E76 against the individual source fell from 15.33 to 1.18. Its mean a* difference fell from -12.91 to 0.02, and b* difference from 5.11 to -0.67. The repeated-frame panorama fell from 15.33 to 1.19. After Auto WB on both source and merge, the HDR error fell from 5.41 to 1.86. Against the unchanged camera JPEG, as-shot HDR error fell from 14.31 to 4.02. Sony HDR mean delta E76 against its source fell from 22.48 to 1.22, and the panorama from 22.48 to 1.25. The Sony neutral patch fell from C* 20.73 to 2.17, compared with 1.12 in the source. A synthetic -2, 0 and +2 EV linear-DNG bracket derived from the same ARW produced identical HDR renders on both builds and mean delta E76 0.0078 against each exposure-normalized source. Individual raw renders were also unchanged between builds. Verdict: helps. I found no regression in these controls. This validates the public issue 965 reproducer, but the actual issue 1144 CR2s and issue 917 A6600 ARWs are not linked in their current threads, so I could not validate those panoramas. The approximately 1.2 residual error, omitted chroma curve, changed hue-table luminance behavior and negative-sample clamp remain. These measurements do not establish exact preservation of the Sony look through a real panorama. |
…ces keep their colour, storytold#965) # Conflicts: # crates/engine/src/tests_merge.rs # docs/parity-checklist.md
…torytold#1123 merge) [skip ci] Test-only: the installer built from eece99b is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015gRtdWF1E9358FfzhzYqCS
Same four sets as round 1, merged again in the app and with lightcraft-cli on the build with the fix (release a7iii-hdr-20261013-a1f3e59). - Fixed on all four sets: the HDR DNGs carry OpcodeList3 WarpRectilinear, open with the lens profile on, and the correction changes the render (mean 4.5-7.9 levels, 91-95 % of pixels). - Corrected reference vs corrected HDR now matches the control: 0.41 / 1.83, 0.60 / 2.45, 0.76 / 2.40 px (Sony), 0.15 / 0.62 px (drone), down from 6-13 px median / 20-34 px p95 in round 1. - The drone HDR with the correction on matches Lightroom's baked geometry (0.18 / 0.62 px). - With the correction off, renders are bit-identical to round 1. - Still open: white balance and colour tags of ARW-sourced HDRs (this build predates storytold#1123), magenta fringes, ghosts with Deghost None. Report and numbers only; no photos, DNGs or crops. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The three Sony sets merged again with the build that adds storytold#1123 (release a7iii-hdr-20261013-eece99b). - Rendered colour fixed: default render of the HDR vs its reference ARW CIEDE2000 median 0.41 / 0.82 / 0.50 (round-2 HDR: 7.4 / 11.4 / 7.8, yellow and darker). - The DNG now carries ColorMatrix1 (D65), ForwardMatrix1, AsShotNeutral, ProfileHueSatMap and ProfileToneCurve; the lens correction is still there. - But the declared As Shot white sits at Duv +0.038 (6125-7350 K): LightCraft shows 6113-7307 K / +115-117 where the ARWs read 3932-5268 K / +7-8, and the same Temp/Tint on HDR and ARW gives a green HDR (dE00 10.9-13.1). Report and numbers only; no photos, DNGs or crops. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…up to storytold#1123) dng_colour wrote ColorMatrix1 from the forward matrix, so the as-shot white it declared moved off the source's whenever the fitted look's matrix tints white. On real ARW brackets the HDRs opened at As Shot 6113–7307 K / +115 for the sources' 3932–5268 K / +7 (Duv +0.038), and any white-balance edit (same Temp/Tint, a preset, a copied white balance) rendered them green (CIEDE2000 11–13); the render at As Shot was right (0.4–0.8). ColorMatrix1 is now the source's own white-balance model at its as-shot white (xyz_to_camera; the generic one for a raw without matrices), so the DNG declares the source's as-shot white and white-balance edits give the source's multipliers. The forward matrix and the as-shot neutral are unchanged, so is the render at As Shot. Test with a look that tints white: as-shot white and multipliers at three other whites match the source (fails before: as shot (0.377, 0.355) for (0.36, 0.37)). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015gRtdWF1E9358FfzhzYqCS
|
Thanks for this, it fixes the colour of my ARW HDR merges. I tested it on real brackets and found one problem with the white balance the merged DNG declares. Test: three Sony ILCE-7M3 brackets (ARW, 0 / −2 / +2 EV), merged with a build of main + this PR, rendered with
Cause: Suggested fix: declare the source's own white-balance model at its as-shot white (the generic one for a raw with no matrices). The forward matrix and the neutral don't change, so the render at As Shot stays the same: - let camera_to_xyz = bradford(D50, t.white_xy).mul(&forward).mul(&Mat3::diag(1.0 / neutral[0], 1.0 / neutral[1], 1.0 / neutral[2]));
+ let color_matrix = lightcraft_raw::color::xyz_to_camera(tags, t.white_xy);
+ if !color_matrix.0.iter().flatten().all(|v| v.is_finite()) {
+ return None;
+ }
Some(ColorData {
illuminant: [21, 0],
- color_matrix: [Some(camera_to_xyz.inverse()?), None],
+ color_matrix: [Some(color_matrix), None],plus a test with a look that tints white (e.g. I have both in my fork, on top of this PR: alvarohn/lightcraft@eefb14c46 (branch Generated by Claude Code |
|
Landed on main in #1431. Thank you, @LloydNicholson! Generated by Claude Code |
|
Thanks for this, it fixes the colour of my ARW HDR merges. I tested it on real brackets and found one problem with the white balance the merged DNG declares. Test: three Sony ILCE-7M3 brackets (ARW, 0 / −2 / +2 EV), merged with a build of main + this PR, rendered with
Cause: Suggested fix: declare the white-balance model the app shows and edits the source's white balance with, as pub(crate) fn starting_colour_tags(raw: &mut RawImage, bytes: &[u8]) -> Option<ColorData> {
…
+ let model = wb_model(raw);
let (_, t, look) = starting_colour(raw, bytes);
- dng_colour(&raw.color, &t, look.as_ref())
+ dng_colour(&raw.color, &model, &t, look.as_ref())
}
+
+fn wb_model(raw: &RawImage) -> ColorData {
+ let mut c = ColorData { profile: Default::default(), ..raw.color.clone() };
+ if file_local_look(raw.format)
+ && let Some(camera) = raw.metadata.model.as_deref().and_then(|m| lightcraft_raw::spectral::find(raw.metadata.make.as_deref(), m))
+ {
+ camera.fill(&mut c);
+ }
+ c
+}and in - let camera_to_xyz = bradford(D50, t.white_xy).mul(&forward).mul(&Mat3::diag(1.0 / neutral[0], 1.0 / neutral[1], 1.0 / neutral[2]));
+ let (illuminant, color_matrix) = if lightcraft_raw::color::has_matrix(wb_model) {
+ (wb_model.illuminant, wb_model.color_matrix)
+ } else {
+ ([21, 0], [Some(lightcraft_raw::color::xyz_to_camera(wb_model, t.white_xy)), None])
+ };
Some(ColorData {
- illuminant: [21, 0],
- color_matrix: [Some(camera_to_xyz.inverse()?), None],
- forward_matrix: [Some(forward), None],
+ illuminant,
+ color_matrix,
+ forward_matrix: [Some(forward), color_matrix[1].map(|_| forward)],A test with the ILCE-7M3's matrices and a look that tints white (e.g. Verified on the same brackets with a build of this PR plus that change: the HDRs open at As Shot 4813 / 5268 / 3932 K, +8 / +8 / +7, the same as their ARWs (declared white at Duv +0.003). With the same Temp/Tint on HDR and ARW, CIEDE2000 is 0.8–1.7 in most cases (14–23 before). The largest changes (5268 → 3200 K, 3932 → 6500 K) leave about 5: the ARW rebalances its fitted look with Bradford, while the DNG rebalances in camera space. The default render and the colour at As Shot didn't change. I have both in my fork, on top of this PR: alvarohn/lightcraft@45e02b638 (branch Generated by Claude Code |
Conflicts: crates/engine/src/tests_merge.rs (storytold#1123's test landed where this branch's is; both kept), docs/parity-checklist.md (the LR-MERGE-HDR row: both notes) and docs/whats-new.md (both entries). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015gRtdWF1E9358FfzhzYqCS
Measured against the darkest frame on real ARW brackets, each frame is linear to 1 % up to the clip far from clipped pixels, but within 2 px of them the +2 EV frame's green reads 3–5 % low: demosaicing interpolates it from clipped photosites. That frame carries the most weight (k = 4) and those pixels were unclipped themselves, so they kept it, and bright windows took a magenta tinge. A frame's weight now goes by its brightest channel within 1 px (3 × 3; wider margins changed nothing more). On two real interior brackets (ILCE-7M3, 0 / −2 / +2 EV), bright pixels whose green against red and blue is over 10 % below the darkest frame's, in camera RGB: dining room 0.32 % → 0.08 %, kitchen 2.86 % → 0.28 %. Rendered at −3 EV with main's colour tags (storytold#1123), window pixels with G < 0.85·min(R, B) go 50 → 3 and 16 → 10 (the darkest frame alone: 2 and 205); most of the visible magenta those brackets showed before came from the missing colour tags. Test: a bracket whose +2 EV frame has 5 % less green next to its clipped pixels merges without the deficit (fails before: −1.96 %). Docs: docs/merge.md, the LR-MERGE-HDR row, docs/whats-new.md (also for the frame-order fix). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015gRtdWF1E9358FfzhzYqCS
…rrections Merge storytold/lightcraft main at b3d392b, including the HDR starting-colour tags fix (storytold#1123). Preserve the fork's guarded ILCE-6700/E 70-350mm correction, component diagnostics, and regression tests alongside upstream catalog and white-balance changes. Resolve Rust 1.95 boolean-expression lints and the upstream AllMasks overlay CI blocker: render the union once, with regression checks for both visible regions and hidden masks. Validation: cargo xtask ci passes all eight steps with craft-fonts enabled. Co-Authored-By: Codex <noreply@openai.com>
…s (follow-up to storytold#1123) storytold#1123 gives HDR and panorama merges of raws without colour matrices the colour they open with, but writes ColorMatrix1 from the forward matrix, so the as-shot white the DNG declares lands wherever the fitted look and the generic camera model take it. On real ILCE-7M3 brackets the HDRs opened at As Shot 6113–7307 K / +115 (Duv +0.038) where the ARWs show 3932–5268 K / +7, and any white-balance edit turned them green (CIEDE2000 11–13 against the ARW at the same Temp/Tint). The render at As Shot was right (0.4–0.8). The colour matrices now declare the white balance the source shows, decided by files::WbScaleOf (new dng_white): the camera's measured matrices when they give the source's scale (lightcraft_raw::spectral; the DNG then reads every white as the source does), else a matrix under which the as-shot neutral is the white the scale shows (Sony's presets' reading, 6500 K / 0 on the relative scale, the file's own white otherwise). Forward matrix and neutral are unchanged, so is the render at As Shot. Measured on the same brackets with this change on a fork build: As Shot 4813 / 5268 / 3932 K, +8 / +8 / +7 as the ARWs (declared white Duv +0.003); same Temp/Tint within CIEDE2000 0.8–1.7 of the ARW for most changes, about 5 for the largest (5268 → 3200 K, 3932 → 6500 K: the ARW adapts its look with Bradford, the DNG rebalances in camera space). Tests: a merged DNG shows its source's As Shot on all four scales (measured matrices, presets, relative, own); with a look that tints white the DNG declares the shown white, gives the measured model's multipliers at other whites and renders at As Shot as the source does. Both fail on main (ILCE-7M3 case: (7342, 115) for (5268, 8)). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015gRtdWF1E9358FfzhzYqCS
Measured against the darkest frame on real ARW brackets, each frame is linear to 1 % up to the clip far from clipped pixels, but within 2 px of them the +2 EV frame's green reads 3–5 % low: demosaicing interpolates it from clipped photosites. That frame carries the most weight (k = 4) and those pixels were unclipped themselves, so they kept it, and bright windows took a magenta tinge. A frame's weight now goes by its brightest channel within 1 px (3 × 3; wider margins changed nothing more). On two real interior brackets (ILCE-7M3, 0 / −2 / +2 EV), bright pixels whose green against red and blue is over 10 % below the darkest frame's, in camera RGB: dining room 0.32 % → 0.08 %, kitchen 2.86 % → 0.28 %. Rendered at −3 EV with main's colour tags (storytold#1123), window pixels with G < 0.85·min(R, B) go 50 → 3 and 16 → 10 (the darkest frame alone: 2 and 205); most of the visible magenta those brackets showed before came from the missing colour tags. Test: a bracket whose +2 EV frame has 5 % less green next to its clipped pixels merges without the deficit (fails before: −1.96 %). Docs: docs/merge.md, the LR-MERGE-HDR row, docs/whats-new.md (also for the frame-order fix). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015gRtdWF1E9358FfzhzYqCS
Fixes #965
An HDR merge of Canon CR2 files came out green and dark, while each CR2 on its own rendered fine. The merge decoded every raw itself and wrote the reference frame's own colour tags into the DNG. A CR2 has none: its colour is a look fitted to its embedded camera JPEG when it is opened. So the merged DNG had no camera colour and no white balance.
Now each source goes through
starting_colour, as when it is opened alone, and the result is written as DNG tags:AsShotNeutralthat agree with it at the as-shot whiteProfileHueSatMapProfileToneCurve, whichfiles::dng_tone_curvealready reads backRaws with colour matrices of their own (DNG) keep their tags, and nothing extra is computed for them. Without a fitted look, the tags give the colour the raw falls back to (spectral matrices or the neutral fallback). HDR, panorama and HDR panorama all load frames the same way, so panoramas get this too. #917 (A6600 panorama colour shift) may have the same cause; that has not been checked against an ARW panorama.
How:
lightcraft_merge::load_frame_withtakes a callback that can supply a raw's colour tags (load_frameis unchanged), because the merge crate sits below the engine.MergeJob::loadpassescamera_preview::starting_colour_tags.Not quite identical to the single photo:
HueSat). Writing it anyway was measured to be closer than leaving it out, on every measure below.Measured
Two CC0 CR2s from the corpus list in
xtask(raw.pixls.us, sha256 checked): an HDR merge of three copies of the photo, rendered withlightcraft-cli renderand compared with the photo rendered alone (200 px, CIE76 ΔE):On main the 550D merge's average hue was 139° (green) against 76° for the photo, and its L* was 16 lower. With this PR: hue 74°, L* equal.
The look fit now runs for each frame: a full-size HDR merge of three 18 MP 550D frames took 2.17 s instead of 1.70 s.
Tests
camera_preview::tests::dng_colour_renders_like_the_raws_starting_colour: the tags give the same white balance and the same colour and brightness as the look (within 1e-5), with the same table and tone curve. The tone curve is within 0.0031 of white after the reader's 32-knot resampling. Without a look, the tags give the camera transform's colour.tests_merge::a_merge_of_raws_without_colour_matrices_keeps_their_colour: an HDR merge of DNGs stripped of their colour matrices writes a DNG with matrices and the sources' white balance. It fails on main with a merged DNG that has no matrix.cargo xtask ci: all 8 steps pass on macOS (Apple silicon, Rust 1.99). Main itself doesn't passxtask cion macOS right now (main does not build or pass its tests on macOS (995d5ea4): app won't compile, 12 tests fail, one clippy lint #989), so the run had the diffs of Issue #989: the lock test finds true on the PATH #990, Issue #989: clippy 1.99, fill_box reads its buffer with as_chunks::<3>() (item 4) #997, Issue #989: odd_folders_never_fail_the_check skips non-UTF-8 names on APFS (item 3, one of eleven) #1003, Issue #989: the ten sidecar repair tests also pass on a case-insensitive volume (item 3, ten of eleven) #1007 and Issue #989: the Export dialog height test expects the macOS row (Add to Apple Photos, 876 pt) #1018 applied locally. Those diffs are not part of this PR.Not changed: frames are still clamped at 0 before merging (
v.max(0.0)inload_frame), the other point raised in the issue. That is a separate change.Docs:
docs/camera-preview-colour.md(Photo Merge), the LR-MERGE-HDR row indocs/parity-checklist.md,docs/whats-new.md.🤖 Generated with Claude Code