Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fade8e7
LR-PROF-CAMERACOLOR: align lens-corrected camera JPEG training pairs
r3d42-git Oct 23, 2026
46e809f
LR-PROF-CAMERACOLOR: merge current main and preserve geometry alignment
r3d42-git Oct 28, 2026
3f969c2
LR-PROF-CAMERACOLOR: synchronize external geometry with main
r3d42-git Nov 1, 2026
1424afa
LR-PROF-CAMERACOLOR: reject gains from dropped correspondence edges
r3d42-git Nov 1, 2026
04f8c67
LR-PROF-CAMERACOLOR: preserve lens dependencies in colour fits
r3d42-git Nov 2, 2026
d305b7b
LR-PROF-CAMERACOLOR: require original provenance for proxy repairs
r3d42-git Nov 2, 2026
20b954f
LR-PROF-CAMERACOLOR: reconcile current upstream integration
r3d42-git Nov 4, 2026
1fc885f
LR-PROF-CAMERACOLOR: reconcile runtime lens database integration
r3d42-git Nov 4, 2026
fbc601a
LR-PROF-CAMERACOLOR: reconcile DCP and display rendering integration
r3d42-git Nov 5, 2026
968c23b
LR-PROF-CAMERACOLOR: integrate upstream dither test follow-up
r3d42-git Nov 5, 2026
d593ba5
LR-PROF-CAMERACOLOR: integrate prepared culling previews
r3d42-git Nov 5, 2026
d1ab8b7
LR-PROF-CAMERACOLOR: preserve raw decode options in fresh smart previews
r3d42-git Nov 5, 2026
d505f21
LR-PROF-CAMERACOLOR: integrate current main and retain geometry regre…
r3d42-git Nov 5, 2026
fbb318a
LR-PROF-CAMERACOLOR: publish known activity totals before worker disp…
r3d42-git Nov 5, 2026
bd3ee7e
LR-PROF-CAMERACOLOR: narrow standalone color geometry scope
r3d42-git Nov 6, 2026
8d45e43
LR-PROF-CAMERACOLOR: keep DNG colour fits in stored sample space
r3d42-git Nov 16, 2026
1e27473
LR-PROF-CAMERACOLOR: align TIFF fixtures with current main
r3d42-git Nov 16, 2026
37c68e3
LR-PROF-CAMERACOLOR: record proposed geometry in the tracker row
r3d42-git Nov 17, 2026
aa54dd7
LR-PROF-CAMERACOLOR: merge current main and preserve correspondence s…
r3d42-git Nov 18, 2026
20c0943
Merge upstream main and retain camera profile cache invalidation
r3d42-git Nov 19, 2026
de8e20b
Keep the loaded camera profile fingerprint across lens reloads
r3d42-git Nov 19, 2026
1fd4a49
Merge upstream main and preserve Smart Preview provenance
r3d42-git Nov 25, 2026
344ac41
Keep Smart Preview scans valid across LensDB changes
r3d42-git Nov 25, 2026
fd17163
Merge main and preserve non-CR3 correspondence geometry
r3d42-git Nov 26, 2026
25a4377
Keep exact correspondence samples at invalid borders
r3d42-git Nov 26, 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
5 changes: 3 additions & 2 deletions crates/engine/src/camera_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod tone;
pub(crate) use colour::{PROFILE_PROXY, dng_colour, dng_tone_eligible};
#[cfg(test)]
use colour::{PROXY, starting_colour_with};
pub(crate) use colour::{file_local_look, starting_colour, starting_colour_tags, with_starting_colour};
pub(crate) use colour::{correspondence_correction, file_local_look, starting_colour, starting_colour_tags, with_starting_colour};
pub(crate) use hue_sat::HueSat;
#[cfg(test)]
use hue_sat::{MIN_LUMINANCE_KEPT, NO_LUMINANCE_KEPT, fit_hue_sat, hue_saturation, restore_weight};
Expand Down Expand Up @@ -94,7 +94,8 @@ use tone::{HighlightCheck, ToneFit, fit_tone, fit_tone_conditional, highlights};
/// 26: a lens database's vignetting correction reaches the sensor proxy only in the share the camera JPEG shows
/// (`camera_vignetting_amount`, ranked within chromaticity classes), not whole: JPEGs that show less of it fitted looks too
/// dark, with skewed colour. The same for a DNG's tone fit; a CR3 proxy gets the gain where its framed pixels come from.
pub const LOOK_VERSION: u32 = 26;
/// 27: geometry-gated external lens and camera framing for JPEG calibration correspondences.
pub const LOOK_VERSION: u32 = 27;

