Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c7e8c5f
LR-PROF-CAMERACOLOR: a partial look from the bright pairs for mostly-…
AlexChambers Oct 10, 2026
4ac5576
LR-PROF-CAMERACOLOR: wire bright-fit helpers into the split modules
AlexChambers Oct 28, 2026
9de0650
LR-PROF-CAMERACOLOR: merge current main and retain bright-tone cache …
AlexChambers Oct 30, 2026
cc373c2
631: preserve bright camera fits on current main
AlexChambers Oct 31, 2026
056aa08
LC-CAMERACOLOR: use effective JPEG primaries for bright tone pairs
AlexChambers Oct 31, 2026
6ee32f6
LC-CAMERACOLOR: keep bright retry holdouts out of chroma training
AlexChambers Oct 31, 2026
df5f2c2
LC-CAMERACOLOR: honor every known preview colour space
AlexChambers Oct 31, 2026
db8624e
LR-PROF-CAMERACOLOR: merge current main (CRW decoder, 0.18.0)
AlexChambers Nov 3, 2026
3480e88
LR-PROF-CAMERACOLOR: merge current main (lens database download, mask…
AlexChambers Nov 4, 2026
2f26347
LR-PROF-CAMERACOLOR: merge current main (GPU render, process V3 and V…
AlexChambers Nov 5, 2026
1992af5
LR-PROF-CAMERACOLOR: merge current main eaef01e98 (light tests allow …
AlexChambers Nov 5, 2026
f3dd5fb
LR-PROF-CAMERACOLOR: refresh the parity summary after the merge
AlexChambers Nov 5, 2026
268358c
LR-PROF-CAMERACOLOR: merge current main 5b4eb6924 (BM3D denoise, Remo…
AlexChambers Nov 5, 2026
e3156be
LR-PROF-CAMERACOLOR: merge current main eab130ece (doc headers keep n…
AlexChambers Nov 5, 2026
c7caa3e
LR-PROF-CAMERACOLOR: refresh the parity summary after the merge
AlexChambers Nov 5, 2026
f40d859
LR-PROF-CAMERACOLOR: merge current main ba282d363 (ORF decoder, exact…
AlexChambers Nov 5, 2026
36f2624
LR-PROF-CAMERACOLOR: refresh the parity summary after the merge
AlexChambers Nov 5, 2026
3d58358
LR-PROF-CAMERACOLOR: merge current main fe632e05f (CR3 white level, p…
AlexChambers Nov 5, 2026
3398e85
LR-PROF-CAMERACOLOR: merge current main e9c29e2c5 (crystal grain proc…
AlexChambers Nov 10, 2026
f4354eb
LR-PROF-CAMERACOLOR: merge current main c4b899f9d (craft-libs and cra…
AlexChambers Nov 14, 2026
07977d3
Merge remote-tracking branch 'origin/main' into camera-look-bright-tone
AlexChambers Nov 18, 2026
d2df0f1
LR-PROF-CAMERACOLOR: cover bright retry rejections (#631)
AlexChambers Nov 22, 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 @@ -44,7 +44,7 @@ use mono::{fit_dark_tone, fit_tone_only, monochrome, monochrome_look, to_prophot
#[cfg(test)]
use pairs::{
Attempt, Pairs, TONE_FITS, collect_pairs, colour_pair, displayed, fit_attempt, fit_pairs, fit_pairs_ordered, fit_pairs_with, fit_partial,
fit_tone_with_shadows, luma, rank_correlation_ties, search_ordered,
fit_partial_on, fit_tone_with_shadows, jpeg_clipped, luma, rank_correlation_ties, search_ordered,
};
#[cfg(test)]
pub(crate) use proxy::LensGeometry;
Expand Down Expand Up @@ -86,7 +86,9 @@ use tone::{HighlightCheck, ToneFit, fit_tone, fit_tone_conditional, highlights};
/// the warped candidate's alignment leaves out the pixels outside the sensor instead of reading them as black.
/// 14: bundled camera profiles also match the Nikon model spellings that differ in case, spacing or the Z8 alias,
/// so previews made without the profile are rebuilt.
pub const LOOK_VERSION: u32 = 14;
/// 24: retry the partial look with unclipped bright pairs (#631). Check clipping in the decoded JPEG's colour space
/// and keep the retry's holdouts out of chroma training.
pub const LOOK_VERSION: u32 = 24;

#[derive(Clone, Debug)]
pub(crate) struct CameraLook {
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/camera_preview/colour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(crate) fn starting_colour(
if !file_local_look(raw.format) {
return None;
}
let (sensor, reference, clipped) = look_proxies(raw, bytes, t, lens, embedded)?;
let (sensor, reference, clipped, _) = look_proxies(raw, bytes, t, lens, embedded)?;
fit_dark_tone(&sensor, &reference, &clipped)
},
);
Expand Down
8 changes: 7 additions & 1 deletion crates/engine/src/camera_preview/hue_sat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ const CHROMA_SHRINK: f64 = 2.0;
/// train, one third held out), when that lowers the held-out error. Colourfulness is compared as
/// the distance from neutral of luminance-normalised RGB.
pub(super) fn fit_chroma(pairs: &[([f64; 3], [f64; 3])], look: &CameraLook) -> Option<CameraTone> {
fit_chroma_excluding(pairs, look, &[])
}

/// Fit chroma without the retry's additional holdouts. Flags retain the original pair positions;
/// the usual chroma holdouts also remain excluded from training and own its acceptance check.
pub(super) fn fit_chroma_excluding(pairs: &[([f64; 3], [f64; 3])], look: &CameraLook, holdouts: &[bool]) -> Option<CameraTone> {
let correction = look.hue_sat.as_ref().and_then(HueSat::new);
let scene = |x: &[f64; 3]| {
let p = look.matrix.apply(*x);
Expand All @@ -231,7 +237,7 @@ pub(super) fn fit_chroma(pairs: &[([f64; 3], [f64; 3])], look: &CameraLook) -> O
let samples: Vec<(f64, f64, f64)> = pairs
.iter()
.enumerate()
.filter(|(i, _)| i % 3 != 0)
.filter(|(i, _)| i % 3 != 0 && !holdouts.get(*i).copied().unwrap_or(false))
.filter_map(|(_, (x, y))| {
let p = predict(x);
let (cp, cy) = (chroma(p)?, chroma(*y)?);
Expand Down
37 changes: 28 additions & 9 deletions crates/engine/src/camera_preview/look_fit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,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, LensGeometry, MIN_PREVIEW_FRACTION, proxies, structure_agrees};
use super::tone::{HighlightCheck, highlights};
use super::tone::{HighlightCheck, clipped_highlights, highlights};
use super::{CameraLook, CameraTone, CameraTransform, HsvTable, Mat3, RawImage, Rgb32f, ToneMap, luminance_2020};

/// The look fitted to the file's camera JPEG, and whether that JPEG is black and white ([`monochrome`]).
Expand All @@ -17,7 +17,7 @@ pub(crate) fn fit_preview(
if !transform.matrix_is_fallback || !file_local_look(raw.format) {
return (None, false);
}
let Some((sensor, reference, clipped)) = look_proxies(raw, bytes, transform, lens, embedded) else { return (None, false) };
let Some((sensor, reference, clipped, jpeg_space)) = look_proxies(raw, bytes, transform, lens, embedded) else { return (None, false) };
let black_and_white = monochrome(&reference);
// A camera profile pooled from many photos knows colours this photo shows too little of;
// try its colour first and fit tone/chroma per photo (picture styles vary).
Expand All @@ -26,13 +26,19 @@ pub(crate) fn fit_preview(
// Sony's Dynamic Range Optimizer (on by default) brightens the camera JPEG's darker regions,
// not the raw: keep the colour fitted to the JPEG, take the tone curve without DRO.
let dro = lightcraft_raw::embedded_preview_dynamic_range_optimized(bytes) == Some(true);
let look = match fit_look_with(&sensor, &reference, &clipped, colour.clone(), dro) {
let look = match fit_look_with(&sensor, &reference, &clipped, colour.clone(), dro, jpeg_space) {
Some(look) => look,
// A black-and-white JPEG has no colour to fit: the profile's colour and the JPEG's tone curve
// (`monochrome_look` does it without a profile).
None if colour.is_some() && black_and_white => {
let unclipped = without_clipped(&sensor, &clipped);
let bright = HighlightCheck { pairs: highlights(&sensor, &reference), dro, grey: true };
let bright = HighlightCheck {
jpeg_space,
pairs: highlights(&sensor, &reference),
clipped: clipped_highlights(&sensor, &reference, &clipped),
dro,
grey: true,
};
let Some(look) = fit_tone_only_with(unclipped.as_ref().unwrap_or(&sensor), &reference, colour, &bright) else { return (None, true) };
look
}
Expand All @@ -59,7 +65,7 @@ pub(super) const SENSOR_CLIP: f32 = 0.99;
/// [`fit_look_with`] for a photo without Sony's DRO.
#[cfg(test)]
pub(super) fn fit_look(sensor: &Rgb32f, reference: &Rgb32f, clipped: &[bool], colour: Option<(Mat3, Option<HsvTable>)>) -> Option<CameraLook> {
fit_look_with(sensor, reference, clipped, colour, false)
fit_look_with(sensor, reference, clipped, colour, false, None)
}

/// The photo's look, refitted without the proxy pixels whose sensor values are clipped.
Expand All @@ -86,10 +92,17 @@ pub(super) fn fit_look_with(
clipped: &[bool],
colour: Option<(Mat3, Option<HsvTable>)>,
dro: bool,
jpeg_space: Option<lightcraft_codecs::NamedSpace>,
) -> Option<CameraLook> {
let unclipped = without_clipped(sensor, clipped);
// from the proxies as they are: the retries' filters (clipped pixels, edges) don't remove them
let bright = HighlightCheck { pairs: highlights(sensor, reference), dro, grey: false };
let bright = HighlightCheck {
jpeg_space,
pairs: highlights(sensor, reference),
clipped: clipped_highlights(sensor, reference, clipped),
dro,
grey: false,
};
let Some((look, attempt)) = search_ordered(sensor, reference, colour.clone(), TONE_FITS, &bright) else {
return unclipped
.as_ref()
Expand Down Expand Up @@ -219,7 +232,7 @@ pub(super) fn fit_dng_tone(
}
None
};
let Some((mut sensor, reference, clipped)) = proxies(raw, bytes, transform, PROXY, MIN_PREVIEW_FRACTION, None, None) else {
let Some((mut sensor, reference, clipped, jpeg_space)) = proxies(raw, bytes, transform, PROXY, MIN_PREVIEW_FRACTION, None, None) else {
return refuse("preview");
};
// As the loader renders it: the profile's tables around the baseline exposure.
Expand All @@ -238,7 +251,13 @@ pub(super) fn fit_dng_tone(
let unclipped = without_clipped(&sensor, &clipped);
let fit_on = unclipped.as_ref().unwrap_or(&sensor);
let colour = Some((Mat3::IDENTITY, None));
let bright = HighlightCheck { pairs: highlights(&sensor, &reference), dro: false, grey: false };
let bright = HighlightCheck {
jpeg_space,
pairs: highlights(&sensor, &reference),
clipped: clipped_highlights(&sensor, &reference, &clipped),
dro: false,
grey: false,
};
let look = TONE_FITS.iter().find_map(|&tone| {
[false, true].into_iter().find_map(|away_from_edges| {
fit_attempt(fit_on, &reference, &colour, Attempt { tone, profile: true, away_from_edges, dark: true }, &bright)
Expand Down Expand Up @@ -281,7 +300,7 @@ pub(super) fn look_proxies(
transform: &CameraTransform,
lens: Option<&LensGeometry>,
embedded: Option<&lightcraft_develop::EmbeddedLens>,
) -> Option<(Rgb32f, Rgb32f, Vec<bool>)> {
) -> Option<(Rgb32f, Rgb32f, Vec<bool>, Option<lightcraft_codecs::NamedSpace>)> {
proxies(raw, bytes, transform, PROXY, 0.0, lens, embedded)
}

Expand Down
23 changes: 17 additions & 6 deletions crates/engine/src/camera_preview/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::pairs::{
rank_correlation_ties,
};
use super::proxy::LensGeometry;
use super::tone::{HighlightCheck, ToneFit, fit_tone, highlights, highlights_hold};
use super::tone::{HighlightCheck, ToneFit, clipped_highlights, fit_tone, highlights, highlights_hold};
use super::{CameraLook, CameraTransform, D50, D65, HsvTable, Mat3, PROPHOTO, REC2020, RawImage, Rgb32f, ToneMap, bradford, luminance_2020};

/// A camera JPEG pixel's channels may differ by this much (linear) and still count as grey.
Expand Down Expand Up @@ -44,14 +44,20 @@ pub(super) fn monochrome_look(
if !file_local_look(raw.format) {
return None;
}
let (sensor, reference, clipped) = look_proxies(raw, bytes, transform, lens, embedded)?;
let (sensor, reference, clipped, jpeg_space) = look_proxies(raw, bytes, transform, lens, embedded)?;
if !monochrome(&reference) {
return None;
}
// Sony's Dynamic Range Optimizer brightens a B/W JPEG as much as a colour one
let dro = lightcraft_raw::embedded_preview_dynamic_range_optimized(bytes) == Some(true);
let unclipped = without_clipped(&sensor, &clipped);
let bright = HighlightCheck { pairs: highlights(&sensor, &reference), dro, grey: true };
let bright = HighlightCheck {
jpeg_space,
pairs: highlights(&sensor, &reference),
clipped: clipped_highlights(&sensor, &reference, &clipped),
dro,
grey: true,
};
let look = fit_tone_only_with(unclipped.as_ref().unwrap_or(&sensor), &reference, None, &bright)?;
let look = if dro { with_dro_off_tone(look) } else { look };
if lightcraft_pipeline::profiling() {
Expand Down Expand Up @@ -83,7 +89,12 @@ pub(super) fn fit_tone_only_with(
/// [`fit_tone_only_with`] for a photo without Sony's DRO, checked against its own bright areas.
#[cfg(test)]
pub(super) fn fit_tone_only(sensor: &Rgb32f, reference: &Rgb32f, colour: Option<(Mat3, Option<HsvTable>)>) -> Option<CameraLook> {
fit_tone_only_with(sensor, reference, colour, &HighlightCheck { pairs: highlights(sensor, reference), dro: false, grey: true })
fit_tone_only_with(
sensor,
reference,
colour,
&HighlightCheck { jpeg_space: None, pairs: highlights(sensor, reference), clipped: Vec::new(), dro: false, grey: true },
)
}

fn fit_tone_only_on(
Expand Down Expand Up @@ -117,7 +128,7 @@ pub(super) fn fit_dark_tone(sensor: &Rgb32f, reference: &Rgb32f, clipped: &[bool
return None;
}
// no JPEG pixel reaches 0.85 here, so the bright-area check has nothing to hold
let bright = HighlightCheck { pairs: highlights(sensor, reference), dro: false, grey: true };
let bright = HighlightCheck { jpeg_space: None, pairs: highlights(sensor, reference), clipped: Vec::new(), dro: false, grey: true };
[None, Some(EDGE_CONTRAST)].into_iter().find_map(|edge_limit| {
let pairs: Pairs = sensor
.data
Expand Down Expand Up @@ -182,7 +193,7 @@ fn fit_tone_only_pairs(
pairs.iter().enumerate().filter(|(i, _)| i % 3 != 0).map(|(_, (x, y))| (luma(coloured(*x).map(|v| v.max(0.0))), luma(*y))).collect(),
)?
} else {
fit_tone_with_shadows(ToneFit::Quantile, pairs, sensor, reference, edge_limit, coloured)?
fit_tone_with_shadows(ToneFit::Quantile, pairs, &[], sensor, reference, edge_limit, coloured)?
};
let look = CameraLook { matrix, tone, hue_sat: hue_sat.clone() };
if !highlights_hold(&look.tone, highlights, coloured) {
Expand Down
Loading
Loading