Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c739e1b
LR-CI: fix Rust 1.95 lints and standard-font menu hints
r3d42-git Oct 27, 2026
8975b2e
LR-PROF-CAMERACOLOR: align CR3 calibration with resolved lens profiles
r3d42-git Oct 27, 2026
8f3412c
LR-CI: document functions touched by readiness fixes
r3d42-git Oct 27, 2026
979461b
LR-PROF-CAMERACOLOR: document calibration geometry and regression hel…
r3d42-git Oct 27, 2026
49f4cd6
LR-PROF-CAMERACOLOR: report unavailable CR3 diagnostic proxies
r3d42-git Oct 27, 2026
c0f1aa3
LR-PROF-CAMERACOLOR: synchronize CR3 calibration with current main
r3d42-git Oct 28, 2026
4486c1b
LR-PROF-CAMERACOLOR: synchronize CR3 geometry with main
r3d42-git Nov 1, 2026
3a8dbe9
LR-PROF-CAMERACOLOR: exercise as-shot WB with vignetted CR3 geometry
r3d42-git Nov 1, 2026
71ceb01
LR-PROF-CAMERACOLOR: compare geometry proposals on common edges
r3d42-git Nov 1, 2026
eee56f1
LR-PROF-CAMERACOLOR: verify CR3 geometry mask coverage
r3d42-git Nov 2, 2026
ca329e6
LR-PROF-CAMERACOLOR: reconcile CR3 proposal with current main
r3d42-git Nov 3, 2026
be5ebcc
LR-PROF-CAMERACOLOR: synchronize CR3 proposal with current upstream
r3d42-git Nov 4, 2026
d01b48e
LR-PROF-CAMERACOLOR: retain CR3 scope alongside upstream mask geometry
r3d42-git Nov 4, 2026
25b6ce0
LR-PROF-CAMERACOLOR: reconcile renewed CR3 upstream conflicts
r3d42-git Nov 4, 2026
1031d05
LR-PROF-CAMERACOLOR: synchronize CR3 proposal with current upstream
r3d42-git Nov 5, 2026
61b4c49
LR-PROF-CAMERACOLOR: preserve CR3 scope with prepared culling views
r3d42-git Nov 5, 2026
109011e
LR-PROF-CAMERACOLOR: retain raw decode options in CR3 proxy refresh
r3d42-git Nov 5, 2026
0cf64ff
LR-PROF-CAMERACOLOR: integrate current main and retain geometry regre…
r3d42-git Nov 5, 2026
25d29d7
LR-PROF-CAMERACOLOR: publish known activity totals before worker disp…
r3d42-git Nov 5, 2026
147cda1
LR-PROF-CAMERACOLOR: narrow standalone cr3 geometry scope
r3d42-git Nov 6, 2026
9eb05fa
LR-PROF-CAMERACOLOR: avoid CR3 correspondence buffer clones
r3d42-git Nov 8, 2026
2a8f8da
LR-PROF-CAMERACOLOR: fit CR3 DNG tags without external shading
r3d42-git Nov 16, 2026
642e924
LR-PROF-CAMERACOLOR: merge current main and retain CR3 contracts
r3d42-git Nov 18, 2026
3135bd9
LR-PROF-CAMERACOLOR: keep CR3 diagnostic reports unambiguous
r3d42-git Nov 18, 2026
099b62d
Merge upstream main and retain camera profile cache invalidation
r3d42-git Nov 19, 2026
a680985
Keep the loaded camera profile fingerprint across lens reloads
r3d42-git Nov 19, 2026
971deb7
Preserve pooled CR3 color pairs when profile geometry falls back
r3d42-git Nov 19, 2026
d7dd445
Merge upstream main and preserve Smart Preview provenance
r3d42-git Nov 25, 2026
e7f55d5
Keep Smart Preview scans valid across LensDB changes
r3d42-git Nov 25, 2026
2e54242
Port CR3 profile alignment to current camera calibration
r3d42-git Nov 26, 2026
5e4e4f2
Keep CR3 diagnostic PNGs keyed by the native filename
r3d42-git Nov 26, 2026
da832f0
Preserve valid CR3 correspondence samples at invalid borders
r3d42-git Nov 27, 2026
23eabbb
Start the CR3 port from main after the shared preview changes landed
r3d42-git Nov 28, 2026
b7c3877
Align CR3 camera preview samples against the resolved lens and framin…
r3d42-git Nov 28, 2026
3295921
Refresh Smart Previews and cached renders after the CR3 look changes
r3d42-git Nov 28, 2026
055fba8
Clarify CR3 shading and surface corpus fixture read errors
r3d42-git Nov 28, 2026
8443441
Merge main into r3d/cr3-profile-alignment
FredApps Dec 2, 2026
1e5d829
Compare pooled CR3 warps with the unshaded fallback and isolate diagn…
r3d42-git Dec 2, 2026
4a43918
Synchronize denoiser model-change tests with worker completion
r3d42-git Dec 2, 2026
a5c5311
Verify fixed-mount CR3 correspondence through the shared lens lookup
r3d42-git Dec 2, 2026
95fa914
Distinguish frame and calibration crop factors in CR3 lookup
r3d42-git Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions crates/engine/src/camera_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ use pairs::{
pub(crate) use proxy::LensGeometry;
#[cfg(test)]
use proxy::{
Cr3Framing, MIN_PREVIEW_FRACTION, alignment, estimate_cr3_framing, into_lens_geometry, proxies, reference_at, sensor_proxy, structure_agrees,
Cr3Framing, MIN_PREVIEW_FRACTION, align_profile_geometry, alignment, estimate_cr3_framing, into_lens_geometry, proxies, reference_at,
resample_correspondence, sensor_proxy, structure_agrees,
};
pub(crate) use proxy::{fit_profile, lens_geometry, profile_pairs};
#[cfg(test)]
Expand Down Expand Up @@ -84,7 +85,8 @@ use tone::{HighlightCheck, ToneFit, fit_tone, fit_tone_conditional, highlights};
/// 13: the sensor proxy of every per-file fit gets the embedded vignetting correction the render applies (Fujifilm
/// RAF; other makes with a lens database), so the render no longer applies it twice, at the position a lens warp samples;
/// the warped candidate's alignment leaves out the pixels outside the sensor instead of reading them as black.
pub const LOOK_VERSION: u32 = 13;
/// 14: geometry-gated CR3 lens profiles for JPEG correspondences, preserving the framing fallback.
pub const LOOK_VERSION: u32 = 14;

#[derive(Clone, Debug)]
pub(crate) struct CameraLook {
Expand Down
15 changes: 13 additions & 2 deletions crates/engine/src/camera_preview/colour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) fn file_local_look(format: RawFormat) -> bool {
/// `lens` is the file's own lens-correction warp ([`lens_geometry`], read before the caller removes it from
/// `OpcodeList3`): the camera applied it to its JPEG, so the sensor proxy is warped the same way before pairing.
/// `embedded` is the file's embedded lens correction: its vignetting is applied to the sensor proxy of every fit, as
/// the render applies it.
/// the render applies it. Its resolved warp may also align CR3 correspondences, subject to geometry gates.
pub(crate) fn starting_colour(
raw: &mut RawImage,
bytes: &[u8],
Expand Down Expand Up @@ -132,11 +132,22 @@ pub(crate) fn starting_colour_tags(raw: &mut RawImage, bytes: &[u8]) -> Option<C
if lightcraft_raw::color::has_matrix(&raw.color) {
return None;
}
let correction = if raw.format == RawFormat::Cr3 { crate::lens_profiles::for_raw(&raw.info(), || lightcraft_meta::extract(bytes)) } else { None };
starting_colour_tags_with_correction(raw, bytes, correction.as_ref())
}

/// Build DNG colour tags using `correction` only for CR3 camera-JPEG correspondence geometry.
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);
// 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));
// (a merge frame arrives without its lens warp: `lightcraft_merge` removes it before calling)
let (_, t, look) = starting_colour(raw, bytes, None, None);
let (_, t, look) = starting_colour(raw, bytes, None, correction);
Comment thread
r3d42-git marked this conversation as resolved.
Resolved
dng_colour(&raw.color, &white, &t, look.as_ref())
}

