diff --git a/crates/engine/src/camera_preview/colour.rs b/crates/engine/src/camera_preview/colour.rs index 4ac732cf09..4468361868 100644 --- a/crates/engine/src/camera_preview/colour.rs +++ b/crates/engine/src/camera_preview/colour.rs @@ -144,12 +144,17 @@ pub(crate) fn starting_colour_tags(raw: &mut RawImage, bytes: &[u8]) -> Option, ) -> Option { - let correction = correction.filter(|_| raw.format != RawFormat::Cr3); + let correction = correction.filter(|_| raw.format != RawFormat::Cr3).map(|correction| lightcraft_develop::EmbeddedLens { + vignette: crate::files::embedded_lens(&raw.info()).and_then(|lens| lens.vignette), + ..*correction + }); // the white the source shows, decided before `starting_colour` may fill in measured matrices let scale = crate::files::WbScaleOf::new(raw.format, &raw.color, raw.wb_multipliers, &raw.metadata); let white = scale.dng_white(&raw.color, lightcraft_raw::color::as_shot_white_xy(raw)); @@ -158,7 +163,7 @@ pub(super) fn starting_colour_tags_with_correction( let lens = super::lens_geometry(&raw.opcodes.list3); let list3 = std::mem::take(&mut raw.opcodes.list3); raw.opcodes.list3 = list3.iter().filter(|op| !op.is_lens_correction()).cloned().collect(); - let (_, t, look) = starting_colour(raw, bytes, lens.as_ref(), correction); + let (_, t, look) = starting_colour(raw, bytes, lens.as_ref(), correction.as_ref()); raw.opcodes.list3 = list3; dng_colour(&raw.color, &white, &t, look.as_ref()) } diff --git a/crates/engine/src/camera_preview/tests.rs b/crates/engine/src/camera_preview/tests.rs index f6e310196c..92f5906905 100644 --- a/crates/engine/src/camera_preview/tests.rs +++ b/crates/engine/src/camera_preview/tests.rs @@ -1209,6 +1209,64 @@ fn configured_lens_geometry_reaches_pool_add_after_raw_decode() { assert_eq!(pool.fit(1), vec![Ok(expected)], "Pool::add must forward the database correction after decoding the actual bytes"); } +/// Exclude unsaved external shading while keeping the resolved DNG correspondence warp. +fn assert_external_dng_vignette_contract( + raw: &RawImage, + file: &[u8], + lens: &lightcraft_develop::EmbeddedLens, + white: &crate::files::DngWhite, + expected_tags: &ColorData, + converted: &RawImage, +) { + // An external database vignette is absent from a DNG of the original samples. + let mut vignetted = *lens; + vignetted.vignette = + Some(lightcraft_develop::EmbeddedVignette { k: [1.0, 0.0, 0.0, 0.0, 0.0], center: lightcraft_geom::Point::new(0.45, 0.55), radius: 0.6 }); + let mut full_fit = raw.clone(); + let (_, full_transform, full_look) = starting_colour(&mut full_fit, file, None, Some(&vignetted)); + assert_ne!( + dng_colour(&full_fit.color, white, &full_transform, full_look.as_ref()), + Some(expected_tags.clone()), + "the fixture must distinguish corrected shading from the uncorrected DNG samples" + ); + let actual = super::colour::starting_colour_tags_with_correction(&mut raw.clone(), file, Some(&vignetted)).unwrap(); + assert_eq!(actual, *expected_tags, "DNG colour fitting must exclude external vignette gains"); + let mut corrected = raw.clone(); + corrected.color = actual; + let options = lightcraft_raw::DngWriteOptions::default(); + let saved = lightcraft_raw::write_dng(&corrected, &options).unwrap(); + assert_eq!(saved, lightcraft_raw::write_dng(converted, &options).unwrap(), "saved DNG matches the warp-only colour contract"); + assert!(lightcraft_raw::decode(&saved).unwrap().opcodes.list3.is_empty()); +} + +/// A DNG's own vignette is serialized and must remain in its fit and retained opcodes. +fn assert_file_owned_dng_vignette_contract( + raw: &mut RawImage, + file: &[u8], + lens: &lightcraft_develop::EmbeddedLens, + white: &crate::files::DngWhite, + expected_tags: &ColorData, +) { + // A file's own (identity) warp must suppress the unrelated database proposal. This also + // checks that colour fitting temporarily strips, then restores, the original opcodes. + raw.opcodes.list3.push(lightcraft_raw::Opcode::WarpRectilinear { planes: vec![[1.0, 0.0, 0.0, 0.0, 0.0, 0.0]], center: [0.5, 0.5] }); + raw.opcodes.list3.push(lightcraft_raw::Opcode::FixVignetteRadial { k: [0.3, 0.0, 0.0, 0.0, 0.0], center: [0.5, 0.5] }); + let ops = raw.opcodes.list3.clone(); + let own = crate::files::embedded_lens(&raw.info()).unwrap(); + assert!(own.vignette.is_some(), "file-owned shading must remain part of the DNG fit and opcodes"); + assert_ne!(own, *lens); + let mut opened = raw.clone(); + let geometry = lens_geometry(&opened.opcodes.list3); + opened.opcodes.list3.clear(); + let (_, t, look) = starting_colour(&mut opened, file, geometry.as_ref(), Some(&own)); + let expected = dng_colour(&raw.color, white, &t, look.as_ref()).unwrap(); + assert_ne!(expected, *expected_tags, "fixture distinguishes own warp from database geometry"); + assert_eq!(starting_colour_tags(&mut raw.clone(), file), Some(expected.clone())); + with_starting_colour(raw, file); + assert_eq!(raw.color, expected, "standalone DNG colour agrees with opening the RAW"); + assert_eq!(raw.opcodes.list3, ops, "DNG retains its file corrections"); +} + #[test] fn external_profile_geometry_reaches_file_and_pooled_pairs_in_the_default_crop() { const DB: &str = r#" @@ -1331,22 +1389,9 @@ fn external_profile_geometry_reaches_file_and_pooled_pairs_in_the_default_crop() with_starting_colour(&mut converted, &file); assert_eq!(converted.color, expected_tags); - // A file's own (identity) warp must suppress the unrelated database proposal. This also - // checks that colour fitting temporarily strips, then restores, the original opcodes. - raw.opcodes.list3.push(lightcraft_raw::Opcode::WarpRectilinear { planes: vec![[1.0, 0.0, 0.0, 0.0, 0.0, 0.0]], center: [0.5, 0.5] }); - let ops = raw.opcodes.list3.clone(); - let own = crate::files::embedded_lens(&raw.info()).unwrap(); - assert_ne!(own, lens); - let mut opened = raw.clone(); - let geometry = lens_geometry(&opened.opcodes.list3); - opened.opcodes.list3.clear(); - let (_, t, look) = starting_colour(&mut opened, &file, geometry.as_ref(), Some(&own)); - let expected = dng_colour(&raw.color, &white, &t, look.as_ref()).unwrap(); - assert_ne!(expected, expected_tags, "fixture distinguishes own warp from database geometry"); - assert_eq!(starting_colour_tags(&mut raw.clone(), &file), Some(expected.clone())); - with_starting_colour(&mut raw, &file); - assert_eq!(raw.color, expected, "standalone DNG colour agrees with opening the RAW"); - assert_eq!(raw.opcodes.list3, ops, "DNG retains its file corrections"); + assert_external_dng_vignette_contract(&raw, &file, &lens, &white, &expected_tags, &converted); + + assert_file_owned_dng_vignette_contract(&mut raw, &file, &lens, &white, &expected_tags); // A real configured profile with nonzero vignetting must still be available to Main's // per-file CR3 path, while this proposal's new Pool/DNG lookup stays excluded. diff --git a/docs/camera-preview-colour.md b/docs/camera-preview-colour.md index dc7a423535..74f74fa9ac 100644 --- a/docs/camera-preview-colour.md +++ b/docs/camera-preview-colour.md @@ -356,7 +356,10 @@ on the proxy so it can still be recognized as stale. A scan interrupted by a dat new database as checked. Existing destinations remain untouched when a build is rejected. DNG conversion and merge resolve the file's own lens warp and correction before removing lens opcodes from the -colour-only sensor fit. The opcodes remain in standalone DNGs and in merge reference corrections. Synthetic tests +colour-only sensor fit. The opcodes remain in standalone DNGs and in merge reference corrections. +The DNG colour fit retains only file-owned vignette gains: an external database vignette is not +stored with those sensor samples. External correspondence geometry remains available; normal +photo and pooled fits keep their existing vignetting. Synthetic tests exercise the production database lookup in a fresh child process, file-warp precedence and merge callback ordering; they add no real-photo validation beyond the historical evidence above. Profile proposals below 0.90 training agreement now skip the unnecessary original-side scan; thresholds are unchanged and no timing improvement is claimed. diff --git a/docs/lens-profiles.md b/docs/lens-profiles.md index 4ad7d0fa3b..04bde55c33 100644 --- a/docs/lens-profiles.md +++ b/docs/lens-profiles.md @@ -105,4 +105,4 @@ match score still wins even when its crop is unknown. - The focus distance is not read from maker notes yet: vignetting uses the farthest calibrated distance. - No manual make / model picker and no choice between sources (in the file, lens database, an own calibration) yet; matching is automatic, the file's own correction wins. -- Automated tests use synthetic profiles and grids. Limited real-file validation of the fixed-mount fallback and its use for colour correspondences covers five private G7 X II photographs; this does not establish geometric accuracy across other cameras or profiles. +- Automated tests use synthetic profiles and grids. Historical validation of the fixed-mount fallback and its use for colour correspondences covered five private G7 X II photographs; it was not rerun on the subsequently synchronized source and does not establish geometric accuracy across other cameras or profiles.