#[derive(Clone, Debug)]
pub(crate) struct CameraLook {
Expand Down
35 changes: 30 additions & 5 deletions crates/engine/src/camera_preview/colour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,46 @@ pub(super) fn starting_colour_with(
(xy, t, look.or_else(|| dark(raw, &t)))
}

/// Additional profile resolution for this proposal's pooled/DNG routes; CR3 keeps Main's route.
pub(crate) fn correspondence_correction(raw: &RawImage, bytes: &[u8]) -> Option<lightcraft_develop::EmbeddedLens> {
if raw.format == RawFormat::Cr3 {
return None;
}
crate::lens_profiles::for_raw(&raw.info(), || lightcraft_meta::extract(bytes))
}

/// The colour a raw starts from ([`starting_colour`]) as DNG colour tags, for a DNG of the raw's camera RGB (Photo
/// Merge, issue #965): without them a merge of CR2s, whose colour comes from a look fitted to their JPEG, rendered
/// green and dark. `None` when the file has colour matrices of its own (a DNG keeps them).
pub(crate) fn starting_colour_tags(raw: &mut RawImage, bytes: &[u8]) -> Option<ColorData> {
if lightcraft_raw::color::has_matrix(&raw.color) {
return None;
}
let correction = correspondence_correction(raw, bytes);
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).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));
// (a merge frame arrives without its lens warp: `lightcraft_merge` removes it before calling)
let (_, t, look) = starting_colour(raw, bytes, None, None);
// Resolve the file warp before removing lens opcodes, just as opening the RAW does.
// The fit needs uncorrected sensor samples; the caller still owns the original opcodes.
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.as_ref());
raw.opcodes.list3 = list3;
dng_colour(&raw.color, &white, &t, look.as_ref())
}