Expand Down
204 changes: 187 additions & 17 deletions crates/engine/src/camera_preview/proxy.rs

Large diffs are not rendered by default.

605 changes: 605 additions & 0 deletions crates/engine/src/camera_preview/tests.rs

Large diffs are not rendered by default.

92 changes: 87 additions & 5 deletions crates/engine/src/camera_profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,28 @@ pub fn get(model: &str) -> Option<Arc<CameraProfile>> {
}

/// Changes when the profiles folder's contents change (per process): part of the render cache
/// keys, so thumbnails rendered before a profile existed are not reused after.
/// keys, so thumbnails rendered before a profile existed are not reused after. Includes the
/// loaded lens database: its geometry determines which sensor/JPEG samples fit the camera look.
pub fn cache_key() -> u64 {
static KEY: OnceLock<u64> = OnceLock::new();
*KEY.get_or_init(|| cache_key_for(dir().as_deref()))
static KEY: Mutex<Option<(u64, u64)>> = Mutex::new(None);
let lens_key = crate::lens_profiles::cache_key();
let mut key = KEY.lock().unwrap_or_else(PoisonError::into_inner);
if let Some((previous_lens, value)) = *key
&& previous_lens == lens_key
{
return value;
}
let value = cache_key_with_lens(dir().as_deref(), lens_key);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
*key = Some((lens_key, value));
value
}

