From 8b0e348fe84ba0ba189310683602f4fb85ddcbd0 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 20 Nov 2026 16:02:05 -0500 Subject: [PATCH 1/5] develop,pipeline,color: add Process::V9 checked warm-green WB fallback (#587) --- Cargo.lock | 32 +++++++++++++++++++++-- Cargo.toml | 1 + crates/color/Cargo.toml | 1 + crates/color/src/cct.rs | 14 ++++++++++ crates/develop/src/settings.rs | 9 +++++-- crates/gpu/tests/it/equivalence.rs | 21 +++++++++++++++ crates/pipeline/src/finish.rs | 6 ++--- crates/pipeline/src/light_v3.rs | 2 +- crates/pipeline/src/local.rs | 15 ++++++++--- crates/pipeline/src/tests.rs | 42 ++++++++++++++++++++++++++++++ crates/pipeline/src/tests_grain.rs | 2 +- 11 files changed, 132 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 71da5b6f9dc..2d9b9b206a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1196,11 +1196,38 @@ dependencies = [ "rayon", ] +[[package]] +name = "craft-cms" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=d7fc79387dadb8bd666e0ae4fbfc4b3fc6710373#d7fc79387dadb8bd666e0ae4fbfc4b3fc6710373" +dependencies = [ + "md-5", + "rayon", +] + [[package]] name = "craft-codepage" version = "0.1.0" source = "git+https://github.com/storytold/craft-libs?rev=23acc704933a9a5619a5cd1cddc9bb1fb5a9b2d3#23acc704933a9a5619a5cd1cddc9bb1fb5a9b2d3" +[[package]] +name = "craft-color" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=d7fc79387dadb8bd666e0ae4fbfc4b3fc6710373#d7fc79387dadb8bd666e0ae4fbfc4b3fc6710373" +dependencies = [ + "serde", +] + +[[package]] +name = "craft-color-transform" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=d7fc79387dadb8bd666e0ae4fbfc4b3fc6710373#d7fc79387dadb8bd666e0ae4fbfc4b3fc6710373" +dependencies = [ + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=d7fc79387dadb8bd666e0ae4fbfc4b3fc6710373)", + "craft-color", + "serde", +] + [[package]] name = "craft-crw" version = "0.1.0" @@ -3961,7 +3988,7 @@ name = "lightcraft-codecs" version = "0.21.1" dependencies = [ "bytemuck", - "craft-cms", + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=23acc704933a9a5619a5cd1cddc9bb1fb5a9b2d3)", "craft-gainmap", "craft-gif", "craft-heif", @@ -3989,6 +4016,7 @@ dependencies = [ name = "lightcraft-color" version = "0.21.1" dependencies = [ + "craft-color-transform", "lightcraft-geom", "proptest", "serde", @@ -4227,7 +4255,7 @@ dependencies = [ name = "lightcraft-pipeline" version = "0.21.1" dependencies = [ - "craft-cms", + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=23acc704933a9a5619a5cd1cddc9bb1fb5a9b2d3)", "craft-image-codecs", "dhat", "lightcraft-color", diff --git a/Cargo.toml b/Cargo.toml index f990d90e27a..e0013e4b388 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-l # Canon CRW decoder shared with the other Craft apps craft-crw = { git = "https://github.com/storytold/craft-libs", rev = "23acc704933a9a5619a5cd1cddc9bb1fb5a9b2d3" } craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "23acc704933a9a5619a5cd1cddc9bb1fb5a9b2d3" } +craft-color-transform = { git = "https://github.com/storytold/craft-libs", rev = "d7fc79387dadb8bd666e0ae4fbfc4b3fc6710373" } craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "23acc704933a9a5619a5cd1cddc9bb1fb5a9b2d3", version = "0.1.0" } craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "23acc704933a9a5619a5cd1cddc9bb1fb5a9b2d3", features = ["frames"] } craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "23acc704933a9a5619a5cd1cddc9bb1fb5a9b2d3", default-features = false, features = ["decode", "encode"] } diff --git a/crates/color/Cargo.toml b/crates/color/Cargo.toml index b16a3dcef36..edb24f81501 100644 --- a/crates/color/Cargo.toml +++ b/crates/color/Cargo.toml @@ -9,6 +9,7 @@ description = "LightCraft color (L0)" workspace = true [dependencies] +craft-color-transform = { workspace = true } serde = { workspace = true } lightcraft-geom = { workspace = true } diff --git a/crates/color/src/cct.rs b/crates/color/src/cct.rs index 9cb2b96c5d4..167f6aff614 100644 --- a/crates/color/src/cct.rs +++ b/crates/color/src/cct.rs @@ -117,6 +117,20 @@ pub fn wb_matrix(space: &RgbSpace, src: Xy) -> Mat3 { space.from_xyz().mul(&adapt).mul(&space.to_xyz()) } +/// Checked Bradford white-balance matrix from `craft_color_transform::cct::wb_matrix`: +/// returns `Mat3::IDENTITY` adaptation when the source illuminant's Bradford blue cone response +/// is `<= 0.0` (warm, strongly green illuminants). +pub fn wb_matrix_checked(space: &RgbSpace, src: Xy) -> Mat3 { + let shared_space = craft_color_transform::space::RgbSpace { + r: craft_color_transform::Xy::new(space.r.x, space.r.y), + g: craft_color_transform::Xy::new(space.g.x, space.g.y), + b: craft_color_transform::Xy::new(space.b.x, space.b.y), + white: craft_color_transform::Xy::new(space.white.x, space.white.y), + }; + let m = craft_color_transform::cct::wb_matrix(&shared_space, craft_color_transform::Xy::new(src.x, src.y)); + Mat3(m.0) +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/develop/src/settings.rs b/crates/develop/src/settings.rs index a4e6eab1476..b91f991c6aa 100644 --- a/crates/develop/src/settings.rs +++ b/crates/develop/src/settings.rs @@ -102,12 +102,16 @@ pub enum Process { /// V7, with the Highlights/Shadows base taken of log luminance without its fine detail (clamped /// between a fine and a 3× wider median), so gaps in dark lettering aren't lifted into bright blocks. V8, + /// V8, with the checked Bradford white-balance fallback (`Mat3::IDENTITY` when a source + /// illuminant's Bradford blue cone response is `<= 0.0`, `craft-libs#587`). + V9, } impl Process { /// Every process, oldest first. - pub const ALL: [Process; 8] = [Process::V1, Process::V2, Process::V3, Process::V4, Process::V5, Process::V6, Process::V7, Process::V8]; - pub const LATEST: Process = Process::V8; + pub const ALL: [Process; 9] = + [Process::V1, Process::V2, Process::V3, Process::V4, Process::V5, Process::V6, Process::V7, Process::V8, Process::V9]; + pub const LATEST: Process = Process::V9; pub const fn version(self) -> ProcessVersion { match self { @@ -119,6 +123,7 @@ impl Process { Process::V6 => ProcessVersion(6), Process::V7 => ProcessVersion(7), Process::V8 => ProcessVersion(8), + Process::V9 => ProcessVersion(9), } } } diff --git a/crates/gpu/tests/it/equivalence.rs b/crates/gpu/tests/it/equivalence.rs index a8fa80f8120..7861a8ea0cb 100644 --- a/crates/gpu/tests/it/equivalence.rs +++ b/crates/gpu/tests/it/equivalence.rs @@ -76,6 +76,27 @@ fn v3_luminance_cutoff_chroma_4() { check_v3_luminance_cutoff(4.0, [0.035_338_085, 0.000_048_468_723, 0.010_193_758], [47, 0, 19, 255]); } +#[test] +fn warm_green_wb_zero_crossing_gpu_matches_cpu_on_v9() { + if !gpu() { + return; + } + let src = scene(2, 160, 120); + let info = SourceInfo { as_shot_temp: 5500.0, as_shot_tint: 0.0, ..Default::default() }; + let req = RenderRequest::fit(160, 120); + // Test across the Bradford blue-cone s[2] <= 0.0 zero crossing on Process::V9: + // (2000 K, 0) has s[2] > 0; (2000 K, 30) and (3000 K, 100) have s[2] <= 0. + for (temp, tint) in [(2000.0, 0.0), (2000.0, 30.0), (3000.0, 100.0)] { + let mut s = DevelopSettings::default(); + assert_eq!(s.process.process(), Process::V9); + (s.wb.mode, s.wb.temp, s.wb.tint) = (WbMode::Custom, temp, tint); + let cpu = render(&src, &info, &s, &req).image; + let gpu = lightcraft_gpu::try_render(&src, &info, &s, &req, None).expect("GPU render without CPU fallback").image; + let (mean, max, _) = diff(&cpu, &gpu); + assert!(mean < MEAN_LSB && max <= MAX_LSB, "{temp} K tint {tint}: mean {mean:.3}, max {max}"); + } +} + #[test] fn camera_tone_and_relative_wb() { if !gpu() { diff --git a/crates/pipeline/src/finish.rs b/crates/pipeline/src/finish.rs index a4ec7ddec32..b3d0408bc22 100644 --- a/crates/pipeline/src/finish.rs +++ b/crates/pipeline/src/finish.rs @@ -148,8 +148,8 @@ impl GrainModel { seed: g.seed, }) }), - Process::V7 | Process::V8 if draft => crate::crystal::CrystalGrain::draft(g, px_per_long).map(GrainModel::Crystal), - Process::V7 | Process::V8 => crate::crystal::CrystalGrain::new(g, px_per_long).map(GrainModel::Crystal), + Process::V7 | Process::V8 | Process::V9 if draft => crate::crystal::CrystalGrain::draft(g, px_per_long).map(GrainModel::Crystal), + Process::V7 | Process::V8 | Process::V9 => crate::crystal::CrystalGrain::new(g, px_per_long).map(GrainModel::Crystal), } } } @@ -407,7 +407,7 @@ pub fn base_tone(s: &DevelopSettings, info: &SourceInfo, peak: f32) -> ToneMap { }, // V4, with a raw's tone curve rolling off into white in stops: a camera curve past its last // knot, the generic curve from half a stop below its white point instead of clipping (issue #1632) - Process::V5 | Process::V6 | Process::V7 | Process::V8 => match info.camera_tone.as_ref().filter(|_| info.raw) { + Process::V5 | Process::V6 | Process::V7 | Process::V8 | Process::V9 => match info.camera_tone.as_ref().filter(|_| info.raw) { Some(curve) => ToneMap::camera_rolloff_hdr(curve, 0.0, l.whites, 0.0, peak), None if info.raw => ToneMap::rolloff_hdr(l.contrast, l.whites, l.blacks, peak), None => ToneMap::display_hdr(l.contrast, l.whites, l.blacks, peak), diff --git a/crates/pipeline/src/light_v3.rs b/crates/pipeline/src/light_v3.rs index 5f3e0f9bf24..da245e7995b 100644 --- a/crates/pipeline/src/light_v3.rs +++ b/crates/pipeline/src/light_v3.rs @@ -284,7 +284,7 @@ pub fn applies(s: &DevelopSettings, info: &SourceInfo) -> bool { let camera_look = info.raw && info.camera_tone.is_some(); match s.process.process() { Process::V1 | Process::V2 | Process::V3 => false, - Process::V4 | Process::V5 | Process::V6 | Process::V7 | Process::V8 => camera_look, + Process::V4 | Process::V5 | Process::V6 | Process::V7 | Process::V8 | Process::V9 => camera_look, } } diff --git a/crates/pipeline/src/local.rs b/crates/pipeline/src/local.rs index 749e10139df..68d690c03b2 100644 --- a/crates/pipeline/src/local.rs +++ b/crates/pipeline/src/local.rs @@ -1,7 +1,7 @@ //! Scene-linear preparation: white balance + exposure, and the spatial planes the per-pixel stage //! needs (edge-aware base layer for highlights/shadows, clarity/texture bands, dehaze veil). -use lightcraft_color::cct::{temp_tint_to_xy, wb_matrix, xy_to_temp_tint}; +use lightcraft_color::cct::{temp_tint_to_xy, wb_matrix, wb_matrix_checked, xy_to_temp_tint}; use lightcraft_color::{REC2020, luminance_2020}; use lightcraft_develop::{DevelopSettings, Process}; use lightcraft_raster::blur::{gauss_taps, gaussian, gaussian_taps}; @@ -37,8 +37,13 @@ pub fn wb_matrix_for(info: &SourceInfo, s: &DevelopSettings) -> Option<[[f32; 3] { return Some(m.to_f32()); } - let set = wb_matrix(&REC2020, effective_white(info, s)); - let shot = wb_matrix(&REC2020, temp_tint_to_xy(info.as_shot_temp, info.as_shot_tint)); + let checked = s.process.process() >= Process::V9; + let set = if checked { wb_matrix_checked(&REC2020, effective_white(info, s)) } else { wb_matrix(&REC2020, effective_white(info, s)) }; + let shot = if checked { + wb_matrix_checked(&REC2020, temp_tint_to_xy(info.as_shot_temp, info.as_shot_tint)) + } else { + wb_matrix(&REC2020, temp_tint_to_xy(info.as_shot_temp, info.as_shot_tint)) + }; let m = set.mul(&shot.inverse().unwrap_or(lightcraft_color::Mat3::IDENTITY)); // Normalize so neutral luminance is preserved (WB shouldn't change exposure). let g = m.apply([1.0, 1.0, 1.0]); @@ -375,7 +380,9 @@ pub fn base_detail_radius(px_per_long: f64) -> usize { pub fn tone_base_detail(s: &DevelopSettings, px_per_long: f64) -> usize { match s.process.process() { Process::V1 => 0, - Process::V2 | Process::V3 | Process::V4 | Process::V5 | Process::V6 | Process::V7 | Process::V8 => base_detail_radius(px_per_long), + Process::V2 | Process::V3 | Process::V4 | Process::V5 | Process::V6 | Process::V7 | Process::V8 | Process::V9 => { + base_detail_radius(px_per_long) + } } } diff --git a/crates/pipeline/src/tests.rs b/crates/pipeline/src/tests.rs index f1229bd5690..9330a094678 100644 --- a/crates/pipeline/src/tests.rs +++ b/crates/pipeline/src/tests.rs @@ -775,6 +775,48 @@ fn custom_white_balance_redevelops_in_camera_space() { assert!(wb_matrix_for(&info, &s).is_none()); } +#[test] +fn saved_warm_green_wb_preserves_legacy_bradford_while_v9_uses_checked_fallback() { + use crate::local::wb_matrix_for; + use lightcraft_color::REC2020; + use lightcraft_color::cct::{temp_tint_to_xy, wb_matrix, wb_matrix_checked}; + use lightcraft_develop::{Process, ProcessVersion, WbMode}; + + let info = SourceInfo { as_shot_temp: 5500.0, as_shot_tint: 0.0, ..Default::default() }; + // Saved V8 edit in the reachable warm-green region (Bradford blue cone response <= 0.0) + // must reopen without upgrading its process version and must keep the legacy Bradford result. + let saved_json = serde_json::json!({ + "process": 8, + "wb": { "mode": "Custom", "temp": 2000.0, "tint": 30.0 } + }); + let saved = DevelopSettings::from_json(&saved_json).unwrap(); + assert_eq!(saved.process, ProcessVersion(8)); + assert_eq!(saved.process.process(), Process::V8); + let legacy_m = wb_matrix_for(&info, &saved).unwrap(); + + // New V9 edit at the same warm-green WB uses the shared checked Mat3::IDENTITY fallback. + let mut v9 = DevelopSettings::default(); + assert_eq!(v9.process.process(), Process::V9); + (v9.wb.mode, v9.wb.temp, v9.wb.tint) = (WbMode::Custom, 2000.0, 30.0); + let v9_m = wb_matrix_for(&info, &v9).unwrap(); + + assert_ne!(legacy_m, v9_m, "saved V8 edit must not silently adopt V9's checked fallback"); + + // Verify exact correspondence to legacy wb_matrix (V8) vs checked wb_matrix_checked (V9). + let expected_shot = wb_matrix(&REC2020, temp_tint_to_xy(5500.0, 0.0)).inverse().unwrap(); + let legacy_raw = wb_matrix(&REC2020, temp_tint_to_xy(2000.0, 30.0)).mul(&expected_shot); + let legacy_g = legacy_raw.apply([1.0, 1.0, 1.0]); + let legacy_y = legacy_g[0] * 0.2627 + legacy_g[1] * 0.6780 + legacy_g[2] * 0.0593; + let legacy_expected = legacy_raw.mul(&lightcraft_color::Mat3::diag(1.0 / legacy_y, 1.0 / legacy_y, 1.0 / legacy_y)).to_f32(); + assert_eq!(legacy_m, legacy_expected); + + let v9_raw = wb_matrix_checked(&REC2020, temp_tint_to_xy(2000.0, 30.0)).mul(&expected_shot); + let v9_g = v9_raw.apply([1.0, 1.0, 1.0]); + let v9_y = v9_g[0] * 0.2627 + v9_g[1] * 0.6780 + v9_g[2] * 0.0593; + let v9_expected = v9_raw.mul(&lightcraft_color::Mat3::diag(1.0 / v9_y, 1.0 / v9_y, 1.0 / v9_y)).to_f32(); + assert_eq!(v9_m, v9_expected); +} + /// Every stored process number renders with a process this build knows: settings saved before /// process versions existed exactly as V1, and a number from a newer LightCraft exactly as the /// latest process here (`docs/process-versions.md`). Raw (base tone curve), camera-tone and diff --git a/crates/pipeline/src/tests_grain.rs b/crates/pipeline/src/tests_grain.rs index 9dc48924530..4da1820d361 100644 --- a/crates/pipeline/src/tests_grain.rs +++ b/crates/pipeline/src/tests_grain.rs @@ -35,7 +35,7 @@ fn processes_before_v7_keep_the_value_noise() { Process::V1 | Process::V2 | Process::V3 | Process::V4 | Process::V5 | Process::V6 => { assert!(matches!(model, Some(GrainModel::Value(_))), "{p:?}") } - Process::V7 | Process::V8 => assert!(matches!(model, Some(GrainModel::Crystal(_))), "{p:?}"), + Process::V7 | Process::V8 | Process::V9 => assert!(matches!(model, Some(GrainModel::Crystal(_))), "{p:?}"), } assert!(GrainModel::new(&on(p, 0.0), 2000.0, false).is_none(), "{p:?}: no grain at Amount 0"); } From ceadfc56266f79c9f2fdad7e3a8089c16cf11afc Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 20 Nov 2026 16:06:29 -0500 Subject: [PATCH 2/5] fix(color): use root-reexported craft_color_transform::RgbSpace --- crates/color/src/cct.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/color/src/cct.rs b/crates/color/src/cct.rs index 167f6aff614..20c0fdb1ab1 100644 --- a/crates/color/src/cct.rs +++ b/crates/color/src/cct.rs @@ -121,7 +121,7 @@ pub fn wb_matrix(space: &RgbSpace, src: Xy) -> Mat3 { /// returns `Mat3::IDENTITY` adaptation when the source illuminant's Bradford blue cone response /// is `<= 0.0` (warm, strongly green illuminants). pub fn wb_matrix_checked(space: &RgbSpace, src: Xy) -> Mat3 { - let shared_space = craft_color_transform::space::RgbSpace { + let shared_space = craft_color_transform::RgbSpace { r: craft_color_transform::Xy::new(space.r.x, space.r.y), g: craft_color_transform::Xy::new(space.g.x, space.g.y), b: craft_color_transform::Xy::new(space.b.x, space.b.y), From 1b905a00c05c50a4f156b09b6c2c84765418c287 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 20 Nov 2026 16:47:34 -0500 Subject: [PATCH 3/5] develop,pipeline,docs: use Process::V10 for checked WB and reserve V9 for #4069 --- crates/develop/src/settings.rs | 11 ++++++----- crates/develop/src/tests_process.rs | 3 +++ crates/gpu/tests/it/equivalence.rs | 6 +++--- crates/pipeline/src/finish.rs | 6 +++--- crates/pipeline/src/light_v3.rs | 2 +- crates/pipeline/src/local.rs | 4 ++-- crates/pipeline/src/tests.rs | 30 ++++++++++++++--------------- crates/pipeline/src/tests_grain.rs | 2 +- docs/process-versions.md | 4 +++- 9 files changed, 37 insertions(+), 31 deletions(-) diff --git a/crates/develop/src/settings.rs b/crates/develop/src/settings.rs index b91f991c6aa..c069e859f58 100644 --- a/crates/develop/src/settings.rs +++ b/crates/develop/src/settings.rs @@ -104,14 +104,15 @@ pub enum Process { V8, /// V8, with the checked Bradford white-balance fallback (`Mat3::IDENTITY` when a source /// illuminant's Bradford blue cone response is `<= 0.0`, `craft-libs#587`). - V9, + /// `ProcessVersion(9)` is reserved for `HealMethod::Pinned` (`#4069`). + V10, } impl Process { - /// Every process, oldest first. + /// Every process, oldest first (`ProcessVersion(9)` is reserved for `#4069`). pub const ALL: [Process; 9] = - [Process::V1, Process::V2, Process::V3, Process::V4, Process::V5, Process::V6, Process::V7, Process::V8, Process::V9]; - pub const LATEST: Process = Process::V9; + [Process::V1, Process::V2, Process::V3, Process::V4, Process::V5, Process::V6, Process::V7, Process::V8, Process::V10]; + pub const LATEST: Process = Process::V10; pub const fn version(self) -> ProcessVersion { match self { @@ -123,7 +124,7 @@ impl Process { Process::V6 => ProcessVersion(6), Process::V7 => ProcessVersion(7), Process::V8 => ProcessVersion(8), - Process::V9 => ProcessVersion(9), + Process::V10 => ProcessVersion(10), } } } diff --git a/crates/develop/src/tests_process.rs b/crates/develop/src/tests_process.rs index 1694a3ea075..d576dab4caa 100644 --- a/crates/develop/src/tests_process.rs +++ b/crates/develop/src/tests_process.rs @@ -103,6 +103,9 @@ fn unknown_process_numbers_load_and_render_with_the_newest_known() { assert_eq!(max.process(), Process::LATEST); // a whole number written as a float is that number assert_eq!(DevelopSettings::from_json(&json!({"process": 2.0})).unwrap().process, ProcessVersion(2)); + // reserved V9 falls back to V8 without upgrading to V10 + let reserved_v9 = DevelopSettings::from_json(&json!({"process": 9})).unwrap().process; + assert_eq!((reserved_v9.process(), reserved_v9.is_known(), reserved_v9.is_outdated()), (Process::V8, false, true)); } #[test] diff --git a/crates/gpu/tests/it/equivalence.rs b/crates/gpu/tests/it/equivalence.rs index 7861a8ea0cb..2833c475fc8 100644 --- a/crates/gpu/tests/it/equivalence.rs +++ b/crates/gpu/tests/it/equivalence.rs @@ -77,18 +77,18 @@ fn v3_luminance_cutoff_chroma_4() { } #[test] -fn warm_green_wb_zero_crossing_gpu_matches_cpu_on_v9() { +fn warm_green_wb_zero_crossing_gpu_matches_cpu_on_v10() { if !gpu() { return; } let src = scene(2, 160, 120); let info = SourceInfo { as_shot_temp: 5500.0, as_shot_tint: 0.0, ..Default::default() }; let req = RenderRequest::fit(160, 120); - // Test across the Bradford blue-cone s[2] <= 0.0 zero crossing on Process::V9: + // Test across the Bradford blue-cone s[2] <= 0.0 zero crossing on Process::V10: // (2000 K, 0) has s[2] > 0; (2000 K, 30) and (3000 K, 100) have s[2] <= 0. for (temp, tint) in [(2000.0, 0.0), (2000.0, 30.0), (3000.0, 100.0)] { let mut s = DevelopSettings::default(); - assert_eq!(s.process.process(), Process::V9); + assert_eq!(s.process.process(), Process::V10); (s.wb.mode, s.wb.temp, s.wb.tint) = (WbMode::Custom, temp, tint); let cpu = render(&src, &info, &s, &req).image; let gpu = lightcraft_gpu::try_render(&src, &info, &s, &req, None).expect("GPU render without CPU fallback").image; diff --git a/crates/pipeline/src/finish.rs b/crates/pipeline/src/finish.rs index b3d0408bc22..014c2573b7b 100644 --- a/crates/pipeline/src/finish.rs +++ b/crates/pipeline/src/finish.rs @@ -148,8 +148,8 @@ impl GrainModel { seed: g.seed, }) }), - Process::V7 | Process::V8 | Process::V9 if draft => crate::crystal::CrystalGrain::draft(g, px_per_long).map(GrainModel::Crystal), - Process::V7 | Process::V8 | Process::V9 => crate::crystal::CrystalGrain::new(g, px_per_long).map(GrainModel::Crystal), + Process::V7 | Process::V8 | Process::V10 if draft => crate::crystal::CrystalGrain::draft(g, px_per_long).map(GrainModel::Crystal), + Process::V7 | Process::V8 | Process::V10 => crate::crystal::CrystalGrain::new(g, px_per_long).map(GrainModel::Crystal), } } } @@ -407,7 +407,7 @@ pub fn base_tone(s: &DevelopSettings, info: &SourceInfo, peak: f32) -> ToneMap { }, // V4, with a raw's tone curve rolling off into white in stops: a camera curve past its last // knot, the generic curve from half a stop below its white point instead of clipping (issue #1632) - Process::V5 | Process::V6 | Process::V7 | Process::V8 | Process::V9 => match info.camera_tone.as_ref().filter(|_| info.raw) { + Process::V5 | Process::V6 | Process::V7 | Process::V8 | Process::V10 => match info.camera_tone.as_ref().filter(|_| info.raw) { Some(curve) => ToneMap::camera_rolloff_hdr(curve, 0.0, l.whites, 0.0, peak), None if info.raw => ToneMap::rolloff_hdr(l.contrast, l.whites, l.blacks, peak), None => ToneMap::display_hdr(l.contrast, l.whites, l.blacks, peak), diff --git a/crates/pipeline/src/light_v3.rs b/crates/pipeline/src/light_v3.rs index da245e7995b..d9f4fac5d39 100644 --- a/crates/pipeline/src/light_v3.rs +++ b/crates/pipeline/src/light_v3.rs @@ -284,7 +284,7 @@ pub fn applies(s: &DevelopSettings, info: &SourceInfo) -> bool { let camera_look = info.raw && info.camera_tone.is_some(); match s.process.process() { Process::V1 | Process::V2 | Process::V3 => false, - Process::V4 | Process::V5 | Process::V6 | Process::V7 | Process::V8 | Process::V9 => camera_look, + Process::V4 | Process::V5 | Process::V6 | Process::V7 | Process::V8 | Process::V10 => camera_look, } } diff --git a/crates/pipeline/src/local.rs b/crates/pipeline/src/local.rs index 68d690c03b2..e68bd31b037 100644 --- a/crates/pipeline/src/local.rs +++ b/crates/pipeline/src/local.rs @@ -37,7 +37,7 @@ pub fn wb_matrix_for(info: &SourceInfo, s: &DevelopSettings) -> Option<[[f32; 3] { return Some(m.to_f32()); } - let checked = s.process.process() >= Process::V9; + let checked = s.process.process() >= Process::V10; let set = if checked { wb_matrix_checked(&REC2020, effective_white(info, s)) } else { wb_matrix(&REC2020, effective_white(info, s)) }; let shot = if checked { wb_matrix_checked(&REC2020, temp_tint_to_xy(info.as_shot_temp, info.as_shot_tint)) @@ -380,7 +380,7 @@ pub fn base_detail_radius(px_per_long: f64) -> usize { pub fn tone_base_detail(s: &DevelopSettings, px_per_long: f64) -> usize { match s.process.process() { Process::V1 => 0, - Process::V2 | Process::V3 | Process::V4 | Process::V5 | Process::V6 | Process::V7 | Process::V8 | Process::V9 => { + Process::V2 | Process::V3 | Process::V4 | Process::V5 | Process::V6 | Process::V7 | Process::V8 | Process::V10 => { base_detail_radius(px_per_long) } } diff --git a/crates/pipeline/src/tests.rs b/crates/pipeline/src/tests.rs index 9330a094678..45d77643832 100644 --- a/crates/pipeline/src/tests.rs +++ b/crates/pipeline/src/tests.rs @@ -776,15 +776,15 @@ fn custom_white_balance_redevelops_in_camera_space() { } #[test] -fn saved_warm_green_wb_preserves_legacy_bradford_while_v9_uses_checked_fallback() { +fn saved_warm_green_wb_preserves_legacy_bradford_while_v10_uses_checked_fallback() { use crate::local::wb_matrix_for; use lightcraft_color::REC2020; use lightcraft_color::cct::{temp_tint_to_xy, wb_matrix, wb_matrix_checked}; use lightcraft_develop::{Process, ProcessVersion, WbMode}; let info = SourceInfo { as_shot_temp: 5500.0, as_shot_tint: 0.0, ..Default::default() }; - // Saved V8 edit in the reachable warm-green region (Bradford blue cone response <= 0.0) - // must reopen without upgrading its process version and must keep the legacy Bradford result. + // Saved V8 (and reserved V9) edits in the reachable warm-green region (Bradford blue cone + // response <= 0.0) must reopen without upgrading and must keep the legacy Bradford result. let saved_json = serde_json::json!({ "process": 8, "wb": { "mode": "Custom", "temp": 2000.0, "tint": 30.0 } @@ -794,15 +794,15 @@ fn saved_warm_green_wb_preserves_legacy_bradford_while_v9_uses_checked_fallback( assert_eq!(saved.process.process(), Process::V8); let legacy_m = wb_matrix_for(&info, &saved).unwrap(); - // New V9 edit at the same warm-green WB uses the shared checked Mat3::IDENTITY fallback. - let mut v9 = DevelopSettings::default(); - assert_eq!(v9.process.process(), Process::V9); - (v9.wb.mode, v9.wb.temp, v9.wb.tint) = (WbMode::Custom, 2000.0, 30.0); - let v9_m = wb_matrix_for(&info, &v9).unwrap(); + // New V10 edit at the same warm-green WB uses the shared checked Mat3::IDENTITY fallback. + let mut v10 = DevelopSettings::default(); + assert_eq!(v10.process.process(), Process::V10); + (v10.wb.mode, v10.wb.temp, v10.wb.tint) = (WbMode::Custom, 2000.0, 30.0); + let v10_m = wb_matrix_for(&info, &v10).unwrap(); - assert_ne!(legacy_m, v9_m, "saved V8 edit must not silently adopt V9's checked fallback"); + assert_ne!(legacy_m, v10_m, "saved V8 edit must not silently adopt V10's checked fallback"); - // Verify exact correspondence to legacy wb_matrix (V8) vs checked wb_matrix_checked (V9). + // Verify exact correspondence to legacy wb_matrix (V8) vs checked wb_matrix_checked (V10). let expected_shot = wb_matrix(&REC2020, temp_tint_to_xy(5500.0, 0.0)).inverse().unwrap(); let legacy_raw = wb_matrix(&REC2020, temp_tint_to_xy(2000.0, 30.0)).mul(&expected_shot); let legacy_g = legacy_raw.apply([1.0, 1.0, 1.0]); @@ -810,11 +810,11 @@ fn saved_warm_green_wb_preserves_legacy_bradford_while_v9_uses_checked_fallback( let legacy_expected = legacy_raw.mul(&lightcraft_color::Mat3::diag(1.0 / legacy_y, 1.0 / legacy_y, 1.0 / legacy_y)).to_f32(); assert_eq!(legacy_m, legacy_expected); - let v9_raw = wb_matrix_checked(&REC2020, temp_tint_to_xy(2000.0, 30.0)).mul(&expected_shot); - let v9_g = v9_raw.apply([1.0, 1.0, 1.0]); - let v9_y = v9_g[0] * 0.2627 + v9_g[1] * 0.6780 + v9_g[2] * 0.0593; - let v9_expected = v9_raw.mul(&lightcraft_color::Mat3::diag(1.0 / v9_y, 1.0 / v9_y, 1.0 / v9_y)).to_f32(); - assert_eq!(v9_m, v9_expected); + let v10_raw = wb_matrix_checked(&REC2020, temp_tint_to_xy(2000.0, 30.0)).mul(&expected_shot); + let v10_g = v10_raw.apply([1.0, 1.0, 1.0]); + let v10_y = v10_g[0] * 0.2627 + v10_g[1] * 0.6780 + v10_g[2] * 0.0593; + let v10_expected = v10_raw.mul(&lightcraft_color::Mat3::diag(1.0 / v10_y, 1.0 / v10_y, 1.0 / v10_y)).to_f32(); + assert_eq!(v10_m, v10_expected); } /// Every stored process number renders with a process this build knows: settings saved before diff --git a/crates/pipeline/src/tests_grain.rs b/crates/pipeline/src/tests_grain.rs index 4da1820d361..00f83118fac 100644 --- a/crates/pipeline/src/tests_grain.rs +++ b/crates/pipeline/src/tests_grain.rs @@ -35,7 +35,7 @@ fn processes_before_v7_keep_the_value_noise() { Process::V1 | Process::V2 | Process::V3 | Process::V4 | Process::V5 | Process::V6 => { assert!(matches!(model, Some(GrainModel::Value(_))), "{p:?}") } - Process::V7 | Process::V8 | Process::V9 => assert!(matches!(model, Some(GrainModel::Crystal(_))), "{p:?}"), + Process::V7 | Process::V8 | Process::V10 => assert!(matches!(model, Some(GrainModel::Crystal(_))), "{p:?}"), } assert!(GrainModel::new(&on(p, 0.0), 2000.0, false).is_none(), "{p:?}: no grain at Amount 0"); } diff --git a/docs/process-versions.md b/docs/process-versions.md index 7424cf02e9f..6d00891ab9f 100644 --- a/docs/process-versions.md +++ b/docs/process-versions.md @@ -16,7 +16,9 @@ stronger Light sliders, issue #196) without changing a single photo someone has | **V5** | V4 plus: a raw's tone curve rolls off into white in stops instead of reaching it within about a stop of the sensor's white, so raising Exposure keeps the highlights the sensor recorded (issue #1632). **Camera curve** (the look fitted to the embedded JPEG, or a DNG's `ProfileToneCurve`; `CameraTone`): past its last knot `CameraTone::apply_rolloff` closes the gap to white by `gap / (1 + c·(2^t − 1))` at `t` stops past the knot, with `c` matching the curve's slope there and the gap halving every stop in the end (`tone::ROLLOFF_STOPS`); `ToneMap::camera_rolloff_hdr` builds the table from it. Under V1 to V4 the curve past its last knot (fitted only to camera JPEG tones below 0.85, so 1 to 3 stops below the sensor's white on most photos) closes on white exponentially in linear light: the sensor's white renders at 8-bit 246 to 254 at Exposure 0 and 254 to 255 from Exposure +1. On the 11 CC0 corpus files with a fitted look (8 Sony, 2 Nikon, 1 Fujifilm) it now renders at 239 to 250 at Exposure 0 and 247 to 253 at +1. A DNG curve that reaches white at the sensor's white renders as before. **Generic curve** (raws without a camera curve, `ToneMap::rolloff_hdr`): from half a stop below its white point (`tone::GENERIC_KNEE_STOPS`) the same shoulder takes over, with the extended Reinhard curve's value and slope at the join, where V1 to V4 clip at the white point (scene 1.18 at default settings, ¼ stop above the sensor's white). The sensor's white renders at about 235, 248 and 252 at Exposure 0, +1 and +2 (V1 to V4: 239, 255, 255; the CC0 Canon R8 file and 6 CC0 DNGs without a camera curve). Content past the old clip point, such as a clipped sky, now renders up to 15 codes below white at Exposure 0 and reaches 255 about 5 stops past the sensor's white. Below the last knot or the join, JPEGs and other display-referred sources, and the camera fit itself are unchanged; CPU and GPU share the tone LUT. | | **V6** | V5 plus: colour noise reduction filters the linear colour differences R−Y and B−Y with the joint method (issue #815, `docs/nr-color-joint.md`): edge-aware weights from a denoised guide shared by both differences, anisotropic diffusion over scales, a brake for isolated colour specks; Y is kept exactly. V1 to V5 keep the blurred chromaticity (`local::denoise`). CPU (`local::denoise`) and GPU (`render::denoise`) branch on `local::joint_colour_nr`. Renders with Color 0 are the same as V2's. | | **V7** | V6 plus: film grain from crystal layers ([grain.md](grain.md), `crates/pipeline/src/crystal.rs`), after Aurélien Pierre's model: resolution independent (a preview is the export's grain box-downscaled), fading out at black and white, calibrated to Lightroom Classic's strength and width at mid grey. V1 to V6 keep their two-octave value noise exactly (`finish::ValueGrain`; on the GPU `F_GRAIN_MODEL` 0); `finish::GrainModel::new` picks the model per process. Renders without grain don't depend on this. | -| **V8** (the latest) | V7 plus: Highlights and Shadows take their edge-aware filter of log luminance without its fine detail (`local::detail_free`: each value clamped between its separable median at the V2 radius and the median of a 3× wider neighbourhood) instead of V2's plain median (`local::base_keeps_gaps`), so the gaps in dark lettering on a bright panel are not lifted into bright blocks (issue #3460). CPU (`local::tone_base`) and GPU (`render::tone_base`) branch on it; the base plane is keyed by process. Renders without Highlights or Shadows (global or local) are the same as V7's. | +| **V8** | V7 plus: Highlights and Shadows take their edge-aware filter of log luminance without its fine detail (`local::detail_free`: each value clamped between its separable median at the V2 radius and the median of a 3× wider neighbourhood) instead of V2's plain median (`local::base_keeps_gaps`), so the gaps in dark lettering on a bright panel are not lifted into bright blocks (issue #3460). CPU (`local::tone_base`) and GPU (`render::tone_base`) branch on it; the base plane is keyed by process. Renders without Highlights or Shadows (global or local) are the same as V7's. | +| **V9** *(reserved)* | Reserved for `HealMethod::Pinned` (`#4069`). | +| **V10** (the latest) | V8 plus: checked Bradford white-balance fallback (`craft_color_transform::cct::wb_matrix`, returning `Mat3::IDENTITY` when a source illuminant's Bradford blue cone response `s[2] <= 0.0`, `craft-libs#587`). V1 to V8 (and reserved V9) keep the legacy Bradford result for saved edits (`local::wb_matrix_for`). | ## The rule From 557d2ad86917c15a505c9aaf78c51e7882f13cbd Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 21 Nov 2026 08:02:23 -0500 Subject: [PATCH 4/5] pipeline: include checked_wb in pre_nr_key for StageCache invalidation --- crates/pipeline/src/lib.rs | 2 ++ crates/pipeline/src/local.rs | 8 +++++++- crates/pipeline/src/tests.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/crates/pipeline/src/lib.rs b/crates/pipeline/src/lib.rs index 7ca709ac3f4..92f4634fd7a 100644 --- a/crates/pipeline/src/lib.rs +++ b/crates/pipeline/src/lib.rs @@ -541,6 +541,8 @@ pub fn plan<'a>(src: &Rgb32f, info: &SourceInfo, s: &'a DevelopSettings, req: &R let pre_nr_key = hash_of(( geo, [wb_t, wb_tint, info.as_shot_temp, info.as_shot_tint].map(f64::to_bits), + // the process picks checked vs legacy Bradford WB (Update to Current Process, undo) + local::checked_wb(s), format!("{:?}", s.spots), format!("{eyes:?}"), // defringe runs in this stage diff --git a/crates/pipeline/src/local.rs b/crates/pipeline/src/local.rs index e68bd31b037..ee947b0c1d2 100644 --- a/crates/pipeline/src/local.rs +++ b/crates/pipeline/src/local.rs @@ -22,6 +22,12 @@ pub fn white_balance(img: &mut Rgb32f, info: &SourceInfo, s: &DevelopSettings) { wb_gain(img, info, s, 1.0); } +/// Whether `s` uses the checked Bradford white-balance adaptation (`Process::V10` on) instead +/// of the legacy matrix (V1 to V9, which stay frozen). +pub fn checked_wb(s: &DevelopSettings) -> bool { + s.process.process() >= Process::V10 +} + /// The white-balance matrix (linear Rec.2020) for the settings, or `None` when the as-shot white /// is kept. A raw source with its camera colour model ([`crate::CameraColor`]) is re-developed for /// the new white in camera space, as Lightroom does (so a neutral under the chosen white renders @@ -37,7 +43,7 @@ pub fn wb_matrix_for(info: &SourceInfo, s: &DevelopSettings) -> Option<[[f32; 3] { return Some(m.to_f32()); } - let checked = s.process.process() >= Process::V10; + let checked = checked_wb(s); let set = if checked { wb_matrix_checked(&REC2020, effective_white(info, s)) } else { wb_matrix(&REC2020, effective_white(info, s)) }; let shot = if checked { wb_matrix_checked(&REC2020, temp_tint_to_xy(info.as_shot_temp, info.as_shot_tint)) diff --git a/crates/pipeline/src/tests.rs b/crates/pipeline/src/tests.rs index 795b3564cf5..43c9702c38f 100644 --- a/crates/pipeline/src/tests.rs +++ b/crates/pipeline/src/tests.rs @@ -832,6 +832,33 @@ fn saved_warm_green_wb_preserves_legacy_bradford_while_v10_uses_checked_fallback assert_eq!(v10_m, v10_expected); } +#[test] +fn stage_cache_invalidates_wb_on_process_switch_and_undo() { + use crate::{StageCache, render_cached}; + use lightcraft_develop::{Process, WbMode}; + + let src = scene(); + let info = SourceInfo { as_shot_temp: 5500.0, as_shot_tint: 0.0, ..Default::default() }; + let req = RenderRequest::fit(src.width, src.height); + let cache = StageCache::default(); + + let mut s_v8 = DevelopSettings { process: Process::V8.version(), ..Default::default() }; + (s_v8.wb.mode, s_v8.wb.temp, s_v8.wb.tint) = (WbMode::Custom, 2000.0, 30.0); + + let s_v10 = DevelopSettings { process: Process::V10.version(), ..s_v8.clone() }; + + let ref_v8 = render(&src, &info, &s_v8, &req).image.data; + let ref_v10 = render(&src, &info, &s_v10, &req).image.data; + assert_ne!(ref_v8, ref_v10, "V8 and V10 must differ at warm-green WB"); + + // Initial render at V8. + assert_eq!(render_cached(&src, &info, &s_v8, &req, &cache).image.data, ref_v8); + // Switch to V10 (Update to Current Process): must not reuse V8's cached WB linear image. + assert_eq!(render_cached(&src, &info, &s_v10, &req, &cache).image.data, ref_v10); + // Undo back to V8: must not reuse V10's cached WB linear image. + assert_eq!(render_cached(&src, &info, &s_v8, &req, &cache).image.data, ref_v8); +} + /// Every stored process number renders with a process this build knows: settings saved before /// process versions existed exactly as V1, and a number from a newer LightCraft exactly as the /// latest process here (`docs/process-versions.md`). Raw (base tone curve), camera-tone and From 9b65d28337c4b17e1038bd0bb6da4c60554e9c7a Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 21 Nov 2026 08:12:36 -0500 Subject: [PATCH 5/5] pipeline: wrap scene in Arc for render_cached in WB cache test --- crates/pipeline/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/pipeline/src/tests.rs b/crates/pipeline/src/tests.rs index 43c9702c38f..d07aae53486 100644 --- a/crates/pipeline/src/tests.rs +++ b/crates/pipeline/src/tests.rs @@ -837,7 +837,7 @@ fn stage_cache_invalidates_wb_on_process_switch_and_undo() { use crate::{StageCache, render_cached}; use lightcraft_develop::{Process, WbMode}; - let src = scene(); + let src = std::sync::Arc::new(scene()); let info = SourceInfo { as_shot_temp: 5500.0, as_shot_tint: 0.0, ..Default::default() }; let req = RenderRequest::fit(src.width, src.height); let cache = StageCache::default();