LR-PROF-CAMERACOLOR: keep DNG colour fits in stored sample space

Exclude unsaved external vignette gains from non-CR3 DNG colour fitting while retaining correspondence geometry and the vignette carried by the file's own opcodes. Preserve file-local and pooled calibration.

Add causal procedural DNG coverage and retain the file-owned correction assertions in bounded test helpers. Clarify that the five-photo fixed-mount validation is historical and was not rerun on the synchronized source. Full cargo xtask ci passes with Rust 1.95.0, actual Metal and WASM; capability skips are separate.

Co-authored-by: Codex <[email protected]>
This commit is contained in:
r3d42-gitandCodex committed 2026-11-16 22:42:25 +01:00
1 parent bd3ee7ea8d
commit 8d45e43cf3
4 files changed
+73 -20

No files matched your search

+7 -2
View File
@@ -144,12 +144,17 @@ pub(crate) fn starting_colour_tags(raw: &mut RawImage, bytes: &[u8]) -> Option<C
starting_colour_tags_with_correction(raw, bytes, correction.as_ref())
}
/// Fit DNG colour in the stored sample space. Only a vignette owned by the file's
/// retained opcodes may enter the fit; external profile geometry still aligns the pairs.
pub(super) fn starting_colour_tags_with_correction(
raw: &mut RawImage,
bytes: &[u8],
correction: Option<&lightcraft_develop::EmbeddedLens>,
) -> Option<ColorData> {
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())
}
+61 -16
View File
@@ -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#"<lensdatabase>
@@ -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.
+4 -1
View File
@@ -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.
+1 -1
View File
@@ -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.