#[cfg(test)]
fn cache_key_for(directory: Option<&Path>) -> u64 {
cache_key_with_lens(directory, 0)
}

fn cache_key_with_lens(directory: Option<&Path>, lens_key: u64) -> u64 {
let entries = directory.and_then(|d| std::fs::read_dir(d).ok());
let mut files: Vec<(String, u64, std::time::Duration)> = entries
.into_iter()
Expand All @@ -179,6 +194,7 @@ fn cache_key_for(directory: Option<&Path>) -> u64 {
.collect();
files.sort();
let mut h = lightcraft_preview::Hasher128::new();
h.str("camera-profiles-with-lens-v1").u64(lens_key);
for (name, len, modified) in &files {
h.str(name).u64(*len).u64(modified.as_secs()).u64(u64::from(modified.subsec_nanos()));
}
Expand All @@ -199,15 +215,20 @@ const PAIRS_PER_FILE: usize = 4000;

impl Pool {
/// Add one raw file's colour pairs. `Ok(None)` when the file can't contribute (not an ARW,
/// NEF or RAF without colour matrices, no usable camera JPEG, too little colour).
/// NEF, RAF, CR2/CR3 or another file-local format without colour matrices, no usable camera JPEG, too little colour).
pub fn add(&mut self, bytes: &[u8]) -> Result<Option<String>, String> {
let mut raw = lightcraft_raw::decode(bytes).map_err(|e| e.to_string())?;
// colour only: geometric lens corrections would stop the sensor proxy from binning (the pairs still follow
// the warp the camera applied to its JPEG)
let correction = if raw.format == lightcraft_raw::RawFormat::Cr3 {
crate::lens_profiles::for_raw(&raw.info(), || lightcraft_meta::extract(bytes))
} else {
None
};
let lens = crate::camera_preview::lens_geometry(&raw.opcodes.list3);
raw.opcodes.list3.retain(|op| !op.is_lens_correction());
let Some(model) = raw.metadata.model.as_deref().map(str::trim).filter(|m| !m.is_empty()) else { return Ok(None) };
let Some(pairs) = crate::camera_preview::profile_pairs(&raw, bytes, lens.as_ref()) else { return Ok(None) };
let Some(pairs) = crate::camera_preview::profile_pairs(&raw, bytes, lens.as_ref(), correction.as_ref()) else { return Ok(None) };
let step = pairs.len().div_ceil(PAIRS_PER_FILE).max(1);
let entry = self.models.entry(model.to_owned()).or_default();
entry.0 += 1;
Expand Down Expand Up @@ -255,6 +276,60 @@ mod tests {
CameraProfile::new("ILCE-7M4", 12, 3456, Mat3([[1.6, -0.5, -0.1], [-0.2, 1.3, -0.1], [-0.1, -0.2, 1.3]]), Some(table))
}

#[test]
fn public_cache_key_includes_the_configured_lens_database() {
const CHILD: &str = "LIGHTCRAFT_TEST_CAMERA_CACHE_KEY_CHILD";
if std::env::var_os(CHILD).is_none() {
let dir = std::env::temp_dir().join(format!("lc-camera-key-wiring-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(
dir.join("lens.xml"),
r#"<lensdatabase><lens><maker>Test</maker><model>18mm</model><mount>T</mount><cropfactor>1.5</cropfactor>
<calibration><distortion model="poly3" focal="18" k1="-0.03" /></calibration></lens></lensdatabase>"#,
)
.unwrap();
// The loaded snapshots and configured camera-profile folder belong to the child only.
let output = std::process::Command::new(std::env::current_exe().unwrap())
.args(["--exact", "camera_profiles::tests::public_cache_key_includes_the_configured_lens_database", "--nocapture"])
.env(CHILD, "1")
.env(crate::lens_profiles::ENV, &dir)
.env("LIGHTCRAFT_CONFIG_DIR", &dir)
.env("LIGHTCRAFT_CAMERA_PROFILES", &dir)
.output()
.unwrap();
std::fs::remove_dir_all(&dir).unwrap();
assert!(output.status.success(), "{}\n{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr));
return;
}
assert!(crate::lens_profiles::database().is_some(), "fixture database was loaded by the public loader");
let lens_key = crate::lens_profiles::cache_key();
assert_ne!(lens_key, 0);
let directory = dir();
assert_eq!(cache_key(), cache_key_with_lens(directory.as_deref(), lens_key));
assert_ne!(cache_key(), cache_key_with_lens(directory.as_deref(), 0), "public camera key must forward the loaded lens key");
let first = cache_key();
// The culling path now reuses rendered views before decoding. Their identity
// must follow the same loaded lens snapshot as camera fitting and thumbnails.
let mut session = crate::Session::with_demo();
let id = session.active().unwrap();
let view = session.loupe_job(id, 64, 64, true).unwrap();
let (views, view_key) = view.view_cache.as_ref().unwrap();
views.put_memory(*view_key, std::sync::Arc::new(lightcraft_raster::Rgba8::from_fn(64, 64, |_, _| [7, 19, 31, 255])));
assert!(session.loupe_job(id, 64, 64, true).unwrap().cached_view().is_some());
let file = directory.unwrap().join("lens.xml");
let xml = std::fs::read_to_string(&file).unwrap();
std::fs::write(&file, xml.replace("-0.03", "-0.05")).unwrap();
assert_eq!(cache_key(), first, "unreloaded files do not change the loaded database");
crate::lens_profiles::replaced();
assert_ne!(cache_key(), first, "camera keys follow runtime lens replacements too");
assert!(session.loupe_job(id, 64, 64, true).unwrap().cached_view().is_none(), "a view from the old snapshot is not reused");
assert_eq!(cache_key(), cache_key_with_lens(dir().as_deref(), crate::lens_profiles::cache_key()));
std::fs::write(&file, xml).unwrap();
crate::lens_profiles::reload();
assert_eq!(cache_key(), first, "restored semantic data restores the camera key");
assert!(session.loupe_job(id, 64, 64, true).unwrap().cached_view().is_some(), "restoring the snapshot restores its view identity");
}

#[test]
fn profiles_round_trip_and_reject_bad_files() {
let dir = std::env::temp_dir().join(format!("lc-camera-profiles-{}", std::process::id()));
Expand Down Expand Up @@ -301,6 +376,13 @@ mod tests {
assert_eq!(file_name("Canon EOS D60"), "Canon_EOS_D60.json");
}

#[test]
fn lens_database_identity_invalidates_camera_render_cache() {
assert_ne!(cache_key_with_lens(None, 0), cache_key_with_lens(None, 123));
assert_ne!(cache_key_with_lens(None, 123), cache_key_with_lens(None, 456));
assert_eq!(cache_key_with_lens(None, 123), cache_key_with_lens(None, 123));
}

#[test]
fn same_second_profile_replacement_changes_render_cache_key() {
let dir = std::env::temp_dir().join(format!("lc-camera-profile-cache-{}", std::process::id()));
Expand Down
Loading
Loading