Expand All @@ -149,10 +177,7 @@ pub(crate) fn with_starting_colour(raw: &mut RawImage, bytes: &[u8]) {
if lightcraft_raw::color::has_matrix(&raw.color) {
return;
}
let list3 = raw.opcodes.list3.clone();
raw.opcodes.list3.retain(|op| !op.is_lens_correction());
let tags = starting_colour_tags(raw, bytes);
raw.opcodes.list3 = list3;
if let Some(tags) = tags {
raw.color = tags;
}
Expand Down
35 changes: 10 additions & 25 deletions crates/engine/src/camera_preview/look_fit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::colour::{PROXY, file_local_look};
use super::mono::{fit_tone_only_with, monochrome};
use super::pairs::{Attempt, TONE_FITS, fit_attempt, fit_partial, search_ordered};
use super::proxy::{CLIP_TOLERANCE, Cr3Framing, LensGeometry, MIN_PREVIEW_FRACTION, extend_tone, framed_proxies, proxies, structure_agrees};
use super::proxy::{CLIP_TOLERANCE, Cr3Framing, LensGeometry, MIN_PREVIEW_FRACTION, extend_tone, proxies, structure_agrees};
use super::tone::{HighlightCheck, highlights};
use super::{CameraLook, CameraTone, CameraTransform, HsvTable, Mat3, RawImage, Rgb32f, ToneMap, luminance_2020};

Expand Down Expand Up @@ -315,31 +315,12 @@ pub(super) fn look_proxies(
lens: Option<&LensGeometry>,
embedded: Option<&lightcraft_develop::EmbeddedLens>,
) -> Option<(Rgb32f, Rgb32f, Vec<bool>)> {
// The file's own vignetting data is what its camera applied to the JPEG. A lens database profile describes the
// lens, not what this camera did: an ILCE-7M3 JPEG with an FE 28mm F2 at f/2 (maker note: vignetting correction
// Auto) shows none of lensfun's correction relative to its raw (the A7CR's shading Auto JPEGs show no consistent
// peripheral brightening either, docs/sony-lens-corrections.md). With the whole profile on the sensor that fit
// learned corners the JPEG doesn't have: 0.062 held-out RMS instead of 0.027, a darker, orange render. So the share
// of the profile the JPEG shows is measured. (Only without a lens warp: the gain goes on the returned proxy, and a
// warped one no longer has each pixel at its source position. A warp comes from the file's own opcodes, and a file
// with its own correction never gets a database profile, `lens_profiles::for_raw`.)
let database = embedded.filter(|e| e.source == lightcraft_develop::LensSource::Database && lens.is_none());
let Some(vignette) = database.and_then(|e| e.vignette) else {
return proxies(raw, bytes, transform, PROXY, 0.0, lens, embedded);
};
// A CR3's framing (`estimate_cr3_framing`) is estimated here on the uncorrected sensor, not the corrected one as
// before: it compares edge directions, which a smooth vignetting gain hardly moves. On the 22 corpus CR3s with a
// database profile it came out the same both ways (21 unmoved, the R50 V at scale 0.986).
let (mut sensor, reference, clipped, framing) = framed_proxies(raw, bytes, transform, PROXY, 0.0, lens, None)?;
// CR3 proxies come back oriented like the JPEG (their framing aligned to it), the others in sensor orientation
let orientation = if raw.format == lightcraft_raw::RawFormat::Cr3 { lightcraft_geom::Orientation::Normal } else { raw.orientation };
database_vignetting(&mut sensor, &reference, &clipped, &vignette, ProxyFrame { orientation, framing });
Some((sensor, reference, clipped))
proxies(raw, bytes, transform, PROXY, 0.0, lens, embedded)
}

/// Multiply `sensor` by the share of a lens database's `vignette` correction that the camera JPEG `reference` shows
/// ([`camera_vignetting_amount`]).
fn database_vignetting(
pub(super) fn database_vignetting(
sensor: &mut Rgb32f,
reference: &Rgb32f,
clipped: &[bool],
Expand All @@ -354,7 +335,7 @@ fn database_vignetting(
}

/// Where a sensor proxy's pixels sit in the oriented, cropped frame a lens's vignetting is in: `framing` (a CR3 proxy
/// moved to its camera JPEG's framing, [`framed_proxies`]) takes each pixel to the position it shows, and
/// moved to its camera JPEG's framing, [`super::proxy::framed_proxies`]) takes each pixel to the position it shows, and
/// `orientation` maps that position to the oriented frame.
#[derive(Clone, Copy, Debug)]
pub(super) struct ProxyFrame {
Expand Down Expand Up @@ -425,10 +406,14 @@ pub(super) fn camera_vignetting_amount(
vignette: &lightcraft_develop::EmbeddedVignette,
frame: ProxyFrame,
) -> f64 {
vignetting_amount_from_gains(sensor, reference, clipped, vignetting_gains(sensor, vignette, frame))
}

/// Estimate the share shown by the JPEG, with each gain evaluated at the sensor position that supplied its pixel.
pub(super) fn vignetting_amount_from_gains(sensor: &Rgb32f, reference: &Rgb32f, clipped: &[bool], gains: impl IntoIterator<Item = f64>) -> f64 {
if sensor.data.len() != reference.data.len() {
return 1.0;
}
let gains = vignetting_gains(sensor, vignette, frame);
let usable = |p: &[f32; 3]| p.iter().all(|v| v.is_finite()) && luminance_2020(*p) > 0.0;
let mut classes: Vec<Vec<(f64, [f64; 3], [f64; 3])>> = vec![Vec::new(); HUE_SECTORS + 1];
for (i, ((s, r), g)) in sensor.data.iter().zip(&reference.data).zip(gains).enumerate() {
Expand Down Expand Up @@ -486,7 +471,7 @@ pub(super) fn vignetting_gains(sensor: &Rgb32f, vignette: &lightcraft_develop::E
}

/// Multiply `sensor` by `amount` of `vignette`'s correction, as the Vignetting amount slider scales it.
fn apply_vignetting(sensor: &mut Rgb32f, vignette: &lightcraft_develop::EmbeddedVignette, frame: ProxyFrame, amount: f64) {
pub(super) fn apply_vignetting(sensor: &mut Rgb32f, vignette: &lightcraft_develop::EmbeddedVignette, frame: ProxyFrame, amount: f64) {
let gains = vignetting_gains(sensor, vignette, frame);
for (p, g) in sensor.data.iter_mut().zip(gains) {
let gain = (1.0 + (g - 1.0) * amount) as f32;
Expand Down
Loading
Loading