LR-BEHAV-RENDER-FIDELITY: calibrated Contrast and Blacks in process V3 (#523) (#1383)

* LR-BEHAV-RENDER-FIDELITY: split V3 Contrast and Blacks

Port calibrated global Contrast and Blacks with shared CPU and GPU tables.
Preserve V2 Whites, local adjustments, other source paths, and all V1 and V2
renders and persistent cache keys.

Generate the constants from public Contrast and Blacks fits. Cover numeric
references, legacy renders, keys that include the resolved process, windows
and GPU parity. Document the measurements, limits and provisional number.

Co-Authored-By: Codex <noreply@openai.com>

* LR-BEHAV-RENDER-FIDELITY: reduce V3 preview cost and sanitize fits

Compose calibrated CPU preview operators over linear input and skip unused
mix endpoints. Keep high-bit-depth exports on the original operator path.

Require three distinct photos per published error group and band, regenerate
the fit hashes, and cover the sanitizer with synthetic tests. Document release
measurements and identify the separate measurement tool proposed in #1181.

Co-Authored-By: Codex <noreply@openai.com>

* LR-BEHAV-RENDER-FIDELITY: preserve V3 luminance evaluation

Retain the original operator evaluation for luminance mixes, including
preceding Contrast, so preview interpolation cannot change the cutoff.
Keep the fused per-channel path and exact deep exports.

Add CPU and GPU regressions for both uniform cutoff fixtures. Document
the measured CPU cost of positive Blacks and the retained fused path.

Co-Authored-By: Codex <noreply@openai.com>

* LR-BEHAV-RENDER-FIDELITY: finish split-module integration

Import the persistent process-key helper directly in the session module. Keep the existing V3 operator selection and evaluation order in an inline helper so the combined finish-stage closure stays within the complexity limit.

Refresh the V1/V2 golden hashes only after the exact fixture produces identical hashes on plain current main. Keep the cross-platform legacy samples unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* LR-BEHAV-RENDER-FIDELITY: date the calibrated Light gap summary

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-05 06:15:05 +01:00
1 parent 67782d8f65
commit fc97c72864
27 files changed
+3654 -36

No files matched your search

+3
View File
@@ -14,3 +14,6 @@ plan/
# model weights are never committed (SAM 3: docs/ai-masks.md)
*.safetensors
*.safetensors.part
# Python tools import their public operator family.
__pycache__/
+7 -2
View File
@@ -86,18 +86,23 @@ pub enum Process {
V2,
/// Pixel-scale sharpening with working Radius and Detail controls.
V3,
/// V3, with Contrast and Blacks on a raw's camera look calibrated to Lightroom: the
/// camera curve keeps V2 Whites and fitted pointwise operators follow it
/// (`lightcraft_pipeline::light_v3`, `docs/light-v3.md`).
V4,
}
impl Process {
/// Every process, oldest first.
pub const ALL: [Process; 3] = [Process::V1, Process::V2, Process::V3];
pub const LATEST: Process = Process::V3;
pub const ALL: [Process; 4] = [Process::V1, Process::V2, Process::V3, Process::V4];
pub const LATEST: Process = Process::V4;
pub const fn version(self) -> ProcessVersion {
match self {
Process::V1 => ProcessVersion(1),
Process::V2 => ProcessVersion(2),
Process::V3 => ProcessVersion(3),
Process::V4 => ProcessVersion(4),
}
}
}
+7 -13
View File
@@ -1,5 +1,6 @@
use super::quick::{QuickJob, content_key, source_info};
use super::render::{RenderJob, RenderResult};
use super::settings_hash::with_process;
use super::source::{PreviewLoader, RENDER_CACHE_VERSION, SourceLevel, SourceRef, THUMB_SIZES, face_edge, source_edge_needed, thumb_bucket};
use super::{Arc, DevelopSettings, Hash128, Hasher128, MediaKind, Op, Photo, PhotoId, RenderRequest, Rendered, Rgb32f, Source, SourceInfo};
@@ -64,7 +65,8 @@ impl crate::Session {
^ lens.rotate_left(29);
let cache = thumb_bucket.map(|b| {
let mut k = Hasher128::new();
k.str(&content_key).u64(settings_hash).u64(b as u64).u64(RENDER_CACHE_VERSION).u64(crate::camera_profiles::cache_key());
k.str(&content_key).u64(settings_hash).u64(b as u64).u64(RENDER_CACHE_VERSION);
with_process(&mut k, &settings).u64(crate::camera_profiles::cache_key());
// (only a render that uses a denoised picture has it in its key, so every other thumbnail stays valid)
if salt != 0 {
k.u64(salt);
@@ -117,12 +119,8 @@ impl crate::Session {
/// Cache key of a variant thumbnail ([`Self::variant_job`]).
pub fn variant_key(p: &Photo, settings: &DevelopSettings, edge: usize) -> Hash128 {
let mut k = Hasher128::new();
k.str(&content_key(p))
.str("variant")
.u64(settings.hash64())
.u64(edge as u64)
.u64(RENDER_CACHE_VERSION)
.u64(crate::camera_profiles::cache_key());
k.str(&content_key(p)).str("variant").u64(settings.hash64()).u64(edge as u64).u64(RENDER_CACHE_VERSION);
with_process(&mut k, settings).u64(crate::camera_profiles::cache_key());
let lens = super::quick::lens_key(p);
if lens != 0 {
k.u64(lens);
@@ -240,12 +238,8 @@ impl crate::Session {
/// included as in [`Self::variant_key`].
pub(crate) fn view_key(p: &Photo, apply_crop: bool) -> Hash128 {
let mut k = Hasher128::new();
k.str(&content_key(p))
.str("view")
.u64(p.develop.hash64())
.u64(apply_crop as u64)
.u64(RENDER_CACHE_VERSION)
.u64(crate::camera_profiles::cache_key());
k.str(&content_key(p)).str("view").u64(p.develop.hash64()).u64(apply_crop as u64).u64(RENDER_CACHE_VERSION);
with_process(&mut k, &p.develop).u64(crate::camera_profiles::cache_key());
let lens = super::quick::lens_key(p);
if lens != 0 {
k.u64(lens);
+16 -1
View File
@@ -1,4 +1,4 @@
use super::{Arc, DevelopSettings, HashMap, PhotoId, VecDeque, Weak};
use super::{Arc, DevelopSettings, HashMap, Hasher128, PhotoId, VecDeque, Weak};
pub(super) const SETTINGS_HASH_ENTRIES: usize = 1024;
@@ -34,3 +34,18 @@ impl SettingsHashes {
hash
}
}
/// Add the rendering process `s` renders with in this build to persistent render key `h`, from
/// process V3 on: a process number from a newer LightCraft renders with an older build's latest
/// process, so the same settings (and settings hash) render differently in a build that knows that
/// process, and the keys must tell those renders apart. Builds before V3 (which have no process in
/// their keys) resolve every number above V2 to V2: naming V3 and later keeps this build's renders
/// of those numbers apart from theirs, and V1 and V2 keep the keys they always had, so their
/// cached renders stay valid (`docs/process-versions.md`).
pub(super) fn with_process<'a>(h: &'a mut Hasher128, s: &DevelopSettings) -> &'a mut Hasher128 {
let v = s.process.process().version().0;
if v >= lightcraft_develop::Process::V3.version().0 {
h.u64(u64::from(v));
}
h
}
@@ -6,6 +6,77 @@ fn session() -> crate::Session {
s.catalog.apply(Op::AddPhoto { photo: Box::new(p) }).unwrap();
s
}
/// Settings saved by a newer LightCraft (a process number this build doesn't know) render with
/// this build's latest process, and a build that resolved the number to an older process
/// cached other pixels under the same settings hash: the persistent keys (thumbnails, the
/// loupe's view render, variants) name the process the settings render with, so those are
/// never served (review of 5a7016c8: a catalog saved with a newer process kept main's V2 thumbnails).
#[test]
fn persistent_keys_name_the_process_the_settings_render_with() {
use lightcraft_develop::ProcessVersion;
let mut s = session();
let newer = DevelopSettings { process: ProcessVersion(ProcessVersion::LATEST.0 + 1), ..DevelopSettings::default() };
s.catalog.apply(Op::SetDevelop { id: PhotoId(1), settings: Arc::new(newer.clone()), label: "newer".into(), edited: None }).unwrap();
let p = s.catalog.photo(PhotoId(1)).unwrap().clone();
let unnamed = |kind: Option<&str>, size: u64| {
let mut h = Hasher128::new();
h.str(&content_key(&p));
if let Some(k) = kind {
h.str(k);
}
h.u64(newer.hash64()).u64(size).u64(RENDER_CACHE_VERSION).u64(crate::camera_profiles::cache_key()).finish()
};
let named = |kind: Option<&str>, size: u64, process: u64| {
let mut h = Hasher128::new();
h.str(&content_key(&p));
if let Some(k) = kind {
h.str(k);
}
h.u64(newer.hash64()).u64(size).u64(RENDER_CACHE_VERSION).u64(process).u64(crate::camera_profiles::cache_key()).finish()
};
let resolved = u64::from(lightcraft_develop::Process::LATEST.version().0);
let keys = [
(s.thumb_job(PhotoId(1), 256).unwrap().cache.unwrap().1, None, 256),
(crate::Session::view_key(&p, true), Some("view"), 1),
(crate::Session::variant_key(&p, &newer, 256), Some("variant"), 256),
];
for (key, kind, size) in keys {
assert_ne!(key, unnamed(kind, size), "old builds did not name their resolved process");
assert_eq!(key, named(kind, size, resolved), "the key names the process used for rendering");
assert_ne!(key, named(kind, size, u64::from(newer.process.0)), "the saved future number is not the resolved process");
}
}
/// Photos on V1 and V2 keep the persistent keys builds before process V3 gave them (no process
/// in them), so their cached thumbnails, view renders and variants stay valid after upgrading
/// (review of 26cd2df1: every V1/V2 photo rendered again, and offline ones without smart
/// previews lost their thumbnails); V3 and later name their process.
#[test]
fn v1_and_v2_photos_keep_the_render_cache_keys_they_had() {
use lightcraft_develop::Process;
let mut s = session();
for process in [Process::V1, Process::V2, Process::V3] {
let settings = DevelopSettings { process: process.version(), ..DevelopSettings::default() };
s.catalog.apply(Op::SetDevelop { id: PhotoId(1), settings: Arc::new(settings.clone()), label: "p".into(), edited: None }).unwrap();
let p = s.catalog.photo(PhotoId(1)).unwrap().clone();
let before_v3 = |kind: Option<&str>, size: u64| {
let mut h = Hasher128::new();
h.str(&content_key(&p));
if let Some(k) = kind {
h.str(k);
}
h.u64(settings.hash64()).u64(size).u64(RENDER_CACHE_VERSION).u64(crate::camera_profiles::cache_key()).finish()
};
let keys = [
s.thumb_job(PhotoId(1), 256).unwrap().cache.unwrap().1 == before_v3(None, 256),
crate::Session::view_key(&p, true) == before_v3(Some("view"), 1),
crate::Session::variant_key(&p, &settings, 256) == before_v3(Some("variant"), 256),
];
let old = process <= Process::V2;
assert_eq!(keys, [old; 3], "{process:?}: thumbnail, view and variant keys");
}
}
#[test]
fn hashes_match_uncached_keys_and_are_not_recomputed_for_sizes_metadata_or_before() {
let mut s = session();
@@ -21,6 +92,7 @@ fn hashes_match_uncached_keys_and_are_not_recomputed_for_sizes_metadata_or_befor
.u64(settings)
.u64(b as u64)
.u64(RENDER_CACHE_VERSION)
.u64(u64::from(p.develop.process.process().version().0))
.u64(crate::camera_profiles::cache_key())
.finish();
let job = s.thumb_job(p.id, edge).unwrap();
+11 -1
View File
@@ -365,7 +365,15 @@ fn constants() -> String {
use lightcraft_pipeline::tone::{CHROMA_N, LUT_MAX_EV, LUT_MIN_EV, LUT_N};
let mut s = String::new();
let [to_lms, from_lms, to_lab, from_lab] = lightcraft_color::perceptual::oklab_matrices();
for (name, m) in [("OK_TO_LMS", to_lms), ("OK_FROM_LMS", from_lms), ("OK_TO_LAB", to_lab), ("OK_FROM_LAB", from_lab)] {
let (to_pro, from_pro) = lightcraft_pipeline::light_v3::prophoto_matrices();
for (name, m) in [
("OK_TO_LMS", to_lms),
("OK_FROM_LMS", from_lms),
("OK_TO_LAB", to_lab),
("OK_FROM_LAB", from_lab),
("PRO_FROM_2020", to_pro),
("PRO_TO_2020", from_pro),
] {
let rows: Vec<String> = m.iter().map(|r| format!("vec3<f32>({:?}, {:?}, {:?})", r[0], r[1], r[2])).collect();
s += &format!("const {name} = array<vec3<f32>, 3>({});\n", rows.join(", "));
}
@@ -380,6 +388,8 @@ fn constants() -> String {
crate::params::CURVE_N
);
s += &format!("const POINT_WORDS: u32 = {}u;\n", lightcraft_pipeline::colorops::POINT_WORDS);
let y = lightcraft_pipeline::light_v3::PRO_Y;
s += &format!("const PRO_Y = vec3<f32>({:?}, {:?}, {:?});\nconst LIGHT_N: u32 = {}u;\n", y[0], y[1], y[2], lightcraft_pipeline::light_v3::LUT_N);
s += &format!("const EYE_WORDS: u32 = {}u;\n", lightcraft_pipeline::redeye::EYE_WORDS);
use lightcraft_pipeline::masks::{AUTO_TOL_CHROMA, AUTO_TOL_EV};
s += &format!("const AUTO_TOL_EV: f32 = {AUTO_TOL_EV:?};\nconst AUTO_TOL_CHROMA: f32 = {AUTO_TOL_CHROMA:?};\n");
+24 -1
View File
@@ -94,6 +94,13 @@ const FIELDS: &[(&str, usize)] = &[
("PROOF_DISP_WARN", 1),
// first row of a band dispatch (the kernel runs over rows Y0.., see `render`)
("Y0", 1),
// process V4's calibrated Contrast, Blacks (`FinishParams::light`): the number of active
// operators (0 = none), each one's mode (`light_v3::Mode::code`) and mix weight, and the offset
// of their tables in `aux` (LIGHT_N entries each, in order)
("LIGHT_OPS", 1),
("LIGHT_MODE", 2),
("LIGHT_W", 2),
("LIGHT_OFF", 1),
];
/// `(name, index)` of every field (for the WGSL constants).
@@ -160,7 +167,7 @@ pub struct Present {
}
/// The `finish` kernel's parameter block and auxiliary table (tone LUT | chroma curve | sRGB LUT | curve LUTs |
/// mask terms) for `fp` with `masks` (their local adjustments' terms).
/// mask terms | light operator tables) for `fp` with `masks` (their local adjustments' terms).
pub fn finish_block(fp: &FinishParams, masks: &[[f32; MASK_TERMS]], present: &Present) -> (Vec<u32>, Vec<f32>) {
let mut aux: Vec<f32> = fp.tone.lut().to_vec();
aux.extend_from_slice(fp.tone.chroma_lut());
@@ -177,12 +184,28 @@ pub fn finish_block(fp: &FinishParams, masks: &[[f32; MASK_TERMS]], present: &Pr
for m in masks {
aux.extend_from_slice(m);
}
let light_off = aux.len();
let light = fp.light.as_ref().map_or(&[][..], |l| &l.ops[..]);
let light = &light[..light.len().min(2)];
for op in light {
aux.extend_from_slice(&op.lut[..]);
}
let lut_off = aux.len();
if let Some((l, _)) = &fp.lut {
aux.extend(l.data.iter().flatten());
}
let mut p = Block::new();
p.u("LIGHT_OPS", light.len() as u32);
p.u("LIGHT_OFF", light_off as u32);
if let Some(i) = index("LIGHT_MODE") {
for (k, op) in light.iter().enumerate() {
if let Some(slot) = p.0.get_mut(i + k) {
*slot = op.mode.code();
}
}
}
p.fs("LIGHT_W", &light.iter().map(|op| op.weight).collect::<Vec<f32>>());
p.u("W", fp.w as u32);
p.u("H", fp.h as u32);
p.u("NMASK", masks.len() as u32);
+56 -1
View File
@@ -1,7 +1,7 @@
// The per-pixel stage: a straight port of `lightcraft_pipeline::finish` (keep in step with it).
// Bindings: img (rgb, pre-exposure), log_l, base, clar, tex, dark, masks (NMASK planes, then the
// blurred chromaticity when HAS_CHROMA), aux
// (tone LUT | chroma curve | sRGB LUT | curve LUTs | mask terms), out (packed RGBA8).
// (tone LUT | chroma curve | sRGB LUT | curve LUTs | mask terms | light operator tables), out (packed RGBA8).
fn tone_apply(y: f32) -> f32 {
if (y <= 0.0) {
@@ -47,6 +47,56 @@ fn curve(ch: u32, x: f32) -> f32 {
return aux[o + i] + (aux[o + i + 1u] - aux[o + i]) * t;
}
// Process V4's calibrated Contrast, Blacks (`lightcraft_pipeline::light_v3`): operator `k`'s
// table (linear output over encoded v) at v (`Operator::eval`).
fn light_eval(k: u32, v: f32) -> f32 {
let o = pu(F_LIGHT_OFF) + k * LIGHT_N;
let f = clamp(v, 0.0, 1.0) * f32(LIGHT_N - 1u);
let i = min(u32(f), LIGHT_N - 2u);
let t = f - f32(i);
return aux[o + i] + (aux[o + i + 1u] - aux[o + i]) * t;
}
// `Operator::channel`: one linear value; above 1 unchanged, below 0 shifted by F(0).
fn light_channel(k: u32, x: f32) -> f32 {
if (x > 1.0) {
return x;
}
if (x < 0.0) {
return aux[pu(F_LIGHT_OFF) + k * LIGHT_N] + x;
}
return light_eval(k, encode_srgb(x));
}
// `Operator::luminance`: scaled by F of the ProPhoto luminance over it.
fn light_lum(k: u32, p: vec3<f32>) -> vec3<f32> {
let y = PRO_Y.x * p.x + PRO_Y.y * p.y + PRO_Y.z * p.z;
if (!(y > 1e-6) || y > 1.0) {
return p;
}
return p * (light_channel(k, y) / y);
}
// `LightOps::apply`: linear Rec.2020 → ProPhoto, the operators in order, back.
fn light_ops(d: vec3<f32>) -> vec3<f32> {
var p = mul3(PRO_FROM_2020, d);
let n = min(pu(F_LIGHT_OPS), 2u);
for (var k = 0u; k < n; k++) {
let mode = pu(F_LIGHT_MODE + k);
if (mode == 0u) {
p = vec3<f32>(light_channel(k, p.x), light_channel(k, p.y), light_channel(k, p.z));
} else if (mode == 1u) {
p = light_lum(k, p);
} else {
let a = vec3<f32>(light_channel(k, p.x), light_channel(k, p.y), light_channel(k, p.z));
let b = light_lum(k, p);
let w = pf(F_LIGHT_W + k);
p = vec3<f32>(w * a.x + (1.0 - w) * b.x, w * a.y + (1.0 - w) * b.y, w * a.z + (1.0 - w) * b.z);
}
}
return mul3(PRO_TO_2020, p);
}
fn band_weights(h: f32) -> array<f32, 8> {
var w: array<f32, 8>;
for (var i = 0u; i < 8u; i++) {
@@ -507,6 +557,11 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
d = d + (o - d) * t;
}
// --- process V4: calibrated Contrast, Blacks
if (pu(F_LIGHT_OPS) != 0u) {
d = light_ops(d);
}
// --- colour
d = color_ops(d, lt[11], lt[12]);
if (tint_on) {
+103 -1
View File
@@ -31,6 +31,47 @@ fn gpu() -> bool {
ok
}
fn check_v3_luminance_cutoff(chroma: f32, pixel: [f32; 3], expected: [u8; 4]) {
if !gpu() {
return;
}
// These uniform nonnegative sources expose cancellation after camera chroma scaling
// and Contrast, just below the positive Blacks luminance cutoff.
let curve = lightcraft_pipeline::tone::CameraTone::new(std::array::from_fn(|i| {
let x = (i + 1) as f32 / 33.0;
[x, x]
}))
.unwrap()
.with_chroma([chroma; 8])
.unwrap();
let info = SourceInfo { raw: true, camera_tone: Some(curve), ..Default::default() };
let src = Arc::new(Rgb32f::filled(64, 64, pixel));
let mut s = DevelopSettings { process: Process::V4.version(), ..Default::default() };
s.light.contrast = 100.0;
s.light.blacks = 80.0;
let req = RenderRequest::fit(64, 64);
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;
for image in [&cpu, &gpu] {
assert!(image.data.iter().all(|p| *p == image.data[0]));
for (actual, expected) in image.data[0].into_iter().zip(expected) {
assert!(actual.abs_diff(expected) <= 1, "chroma {chroma}: {:?}, expected {expected}", image.data[0]);
}
}
let (_, max, _) = diff(&cpu, &gpu);
assert!(max <= 1, "chroma {chroma}: CPU {:?}, GPU {:?}", cpu.data[0], gpu.data[0]);
}
#[test]
fn v3_luminance_cutoff_chroma_2() {
check_v3_luminance_cutoff(2.0, [0.023_433_316, 0.000_071_107_73, 0.005_175_675], [27, 0, 8, 255]);
}
#[test]
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 camera_tone_and_relative_wb() {
if !gpu() {
@@ -649,6 +690,67 @@ fn cached_renders_match_uncached() {
}
}
/// Calibrated Contrast and Blacks, legacy Whites, combined edits, windows and cache reuse.
#[test]
fn light_v3_operators_match() {
if !gpu() {
return;
}
let src = scene(0, 960, 640);
let curve = lightcraft_pipeline::tone::CameraTone::new(std::array::from_fn(|i| {
let x = 0.004 * 1.18f32.powi(i as i32);
[x, 1.0 - (-2.0 * x).exp()]
}))
.unwrap()
.with_chroma([1.3, 1.2, 1.1, 1.0, 0.9, 0.7, 0.5, 0.4])
.unwrap();
let info = SourceInfo { raw: true, camera_tone: Some(curve), ..Default::default() };
let req = RenderRequest::fit(720, 720);
for id in ["light.contrast", "light.whites", "light.blacks"] {
for v in [-100.0, -50.0, 50.0, 100.0] {
let mut s = DevelopSettings::default();
assert_eq!(s.process.process(), Process::V4);
lightcraft_develop::controls::set(&mut s, id, v);
check(&format!("V4 {id} {v}"), &src, &info, &s, &req);
if id == "light.whites" {
let mut old = s.clone();
old.process = Process::V2.version();
assert_eq!(
lightcraft_gpu::render(&src, &info, &s, &req, None).unwrap().image,
lightcraft_gpu::render(&src, &info, &old, &req, None).unwrap().image
);
}
}
}
let mut s = DevelopSettings::default();
typical(&mut s);
s.light.contrast = 35.0;
s.light.whites = 40.0;
s.light.blacks = -30.0;
check("V4 combined, typical", &src, &info, &s, &req);
s.color.vibrance = 30.0;
s.vignette.amount = -20.0;
check("V4 combined, colour", &src, &info, &s, &req);
use lightcraft_pipeline::PixelWindow;
let win = RenderRequest { window: Some(PixelWindow { x: 1200, y: 800, w: 640, h: 480 }), ..RenderRequest::fit(3000, 2000) };
check("V4 combined, window", &src, &info, &s, &win);
s.hdr.enabled = true;
s.hdr.max_ev = 2.0;
check("V4 HDR preview", &src, &info, &s, &req);
// High-bit-depth exports use the CPU; the GPU kernel writes 8-bit previews.
let hdr_req = RenderRequest { depth: lightcraft_pipeline::OutputDepth::F32Hdr, ..req };
assert_eq!(lightcraft_gpu::try_render(&src, &info, &s, &hdr_req, None).err(), Some(lightcraft_gpu::Fallback::NotTried));
s.hdr.enabled = false;
let cache = StageCache::default();
for k in 0..3 {
s.light.exposure = 0.3 * k as f64;
let warm = lightcraft_gpu::render(&src, &info, &s, &req, Some(&cache)).expect("gpu");
let fresh = lightcraft_gpu::render(&src, &info, &s, &req, None).expect("gpu");
assert_eq!(warm.image, fresh.image, "exposure step {k}");
check(&format!("V4 exposure step {k}"), &src, &info, &s, &req);
}
}
/// Issue #632: the Highlights / Shadows base of each process (V1: the edge-aware filter of log
/// luminance; V2: of its fine median, a radius that grows with the render) matches the CPU's, and
/// a warm cache never hands one process the other's base.
@@ -681,7 +783,7 @@ fn highlights_shadows_base_matches_on_every_process() {
}];
check(&format!("{p:?} local highlights {w}"), &src, &raw, &s, &req);
}
for p in [Process::V1, Process::V2, Process::V1, Process::V2] {
for p in [Process::V1, Process::V2, Process::V4, Process::V1, Process::V2, Process::V4] {
let mut s = DevelopSettings { process: p.version(), ..DevelopSettings::default() };
s.light.highlights = -100.0;
let warm = lightcraft_gpu::render(&src, &raw, &s, &req, Some(&cache)).expect("gpu");
+35 -2
View File
@@ -180,6 +180,9 @@ pub struct FinishParams {
/// A LUT profile and its amount (0..2), applied to the display-encoded colour.
pub lut: Option<(std::sync::Arc<crate::lut::Lut3d>, f32)>,
pub tone: ToneMap,
/// Process V4's calibrated Contrast and Blacks on the camera-look path, applied after
/// the tone map (`None`: another process or path, or both at 0; see [`crate::light_v3`]).
pub light: Option<crate::light_v3::LightOps>,
pub ops: ColorOps,
/// Calibration: primaries matrix (row-major, linear Rec.2020) and shadows tint (−1..1).
pub calib: Option<[[f32; 3]; 3]>,
@@ -271,6 +274,7 @@ impl FinishParams {
calib: if calibration { crate::colorops::calibration_matrix(&s.calibration) } else { None },
shadow_tint: if calibration { (s.calibration.shadows_tint / 100.0) as f32 } else { 0.0 },
tone: base_tone(s, info, peak),
light: crate::light_v3::LightOps::new(s, info),
lut: crate::lut::get(&s.profile.id).map(|l| (l, (s.profile.amount / 100.0).clamp(0.0, 2.0) as f32)),
ops: ColorOps::new(s),
curves: curve_luts(&s.curve),
@@ -323,6 +327,8 @@ impl FinishParams {
/// rendering process. This is where a new tone model branches: a retuned default tone curve (issue
/// #146) is a new [`Process`] with its own arm here, and V1's arm stays as it is, so photos edited
/// under V1 keep their look (`docs/process-versions.md`). CPU and GPU both take it from here.
/// From V4 the camera curve keeps V2 Whites; its Contrast and Blacks are the
/// calibrated operators that follow the tone map ([`crate::light_v3`], [`FinishParams::light`]).
/// `peak` is the HDR render's peak relative to SDR white ([`lightcraft_develop::Hdr::peak`]); at 1.0 (SDR)
/// every arm is the SDR tone map. An HDR render keeps the camera's look through the midtones and
/// lifts its highlights past white ([`ToneMap::camera_hdr`]), so it matches the SDR render below them.
@@ -335,6 +341,12 @@ pub fn base_tone(s: &DevelopSettings, info: &SourceInfo, peak: f32) -> ToneMap {
None if info.raw => ToneMap::hdr(l.contrast, l.whites, l.blacks, peak),
None => ToneMap::display_hdr(l.contrast, l.whites, l.blacks, peak),
},
// Keep V2 Whites in the camera curve; calibrated Contrast and Blacks follow it.
Process::V4 => match info.camera_tone.as_ref().filter(|_| info.raw) {
Some(curve) => ToneMap::camera_hdr(curve, 0.0, l.whites, 0.0, peak),
None if info.raw => ToneMap::hdr(l.contrast, l.whites, l.blacks, peak),
None => ToneMap::display_hdr(l.contrast, l.whites, l.blacks, peak),
},
}
}
@@ -415,7 +427,7 @@ pub(crate) fn finish_with<T: Copy + Default + Send>(
) -> Vec<T> {
let (w, h) = (p.img.width, p.img.height);
let p_lut = fp.lut.clone();
let FinishParams { curves, vig, to_out, out_luma, grain, .. } = fp;
let FinishParams { light, curves, vig, to_out, out_luma, grain, .. } = fp;
let terms: Vec<[f32; MASK_TERMS]> = p.masks.iter().map(|m| mask_terms(&m.adjust)).collect();
let out_to_norm = fp.out_to_norm;
let long = fp.ow.max(fp.oh);
@@ -424,6 +436,7 @@ pub(crate) fn finish_with<T: Copy + Default + Send>(
let aspect = vw / vh;
let srgb = srgb_lut();
let preview_light = if exact { None } else { light.as_ref().and_then(|lo| crate::light_v3::PreviewOps::new(lo, &|v| encode_srgb(srgb, v))) };
let peak = fp.peak;
let hdr = peak > 1.0;
let mut out = vec![T::default(); w * h];
@@ -466,6 +479,9 @@ pub(crate) fn finish_with<T: Copy + Default + Send>(
d = d.map(|v| v + (o - v) * t);
}
// --- process V4: calibrated Contrast, Blacks (ProPhoto with the sRGB transfer)
d = apply_light(d, light.as_ref(), preview_light.as_ref(), exact, srgb);
// --- colour
d = fp.ops.apply(d, l_sat, l_hue);
if let Some((dir, amt)) = local.tint {
@@ -593,6 +609,23 @@ pub(crate) fn finish_with<T: Copy + Default + Send>(
out
}
#[inline]
fn apply_light(
color: [f32; 3],
light: Option<&crate::light_v3::LightOps>,
preview: Option<&crate::light_v3::PreviewOps>,
exact: bool,
srgb: &[f32; SRGB_LUT_N + 1],
) -> [f32; 3] {
if let Some(lo) = preview {
lo.apply(color)
} else if let Some(lo) = light {
if exact { lo.apply(color, &linear_to_srgb) } else { lo.apply(color, &|v| encode_srgb(srgb, v)) }
} else {
color
}
}
struct PixelLocalTerms {
values: [f32; MASK_SUMS],
tint: Option<([f32; 3], f32)>,
@@ -817,7 +850,7 @@ pub fn srgb_lut() -> &'static [f32; SRGB_LUT_N + 1] {
/// Linear → sRGB-encoded (clamped to 0..1) by an interpolated table: within 2e-5 of the exact
/// curve (≪ one 8-bit or 10-bit step), several times faster than `powf`.
#[inline]
fn encode_srgb(lut: &[f32; SRGB_LUT_N + 1], v: f32) -> f32 {
pub(crate) fn encode_srgb(lut: &[f32; SRGB_LUT_N + 1], v: f32) -> f32 {
let f = v.clamp(0.0, 1.0) * SRGB_LUT_N as f32;
let i = (f as usize).min(SRGB_LUT_N - 1);
let t = f - i as f32;
+8
View File
@@ -31,6 +31,10 @@ pub mod curve;
pub mod dust;
pub mod finish;
pub mod geometry;
pub mod light_v3;
// generated (`light_v3_params.rs`), kept in its own compact layout
#[rustfmt::skip]
pub mod light_v3_params;
pub mod local;
pub mod local_tone;
pub mod lut;
@@ -778,6 +782,10 @@ mod tests_geometry;
#[cfg(test)]
mod tests_hdr;
#[cfg(test)]
mod tests_legacy;
#[cfg(test)]
mod tests_light;
#[cfg(test)]
mod tests_local;
#[cfg(test)]
mod tests_mask_geometry;
+439
View File
@@ -0,0 +1,439 @@
//! Process V4's Contrast and Blacks on the camera-look path (a raw with its camera's tone
//! curve): pointwise operators fitted to how Lightroom's sliders move a photo's tones, applied
//! after the camera curve with V2 Whites. Method, operator family and the fitted constants' provenance:
//! `docs/light-v3.md`; the constants are in [`crate::light_v3_params`] (generated).
//!
//! Each slider is an operator `F_a` on encoded values `v` (linear ProPhoto RGB, D50, Bradford from
//! the D65 working space, through the sRGB transfer curve), anchored at `F_0` = identity:
//!
//! - `a > 0`: `F_a(v) = v + s(a)·D₊(v)`; `a < 0`: `F_a(v) = max(0, v − s(a)·D₋(v))`, with `D` piecewise
//! linear on 12 fixed knots (`D(1) = 0`, and for Contrast `D(0) = 0`) and the amount law
//! `s(t) = ((1 − e^(−t/τ)) / (1 − e^(−1/τ)))^q`, `t = |a|/100`, one `(τ, q)` per sign;
//! - applied per channel ([`Mode::PerChannel`]), to the encoded ProPhoto luminance with linear RGB
//! scaled by the luminance ratio ([`Mode::Luminance`]), or a blend of the two in linear light
//! ([`Mode::Mix`], one weight per sign).
//!
//! The functions here port `Family.curve`, `Family.apply`, `Family.law` of
//! `fit_pointwise.py` (the fitting tool) exactly; [`Fit::unpack`] is its `Family.unpack`. Each
//! active operator is tabulated once per render ([`LUT_N`] entries over `v` in 0..1, interpolated
//! linearly). High-bit-depth CPU exports and the GPU read these tables ([`LightOps`]); 8-bit CPU
//! renders compose per-channel operations over linear input ([`PreviewOps`]). Luminance operations
//! retain the original evaluation, including any preceding per-channel operation.
use lightcraft_color::{Mat3, PROPHOTO, REC2020};
use lightcraft_develop::{DevelopSettings, Process};
use crate::SourceInfo;
use crate::light_v3_params as fitted;
/// Entries of an operator's table over encoded `v` in 0..=1.
pub const LUT_N: usize = 1024;
/// Linear ProPhoto RGB luminance (the Y row of ProPhoto → XYZ D50), as the fit computes it.
pub const PRO_Y: [f32; 3] = [0.288_040_2, 0.711_874_1, 0.000_085_7];
/// How an operator is applied to a pixel.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Mode {
/// To each encoded ProPhoto channel.
PerChannel,
/// To the encoded ProPhoto luminance; linear RGB is scaled by the luminance ratio.
Luminance,
/// `w·PerChannel + (1 − w)·Luminance` in linear light, with a weight per sign.
Mix,
}
impl Mode {
/// The GPU kernel's code (`LIGHT_MODE` in `crates/gpu/src/params.rs`).
pub fn code(self) -> u32 {
match self {
Mode::PerChannel => 0,
Mode::Luminance => 1,
Mode::Mix => 2,
}
}
}
/// One slider's fitted parameters, laid out as `fit_pointwise.py`'s `Family`: 11 values of `D₊` at
/// the knots but the last (`D(1) = 0`), 11 of `D₋`, then `ln τ₊, ln q₊, ln τ₋, ln q₋`, then two mix
/// logits (positive, negative amounts) in [`Mode::Mix`].
#[derive(Clone, Copy, Debug)]
pub struct Fit {
pub mode: Mode,
/// Contrast moves tones both ways around a pivot: its shapes are anchored at black too (`D(0) = 0`).
pub signed: bool,
pub params: &'static [f64],
}
const KNOTS_N: usize = fitted::KNOTS.len();
/// A [`Fit`] unpacked (`Family.unpack`).
#[derive(Clone, Copy, Debug)]
pub struct Unpacked {
pub d_pos: [f64; KNOTS_N],
pub d_neg: [f64; KNOTS_N],
/// `(τ, q)` of the amount law, positive and negative amounts.
pub law_pos: (f64, f64),
pub law_neg: (f64, f64),
/// Mix weights of the per-channel result for positive and negative amounts (1 outside [`Mode::Mix`]).
pub weights: (f64, f64),
}
fn sigmoid(x: f64) -> f64 {
1.0 / (1.0 + (-x).exp())
}
impl Fit {
/// The parameters unpacked; `None` when their number doesn't fit the layout.
pub fn unpack(&self) -> Option<Unpacked> {
let n = KNOTS_N - 1;
let p = self.params;
let mix = self.mode == Mode::Mix;
let len = 2 * n + 4 + if mix { 2 } else { 0 };
if p.len() != len {
return None;
}
// D(1) = 0 is appended (the last knot stays 0)
let shape = |off: usize| -> Option<[f64; KNOTS_N]> {
let mut d = [0.0; KNOTS_N];
for (k, slot) in d.iter_mut().take(n).enumerate() {
*slot = *p.get(off + k)?;
}
Some(d)
};
let (mut d_pos, mut d_neg) = (shape(0)?, shape(n)?);
if self.signed {
d_pos[0] = 0.0;
d_neg[0] = 0.0;
}
let at = |i: usize| p.get(i).copied();
let i = 2 * n;
let law_pos = (at(i)?.exp(), at(i + 1)?.exp());
let law_neg = (at(i + 2)?.exp(), at(i + 3)?.exp());
let weights = if mix { (sigmoid(at(i + 4)?), sigmoid(at(i + 5)?)) } else { (1.0, 1.0) };
Some(Unpacked { d_pos, d_neg, law_pos, law_neg, weights })
}
}
/// The amount law `s(t)` (`Family.law`): 1 at `|a| = 100`, linear as `τ` grows, saturating as it
/// shrinks.
pub fn law((tau, q): (f64, f64), a: f64) -> f64 {
let t = (a.abs() / 100.0).min(1.0);
let tau = tau.clamp(1e-3, 1e3);
((1.0 - (-t / tau).exp()) / (1.0 - (-1.0 / tau).exp())).powf(q)
}
/// `numpy.interp(v, KNOTS, d)`: piecewise linear, constant beyond the ends.
fn interp(v: f64, d: &[f64; KNOTS_N]) -> f64 {
let k = &fitted::KNOTS;
if v <= k[0] {
return d[0];
}
for i in 1..KNOTS_N {
if v <= k[i] {
let t = (v - k[i - 1]) / (k[i] - k[i - 1]);
return d[i - 1] + t * (d[i] - d[i - 1]);
}
}
d[KNOTS_N - 1]
}
impl Unpacked {
/// `F_a(v)` on an encoded value (`Family.curve`).
pub fn curve(&self, a: f64, v: f64) -> f64 {
if a == 0.0 {
return v;
}
if a > 0.0 {
return v + law(self.law_pos, a) * interp(v, &self.d_pos);
}
(v - law(self.law_neg, a) * interp(v, &self.d_neg)).max(0.0)
}
}
/// One slider's operator at one amount, tabulated: `lut[i]` is the *linear* value of
/// `F_a(i / (LUT_N − 1))` (decoded with the sRGB curve), made non-decreasing (see [`Operator::new`]).
#[derive(Clone, Debug)]
pub struct Operator {
pub mode: Mode,
/// Weight of the per-channel result ([`Mode::Mix`]; 1 for per channel, 0 for luminance).
pub weight: f32,
pub lut: Box<[f32; LUT_N]>,
}
impl Operator {
/// `fit` at `amount` (-100..100); `None` at 0 (the identity) or for parameters that do not unpack.
///
/// The table is the running maximum of `F_a`: where a fitted shape folds back (a `D` rising
/// faster than 1), it is flat instead, so no two tones swap. None of the shipped fits folds.
/// The fitting tool inverts `F` the same way.
pub fn new(fit: &Fit, amount: f64) -> Option<Operator> {
let a = if amount.is_finite() { amount.clamp(-100.0, 100.0) } else { 0.0 };
if a == 0.0 {
return None;
}
let u = fit.unpack()?;
let weight = match fit.mode {
Mode::PerChannel => 1.0,
Mode::Luminance => 0.0,
Mode::Mix => (if a > 0.0 { u.weights.0 } else { u.weights.1 }) as f32,
};
let mut lut = Box::new([0.0f32; LUT_N]);
let mut top = 0.0f64;
for (i, slot) in lut.iter_mut().enumerate() {
let v = i as f64 / (LUT_N - 1) as f64;
top = top.max(u.curve(a, v));
*slot = srgb_decode(top) as f32;
}
// The negative Blacks fit rounds to exactly 1 in f32. Avoid calculating a luminance
// result that contributes nothing, on both CPU and GPU.
let mode = if weight == 1.0 {
Mode::PerChannel
} else if weight == 0.0 {
Mode::Luminance
} else {
Mode::Mix
};
Some(Operator { mode, weight, lut })
}
/// The table at encoded `v` (clamped to 0..=1), interpolated: linear output.
#[inline]
pub fn eval(&self, v: f32) -> f32 {
let f = v.clamp(0.0, 1.0) * (LUT_N - 1) as f32;
let i = (f as usize).min(LUT_N - 2);
let t = f - i as f32;
self.lut[i] + (self.lut[i + 1] - self.lut[i]) * t
}
/// One linear value through the operator: values above 1 (HDR renders) pass unchanged, which
/// is continuous because `F_a(1) = 1`; values below 0 (outside ProPhoto's gamut) keep their
/// distance below the image of 0, `F_a(0) + x` (continuous and increasing). This is the
/// per-channel domain: on luminance ([`Self::apply`]) a component above 1 is scaled with its
/// pixel unless the pixel's luminance is above 1.
#[inline]
pub fn channel(&self, x: f32, encode: &impl Fn(f32) -> f32) -> f32 {
if x > 1.0 {
x
} else if x < 0.0 {
self.lut[0] + x
} else {
self.eval(encode(x))
}
}
/// The luminance mode: linear ProPhoto `p` scaled by `F` of its luminance over its luminance
/// (unchanged when the luminance is at most 1e-6, or above 1).
#[inline]
fn luminance(&self, p: [f32; 3], encode: &impl Fn(f32) -> f32) -> [f32; 3] {
let y = PRO_Y[0] * p[0] + PRO_Y[1] * p[1] + PRO_Y[2] * p[2];
if y.is_nan() || y <= 1e-6 || y > 1.0 {
return p;
}
let r = self.channel(y, encode) / y;
p.map(|c| c * r)
}
/// The operator on a linear ProPhoto pixel (`Family.apply`). Per channel, each component goes
/// through [`Self::channel`] (one above 1 passes unchanged). On luminance, the pixel is scaled
/// by `F(Y) / Y` as a whole, components above 1 included, and passes unchanged only when `Y`
/// itself is above 1 (or at most 1e-6). Mix blends the two results in linear light, so an HDR
/// component of a pixel with `Y ≤ 1` moves by the luminance part's share.
#[inline]
pub fn apply(&self, p: [f32; 3], encode: &impl Fn(f32) -> f32) -> [f32; 3] {
match self.mode {
Mode::PerChannel => p.map(|c| self.channel(c, encode)),
Mode::Luminance => self.luminance(p, encode),
Mode::Mix => {
let (a, b) = (p.map(|c| self.channel(c, encode)), self.luminance(p, encode));
let w = self.weight;
std::array::from_fn(|k| w * a[k] + (1.0 - w) * b[k])
}
}
}
}
/// sRGB decoding in f64 (the tables are built in f64, like the fit).
fn srgb_decode(e: f64) -> f64 {
if e <= 0.04045 { e / 12.92 } else { ((e + 0.055) / 1.055).powf(2.4) }
}
/// Linear Rec.2020 (the working space) → linear ProPhoto RGB (D50, Bradford), and back.
pub fn prophoto_matrices() -> ([[f32; 3]; 3], [[f32; 3]; 3]) {
let to = REC2020.to_space(&PROPHOTO);
let from = to.inverse().unwrap_or(Mat3::IDENTITY);
(to.to_f32(), from.to_f32())
}
/// The active operators of a render, in order (Contrast, Blacks), and the conversions to
/// and from the space they work in. Applied after the tone map, chroma scaling and highlight
/// desaturation, before the colour stage (`finish::finish_with`, the GPU's `finish.wgsl`).
#[derive(Clone, Debug)]
pub struct LightOps {
pub ops: Vec<Operator>,
pub to_pro: [[f32; 3]; 3],
pub from_pro: [[f32; 3]; 3],
}
/// The fits of Contrast and Blacks, in the order they apply.
pub const FITS: [&Fit; 2] = [&fitted::CONTRAST, &fitted::BLACKS];
/// Whether `s` renders `info` with the V4 operators: process V4 and a raw with its camera's tone
/// curve (other sources keep the tone map's own Contrast and Blacks).
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 => camera_look,
}
}
impl LightOps {
/// The operators of `s` for `info` (see [`applies`]); `None` when they don't apply or every
/// slider is at 0.
pub fn new(s: &DevelopSettings, info: &SourceInfo) -> Option<LightOps> {
if !applies(s, info) {
return None;
}
let l = &s.light;
let ops: Vec<Operator> = FITS.iter().zip([l.contrast, l.blacks]).filter_map(|(f, a)| Operator::new(f, a)).collect();
if ops.is_empty() {
return None;
}
let (to_pro, from_pro) = prophoto_matrices();
Some(LightOps { ops, to_pro, from_pro })
}
/// The operators on a linear Rec.2020 pixel; `encode`: linear → sRGB-encoded on 0..1 (the
/// exact curve or the shared table, as the render encodes).
#[inline]
pub fn apply(&self, d: [f32; 3], encode: &impl Fn(f32) -> f32) -> [f32; 3] {
let mut p = mul3(&self.to_pro, d);
for op in &self.ops {
p = op.apply(p, encode);
}
mul3(&self.from_pro, p)
}
}
/// Number of intervals over linear input for 8-bit CPU renders. Deep exports retain [`LightOps`]
/// with the exact sRGB encoder; this approximation is not used for U16 or F32 samples.
const PREVIEW_INTERVALS: usize = 16_384;
/// An operator with its sRGB encoding and decoding included in one linear-input table.
struct LinearOperator {
black: f32,
white: f32,
// Each linear interval stores [intercept, slope], so a lookup needs no integer-to-float
// conversion or subtraction of neighbouring samples in the pixel loop.
segments: Box<[[f32; 2]; PREVIEW_INTERVALS]>,
}
impl LinearOperator {
fn new(channel: impl Fn(f32) -> f32) -> Self {
let black = channel(0.0);
let mut previous = black;
let mut segments = Box::new([[0.0; 2]; PREVIEW_INTERVALS]);
for (i, segment) in segments.iter_mut().enumerate() {
let next = channel((i + 1) as f32 / PREVIEW_INTERVALS as f32);
let slope = (next - previous) * PREVIEW_INTERVALS as f32;
let intercept = (previous as f64 - slope as f64 * (i as f64 / PREVIEW_INTERVALS as f64)) as f32;
*segment = [intercept, slope];
previous = next;
}
Self { black, white: previous, segments }
}
#[inline(always)]
fn channel(&self, x: f32) -> f32 {
if x >= 1.0 {
if x == 1.0 { self.white } else { x }
} else if x < 0.0 {
self.black + x
} else {
let f = x * PREVIEW_INTERVALS as f32;
let i = (f as u32).min(PREVIEW_INTERVALS as u32 - 1) as usize;
let [intercept, slope] = self.segments[i];
intercept + slope * x
}
}
}
/// CPU preview tables for per-channel operations, built once per render. Luminance operations
/// use [`LightOps`] instead, so interpolation cannot change a nearly cancelling luminance sum.
pub(crate) struct PreviewOps {
ops: PreviewOperators,
to_pro: [[f32; 4]; 3],
from_pro: [[f32; 4]; 3],
}
enum PreviewOperators {
PerChannel(LinearOperator),
Separate(Vec<LinearOperator>),
}
impl PreviewOps {
pub(crate) fn new(exact: &LightOps, encode: &impl Fn(f32) -> f32) -> Option<Self> {
let ops = &exact.ops;
// Small per-channel errors can cross the luminance cutoff at 1e-6, or be amplified
// by F(Y) / Y. Keep every preceding operation exact too, including Contrast.
if ops.iter().any(|o| o.mode != Mode::PerChannel) {
return None;
}
// A preceding black lift could carry a negative input across zero. Only fuse when
// preceding operators fix zero, so the composed negative extension remains F(0) + x.
// Contrast fixes zero and negative Blacks is per channel, so their usual pair fuses.
let fuse = ops.iter().take(ops.len().saturating_sub(1)).all(|o| o.lut[0] == 0.0);
let ops = if fuse {
PreviewOperators::PerChannel(LinearOperator::new(|x| ops.iter().fold(x, |x, o| o.channel(x, encode))))
} else {
PreviewOperators::Separate(ops.iter().map(|o| LinearOperator::new(|x| o.channel(x, encode))).collect())
};
let columns = |m: [[f32; 3]; 3]| std::array::from_fn(|i| [m[0][i], m[1][i], m[2][i], 0.0]);
Some(Self { ops, to_pro: columns(exact.to_pro), from_pro: columns(exact.from_pro) })
}
// Keep the single-table path in the finish loop. An out-of-line call per pixel saves
// little code here but adds register spills to this otherwise small operation.
#[inline(always)]
pub(crate) fn apply(&self, d: [f32; 3]) -> [f32; 3] {
let mut p = mul_preview(&self.to_pro, d);
match &self.ops {
PreviewOperators::PerChannel(op) => p = [op.channel(p[0]), op.channel(p[1]), op.channel(p[2])],
PreviewOperators::Separate(ops) => {
for op in ops {
p = p.map(|c| op.channel(c));
}
}
}
mul_preview(&self.from_pro, p)
}
}
/// Padded columns let the compiler multiply the RGB rows together in vector registers.
/// The fourth lane is unused; each RGB row keeps the same arithmetic order as `mul3`.
#[inline(always)]
fn mul_preview(m: &[[f32; 4]; 3], d: [f32; 3]) -> [f32; 3] {
let out: [f32; 4] = std::array::from_fn(|i| m[0][i] * d[0] + m[1][i] * d[1] + m[2][i] * d[2]);
[out[0], out[1], out[2]]
}
#[inline]
fn mul3(m: &[[f32; 3]; 3], d: [f32; 3]) -> [f32; 3] {
[
m[0][0] * d[0] + m[0][1] * d[1] + m[0][2] * d[2],
m[1][0] * d[0] + m[1][1] * d[1] + m[1][2] * d[2],
m[2][0] * d[0] + m[2][1] * d[1] + m[2][2] * d[2],
]
}
/// `fit_pointwise.py`'s own values for one fit at one amount (generated into
/// [`crate::light_v3_params`]; the tests check the port against them).
#[cfg(test)]
pub struct Reference {
pub amount: f64,
/// `Family.curve` at `light_v3_params::REF_V`.
pub curve: &'static [f64],
/// `Family.apply` on `light_v3_params::REF_PIX` (encoded ProPhoto), where the curve increases.
pub apply: Option<&'static [[f64; 3]]>,
}
+315
View File
@@ -0,0 +1,315 @@
//! Fitted constants of process V4's Contrast and Blacks ([`crate::light_v3`]).
//!
//! GENERATED by `tools/light_v3_constants.py rust` from the committed fits named below: do not edit by hand,
//! regenerate (the script must reproduce this file byte for byte).
//!
//! The values are fitted to black-box Lightroom exports of one person's Sony ILCE-7CR photos (the exports'
//! pixels only: no Lightroom code, tables or files), each slider against the same photo's Neutral or another
//! amount exported in the same batch, on the tune photos; the check photos were held out. The exports are
//! private; errors are published only with at least three contributing photos. These are our operator family's
//! parameters (`docs/light-v3.md`), not Lightroom's.
//!
//! - Contrast: `tools/light_v3_fits/contrast.json` (fitted as `v2-contrast-pc.json`), mode `pc`; 155 tune pairs on 20 photos, 61 check pairs on 6 photos;
//! sha256 `2f04d078f1866ccb05fc279b493ccab545adbe2ac178b12df9ebc524c79c2ce1`.
//! - Blacks: `tools/light_v3_fits/blacks.json` (fitted as `v2-blacks-mix.json`), mode `mix`; 148 tune pairs on 19 photos, 60 check pairs on 6 photos;
//! sha256 `b8ee89df8f632d9559649fcba917607ade1511ecaa2041f481dd5b73a318c090`.
use crate::light_v3::{Fit, Mode};
#[cfg(test)]
use crate::light_v3::Reference;
/// The family's knots: the displacement shapes are piecewise linear on them.
pub const KNOTS: [f64; 12] = [0.0, 0.02, 0.05, 0.09, 0.14, 0.2, 0.28, 0.38, 0.5, 0.65, 0.82, 1.0];
/// `tools/light_v3_fits/contrast.json`.
pub const CONTRAST: Fit = Fit {
mode: Mode::PerChannel,
signed: true,
params: &[
9.797174393178826e-18, -0.017053489024880908, -0.04260284838408044, -0.07195939270312468, -0.09738651081071477,
-0.1088504066519633, -0.10140378035603768, -0.06947815571389163, -0.007856500339789655, 0.08463087858854193, 0.1098534938016389,
0.30583740028604467, -0.05850866310699469, -0.07854274245013221, -0.09074476735486797, -0.0906596002773617, -0.08429179542961336,
-0.07428102082426319, -0.05004459522573259, -0.00906946010144, 0.056653920573147026, 0.09818533983265328, 0.3070552562874873,
0.10657448975892592, -0.13962415708911588, 0.37724097657204825,
],
};
/// `tools/light_v3_fits/blacks.json`.
pub const BLACKS: Fit = Fit {
mode: Mode::Mix,
signed: false,
params: &[
0.0016748697345088984, 0.032126630862752484, 0.07188512588294256, 0.09530584096821723, 0.12925288090794965, 0.12680972925019743,
0.10913227308994669, 0.10024857312175768, 0.0835198499581404, 0.05136152009684992, 0.02045048232256003, 0.00011845423640374467,
0.2706623236742467, 0.42355931120492346, 0.37893058797626605, 0.22045052169596244, 0.20955478047682013, 0.2107908996685734,
0.16685612159796198, 0.13055496600268582, 0.08667135921560576, 0.03499725744978859, 14.344979966519135, 0.1199976090379452,
6.829791928600096, 0.5956122696562978, 0.6007994346537187, 22.053184691621333,
],
};
/// Where the reference values are taken: encoded values and pixels (encoded ProPhoto).
#[cfg(test)]
pub const REF_V: [f64; 16] = [
0.0, 0.004, 0.012, 0.03, 0.07, 0.11, 0.17, 0.25, 0.33, 0.45, 0.58, 0.7, 0.81, 0.9, 0.97, 1.0,
];
#[cfg(test)]
pub const REF_PIX: [[f64; 3]; 6] = [
[0.02, 0.05, 0.01], [0.3, 0.25, 0.2], [0.55, 0.5, 0.62], [0.9, 0.85, 0.7], [0.15, 0.4, 0.35], [0.75, 0.97, 0.99],
];
/// The family's own `curve` at [`REF_V`] and `apply` on [`REF_PIX`] for `tools/light_v3_fits/contrast.json` (12 significant
/// digits).
#[cfg(test)]
pub const CONTRAST_REFERENCE: &[Reference] = &[
Reference {
amount: -100.0,
curve: &[
0.0, 0.0157017326214, 0.0471051978642, 0.0951866895547, 0.154643754903, 0.200710700524, 0.257475697853, 0.328035061301,
0.392162808025, 0.47614243307, 0.554016990408, 0.631130956115, 0.71425768483, 0.845452588982, 0.953635776695, 1.0,
],
apply: Some(&[
[0.078508663107, 0.12854274245, 0.0392543315535], [0.369433735705, 0.328035061301, 0.28429179543],
[0.537161666543, 0.509069460101, 0.576490755562], [0.845452588982, 0.768178883473, 0.631130956115],
[0.239598299469, 0.443215406038, 0.407315522905], [0.668915832804, 0.953635776695, 0.984545258898],
]),
},
Reference {
amount: -63.0,
curve: &[
0.0, 0.0117558826379, 0.0352676479138, 0.0732055944278, 0.126101694535, 0.170122852746, 0.227978700093, 0.301721466955,
0.371201372402, 0.467327147126, 0.562778518405, 0.654353749223, 0.746542204136, 0.86384609598, 0.959153828794, 1.0,
],
apply: Some(&[
[0.0587794131897, 0.102057956904, 0.0293897065949], [0.346020527272, 0.301721466955, 0.255868416571],
[0.541490780829, 0.506011218203, 0.591162168506], [0.86384609598, 0.79576914397, 0.654353749223],
[0.209385555774, 0.428643076049, 0.387988602489], [0.696257592365, 0.959153828794, 0.986384609598],
]),
},
Reference {
amount: -25.0,
curve: &[
0.0, 0.00669797632024, 0.0200939289607, 0.0450295815589, 0.0895156438599, 0.130914451725, 0.19016858264, 0.267991929431,
0.344332389013, 0.456027454879, 0.574009302137, 0.684121407008, 0.787925448518, 0.887423433092, 0.966227029927, 1.0,
],
apply: Some(&[
[0.0334898816012, 0.0681089814742, 0.0167449408006], [0.316008789537, 0.267991929431, 0.219434495337],
[0.547039966578, 0.502091073979, 0.609968416216], [0.887423433092, 0.831135149637, 0.684121407008],
[0.170657974176, 0.409963835778, 0.363214788663], [0.73130506224, 0.966227029927, 0.988742343309],
]),
},
Reference {
amount: -4.0,
curve: &[
0.0, 0.0042211975466, 0.0126635926398, 0.0312322222928, 0.0716000186917, 0.111714702007, 0.171653550835, 0.251475094729,
0.331175061939, 0.450494169731, 0.579508843847, 0.698698170259, 0.808190185513, 0.898968891712, 0.969690667514, 1.0,
],
apply: Some(&[
[0.021105987733, 0.0514846914124, 0.0105529938665], [0.301312504095, 0.251475094729, 0.201593365611],
[0.549757317317, 0.500171439768, 0.619177545887], [0.898968891712, 0.848453337568, 0.698698170259],
[0.151693674318, 0.400816899693, 0.351083433835], [0.748467268102, 0.969690667514, 0.989896889171],
]),
},
Reference {
amount: -1.0,
curve: &[
0.0, 0.00403003956988, 0.0120901187096, 0.0301673410408, 0.0702172893598, 0.110232863843, 0.170224559253, 0.250200324153,
0.330159578421, 0.450067110356, 0.5799332989, 0.699823205971, 0.809754219477, 0.899859971098, 0.96995799133, 1.0,
],
apply: Some(&[
[0.0201501978494, 0.0502016274236, 0.0100750989247], [0.300178243652, 0.250200324153, 0.200216385843],
[0.549967042657, 0.500023282251, 0.619888307225], [0.899859971098, 0.849789956648, 0.699823205971],
[0.150230008193, 0.400110938461, 0.350147134934], [0.749791848474, 0.96995799133, 0.98998599711],
]),
},
Reference {
amount: 1.0,
curve: &[
0.0, 0.00397028327185, 0.0119108498156, 0.0297772142058, 0.0695009210477, 0.109284415638, 0.169101549483, 0.249092158771,
0.329255569926, 0.449707840731, 0.580361320706, 0.700802007104, 0.810944204495, 0.900531739739, 0.970159521922, 1.0,
],
apply: Some(&[
[0.0198514163593, 0.0496288098987, 0.00992570817964], [0.29917212145, 0.249092158771, 0.199051608167],
[0.550200155898, 0.499931547883, 0.620576207118], [0.900531739739, 0.850797609609, 0.700802007104],
[0.149134843694, 0.399484133579, 0.349311202243], [0.750866642282, 0.970159521922, 0.990053173974],
]),
},
Reference {
amount: 4.0,
curve: &[
0.0, 0.00386276829016, 0.0115883048705, 0.0289711762573, 0.067695255762, 0.106695434805, 0.165850959769, 0.245807593504,
0.326562225444, 0.44865080988, 0.581668577311, 0.70370366501, 0.814360331887, 0.902455571598, 0.970736671479, 1.0,
],
apply: Some(&[
[0.0193138414508, 0.0482858458702, 0.0096569207254], [0.296176860778, 0.245807593504, 0.195620331007],
[0.550924318987, 0.499683888448, 0.622660921742], [0.902455571598, 0.853683357397, 0.70370366501],
[0.146004712278, 0.397617731312, 0.34681913522], [0.754002149954, 0.970736671479, 0.99024555716],
]),
},
Reference {
amount: 25.0,
curve: &[
0.0, 0.00303130723309, 0.00909392169928, 0.0227377271685, 0.0537312449465, 0.0866736973109, 0.140712707247, 0.220406592954,
0.305733397543, 0.440476321314, 0.591778172653, 0.726143473036, 0.840778760722, 0.917333416951, 0.975200025085, 1.0,
],
apply: Some(&[
[0.0151565361655, 0.0379001091744, 0.00757826808274], [0.273013181027, 0.220406592954, 0.169084742294],
[0.556524593466, 0.497768628155, 0.638782944901], [0.917333416951, 0.876000125426, 0.726143473036],
[0.121798017215, 0.383184014474, 0.327546875221], [0.778250421984, 0.975200025085, 0.991733341695],
]),
},
Reference {
amount: 63.0,
curve: &[
0.0, 0.00166203669924, 0.00498611009773, 0.0124723297827, 0.0307349682338, 0.0537014072028, 0.0993144142548, 0.178575600043,
0.271431971089, 0.427014372342, 0.608426903093, 0.763097901214, 0.884285279574, 0.941834618872, 0.982550385662, 1.0,
],
apply: Some(&[
[0.00831018349621, 0.0207966223556, 0.00415509174811], [0.234866663076, 0.178575600043, 0.125385281671],
[0.56574726332, 0.494614530364, 0.665333089458], [0.941834618872, 0.912751928309, 0.763097901214],
[0.0819338359776, 0.35941421432, 0.295808843098], [0.818183073196, 0.982550385662, 0.994183461887],
]),
},
Reference {
amount: 100.0,
curve: &[
0.0, 0.000589302195024, 0.00176790658507, 0.00443005785539, 0.0127188794564, 0.0278697600538, 0.0668815412687, 0.145803734783,
0.244559031965, 0.416467809921, 0.621470101755, 0.792049294828, 0.918369810554, 0.961029718779, 0.988308915634, 1.0,
],
apply: Some(&[
[0.00294651097512, 0.00739715161592, 0.00147325548756], [0.204981344572, 0.145803734783, 0.091149593348],
[0.57297262597, 0.49214349966, 0.686133402803], [0.961029718779, 0.941544578168, 0.792049294828],
[0.0507028398824, 0.340792120182, 0.270944156893], [0.849467711067, 0.988308915634, 0.996102971878],
]),
},
];
/// The family's own `curve` at [`REF_V`] and `apply` on [`REF_PIX`] for `tools/light_v3_fits/blacks.json` (12 significant
/// digits).
#[cfg(test)]
pub const BLACKS_REFERENCE: &[Reference] = &[
Reference {
amount: -100.0,
curve: &[
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0396726450283, 0.141176489367, 0.304319552499, 0.472849624284, 0.62852690601,
0.771963089505, 0.880557079195, 0.964167123758, 1.0,
],
apply: Some(&[
[0.0, 0.0, 0.0], [0.0979960559384, 0.0396726450312, 8.67909201708e-12], [0.434072902922, 0.369445033999, 0.524551919414],
[0.880557079192, 0.820835618793, 0.628526906024], [1.62784132506e-11, 0.239194070991, 0.169963444981],
[0.693725171247, 0.964167123755, 0.988055707915],
]),
},
Reference {
amount: -63.0,
curve: &[
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0769799089595, 0.159002658298, 0.248306215942, 0.386971900482, 0.533641791607, 0.669077433807,
0.793543473258, 0.891588093197, 0.967476427959, 1.0,
],
apply: Some(&[
[0.0, 0.0, 0.0], [0.212603750827, 0.159002658299, 0.109336909762], [0.49984457601, 0.443515883354, 0.578704745728],
[0.891588093196, 0.837382139795, 0.669077433813], [0.0554085751144, 0.330427917606, 0.27210785935],
[0.72565290629, 0.967476427958, 0.989158809318],
]),
},
Reference {
amount: -25.0,
curve: &[
0.0, 0.0, 0.0, 0.0039713718625, 0.0375281504298, 0.0844641752827, 0.152600319953, 0.232978681132, 0.314718938796,
0.438210409673, 0.571328561555, 0.694215843567, 0.806921758549, 0.898426528234, 0.96952795847, 1.0,
],
apply: Some(&[
[1.38361828441e-12, 0.0157222994288, 6.91809142207e-13], [0.28365227602, 0.232978681132, 0.183041203846],
[0.540618281274, 0.489434480805, 0.612275601929], [0.898426528233, 0.84763979235, 0.694215843568],
[0.132306397362, 0.386986338539, 0.335430047312], [0.745445804924, 0.96952795847, 0.989842652823],
]),
},
Reference {
amount: -4.0,
curve: &[
0.0, 0.00384203333958, 0.0115267901451, 0.029063081396, 0.0688311531515, 0.109080820198, 0.169373686394, 0.249387305769,
0.329449947556, 0.449575625482, 0.579687865532, 0.699791795259, 0.809889196554, 0.899943361788, 0.969983008536, 1.0,
],
apply: Some(&[
[0.0192115469507, 0.0487661502866, 0.00960560094376], [0.299411552286, 0.249387305769, 0.199389556317],
[0.549662298498, 0.499619686776, 0.61972195491], [0.899943361788, 0.849915042681, 0.699791795259],
[0.149363106446, 0.399531564189, 0.349475544402], [0.749836068575, 0.969983008536, 0.989994336179],
]),
},
Reference {
amount: -1.0,
curve: &[
0.0, 0.00398722513591, 0.0119617312187, 0.0299242307978, 0.0699054746135, 0.109925665346, 0.169949349621, 0.249950451029,
0.32995551691, 0.449965680563, 0.579974757487, 0.69998316235, 0.809991039255, 0.899995419632, 0.96999862589, 1.0,
],
apply: Some(&[
[0.0199362373015, 0.0499002177906, 0.009968104698], [0.29995241186, 0.249950451029, 0.199950633032],
[0.549972689865, 0.499969243828, 0.619977514317], [0.899995419632, 0.849993129448, 0.69998316235],
[0.149948494014, 0.399962117299, 0.349957586943], [0.749986742762, 0.96999862589, 0.989999541963],
]),
},
Reference {
amount: 1.0,
curve: &[
9.31612027339e-06, 0.00404319245864, 0.0121109451354, 0.0302524139772, 0.0704649827756, 0.11060564863, 0.170712147943,
0.250643898657, 0.330582319062, 0.450503332955, 0.580369162543, 0.700235118441, 0.810123865526, 0.900063195347, 0.970018958604,
1.0,
],
apply: Some(&[
[0.0201752429349, 0.0503888012921, 0.0100906298252], [0.300630744288, 0.250626419466, 0.200631616538],
[0.550429399642, 0.500454032729, 0.620394920846], [0.90007223641, 0.850090998192, 0.700176696162],
[0.150565756988, 0.400578185286, 0.350572708933], [0.750135238759, 0.970032675648, 0.990024911688],
]),
},
Reference {
amount: 4.0,
curve: &[
4.44679248931e-05, 0.00420616726172, 0.0125295659354, 0.0312048283459, 0.0722194667453, 0.112890896317, 0.17339924135,
0.253073472246, 0.332779539074, 0.452402520726, 0.581762095353, 0.701122272887, 0.810591237848, 0.900301645519, 0.970090493656,
1.0,
],
apply: Some(&[
[0.0208391227968, 0.0518558616479, 0.0104339209625], [0.303010755867, 0.252990062923, 0.203015330491],
[0.55204964314, 0.502167204295, 0.621885228625], [0.900344802502, 0.850434355079, 0.700843514096],
[0.152703002383, 0.402759872928, 0.352733667786], [0.750645594216, 0.970155972394, 0.990118916658],
]),
},
Reference {
amount: 25.0,
curve: &[
0.000351031037929, 0.00562749010759, 0.0161804082469, 0.0395109485272, 0.0875205323187, 0.132820816064, 0.19683370592,
0.274262075537, 0.351941758888, 0.468965565542, 0.593910029809, 0.708859253437, 0.814667248041, 0.902381198134, 0.97071435944,
1.0,
],
apply: Some(&[
[0.0268094892594, 0.0646518089884, 0.0135180994291], [0.323771669718, 0.273605097162, 0.223833590382],
[0.566181459749, 0.517108276593, 0.63489439536], [0.902722015601, 0.853428836176, 0.7066658074],
[0.171494494367, 0.421790810113, 0.371579649929], [0.755101084946, 0.971231540587, 0.990939254456],
]),
},
Reference {
amount: 63.0,
curve: &[
0.000995014140305, 0.00861319796625, 0.0238495656181, 0.0569592350811, 0.11966278055, 0.174686686427, 0.246061413214,
0.31877200482, 0.392194957135, 0.503758795817, 0.619428639797, 0.725111974413, 0.823229536124, 0.906749619145, 0.972024885744,
1.0,
],
apply: Some(&[
[0.0404539765541, 0.0915381262658, 0.0205483468996], [0.367405560588, 0.316916949778, 0.267702217691],
[0.595875558955, 0.54849590131, 0.662288333975], [0.907716480454, 0.859719346711, 0.718935705489],
[0.211650252506, 0.461789763271, 0.411168543529], [0.764487032294, 0.973492582642, 0.992665468794],
]),
},
Reference {
amount: 100.0,
curve: &[
0.00167486973451, 0.0117652219602, 0.0319459264115, 0.0753794625361, 0.153595483426, 0.218884656944, 0.298031305079,
0.36576131915, 0.434690423106, 0.540490151276, 0.646368740699, 0.742270038399, 0.832268778662, 0.911361379068, 0.97340841372,
1.0,
],
apply: Some(&[
[0.055421940602, 0.119927912612, 0.0288346946948], [0.413495225374, 0.362648809539, 0.314154311953],
[0.627234264731, 0.5816340005, 0.691296631565], [0.912990263469, 0.866360468302, 0.731944464499],
[0.254705410536, 0.504042777472, 0.452962701964], [0.774433618221, 0.975881980047, 0.994492187831],
]),
},
];
+2 -2
View File
@@ -371,11 +371,11 @@ pub fn base_detail_radius(px_per_long: f64) -> usize {
}
/// Median radius (px) of the highlights/shadows base of `s`'s rendering process at `px_per_long`:
/// 0 (no median) under V1, [`base_detail_radius`] from V2.
/// 0 (no median) under V1, [`base_detail_radius`] from V2 (later processes keep V2's base).
pub fn tone_base_detail(s: &DevelopSettings, px_per_long: f64) -> usize {
match s.process.process() {
Process::V1 => 0,
Process::V2 | Process::V3 => base_detail_radius(px_per_long),
Process::V2 | Process::V3 | Process::V4 => base_detail_radius(px_per_long),
}
}
+127
View File
@@ -0,0 +1,127 @@
//! V1 and V2 render as they did before process V3, on every platform: 16-bit samples of small
//! synthetic renders, captured on main at 76b5377 (before process V3 existed), within
//! [`LSB`]. `tests_light::v1_and_v2_render_as_before_v3` checks the same byte for byte, but only
//! on macOS aarch64, where its hashes were captured.
use lightcraft_develop::{DevelopSettings, ProcessVersion, controls};
use lightcraft_raster::Rgb32f;
use crate::{DeepSamples, OutputDepth, RenderRequest, SourceInfo, render};
/// 480 × 320, arithmetic only (no platform maths): luminance rising over 12 stops left to right,
/// four colour bands top to bottom, thin bright and dark lines every 16 px (so V2's
/// Highlights / Shadows median has something to keep), and a few clipped highlights.
fn scene() -> Rgb32f {
Rgb32f::from_fn(480, 320, |x, y| {
let v = 0.0002 * 1.0175f32.powi(x as i32);
let c = match y / 80 {
0 => [v, v, v],
1 => [v * 1.3, v * 0.8, v * 0.4],
2 => [v * 0.35, v * 0.9, v * 1.4],
_ => [v * 0.9, v * 0.3, v * 1.1],
};
if x % 16 == 7 {
c.map(|k| k * 2.5)
} else if y % 16 == 11 {
c.map(|k| k * 0.35)
} else if x > 440 && y % 40 < 3 {
[4.0, 4.0, 4.0]
} else {
c
}
})
}
fn camera_look() -> SourceInfo {
let knots = std::array::from_fn(|i| {
let x = 0.004 * 1.18f32.powi(i as i32);
[x, 1.0 - (-2.0 * x).exp()]
});
let curve = crate::tone::CameraTone::new(knots).unwrap().with_chroma([1.3, 1.2, 1.1, 1.0, 0.9, 0.7, 0.5, 0.4]).unwrap();
SourceInfo { raw: true, as_shot_temp: 5200.0, as_shot_tint: 4.0, camera_tone: Some(curve), ..Default::default() }
}
/// Where the samples are taken (output pixels of the 480 × 320 render).
const AT: [(usize, usize); 12] =
[(20, 20), (120, 30), (232, 40), (300, 27), (400, 60), (470, 1), (60, 100), (200, 125), (350, 140), (90, 200), (263, 210), (420, 290)];
/// 16-bit samples of V1 and V2 renders (the same order as `LEGACY`): three sources (rendered,
/// raw, raw with a camera look) × two edits (plain, a typical edit with Contrast, Highlights,
/// Shadows, Whites, Blacks and Clarity) × two processes.
fn legacy_samples() -> Vec<[u16; 3]> {
let infos = [SourceInfo::default(), SourceInfo { raw: true, as_shot_temp: 5200.0, as_shot_tint: 4.0, ..Default::default() }, camera_look()];
let mut edited = DevelopSettings::for_raw(5200.0, 4.0);
for (id, v) in [
("light.exposure", 0.4),
("light.contrast", 30.0),
("light.highlights", -60.0),
("light.shadows", 40.0),
("light.whites", 15.0),
("light.blacks", -20.0),
("effects.clarity", 20.0),
] {
controls::set(&mut edited, id, v);
}
let req = RenderRequest { depth: OutputDepth::U16, ..RenderRequest::fit(480, 480) };
let src = scene();
let mut out = Vec::new();
for info in &infos {
for s in [DevelopSettings::for_raw(5200.0, 4.0), edited.clone()] {
for process in [ProcessVersion(1), ProcessVersion(2)] {
let s = DevelopSettings { process, ..s.clone() };
let deep = render(&src, info, &s, &req).deep.unwrap();
let DeepSamples::U16(v) = deep.samples else { panic!("16-bit samples") };
for (x, y) in AT {
let i = (y * deep.width + x) * 3;
out.push([v[i], v[i + 1], v[i + 2]]);
}
}
}
}
out
}
/// Largest difference allowed from the captured samples, in 16-bit steps. The renders call the
/// platform's `powf` / `exp2` / `log2`, whose last bit can differ between platforms: a relative
/// change of ~1e-7, far below one step (1.5e-5), so a sample moves by at most one step where it
/// sits at a rounding boundary. A change of how V1 or V2 render moves samples by far more.
const LSB: u16 = 2;
#[test]
fn v1_and_v2_samples_are_as_before_v3_on_every_platform() {
let got = legacy_samples();
assert_eq!(got.len(), LEGACY.len());
let worst = got.iter().zip(&LEGACY).flat_map(|(g, w)| (0..3).map(move |k| g[k].abs_diff(w[k]))).max().unwrap_or(0);
for (i, (g, w)) in got.iter().zip(&LEGACY).enumerate() {
assert!((0..3).all(|k| g[k].abs_diff(w[k]) <= LSB), "sample {i}: {g:?}, captured {w:?} (worst {worst})");
}
}
/// [`legacy_samples`] on main at 76b5377.
#[rustfmt::skip]
const LEGACY: [[u16; 3]; 144] = [
[240, 240, 240], [1222, 1222, 1222], [6573, 6573, 6573], [6760, 6760, 6760], [34082, 34082, 34082], [65535, 65535, 65535],
[796, 355, 165], [6369, 3524, 1681], [28819, 19569, 13215], [0, 770, 1153], [0, 17104, 20902], [41649, 18367, 40817],
[240, 240, 240], [1222, 1222, 1222], [6573, 6573, 6573], [6760, 6760, 6760], [34082, 34082, 34082], [65535, 65535, 65535],
[796, 355, 165], [6369, 3524, 1681], [28819, 19569, 13215], [0, 770, 1153], [0, 17104, 20902], [41649, 18367, 40817],
[314, 314, 314], [1699, 1699, 1699], [8278, 8278, 8278], [6991, 6991, 6991], [34698, 34698, 34698], [65535, 65535, 65535],
[1062, 474, 220], [8221, 4847, 2529], [32250, 22021, 14995], [0, 1040, 1558], [0, 21972, 26663], [44088, 19551, 43211],
[314, 314, 314], [1699, 1699, 1699], [8271, 8271, 8271], [6646, 6646, 6646], [34667, 34667, 34667], [65535, 65535, 65535],
[1062, 474, 220], [8219, 4846, 2528], [32239, 22013, 14989], [0, 1040, 1558], [0, 22622, 27432], [44072, 19543, 43195],
[272, 272, 272], [1384, 1384, 1384], [7098, 7098, 7098], [7293, 7293, 7293], [34521, 34521, 34521], [65535, 65535, 65535],
[902, 403, 187], [6894, 3899, 1901], [29974, 20395, 13815], [0, 872, 1307], [0, 18017, 21983], [42788, 18920, 41935],
[272, 272, 272], [1384, 1384, 1384], [7098, 7098, 7098], [7293, 7293, 7293], [34521, 34521, 34521], [65535, 65535, 65535],
[902, 403, 187], [6894, 3899, 1901], [29974, 20395, 13815], [0, 872, 1307], [0, 18017, 21983], [42788, 18920, 41935],
[16, 16, 16], [127, 127, 127], [5866, 5866, 5866], [3892, 3892, 3892], [36157, 36157, 36157], [65535, 65535, 65535],
[59, 27, 12], [3177, 1437, 666], [32984, 22546, 15376], [0, 63, 95], [0, 22149, 26872], [45537, 20255, 44634],
[16, 16, 16], [127, 127, 127], [5856, 5856, 5856], [3340, 3340, 3340], [36123, 36123, 36123], [65535, 65535, 65535],
[59, 27, 12], [3174, 1436, 665], [32972, 22537, 15370], [0, 63, 95], [0, 22867, 27722], [45520, 20246, 44616],
[477, 477, 477], [2433, 2433, 2433], [9924, 9924, 9924], [10170, 10170, 10170], [42194, 42194, 42194], [65533, 65533, 65533],
[1800, 660, 167], [10387, 5624, 1736], [39549, 25689, 14987], [0, 1533, 2297], [0, 23519, 28494], [54941, 22090, 53814],
[477, 477, 477], [2433, 2433, 2433], [9924, 9924, 9924], [10170, 10170, 10170], [42194, 42194, 42194], [65533, 65533, 65533],
[1800, 660, 167], [10387, 5624, 1736], [39549, 25689, 14987], [0, 1533, 2297], [0, 23519, 28494], [54941, 22090, 53814],
[639, 639, 639], [3436, 3436, 3436], [12637, 12637, 12637], [10872, 10872, 10872], [43751, 43751, 43751], [65393, 65393, 65393],
[2464, 904, 228], [13380, 7612, 2802], [44578, 29433, 18028], [0, 2136, 3161], [0, 30532, 36793], [58572, 24437, 57388],
[639, 639, 639], [3436, 3436, 3436], [12627, 12627, 12627], [10397, 10397, 10397], [43721, 43721, 43721], [65393, 65393, 65393],
[2464, 904, 228], [13377, 7610, 2801], [44566, 29424, 18020], [0, 2136, 3161], [0, 31308, 37712], [58556, 24426, 57373],
];
+514
View File
@@ -0,0 +1,514 @@
//! Process V4's calibrated Contrast and Blacks (`light_v3`): V1 and V2 render as they
//! always did, and the V4 operators behave.
use lightcraft_color::transfer::{linear_to_srgb, srgb_to_linear};
use lightcraft_develop::{DevelopSettings, Process, ProcessVersion, controls};
use lightcraft_raster::{Rgb32f, Rgba8};
use crate::light_v3::{self, FITS, LUT_N, LightOps, Mode, Operator, Reference};
use crate::light_v3_params as fitted;
use crate::{DeepSamples, OutputDepth, PixelWindow, RenderRequest, SourceInfo, StageCache, render, render_cached};
fn camera_curve() -> crate::tone::CameraTone {
let knots = std::array::from_fn(|i| {
let x = 0.004 * 1.18f32.powi(i as i32);
[x, 1.0 - (-2.0 * x).exp()]
});
crate::tone::CameraTone::new(knots).unwrap().with_chroma([1.3, 1.2, 1.1, 1.0, 0.9, 0.7, 0.5, 0.4]).unwrap()
}
/// A raw with a camera look: the path V4 changes.
fn camera_look() -> SourceInfo {
SourceInfo { raw: true, as_shot_temp: 5200.0, as_shot_tint: 4.0, camera_tone: Some(camera_curve()), ..Default::default() }
}
fn check_luminance_cutoff(chroma: f32, pixel: [f32; 3], expected: [u8; 4]) {
// Nonnegative source pixels become mixed-sign ProPhoto values after camera chroma
// scaling. Contrast must not move their nearly cancelling luminance across 1e-6.
let curve = crate::tone::CameraTone::new(std::array::from_fn(|i| {
let x = (i + 1) as f32 / 33.0;
[x, x]
}))
.unwrap()
.with_chroma([chroma; 8])
.unwrap();
let info = SourceInfo { raw: true, camera_tone: Some(curve), ..Default::default() };
let src = Rgb32f::filled(64, 64, pixel);
let mut s = DevelopSettings { process: Process::V4.version(), ..Default::default() };
s.light.contrast = 100.0;
s.light.blacks = 80.0;
let image = render(&src, &info, &s, &RenderRequest::fit(64, 64)).image;
assert!(image.data.iter().all(|p| *p == image.data[0]));
for (actual, expected) in image.data[0].into_iter().zip(expected) {
assert!(actual.abs_diff(expected) <= 1, "chroma {chroma}: {:?}, expected {expected}", image.data[0]);
}
}
#[test]
fn v3_luminance_cutoff_chroma_2() {
check_luminance_cutoff(2.0, [0.023_433_316, 0.000_071_107_73, 0.005_175_675], [27, 0, 8, 255]);
}
#[test]
fn v3_luminance_cutoff_chroma_4() {
check_luminance_cutoff(4.0, [0.035_338_085, 0.000_048_468_723, 0.010_193_758], [47, 0, 19, 255]);
}
fn scenes() -> Vec<Rgb32f> {
let lib = lightcraft_scenes::demo_library();
vec![lib[0].render(480, 320), lib[3].render(400, 300)]
}
/// FNV-1a over the bytes of a render: its 8-bit image and its deep samples.
fn fnv(hash: &mut u64, bytes: impl IntoIterator<Item = u8>) {
for b in bytes {
*hash = (*hash ^ b as u64).wrapping_mul(0x0000_0100_0000_01B3);
}
}
fn render_hash(src: &Rgb32f, info: &SourceInfo, s: &DevelopSettings, req: &RenderRequest) -> u64 {
let r = render(src, info, s, req);
let mut h = 0xCBF2_9CE4_8422_2325u64;
fnv(&mut h, r.image.data.iter().flatten().copied());
match r.deep.map(|d| d.samples) {
Some(DeepSamples::U16(v)) => fnv(&mut h, v.iter().flat_map(|x| x.to_le_bytes())),
Some(DeepSamples::F32(v)) => fnv(&mut h, v.iter().flat_map(|x| x.to_bits().to_le_bytes())),
None => {}
}
h
}
/// The settings the V1 / V2 golden renders cover: plain, a typical edit, and Contrast, Whites and
/// Blacks at both ends on their own.
fn golden_settings() -> Vec<DevelopSettings> {
let mut out = vec![DevelopSettings::for_raw(5200.0, 4.0)];
let mut edited = DevelopSettings::for_raw(5200.0, 4.0);
for (id, v) in [("light.exposure", 0.4), ("light.contrast", 30.0), ("light.highlights", -60.0), ("light.whites", 15.0), ("light.blacks", -20.0)] {
controls::set(&mut edited, id, v);
}
out.push(edited);
for id in ["light.contrast", "light.whites", "light.blacks"] {
for v in [-100.0, 100.0] {
let mut s = DevelopSettings::for_raw(5200.0, 4.0);
controls::set(&mut s, id, v);
out.push(s);
}
}
let mut hdr = DevelopSettings::for_raw(5200.0, 4.0);
hdr.hdr.enabled = true;
hdr.hdr.max_ev = 2.0;
for (id, v) in [("light.contrast", 25.0), ("light.whites", 40.0), ("light.blacks", -30.0)] {
controls::set(&mut hdr, id, v);
}
out.push(hdr);
out
}
/// One hash over every golden render of `process`: two scenes, three sources (rendered, raw,
/// raw with a camera look), the settings above, at 8 and 16 bits and as float HDR.
fn golden(process: ProcessVersion) -> u64 {
let infos = [SourceInfo::default(), SourceInfo { raw: true, as_shot_temp: 5200.0, as_shot_tint: 4.0, ..Default::default() }, camera_look()];
let reqs = [
// (at 480 px V2's Highlights / Shadows base takes its median: V1 and V2 differ)
RenderRequest::fit(480, 480),
RenderRequest { depth: OutputDepth::U16, ..RenderRequest::fit(320, 320) },
RenderRequest { depth: OutputDepth::F32Hdr, ..RenderRequest::fit(240, 240) },
];
let mut h = 0xCBF2_9CE4_8422_2325u64;
for src in scenes() {
for info in &infos {
for s in golden_settings() {
let s = DevelopSettings { process, ..s };
for req in &reqs {
fnv(&mut h, render_hash(&src, info, &s, req).to_le_bytes());
}
}
}
}
h
}
/// V1 and V2 render byte for byte as they do on main before adding process V3. The hashes were captured
/// on main at e2d18b5fb (before `light_v3`) on macOS aarch64, where they are checked: the renders
/// call the platform's `powf` / `exp2` / `log2`, whose last bit can differ on other platforms, so
/// elsewhere the test only prints them. Before updating them during a rebase, run this exact fixture
/// on main and confirm that both hashes match. This PR must not change V1 or V2 rendering.
#[test]
fn v1_and_v2_render_as_before_v3() {
let got = [golden(ProcessVersion(1)), golden(ProcessVersion(2))];
eprintln!("golden V1 {:#018x}, V2 {:#018x}", got[0], got[1]);
if cfg!(all(target_os = "macos", target_arch = "aarch64")) {
assert_eq!(got, GOLDEN, "V1 / V2 renders changed");
}
}
const GOLDEN: [u64; 2] = [0x5bf0_a7c8_579f_3f34, 0x87a3_598c_1597_9e4d];
fn on(process: Process, s: &DevelopSettings) -> DevelopSettings {
DevelopSettings { process: process.version(), ..s.clone() }
}
/// Every slider and amount the operator checks sweep: Contrast and Blacks with
/// their fits and references.
fn fits() -> [(&'static str, &'static light_v3::Fit, &'static [Reference]); 2] {
[("contrast", &fitted::CONTRAST, fitted::CONTRAST_REFERENCE), ("blacks", &fitted::BLACKS, fitted::BLACKS_REFERENCE)]
}
#[test]
fn the_shipped_fits_unpack_as_the_family_lays_them_out() {
assert!(std::ptr::eq(FITS[0], &fitted::CONTRAST) && std::ptr::eq(FITS[1], &fitted::BLACKS));
for (name, fit, _) in fits() {
let u = fit.unpack().unwrap_or_else(|| panic!("{name} doesn't unpack"));
// D(1) = 0, and Contrast's shapes are anchored at black too
assert_eq!((u.d_pos[11], u.d_neg[11]), (0.0, 0.0), "{name}");
assert_eq!(fit.signed, name == "contrast");
if fit.signed {
assert_eq!((u.d_pos[0], u.d_neg[0]), (0.0, 0.0));
}
assert!([u.law_pos, u.law_neg].iter().all(|(t, q)| t.is_finite() && q.is_finite() && *t > 0.0 && *q > 0.0), "{name}");
let (w0, w1) = u.weights;
assert!((0.0..=1.0).contains(&w0) && (0.0..=1.0).contains(&w1), "{name}");
}
assert_eq!(fitted::CONTRAST.mode, Mode::PerChannel);
assert_eq!(fitted::BLACKS.mode, Mode::Mix);
// a parameter vector that doesn't fit the layout is refused, not read past its end
let short = light_v3::Fit { params: &fitted::CONTRAST.params[..20], ..fitted::CONTRAST };
assert!(short.unpack().is_none());
assert!(Operator::new(&short, 50.0).is_none());
}
#[test]
fn exact_mix_endpoints_select_only_the_contributing_mode() {
assert_eq!(Operator::new(&fitted::BLACKS, -30.0).unwrap().mode, Mode::PerChannel);
assert_eq!(Operator::new(&fitted::BLACKS, 30.0).unwrap().mode, Mode::Mix);
// Synthetic logits also exercise a weight that rounds to exactly zero.
let mut params = fitted::BLACKS.params.to_vec();
*params.last_mut().unwrap() = -1000.0;
let fit = light_v3::Fit { params: Box::leak(params.into_boxed_slice()), ..fitted::BLACKS };
assert_eq!(Operator::new(&fit, -30.0).unwrap().mode, Mode::Luminance);
}
#[test]
fn preview_tables_match_exact_operators_over_combined_amounts() {
let info = camera_look();
let encode = |v| crate::finish::encode_srgb(crate::finish::srgb_lut(), v);
let mut worst = 0.0f32;
for contrast in [-100.0, -60.0, -30.0, 0.0, 30.0, 60.0, 100.0] {
for blacks in [-100.0, -60.0, -30.0, 0.0, 30.0, 60.0, 100.0] {
let mut s = DevelopSettings::default();
s.light.contrast = contrast;
s.light.blacks = blacks;
let Some(exact) = LightOps::new(&s, &info) else { continue };
let preview = light_v3::PreviewOps::new(&exact, &encode);
assert_eq!(preview.is_some(), blacks <= 0.0);
for i in 0..=8192 {
let v = i as f32 / 8192.0;
for p in [[v; 3], [v, v * 0.1, v * 0.02], [v * 0.04, v, v * 0.2], [v * 0.1, v * 0.03, v], [v * 3.0, -v * 0.2, v]] {
let a = exact.apply(p, &linear_to_srgb);
let b = preview.as_ref().map_or_else(|| exact.apply(p, &encode), |preview| preview.apply(p));
for (a, b) in a.into_iter().zip(b) {
let error = (linear_to_srgb(a.clamp(0.0, 1.0)) - linear_to_srgb(b.clamp(0.0, 1.0))).abs() * 255.0;
worst = worst.max(error);
assert!(error <= 1.0, "Contrast {contrast}, Blacks {blacks}, input {p:?}: {error} levels");
}
}
}
}
}
eprintln!("Preview table maximum encoded error {worst:.6} of an 8-bit level");
}
/// The port against the family's own Python (`tools/light_v3_family.py`, through the generated
/// references): `Family.curve` to the references' 12 digits, and `Family.apply` on pixels to the
/// tables' interpolation.
#[test]
fn the_operators_are_fit_pointwise_family() {
for (name, fit, refs) in fits() {
let u = fit.unpack().unwrap();
assert!(!refs.is_empty());
let mut worst = 0.0f64;
for r in refs {
for (v, want) in fitted::REF_V.iter().zip(r.curve) {
let got = u.curve(r.amount, *v);
// (the references are written at 12 significant digits)
assert!((got - want).abs() < 1e-11, "{name} {} at {v}: {got} vs {want}", r.amount);
}
let Some(apply) = r.apply else { continue };
let op = Operator::new(fit, r.amount).unwrap();
for (px, want) in fitted::REF_PIX.iter().zip(apply) {
let lin = px.map(|v| srgb_to_linear(v as f32));
let got = op.apply(lin, &linear_to_srgb).map(linear_to_srgb);
for k in 0..3 {
worst = worst.max((got[k] as f64 - want[k]).abs());
}
}
}
eprintln!("{name}: worst |apply - Family.apply| {worst:.2e} (encoded)");
assert!(worst < 1e-3, "{name}: {worst}");
}
}
/// Each operator is non-decreasing at every integer amount and maps white to white.
#[test]
fn every_operator_is_monotone_and_keeps_white() {
for (name, fit, _) in fits() {
for a in (-100..=100).filter(|a| *a != 0) {
let op = Operator::new(fit, a as f64).unwrap();
assert!(op.lut[0] >= 0.0, "{name} {a}: F(0) = {}", op.lut[0]);
assert!((op.lut[LUT_N - 1] - 1.0).abs() < 1e-6, "{name} {a}: F(1) = {}", op.lut[LUT_N - 1]);
assert!(op.lut.windows(2).all(|w| w[1] >= w[0]), "{name} {a} decreases");
let mut prev = f32::MIN;
for i in -50..=1100 {
let x = i as f32 / 1000.0;
let y = op.channel(x, &linear_to_srgb);
assert!(y >= prev, "{name} {a} at {x}: {y} < {prev}");
prev = y;
}
}
}
}
/// The tables flatten a fold instead of letting tones swap; where the fit is increasing they are
/// the fit.
#[test]
fn a_folding_fit_is_flattened_and_others_are_untouched() {
for (name, fit, _) in fits() {
let u = fit.unpack().unwrap();
for a in [-100.0, -50.0, -10.0, 10.0, 50.0, 100.0] {
let mut fold = 0.0f64;
let mut top = 0.0f64;
for i in 0..LUT_N {
let f = u.curve(a, i as f64 / (LUT_N - 1) as f64);
top = top.max(f);
fold = fold.max(top - f);
}
eprintln!("{name} {a}: fitted curve folds back by {fold:.4}");
assert!(fold < 0.03, "{name} {a}: {fold}");
}
}
}
/// A grey ramp through the camera look: each V4 slider moves the tones its way, keeps their order
/// and keeps the ramp neutral.
#[test]
fn v3_sliders_move_a_grey_ramp_their_way() {
let ramp = Rgb32f::from_fn(256, 8, |x, _| [0.0005 * 1.035f32.powi(x as i32); 3]);
let shot = |id: &str, v: f64| {
let mut s = DevelopSettings::default();
assert_eq!(s.process.process(), Process::V4);
controls::set(&mut s, id, v);
let r = render(&ramp, &camera_look(), &s, &RenderRequest::fit(256, 8)).image;
(0..256).map(|x| r.get(x, 4)).collect::<Vec<[u8; 4]>>()
};
let plain = shot("light.exposure", 0.0);
let luma = |p: [u8; 4]| p[1] as i32;
for (id, v) in [
("light.contrast", 60.0),
("light.contrast", -60.0),
("light.whites", 60.0),
("light.whites", -60.0),
("light.blacks", 60.0),
("light.blacks", -60.0),
] {
let r = shot(id, v);
assert!(r.windows(2).all(|w| luma(w[1]) >= luma(w[0])), "{id} {v}: the ramp is no longer increasing");
assert!(r.iter().all(|p| p[0].abs_diff(p[1]) <= 1 && p[1].abs_diff(p[2]) <= 1), "{id} {v}: the ramp is no longer grey");
let diff = |lo: usize, hi: usize| (lo..hi).map(|x| luma(r[x]) - luma(plain[x])).sum::<i32>();
let (dark, light) = (diff(40, 90), diff(170, 220));
match (id, v > 0.0) {
("light.contrast", true) => assert!(dark < 0 && light > 0, "{id} {v}: {dark} {light}"),
("light.contrast", false) => assert!(dark > 0 && light < 0, "{id} {v}: {dark} {light}"),
("light.whites", true) => assert!(light > 0, "{id} {v}: {dark} {light}"),
("light.whites", false) => assert!(light < 0, "{id} {v}: {dark} {light}"),
(_, true) => assert!(dark > 0, "{id} {v}: {dark} {light}"),
(_, false) => assert!(dark < 0, "{id} {v}: {dark} {light}"),
}
}
}
/// V4 with Contrast, Whites and Blacks at 0 is the Neutral camera look exactly (V2's at 0),
/// whatever the other sliders; other sources render under V4 as under V2.
#[test]
fn v3_at_zero_is_the_neutral_camera_look_and_other_paths_are_v2() {
let reqs = [RenderRequest::fit(480, 480), RenderRequest { depth: OutputDepth::U16, ..RenderRequest::fit(320, 320) }];
let mut typical = DevelopSettings::for_raw(5200.0, 4.0);
for (id, v) in [("light.exposure", 0.4), ("light.highlights", -60.0), ("light.shadows", 30.0), ("effects.clarity", 20.0)] {
controls::set(&mut typical, id, v);
}
let mut hdr = typical.clone();
hdr.hdr.enabled = true;
let hdr_req = RenderRequest { depth: OutputDepth::F32Hdr, ..RenderRequest::fit(240, 240) };
for src in scenes() {
for s in [DevelopSettings::for_raw(5200.0, 4.0), typical.clone()] {
for req in &reqs {
assert_eq!(
render_hash(&src, &camera_look(), &on(Process::V4, &s), req),
render_hash(&src, &camera_look(), &on(Process::V3, &s), req)
);
}
}
assert_eq!(
render_hash(&src, &camera_look(), &on(Process::V4, &hdr), &hdr_req),
render_hash(&src, &camera_look(), &on(Process::V3, &hdr), &hdr_req)
);
let mut edited = typical.clone();
for (id, v) in [("light.contrast", 30.0), ("light.whites", 25.0), ("light.blacks", -20.0)] {
controls::set(&mut edited, id, v);
}
for info in [SourceInfo::default(), SourceInfo { raw: true, ..Default::default() }] {
for req in &reqs {
assert_eq!(render_hash(&src, &info, &on(Process::V4, &edited), req), render_hash(&src, &info, &on(Process::V3, &edited), req));
}
}
// and on the camera look the sliders do something
assert_ne!(
render_hash(&src, &camera_look(), &on(Process::V4, &edited), &reqs[0]),
render_hash(&src, &camera_look(), &on(Process::V4, &typical), &reqs[0])
);
}
let info = camera_look();
assert!(LightOps::new(&on(Process::V4, &typical), &info).is_none(), "nothing to apply at 0");
assert!(
LightOps::new(
&on(Process::V3, &DevelopSettings { light: lightcraft_develop::Light { contrast: 50.0, ..Default::default() }, ..typical.clone() }),
&info
)
.is_none()
);
}
/// Cached renders (a view's stage cache) render as uncached ones do, whole or as a window.
#[test]
fn calibrated_operators_match_in_cached_and_windowed_renders() {
let src = std::sync::Arc::new(lightcraft_scenes::demo_library()[3].render(1200, 800));
let info = camera_look();
let mut s = DevelopSettings::default();
s.light.contrast = 40.0;
s.light.blacks = -60.0;
s.light.whites = 80.0;
let cache = StageCache::default();
let req = RenderRequest::fit(1200, 1200);
for _ in 0..2 {
assert!(render_cached(&src, &info, &s, &req, &cache).image == render(&src, &info, &s, &req).image);
}
let win = PixelWindow { x: 300, y: 200, w: 400, h: 300 };
let wreq = RenderRequest { window: Some(win), ..req };
let (f, w) = (render(&src, &info, &s, &req).image, render_cached(&src, &info, &s, &wreq, &cache).image);
assert!(window_diff(&f, &w, win) <= 1, "the window is the frame's pixels");
}
/// Largest channel difference between window `win` of `full` and the window render `w`.
fn window_diff(full: &Rgba8, w: &Rgba8, win: PixelWindow) -> u8 {
let mut max = 0;
for y in 0..win.h {
for x in 0..win.w {
let (a, b) = (full.get(win.x + x, win.y + y), w.get(x, y));
for k in 0..3 {
max = max.max(a[k].abs_diff(b[k]));
}
}
}
max
}
/// HDR values follow the mode (review of 5a7016c8): per channel a component above 1 passes
/// unchanged; on luminance a pixel whose luminance is at most 1 is scaled as a whole, components
/// above 1 included, and one whose luminance is above 1 passes; Mix blends the two. Both are
/// continuous where a component or the luminance crosses 1.
#[test]
fn hdr_components_follow_the_operators_mode() {
let enc = &linear_to_srgb;
let lum = |p: [f32; 3]| light_v3::PRO_Y[0] * p[0] + light_v3::PRO_Y[1] * p[1] + light_v3::PRO_Y[2] * p[2];
for (name, fit, _) in fits() {
for a in [-100.0, -40.0, 40.0, 100.0] {
let op = Operator::new(fit, a).unwrap();
for p in [[1.2f32, 0.2, 0.05], [3.0, 1.5, 0.8], [0.4, 1.1, 0.02]] {
let pc = p.map(|c| op.channel(c, enc));
assert!(p.iter().zip(&pc).all(|(c, o)| *c <= 1.0 || o == c), "{name} {a}: per channel {p:?} -> {pc:?}");
let y = lum(p);
let l = if y > 1.0 { p } else { p.map(|c| c * op.channel(y, enc) / y) };
let want: [f32; 3] = match op.mode {
Mode::PerChannel => pc,
Mode::Luminance => l,
Mode::Mix => std::array::from_fn(|k| op.weight * pc[k] + (1.0 - op.weight) * l[k]),
};
let got = op.apply(p, enc);
assert!(got.iter().all(|v| v.is_finite()));
assert!(got.iter().zip(&want).all(|(g, w)| (g - w).abs() < 1e-6), "{name} {a} ({:?}): {p:?} -> {got:?}, want {want:?}", op.mode);
}
// continuous where a component crosses 1, and where the luminance does
let (lo, hi) = (op.apply([0.9999, 0.3, 0.1], enc), op.apply([1.0001, 0.3, 0.1], enc));
assert!(lo.iter().zip(&hi).all(|(a, b)| (a - b).abs() < 2e-3), "{name} {a}: {lo:?} | {hi:?}");
let (lo, hi) = (op.apply([0.9999; 3], enc), op.apply([1.0001; 3], enc));
assert!(lo.iter().zip(&hi).all(|(a, b)| (a - b).abs() < 2e-3), "{name} {a}: {lo:?} | {hi:?}");
}
}
}
/// Whites keeps the V2 tone curve for both signs, including HDR and render windows.
#[test]
fn whites_is_byte_identical_to_v2() {
let src = scenes().remove(0);
let info = camera_look();
let reqs = [
RenderRequest::fit(480, 480),
RenderRequest { depth: OutputDepth::U16, ..RenderRequest::fit(320, 320) },
RenderRequest { depth: OutputDepth::F32Hdr, ..RenderRequest::fit(240, 240) },
RenderRequest { window: Some(PixelWindow { x: 80, y: 60, w: 160, h: 120 }), ..RenderRequest::fit(480, 480) },
];
for amount in [-100.0, -50.0, -1.0, 0.0, 1.0, 50.0, 100.0] {
for hdr in [false, true] {
let mut s = DevelopSettings::for_raw(5200.0, 4.0);
s.light.whites = amount;
s.light.exposure = 0.35;
s.light.highlights = -30.0;
s.light.shadows = 20.0;
s.hdr.enabled = hdr;
s.hdr.max_ev = 2.0;
for req in &reqs {
assert_eq!(
render_hash(&src, &info, &on(Process::V4, &s), req),
render_hash(&src, &info, &on(Process::V3, &s), req),
"Whites {amount}, HDR {hdr}, {req:?}"
);
}
}
}
}
#[test]
fn invalid_amounts_are_skipped_and_finite_amounts_are_bounded() {
for fit in FITS {
for a in [0.0, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
assert!(Operator::new(fit, a).is_none());
}
for (a, endpoint) in [(-101.0, -100.0), (101.0, 100.0)] {
assert_eq!(Operator::new(fit, a).unwrap().lut, Operator::new(fit, endpoint).unwrap().lut);
}
}
}
#[test]
fn section_bypass_and_local_adjustments_keep_v2_behavior() {
let src = scenes().remove(0);
let info = camera_look();
let req = RenderRequest::fit(480, 480);
let mut s = DevelopSettings::default();
s.light.contrast = 70.0;
s.light.blacks = -50.0;
s.disabled_sections.push("light".into());
assert_eq!(render_hash(&src, &info, &on(Process::V4, &s), &req), render_hash(&src, &info, &on(Process::V3, &s), &req));
s.light = Default::default();
s.disabled_sections.clear();
s.masks = vec![lightcraft_develop::Mask {
components: vec![lightcraft_develop::MaskComponent {
name: None,
op: lightcraft_develop::MaskOp::Add,
invert: false,
shape: lightcraft_develop::MaskShape::Linear { start: lightcraft_geom::Point::new(0.2, 0.0), end: lightcraft_geom::Point::new(0.8, 1.0) },
}],
adjust: lightcraft_develop::LocalAdjustments { contrast: 40.0, whites: 60.0, blacks: -30.0, ..Default::default() },
..Default::default()
}];
assert_eq!(render_hash(&src, &info, &on(Process::V4, &s), &req), render_hash(&src, &info, &on(Process::V3, &s), &req));
}
+3 -2
View File
@@ -1,6 +1,6 @@
# Gaps: where LightCraft falls short of Lightroom
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-05 · **Change:** minor (PERF-STEP-STALL: flags, ratings and edits never wait for the drive; before: gap 1: the Canon EOS D60 is the first chart-calibrated model, its matrices from our own ColorChecker shots give its white balance a Kelvin scale; gap 20: Canon CRW decodes; LR-LIB-VIRTUALCOPY: default number exhaustion is validated before copy creation; gap 8: lens profile work is tracked in #329; gap 8: lensfun's lens database offered on the first launch and downloaded on request, looked up for the library; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; typed GPS input now rejects malformed coordinates before metadata changes; LR-MAP-TRACKLOG decodes GPX character references in coordinates, elevations and timestamps; malformed references error; CDATA stays literal; ranked gaps unchanged; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; import: checked rename-sequence exhaustion; import review: remembered thumbnail size and density-aware previews (#2237, part of #2056); pre-import loupe/keyboard culling remains open; no ranked gap closes; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; gap 9: CI runs the tests on Linux x64 since #2667; macOS, Windows and the GPU equivalence tests still don't; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; gap 8: Sony ILCE-7RM6 in-file distortion conversion extends to the APS-C ILCE-6700; LR-META-EXIF-FULL rejects extra EXIF clock components and preserves date fallbacks; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks mLine truncated
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-05 · **Change:** minor (Contrast and Blacks calibrated in process V4, #523; PERF-STEP-STALL: flags, ratings and edits never wait for the drive; before: gap 1: the Canon EOS D60 is the first chart-calibrated model, its matrices from our own ColorChecker shots give its white balance a Kelvin scale; gap 20: Canon CRW decodes; LR-LIB-VIRTUALCOPY: default number exhaustion is validated before copy creation; gap 8: lens profile work is tracked in #329; gap 8: lensfun's lens database offered on the first launch and downloaded on request, looked up for the library; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; typed GPS input now rejects malformed coordinates before metadata changes; LR-MAP-TRACKLOG decodes GPX character references in coordinates, elevations and timestamps; malformed references error; CDATA stays literal; ranked gaps unchanged; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; import: checked rename-sequence exhaustion; import review: remembered thumbnail size and density-aware previews (#2237, part of #2056); pre-import loupe/keyboard culling remains open; no ranked gap closes; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; gap 9: CI runs the tests on Linux x64 since #2667; macOS, Windows and the GPU equivalence tests still don't; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; gap 8: Sony ILCE-7RM6 in-file distortion conversion extends to the APS-C ILCE-6700; LR-META-EXIF-FULL rejects extra EXIF clock components and preserves date fallbacks; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap Line truncated
Every known shortfall, one entry each, ranked by user impact (how many Lightroom users hit it, and
how hard it blocks them), then by effort. **Agents pick work from the top** (the first entry nobody is
@@ -17,7 +17,7 @@ Hours are Opus 5.5 agent wall-clock hours (see [target-app-parity.md](target-app
|---:|---|---|---|---:|---|
| 1 B | **Camera colour is estimated, not measured** (LR-PROF-CAMERACOLOR). Raws start from a per-file fit to the camera JPEG, 10 bundled profiles, 52 spectral matrices (plus same-sensor bodies, e.g. the X-T30 through the X-T3) or chart-measured matrices (the EOS D60); others use a neutral matrix (a black-and-white camera JPEG gives its tone curve only, #577; dark JPEG tones also guide the toe, #1307) | ΔE vs camera JPEG 2.9–10 after fitting (raw-parity.md); 1 chart-calibrated model (EOS D60: its Kelvin scale and fallback colour, the look stays the JPEG fit) vs 1,500 Adobe Standard profiles | every raw shooter sees colour that is close but not Lightroom's; some get neutral-matrix colour | 50–90 | [raw-parity](raw-parity.md#colour) |
| 2 B | **CR3 variants no public file uses** (LR-IMP-FORMATS): `crx.rs` refuses vertical-tile C-RAW, partial-subband and other plane coding, multi-tile 0x200 and adaptive low-frequency gains, and those files fall back to the preview. All 110 CC0 CR3s on raw.pixls.us (31 folders) decode from sensor data, so none of these variants has a public sample; 26 CR3 bodies are verified (M50 / R100 / R8 exact, R5 Mark II pinned, 22 more pinned on one CC0 file each and checked against the camera JPEG, [cr3.md](cr3.md#further-bodies-one-cc0-file-each)). HEIF stills are `.HIF` files, not CR3; no CR3 sRAW / mRAW sample exists | measured: Canon's share whose camera fully works 73% → 94% (raw-parity.md); 18 of 22 popular Canon bodies write CR3, all 18 now verified | +0.3 points of photographers; the variants surface only as user files that open as a preview | 10–25 | [raw-parity](raw-parity.md#remaining-work-ranked-by-photographers-unlocked-per-hour) |
| 3 B | **Render fidelity unmeasured** (LR-BEHAV-RENDER-FIDELITY): tone, highlights, texture / clarity / dehaze, NR and sharpening are tuned by eye | no side-by-side suite; a retune needs a new process version (only V1 exists) | edits imported from Lightroom look different; the look "isn't Lightroom's" | 30–60 | [raw-parity](raw-parity.md), [process-versions](process-versions.md) |
| 3 B | **Render fidelity partial** (LR-BEHAV-RENDER-FIDELITY): calibrated camera-look Contrast and Blacks; other operators need measurement | process V3 reduces held-out response error from 0.136 to 0.038 stops for Contrast and 0.424 to 0.077 for Blacks on one Sony camera; Whites remains V2 pending a follow-up | imported Lightroom edits still differ, especially on uncalibrated operators and cameras | 30–60 | [calibrated Light operators](light-v3.md), [process versions](process-versions.md) |
| 4 | ~~Original-pixel detail at 100%~~ (LR-VIEW-ZOOM): closed 2026-10-12, see Closed recently | checklist row ✅ | — | 0 | [ui-parity](ui-parity.md) |
| 5 B | **AI masks: Subject, Sky, People, Background, Landscape** are heuristics; Object / Describe run SAM 3 but its download has no mirror configured | `crates/segment`; ai-masks.md; MASK rows 67% | masking is how most Lightroom users edit today | 40–70 + model decision | [target-app-parity](target-app-parity.md#ai) |
| 6 B | **Compressed ORF** (every Olympus / OM body since ~2008) | measured: 66 of 78 Olympus / OM models preview-only; `orf.rs` refuses; OM bucket 3% of photographers, 3% of them fully work | +2.6 points; best gain per hour of any raw gap (~0.2) | 8–15 | [raw-parity](raw-parity.md#compressed-orf-a-clean-room-starting-point) (the two Olympus patents that describe the method) |
@@ -129,6 +129,7 @@ Beta-blocking gaps (B) total **~230–430 h**; with the stability and platform w
| 2026-10-12 | minor | Gap 10: SR2/SRF folder discovery fixed; F828 imports as preview-only. Sensor decoding remains a gap; readiness scores unchanged |
| 2026-10-23 | minor | Gap 28: ⌘L / Ctrl+L (Library ▸ Enable Filters) puts the filter aside and brings it back as it was; the entry drops ⌘L; hours unchanged |
| 2026-10-15 | minor | Gap 28: `\` shows / hides the Filter Bar in the grids; the entry drops `[` `]` (#509), flag cycling (#1490) and F1 (Help), already on main; ⌘L is the filter-bar key left; hours unchanged |
| 2026-10-12 | minor | Measured Contrast and Blacks calibration; Whites and broader fidelity remain open |
| 2026-10-16 | patch | Gap 13: catalog VIDEO records match the Videos filter, including after reimport of older records (#1940, filter issue only). Video playback, frame previews and folder-sync discovery remain outside this repair; no gap closed or counts changed. |
| 2026-10-14 | minor | Gap 26: at 100k photos stack and album lookups are indexed, so an "In a Stack" or "Album" smart album counts in ~14 ms (was 0.6–2.7 s); open time unchanged |
| 2026-10-14 | minor | Gap 10: Camera-coverage sweep (#1327): 30 models verified on 40 CC0 files (coverage.py 515 → 545 verified); sensor verification does not establish colour parity (#1277) |
+5
View File
@@ -8,6 +8,11 @@ CPU fast guided-filter allocation measurements and reproduction commands are doc
[guided-filter-memory.md](guided-filter-memory.md). That optimization retains the full-size base
and does not change the GPU's coefficient buffers.
Process V4's camera-look Contrast and Blacks share the CPU's generated lookup tables and
ProPhoto matrices. `finish.wgsl::light_ops` applies them after V2's Whites tone curve and
before the colour stage. Full frames and render windows use the same pointwise operators;
see [calibrated Light operators](light-v3.md) for HDR rules and limits.
Warped geometry uses a CPU-computed coverage bit mask for the source boundary.
The CPU reference evaluates that boundary in double precision; GPU float
rounding otherwise can turn a blank edge pixel into a photo pixel. The mask
+187
View File
@@ -0,0 +1,187 @@
# Calibrated Contrast and Blacks
> **Last updated:** 2026-10-13 · **Change:** minor (preserve exact evaluation for luminance mixes)
Process V4 calibrates global Contrast and Blacks on the camera-look path: a raw with
`SourceInfo::camera_tone`. Contrast acts per channel. Blacks blends a per-channel result with
luminance scaling. Whites in V4 behaves exactly as V2, for positive and negative amounts.
Whites calibration is a planned follow-up.
This is the Contrast and Blacks split of the original V4 calibration work. The serialized
number is defined by the `Process::V4` arm in `Process::version()`; callers use the enum.
Open PR #944 also proposes V4 and V4, #1283 proposes V4 for Dehaze, and #1286 follows #1283.
Maintainers must assign the final process numbers and inheritance in merge order. V4 here
inherits V2 only.
Raw files without a camera curve, rendered sources such as JPEG and TIFF, and local mask
adjustments keep their V2 operators. This process does not change decoding, source metadata,
smart-preview formats, library opening, or Update and Reset checks.
## Render order
The camera tone curve uses V2 Whites with Contrast and Blacks set to zero. The renderer
maps luminance through that curve, applies its chroma scaling and highlight desaturation,
then applies calibrated Contrast followed by calibrated Blacks, before the colour stage.
When both calibrated sliders are zero, no new operator or colour conversion runs. With any
Whites value and both calibrated sliders at zero, the result is byte-identical to V2.
Combined edits use V2 Whites before the two calibrated operators.
The operators convert linear Rec.2020 to linear ProPhoto RGB (D50, with Bradford white-point
adaptation), encode values with the sRGB transfer curve, apply the fitted curves, and convert
back. The matrices come from `RgbSpace::to_space`. CPU `finish.rs` and GPU `finish.wgsl` use
the same matrices and operator tables. CPU previews compose per-channel operations into
tables indexed by linear input. The computation is pointwise, so a render window needs
no whole-photo measurement.
## Operator family
For a slider amount `a` between -100 and 100, with `t = abs(a) / 100`:
- Positive amounts use `F_a(v) = v + s_pos(t) * D_pos(v)`.
- Negative amounts use `F_a(v) = max(0, v - s_neg(t) * D_neg(v))`.
- Each displacement shape is piecewise linear on 12 knots: 0, .02, .05, .09, .14, .2, .28,
.38, .5, .65, .82 and 1. Both shapes satisfy `D(1) = 0`. Contrast also fixes `D(0) = 0`.
- The amount law is `s(t) = ((1 - exp(-t / tau)) / (1 - exp(-1 / tau)))^q`, with separate
fitted `tau` and `q` for each sign. Zero amount is the identity.
Contrast applies `F` to each encoded ProPhoto channel. For Blacks, the luminance result
scales linear RGB by `F(Y) / Y`, where the linear ProPhoto luminance coefficients are
`[0.2880402, 0.7118741, 0.0000857]` and `F(Y)` includes encoding and decoding. Blacks blends
that result with the per-channel result in linear light, using one fitted weight per sign.
Each active operator has 1024 table entries over encoded values between 0 and 1. The entries
store linear output and are interpolated linearly. A running maximum prevents a fitted
curve from reversing tone order. Neither shipped fit folds back. Non-finite amounts are
skipped, and finite amounts are clamped to the slider range.
When the resolved per-channel weight is exactly one or zero in f32, the renderer selects
only the per-channel or luminance operation. In particular, negative Blacks is per channel.
For 8-bit CPU renders, per-channel Contrast and Blacks share one table with 16,384 intervals
over linear input. If any operator uses luminance, the renderer retains the original
evaluation for every operator, including Contrast before positive Blacks. Preview renders
use the existing sRGB encoding table and the source operator tables without the additional
linear-input approximation. U16 and F32 exports retain the original operator tables and
exact sRGB encoding. Metal retains the original tables too.
Camera chroma scaling can create mixed-sign ProPhoto components from nonnegative source
pixels. Their luminance terms can nearly cancel. A small Contrast approximation error can
then cross the `1e-6` luminance cutoff or be amplified by `F(Y) / Y`. A scalar interpolation
error bound does not bound the rendered error after this scaling. Exact evaluation avoids
introducing this disagreement with the earlier CPU path and Metal. It retains their
pre-existing rounding differences near the cutoff.
### HDR and gamut limits
A per-channel component above 1 passes unchanged. A component below zero keeps its distance
below the image of zero. Luminance scaling leaves a pixel unchanged when its luminance is
above 1 or at most `1e-6`. Otherwise it scales the entire pixel, including components above
1. Blacks blends these two results, so an above-white component can move when the pixel's
luminance is below white. The functions are continuous at white. HDR tone mapping and
Whites retain V2's behavior. GPU renders use 8-bit previews; high-bit-depth exports use the
CPU. These are numerical rules, not measured Lightroom HDR parity.
## Fit provenance and reproduction
The coefficients were fitted to black-box observations of the owner's Lightroom exports:
16-bit sRGB exports of Sony ILCE-7CR photos, paired with the same photo's Neutral or another
slider amount exported in the same batch. Only exported pixels were used. No Adobe code,
profiles, tables or application assets were used. The photos were split into tune photos
used for fitting and check photos held out for measurement.
| Slider | Fit | Mode | Tune | Check |
|---|---|---|---|---|
| Contrast | `v2-contrast-pc` | Per channel | 155 pairs, 20 photos | 61 pairs, 6 photos |
| Blacks | `v2-blacks-mix` | Per-channel/luminance mix | 148 pairs, 19 photos | 60 pairs, 6 photos |
The exports and the optimizer that reads them remain private. Public tools in this change
contain the operator family, sanitized fits with coefficients and aggregate errors, and the
generator. Fit files contain no photo names, paths or per-photo values. Their provenance
records the original fit filename and SHA-256. The Rust constants record each sanitized
fit's SHA-256 as well.
The sanitizer omits error groups and individual bands with fewer than three distinct
contributing photos. Published rows record the distinct photo counts for the group and its
retained bands. Repeated pairs from one photo do not satisfy the threshold. Coefficients
and overall counts remain available. These omissions do not change the fits or the full
paired agreement measurements below.
```sh
python3 -m pip install -r tools/requirements-light-v3.txt
python3 tools/light_v3_constants.py rust
python3 tools/light_v3_constants.py rust --check
```
`--check` must reproduce `crates/pipeline/src/light_v3_params.rs` byte for byte. The generator
writes reference outputs from `tools/light_v3_family.py` to 12 significant digits, avoiding
platform-dependent final bits in NumPy. Rust tests compare the port against those references.
`sanitize` accepts only Contrast and Blacks fits and writes their public aggregate form.
`python3 -m unittest discover -s tools -p 'test_light_v3_constants.py'` checks the publication
threshold with synthetic inputs and scans all committed fit files.
## Measured agreement
The private agreement harness compares the log2-luminance response of each export pair with
LightCraft's response to the same two recipes. The reported error, in stops, is the mean over
rows (amount, reference and size) of the median over photos. Both builds use the same photos;
a registration rejected in either run is omitted from the paired comparison. The historical
V2 baseline is main at `76b53778`. The six check photos were not used to fit the operators.
| Slider | V2 tune | Calibrated tune | V2 check | Calibrated check |
|---|---:|---:|---:|---:|
| Contrast | 0.168 | 0.059 | 0.136 | 0.038 |
| Blacks | 0.540 | 0.112 | 0.424 | 0.077 |
| Whites | 0.176 | 0.176 | 0.075 | 0.075 |
Contrast and Blacks values are the source calibration's measured results, reproduced by
this split's verification. Whites uses V2. A single camera and one person's photos do not
establish fidelity across cameras. Blacks still has larger errors in the darkest band.
Exposure, Highlights, Shadows, Whites and other operators need further work. Local
adjustments and sources without a camera curve have no new calibration.
## Cost and stability
Each active operator has a 4 KiB source table, at most 8 KiB for both. CPU previews also
build one composed table of 128 KiB when all active operators are per channel. Each of its
16,384 intervals stores an intercept and slope. The composed per-channel path uses three
lookups per pixel and two colour matrix multiplications. A luminance mix builds no composed
table. It evaluates the original encoding and source tables, luminance scaling and blend.
There is no extra image pass, source read, per-photo state or statistic. Zero Contrast and
Blacks skip the new work. Metal and high-bit-depth CPU exports allocate only the source tables.
Release measurements on an M3 Max used two Rayon threads and nine interleaved samples per
case against main `701f78ea` and round 2 `41074392`. The two public raw files were from a
Sony ILCE-7M3 and Nikon D750. Fit used a 2560-pixel source preview in a 1920 by 1280 viewport;
1:1 windows used native source pixels in that viewport. Each worker decoded once and warmed
its cache; every timed sample changed exposure. Decode, cache preparation and file encoding
are excluded.
With Contrast +40 and Blacks -30, CPU wall times were 1.22 to 1.28 times main and 1.01 to
1.024 times round 2. A 27-sample confirmation of the slowest Nikon window case measured
75.33 ms on main, 94.76 ms on round 2 and 96.45 ms here. Its ratio is 1.28 times main and
1.018 times round 2. The fused path remains, with a small measured cost increase in this run.
With Contrast +40 and Blacks +30, CPU wall times were 1.97 to 2.02 times main and 1.20 to
1.28 times round 2. Blacks +30 alone took 1.61 to 1.64 times main and 1.17 to 1.19 times
round 2. These positive-Blacks cases exceed the approximate 1.25-times-main cost target.
They need the original operator evaluation because the extra preview interpolation can
change the luminance cutoff result or have its error amplified by luminance scaling.
Metal medians for these settings were 3.25 to 4.97 ms, with the original GPU operators.
CPU neutral controls were 0.99 to 1.00 times main. The general `cargo xtask bench` run also
completed before and after the fix, with no CPU-time regression above its 20% threshold.
Other work on the shared machine was not controlled. These measurements do not establish
tail latency or performance on other GPU backends.
V1 and V2 keep their rendering and persistent cache keys. Persistent keys from process V4
on include the process this build actually renders with, so saved settings from a newer
build cannot reuse pixels generated by a different resolved process. V4 keeps V2's
Highlights and Shadows base. New imports and Reset select the latest process; Update to
Current Process remains one undoable settings change and never downgrades a future number.
## Revision history
| Date | Change | Summary |
|---|---|---|
| 2026-10-13 | minor | Preserve the original evaluation for luminance mixes, including preceding Contrast, and cover two uniform cutoff regressions |
| 2026-10-13 | minor | Compose CPU preview lookups, preserve exact deep exports, and require three distinct photos per published error aggregate |
| 2026-10-12 | new | Split Contrast and Blacks calibration, preserve V2 Whites and legacy rendering |
+9 -8
View File
@@ -31,7 +31,7 @@ cited here still exists. Formerly docs/parity.md.
| C. Views & navigation (VIEW) | 16 | 1 | 1 | 0 | 9/9 (100%) | 4/4 (100%) |
| D. Search & filter (FILT) | 11 | 1 | 1 | 0 | 4/4 (100%) | 4/4 (100%) |
| E. Metadata (META) | 5 | 1 | 0 | 0 | 2/2 (100%) | 2/2 (100%) |
| F. Edit panel — global adjustments (EDIT) | 43 | 3 | 3 | 1 | 27/28 (96%) | 13/14 (93%) |
| F. Edit panel — global adjustments (EDIT) | 40 | 6 | 3 | 1 | 24/28 (86%) | 13/14 (93%) |
| G. Profiles (PROF) | 7 | 1 | 3 | 0 | 3/4 (75%) | 3/3 (100%) |
| H. Crop & rotate (CROP) | 10 | 1 | 0 | 1 | 8/8 (100%) | 2/3 (67%) |
| I. Remove / healing (REM) | 8 | 1 | 2 | 2 | 4/4 (100%) | 2/3 (67%) |
@@ -53,9 +53,9 @@ cited here still exists. Formerly docs/parity.md.
| Y. Menus | 85 | 0 | 4 | 8 | 47/47 (100%) | 23/23 (100%) |
| Z. Keyboard shortcuts (desktop) | 78 | 4 | 2 | 1 | 49/52 (94%) | 24/26 (92%) |
| Lightroom Classic extras | 41 | 25 | 21 | 8 | — | 24/26 (92%) |
| **Total** | 420 | 66 | 57 | 35 | 195/203 (96%) | 146/161 (91%) |
| **Total** | 417 | 69 | 57 | 35 | 192/203 (95%) | 146/161 (91%) |
Weighted completion (✅ = 1, 🟡 = ½, 🚫 left out): **83.4%** of 543 in-scope rows — P0 98.0% of 203 · P1 94.4% of 161 · P2 56.7% of 178.
Weighted completion (✅ = 1, 🟡 = ½, 🚫 left out): **83.1%** of 543 in-scope rows — P0 97.3% of 203 · P1 94.4% of 161 · P2 56.7% of 178.
<!-- /parity:summary -->
## Top gaps and shortcut notes
@@ -179,11 +179,11 @@ differences and missing bindings are in [ui-parity.md](ui-parity.md#shortcuts).
| LR-EDIT-BW | Black & white | P0 | ✅ | `cmd:develop.treatment` | |
| LR-EDIT-HDR-MODE | HDR editing | P2 | ✅ | `cmd:develop.hdr`, `ctl:hdr.maxEv`, `crates/ui-egui/src/panels/edit.rs` (`hdr_row`) | HDR button next to B&W in the Edit panel header, as Lightroom (Visualize HDR and the headroom limit in the Light panel while it's on, sliding open and shut with the histogram's layout change); see Q. HDR |
| LR-EDIT-LIGHT-EXPOSURE | Exposure | P0 | ✅ | `ctl:light.exposure` | Alt/Option-drag shows highlight clipping (black, clipped channels in colour) |
| LR-EDIT-LIGHT-CONTRAST | Contrast | P0 | ✅ | `ctl:light.contrast` | |
| LR-EDIT-LIGHT-CONTRAST | Contrast | P0 | 🟡 | `ctl:light.contrast` | From process V4, global Contrast on the camera-look path is fitted per channel in ProPhoto with the sRGB transfer. Check response error 0.136 to 0.038 stops on six held-out Sony photos. Other sources and local adjustments retain V2; broader parity remains unverified (`docs/light-v3.md`). |
| LR-EDIT-LIGHT-HIGHLIGHTS | Highlights | P0 | ✅ | `ctl:light.highlights`, `crates/raw/src/highlight.rs` | sensor-clipped highlights stay neutral when Highlights (or Exposure, Whites) darkens them: fully clipped content is rebuilt to the neutral of the colour model applied after it, partly clipped content takes its colour from reliable unclipped content nearby (not from dark objects, lens fringes or another surface beside it) and white where there is none, and pale partly clipped content (a white sky) turns white on its way to clipping (#523); binned previews and thumbnails decide clipping per sample before averaging (`develop_binned_masked`, `highlight::reconstruct_masked`), so a block with one clipped specular sample keeps its mean instead of jumping to the clip level, which reconstruction turned into green speckles at 500 px (#548) From process V2 the Highlights/Shadows base is the edge-aware filter of the 0.15 %-of-long-edge median of log luminance: twigs and fine texture take their surroundings' shift, so bright areas keep their local contrast as with Exposure (V1's base kept ~0.6 of it at −100, #632); region edges stay sharp. Alt/Option-drag shows highlight clipping |
| LR-EDIT-LIGHT-SHADOWS | Shadows | P0 | ✅ | `ctl:light.shadows` | From process V2, the same base as Highlights: dark areas keep their local contrast when lifted (#632). Alt/Option-drag shows shadow clipping (white, clipped channels in colour) |
| LR-EDIT-LIGHT-WHITES | Whites | P0 | ✅ | `ctl:light.whites`, `crates/pipeline/src/visualize.rs` | Alt/Option-drag shows highlight clipping (black, clipped channels in colour) |
| LR-EDIT-LIGHT-BLACKS | Blacks | P0 | ✅ | `ctl:light.blacks`, `crates/pipeline/src/visualize.rs` | Alt/Option-drag shows shadow clipping (white, clipped channels in colour) |
| LR-EDIT-LIGHT-WHITES | Whites | P0 | 🟡 | `ctl:light.whites`, `crates/pipeline/src/visualize.rs` | V4 preserves V2 Whites for both signs. Calibration is a planned follow-up; measured V2 check response error is 0.075 stops on the Sony test photos (`docs/light-v3.md`). Alt/Option-drag shows highlight clipping (black, clipped channels in colour) |
| LR-EDIT-LIGHT-BLACKS | Blacks | P0 | 🟡 | `ctl:light.blacks`, `crates/pipeline/src/visualize.rs` | From process V4, global Blacks on the camera-look path uses a fitted per-channel/luminance mix. Check response error 0.424 to 0.077 stops on six held-out Sony photos; deepest tones still differ. Other sources and local adjustments retain V2 (`docs/light-v3.md`). Alt/Option-drag shows shadow clipping (white, clipped channels in colour) |
| LR-EDIT-LIGHT-CURVE-PARAM | Parametric curve | P0 | ✅ | `ctl:curve.highlights`, `ctl:curve.lights`, `ctl:curve.darks`, `ctl:curve.shadows`, `ctl:curve.split*`, `crates/pipeline/src/curve.rs` | the graph draws the renderer's own curve model; dragging the line moves the region under the pointer (one undo step) |
| LR-EDIT-LIGHT-CURVE-POINT | Point curve | P0 | ✅ | `cmd:develop.curve`, `cmd:curve.reset`, `cmd:curve.presets`, `cmd:curve.applyPreset`, `cmd:curve.savePreset`, `cmd:curve.deletePreset`, `cmd:curve.importPresets`, `cmd:curve.exportPresets`, `cmd:file.importCurvePresets`, `cmd:file.exportCurvePresets`, `crates/engine/src/cmd/curves.rs`, `crates/ui-egui/src/panels/edit.rs` | click to add a point; drag a point in both axes (between its neighbours, input / output readout, one undo step per drag; ⌥-drag moves it a tenth as far for fine adjustment, issue #1363); drag empty space to add and drag; double-click removes; reset: double-click a channel selector (that channel), the Reset button under the graph (every curve incl. parametric) or right-click the graph (channel / all); Point Curve preset dropdown: own Linear / Medium Contrast / Strong Contrast, user presets (save the current point curves, delete by right-click; saved with the library), import / export as `.lccurve` JSON |
| LR-EDIT-LIGHT-CURVE-RGB | Per-channel curves | P0 | ✅ | `cmd:develop.curve` (`channel`) | |
@@ -465,7 +465,7 @@ differences and missing bindings are in [ui-parity.md](ui-parity.md#shortcuts).
| LR-BEHAV-OFFLINE | Offline editing | P1 | ✅ | | local-first: everything works offline |
| LR-BEHAV-WEB-SAFETY | Library safety in the browser build | P1 | 🟡 | `cmd:file.backupLibrary`, `cmd:file.restoreLibrary`, `apps/lightcraft-web/src/safety.rs`, `apps/lightcraft-web/src/backup.rs`, `apps/lightcraft-web/src/files.rs` | web only (experimental): Back Up Library (zip of the catalog and every stored original) and a non-destructive Restore; failed saves show as unsaved and are retried; a photo that can't be stored isn't added; one tab per library (Web Locks); notices for storage that isn't persistent and for a library that can't open; `?reset` asks first; a panic shows a message. Missing: `?safe` start, deleting originals of removed photos, zip64 (backups > 4 GB) |
| LR-BEHAV-GPU | GPU acceleration | P0 | ✅ | `crates/gpu/src/render.rs`, `cmd:app.gpu`, `docs/gpu-pipeline.md`, `crates/ui-egui/src/panels/notices.rs` | CPU fallback per render on device limits, out of memory, device errors / loss, incomplete or black results (`perf.gpuReason`, `perf.gpuFallback`; each render reports its own reason — `lightcraft_gpu::try_render`, `gpuFallback` per exported file — issue #675); short submissions for slow iGPUs; backend choice (DX12 only on Windows, `LIGHTCRAFT_GPU_BACKEND` / `WGPU_BACKEND`), device created after the window opens, crash sentinel (issue #136); a GPU lost while LightCraft runs (driver reset) stops it with that message and turns GPU rendering off for the next start, which says why (issue #1337; the window's renderer can't survive the lost device); quitting waits (up to 2 s) for renders in flight and starts no new GPU work, so none is inside the driver when the process exits (`crates/gpu/src/exit.rs`, issue #620; seen crashing only on Linux + NVIDIA, other drivers unverified); with GPU rendering on and no adapter found at all (e.g. no Vulkan loader on NixOS outside `nix develop`), the desktop app says once per session that it renders on the CPU and points to Help ▸ System Info (`gpu_notice`; not when the GPU is turned off or only a software adapter exists); no tiling beyond the buffer limit (CPU) |
| LR-BEHAV-RENDER-FIDELITY | Rendering matches Lightroom | P1 | 🟡 | `crates/pipeline/src/lib.rs`, `crates/pipeline/src/tone.rs` | every slider exists and works, but the character of the result (tone curve shape, highlight recovery, texture / clarity / dehaze, noise reduction, sharpening, default look) is tuned by eye; there is no systematic side-by-side comparison against Lightroom on the same CC0 raws. Needs a fidelity suite: Lightroom reference renders kept only in the local `plan/` (never committed), compared per slider and preset with a perceptual metric. Tuning that changes how existing settings render ships as a new process version (LRC-DEV-PROCESS, `docs/process-versions.md`) |
| LR-BEHAV-RENDER-FIDELITY | Rendering matches Lightroom | P1 | 🟡 | `crates/pipeline/src/lib.rs`, `crates/pipeline/src/tone.rs` | Process V4 calibrates global camera-look Contrast and Blacks against black-box Lightroom exports of Sony ILCE-7CR photos. Held-out response errors are 0.038 and 0.077 stops; V1/V2 keep their rendering. Whites retains V2 and awaits a follow-up. Exposure, Highlights/Shadows, other operators and broader camera coverage remain open (`docs/light-v3.md`). |
| LR-BEHAV-DRAGDROP | Drag and drop | P1 | ✅ | `crates/ui-egui/src/lib.rs`, `crates/ui-egui/src/panels/grid.rs` (`drag_feedback`), `crates/ui-egui/src/panels/left.rs` (`drop_target`, `album_drag_over`, `top_level_drop_target`, `drag_auto_scroll`), `crates/ui-egui/src/destination.rs`, `crates/ui-egui/src/widgets.rs` (`context_menu`), `crates/ui-egui/src/widgets/text_field.rs`, `crates/ui-egui/src/tests/carried_right_click.rs`, `crates/ui-egui/src/tests/carried_text_field_menu.rs` | a right-click while photos are carried opens no context menu (every menu opened through `widgets::context_menu`: sidebar rows, grid cells, lists; a text field's own Cut / Copy / Paste menu too); files → app (a drop-target card while they hover, then the import review); grid photos → an album row (adds the selection, with a count badge while dragging); sidebar album / folder rows → a folder (moves it; its name follows the pointer); a drag of albums or grid photos near the top or bottom edge of the sidebar scrolls it (faster nearer the edge, only while the pointer is over the sidebar); when another folder has the same name, the dragged label, the Move question and the toast name the folder it is in (`home (/a)`); an album drop's toast does the same for an album of that name in another album folder (two in the same place have nothing to tell them apart and keep the plain name); only the primary button drags photos and drops them: a right-button drag over a grid cell neither picks photos up nor changes the selection, and a right-button release while photos are dragged neither drops them nor ends the drag |
| LR-BEHAV-TOAST | Toast notifications | P1 | ✅ | `crates/ui-egui/src/panels.rs` | |
| LR-BEHAV-DIALOGS | Dialogs fit the window | P1 | ✅ | `crates/ui-egui/src/dialogs.rs` (`dialog_body`, `list_height`), `crates/ui-egui/src/tests/dialog_fit.rs`, `crates/ui-egui/src/tests/dialog_copy.rs`, `crates/ui-egui/src/tests/dialogs.rs` (`a_click_outside_closes_the_dialog_when_settings_allow_it`) | a dialog taller than the window (Export on a 1366×768 screen, issue #781) never runs off it: its options scroll while the title bar and the Cancel / confirm row stay on screen (the confirm button names its action: Create, Rename, Create Stacks, Export 3 Photos…, with "OK" kept only for a one-field prompt opened with a command that has no verb, `crates/ui-egui/src/tests/dialog_copy.rs`); lists that scroll on their own (What's New, All Metadata, shortcuts, smart-album rules, credits) get shorter first; dialogs that fit look as before; Import keeps its own resizable, scrolling window; Settings → Dialogs → Close a dialog by clicking outside it (off by default, so a stray click never throws away a dialog's choices): a click pressed and released on the dimmed backdrop closes the dialog like Esc and doesn't reach the panels below, while a drag that ends outside (a slider pulled past the edge) or a click that closes a dropdown keeps it; the import review never closes this way (`clicked_backdrop`); a one-line prompt (Rename Folder, New Folder on Disk, the preset and version names, New Library when its name can't be used, Auto-Tag from Tracklog) the engine refuses stays open with its text and shows the reason in a toast, so the name can be corrected, where it used to close without a word; a New Folder on Disk that works says so (“Created folder “Selects” in “2026/Shoot””, naming the parent by its last two folders as dialogs do) |
@@ -729,7 +729,7 @@ From `08-lightroom-classic-extras.md` (Classic-only features) and part 2 of `06-
| LRC-DEV-CALIB | Calibration panel | P1 | ✅ | `ctl:calibration.*` | |
| LRC-DEV-TAT | Targeted adjustment tools | P1 | ✅ | `cmd:develop.targeted` (`target`: curve / hue / sat / lum) | |
| LRC-DEV-DEFAULTS | Per-camera raw defaults | P1 | ✅ | `cmd:library.preferences` (`camera`, `import.perCamera`), `crates/ui-egui/src/dialogs/settings.rs` | Settings → Import: raw default and per-camera presets |
| LRC-DEV-PROCESS | Process versions, Update to Current Process | P1 | ✅ | `cmd:develop.updateProcess`, `cmd:develop.reset`, `cmd:develop.get`, `crates/develop/src/settings.rs`, `crates/pipeline/src/finish.rs`, `docs/process-versions.md` | each photo records the rendering process its settings are interpreted by: settings saved before this existed load as V1, new photos and Reset get the latest, virtual copies inherit, copy / paste / sync / presets keep each photo's own; Photo ▸ Update to Current Process (one undo step, enabled while a selected photo is on an older process); a number from a newer LightCraft is kept and renders with the newest known process. Only V1 exists so far: this is what lets a retuned default tone (#146) or stronger Light sliders (#196) ship without changing existing edits |
| LRC-DEV-PROCESS | Process versions, Update to Current Process | P1 | ✅ | `cmd:develop.updateProcess`, `cmd:develop.reset`, `cmd:develop.get`, `crates/develop/src/settings.rs`, `crates/pipeline/src/finish.rs`, `docs/process-versions.md` | Each photo keeps its saved rendering process. V1 is legacy, V2 preserves Highlights/Shadows detail, V3 is pixel-scale sharpening, V4 calibrates camera-look Contrast and Blacks. New photos and Reset use the latest; Update is one undoable step and never downgrades a future number. Copy/paste/sync preserve the receiving process. Persistent render keys include the resolved process from V3 on; V1/V2 keys remain unchanged. |
| LRC-DEV-VIEWOPTIONS | Develop view options | P2 | 🟡 | `cmd:view.viewOptions`, `crates/ui-egui/src/dialogs/settings.rs` (`view_options`) | View ▸ View Options… (⌘J), the Loupe View part: Show Info Overlay with Info 1 / Info 2, and the three lines of each (none, file name, capture date, dimensions, exposure, camera, lens, camera + lens) with Use Defaults; Show Briefly When Photo Changes under each Info (one at most): with the overlay off, that Info shows for 3 s each time the loupe changes photo; General's Show message when loading or rendering photos (on by default; off, the loupe does not say "Rendering…"); applied as they change, saved with the app settings; `view.viewOptions {info1, info2, briefly, loupeMessages}` sets them for agents. Not yet: the Grid View tab, more fields (ratings, metadata, copy name), the video-frame option |
| LRC-DEV-LOUPEOVERLAY | Loupe overlay: layout image | P2 | 🟡 | `cmd:view.chooseLayoutImage`, `cmd:view.layoutImage`, `cmd:view.layoutImageOpacity`, `cmd:view.layoutImageMatte`, `crates/ui-egui/src/panels/layout_overlay.rs` | View ▸ Loupe Overlay: a PNG with transparency (a cover layout, a banner's safe areas) fitted and centred over the loupe photo, following zoom and pan; opacity and matte (the photo darkened outside the graphic's box) in steps; ⌥⌘O shows / hides it; read off the UI thread; saved with the UI state. Not yet: the Grid and Guides overlays, moving and resizing the layout with ⌘ held, free opacity / matte sliders |
| LRC-DEV-VIDEO | Video frame capture | P2 | ⬜ | | |
@@ -878,6 +878,7 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove
| 2026-10-13 | minor | LRC-LIB-KEYWORDS: the Keyword List marks a keyword that has an applied keyword inside it (a dot in its box); status unchanged |
| 2026-10-12 | minor | LR-IMP-FORMATS: folder discovery includes SR2/SRF; MCP and CLI reuse the engine extension list. DSC-F828 remains preview-only; decoder support and row status unchanged |
| 2026-10-15 | patch | KEYC-RATING: `\` shows / hides the Filter Bar in Photo Grid and Square Grid (Show Original in Detail); status unchanged (🟡) |
| 2026-10-12 | minor | Calibrated Contrast and Blacks; mark the measured but incomplete Light controls partial and retain V2 Whites |
| 2026-10-16 | minor | KEY-TOGGLEZOOM: Space held over a tool on the photo is the view's hand (click zooms, drag pans, the tool gets neither), a tap still toggles; a held Space toggles once (issue #1895); status unchanged |
| 2026-10-16 | patch | LRC-LIB-CATALOG-IMPORT: VIDEO records appear in the Videos filter; reimport repairs older classification with edits, memberships and undo preserved (#1940, filter issue only). Status and summary counts unchanged. |
| 2026-10-12 | minor | LR-EDIT-OPTICS-PROFILE: Sony ARW shading, CA and distortion tables decoded with settings and provenance (raw IFD, `SR2SubIFD` fallback); applied corrections unchanged (ILCE-7RM4A and ILCE-7RM6 distortion); status unchanged (🟡) |
+16 -2
View File
@@ -1,5 +1,7 @@
# Process versions
> **Last updated:** 2026-10-12 · **Change:** minor (calibrated Contrast and Blacks)
Every photo's develop settings record the **rendering process** they are interpreted by
(`DevelopSettings::process`, a `ProcessVersion` in `crates/develop/src/settings.rs`). Lightroom calls
this the process version. It lets the look of LightCraft improve (a new default tone curve, issue #146;
@@ -9,7 +11,8 @@ stronger Light sliders, issue #196) without changing a single photo someone has
|---|---|
| **V1** | LightCraft's rendering from before process versions existed. Frozen. |
| **V2** | Highlights and Shadows keep fine detail (issue #632): their base layer (`local::tone_base`) is the edge-aware filter of a separable median of log luminance (radius 0.15 % of the long edge, at most 24 px, `local::BASE_DETAIL`) instead of log luminance itself, so twigs, lines and texture take their surroundings' shift and keep their contrast; region edges stay sharp. CPU (`local::prepare`) and GPU prepare branch on `local::tone_base_detail` (0 = no median under V1); the base plane is cached per process (`local::BaseKey`). Renders without Highlights or Shadows (global or local) are the same as V1's. Tone map unchanged. |
| **V3** (the latest) | Pixel-scale sharpening (issue #757): Radius uses the original photo’s pixels, Detail controls halo damping, and downsized sources retain a response-matched sharpening band. V1 and V2 keep texture-band sharpening exactly. The sharpen plane is keyed by radius and process and invalidated after noise-reduction changes. The Highlights/Shadows base and tone map are unchanged from V2. |
| **V3** | Pixel-scale sharpening (issue #757): Radius uses the original photo’s pixels, Detail controls halo damping, and downsized sources retain a response-matched sharpening band. V1 and V2 keep texture-band sharpening exactly. The sharpen plane is keyed by radius and process and invalidated after noise-reduction changes. The Highlights/Shadows base and tone map are unchanged from V2. |
| **V4** (the latest) | V3 plus calibrated global Contrast (per channel) and Blacks (per-channel/luminance mix) on raws with a camera tone curve. Whites behaves exactly as V2, both signs; its calibration is a planned follow-up. Other sources and local adjustments retain V2 operators. See [calibrated Light operators](light-v3.md). |
## The rule
@@ -74,7 +77,7 @@ written against the current rendering. `crs:ProcessVersion` numbers Adobe's rend
ignored; a photo imported with Lightroom edits is on LightCraft's latest process, and an existing
LightCraft photo that receives them keeps its own.
**A number this build doesn't know** (a library or sidecar written by a newer LightCraft) loads, is
**A number above this build's latest** (a library or sidecar written by a newer LightCraft) loads, is
kept when saved, and renders with the newest process this build has. Update to Current Process never
moves a photo to an older process; Reset does move it to this build's latest.
@@ -89,3 +92,14 @@ The process is saved as `"process": <number>` in the settings JSON, except V1, w
Settings made before process versions existed are therefore saved exactly as before, and their
preview-cache keys (`DevelopSettings::hash64`) don't change. `develop.get` (MCP `get_develop`) always
states the process.
From process V3 on, persistent thumbnail, view-render and variant keys also include the
resolved rendering process. A future number can keep the same settings hash across builds
while resolving to different operators, so those keys must differ. V1 and V2 omit this
extra field and retain their existing cached renders. No cache-version bump is needed.
## Revision history
| Date | Change | Summary |
|---|---|---|
| 2026-10-12 | minor | Calibrated Contrast and Blacks, V2 Whites, resolved-process cache keys and number coordination |
+228
View File
@@ -0,0 +1,228 @@
#!/usr/bin/env python3
"""Process V4's fitted Light constants: the committed fits and the Rust file generated from them (docs/light-v3.md).
light_v3_constants.py rust [-o crates/pipeline/src/light_v3_params.rs] [--check]
Write the Rust constants from the committed fits (tools/light_v3_fits/{contrast,blacks}.json): each
fit's parameter vector verbatim (shortest round-trip literals; crates/pipeline/src/light_v3.rs unpacks it as
Family.unpack does), where it came from, and, for the Rust tests only, Family's own curve and apply values at
fixed points (rounded to 12 significant digits, so the file is the same on every machine). Running it on a
checkout must reproduce the committed file byte for byte: --check says whether it does, writing nothing.
light_v3_constants.py sanitize FIT.json SLIDER [-o tools/light_v3_fits/SLIDER.json]
Turn a result of the fitting tool (fit_pointwise.py, kept with the private fitting data) into the committed
form: the coefficients, the counts and aggregate errors only (median per amount, reference, size and split).
Publish an error group or band only when at least three distinct photos contribute,
with no photo names, paths or per-photo values. Swapping a fit is sanitizing the new one over the slider's
file, then `rust`.
The fitting data are private: black-box Lightroom exports of the owner's photos. A public render-fidelity tool for
measuring your own exports is proposed separately in #1181; it is not included in this checkout.
Needs numpy only: tools/requirements-light-v3.txt.
"""
import argparse
import hashlib
import json
import sys
from collections import defaultdict
from pathlib import Path
import numpy as np
sys.path.insert(0, str(Path(__file__).resolve().parent))
from light_v3_family import KNOTS as FAMILY_KNOTS, Family # noqa: E402
ROOT = Path(__file__).resolve().parents[1]
FITS = ROOT / "tools" / "light_v3_fits"
OUT = ROOT / "crates" / "pipeline" / "src" / "light_v3_params.rs"
SLIDERS = {"contrast": "light.contrast", "blacks": "light.blacks"}
MODES = {"pc": "PerChannel", "lum": "Luminance", "mix": "Mix"}
KNOTS = [float(k) for k in FAMILY_KNOTS]
BANDS = ["<.03", ".03-.10", ".10-.25", ".25-.50", ".50-.90", ">.90"]
MIN_PHOTOS = 3
# where the reference values are taken (encoded ProPhoto values, amounts, pixels)
REF_V = [0.0, 0.004, 0.012, 0.03, 0.07, 0.11, 0.17, 0.25, 0.33, 0.45, 0.58, 0.7, 0.81, 0.9, 0.97, 1.0]
REF_A = [-100.0, -63.0, -25.0, -4.0, -1.0, 1.0, 4.0, 25.0, 63.0, 100.0]
REF_PIX = [[0.02, 0.05, 0.01], [0.3, 0.25, 0.2], [0.55, 0.5, 0.62], [0.9, 0.85, 0.7], [0.15, 0.4, 0.35], [0.75, 0.97, 0.99]]
def layout(name, fit, path):
"""Whether a fit is signed, after checking it against the family."""
if fit.get("slider") != SLIDERS[name]:
sys.exit(f"{path}: a fit of {fit.get('slider')}, not {SLIDERS[name]}")
if fit.get("knots") != KNOTS:
sys.exit(f"{path}: knots {fit.get('knots')} are not the family's {KNOTS}")
if fit.get("mode") not in MODES:
sys.exit(f"{path}: unknown mode {fit.get('mode')}")
base = Family(fit["mode"]).size
n = len(fit["params"])
if n != base:
sys.exit(f"{path}: {n} parameters, the family needs {base}")
return name == "contrast"
def sanitize(args):
path = Path(args.fit)
raw = path.read_bytes()
fit = json.loads(raw)
signed = layout(args.slider, fit, path)
errors = {}
for split in ("tune", "check"):
by = defaultdict(list)
for r in fit.get(split, []):
by[(r["a_tgt"], r["a_ref"], r["long_edge"])].append(r)
rows = []
for (a_tgt, a_ref, edge), g in sorted(by.items()):
photos = len({r["photo"] for r in g})
if photos < MIN_PHOTOS:
continue
band_photos = {b: len({r["photo"] for r in g if b in r["cells"]}) for b in BANDS}
band_photos = {b: n for b, n in band_photos.items() if n >= MIN_PHOTOS}
bands = {b: float(np.median([r["cells"][b]["error"] for r in g if b in r["cells"]]))
for b in band_photos}
rows.append({"amount": a_tgt, "reference": a_ref, "long_edge": edge, "pairs": len(g),
"photos": photos, "encoded_error": float(np.median([r["encoded_error"] for r in g])),
"band_error": bands, "band_photos": band_photos})
errors[split] = rows
out = {
"slider": fit["slider"], "mode": fit["mode"], "signed": signed,
"knots": fit["knots"], "params": fit["params"], "amounts": fit.get("amounts"),
"tune_pairs": fit.get("tune_pairs"), "tune_photos": fit.get("tune_photos"),
"check_pairs": fit.get("check_pairs"), "check_photos": len({r["photo"] for r in fit.get("check", [])}),
"cost": fit.get("cost") if len({r["photo"] for r in fit.get("tune", [])}) >= MIN_PHOTOS else None,
"status": fit.get("status"),
"fitted_as": {"file": path.name, "sha256": hashlib.sha256(raw).hexdigest()},
"median_errors": errors,
}
text = json.dumps(out, indent=1) + "\n"
for bad in ("DSC", "/Users", "photo\"", ".ARW", ".arw", ".tif"):
if bad in text:
sys.exit(f"{path}: the sanitized fit still contains {bad!r}")
dest = Path(args.o) if args.o else FITS / f"{args.slider}.json"
dest.write_text(text)
print(f"{args.slider}: {path.name} -> {dest}")
def wrap(tokens, indent, width=140):
"""Comma-separated tokens packed into lines of at most `width` characters, each indented."""
lines, line = [], ""
for t in tokens:
if line and len(indent) + len(line) + len(t) + 2 > width:
lines.append(indent + line.rstrip())
line = ""
line += t + ", "
if line:
lines.append(indent + line.rstrip())
return lines
def exact(v):
return repr(float(v))
def ref12(v):
"""A reference value at 12 significant digits (numpy's last bit differs between machines and libraries)."""
s = f"{float(v):.12g}"
return s if any(c in s for c in ".en") else s + ".0"
def load(name):
path = FITS / f"{name}.json"
raw = path.read_bytes()
fit = json.loads(raw)
signed = layout(name, fit, path)
fam = Family(fit["mode"], signed=signed)
p = np.array(fit["params"], dtype=np.float64)
grid = np.linspace(0, 1, 20001)
ref = []
for a in REF_A:
curve = fam.curve(p, a, np.array(REF_V))
# Apply where the curve increases everywhere (the Rust tables flatten a fold).
increasing = bool(np.all(np.diff(fam.curve(p, a, grid)) >= 0))
apply = fam.apply(p, a, np.array(REF_PIX)) if increasing else None
ref.append((a, list(curve), None if apply is None else [list(r) for r in apply]))
return {"name": name, "path": path.relative_to(ROOT).as_posix(), "sha256": hashlib.sha256(raw).hexdigest(),
"fit": fit, "signed": signed, "reference": ref}
def rust(args):
fits = [load(name) for name in SLIDERS]
out = [
"//! Fitted constants of process V4's Contrast and Blacks ([`crate::light_v3`]).",
"//!",
"//! GENERATED by `tools/light_v3_constants.py rust` from the committed fits named below: do not edit by hand,",
"//! regenerate (the script must reproduce this file byte for byte).",
"//!",
"//! The values are fitted to black-box Lightroom exports of one person's Sony ILCE-7CR photos (the exports'",
"//! pixels only: no Lightroom code, tables or files), each slider against the same photo's Neutral or another",
"//! amount exported in the same batch, on the tune photos; the check photos were held out. The exports are",
"//! private; errors are published only with at least three contributing photos. These are our operator family's",
"//! parameters (`docs/light-v3.md`), not Lightroom's.",
"//!",
]
for f in fits:
fit = f["fit"]
out += [f"//! - {f['name'].capitalize()}: `{f['path']}` (fitted as `{fit['fitted_as']['file']}`), mode "
f"`{fit['mode']}`; {fit['tune_pairs']} tune pairs on "
f"{fit['tune_photos']} photos, {fit['check_pairs']} check pairs on {fit['check_photos']} photos;",
f"//! sha256 `{f['sha256']}`."]
out += ["", "use crate::light_v3::{Fit, Mode};", "#[cfg(test)]", "use crate::light_v3::Reference;", "",
"/// The family's knots: the displacement shapes are piecewise linear on them.",
f"pub const KNOTS: [f64; {len(KNOTS)}] = [{', '.join(exact(k) for k in KNOTS)}];", ""]
for f in fits:
fit = f["fit"]
doc = [f"/// `{f['path']}`."]
out += [*doc,
f"pub const {f['name'].upper()}: Fit = Fit {{",
f" mode: Mode::{MODES[fit['mode']]},",
f" signed: {'true' if f['signed'] else 'false'},",
" params: &[",
*wrap([exact(v) for v in fit["params"]], " "),
" ],",
"};",
""]
out += ["/// Where the reference values are taken: encoded values and pixels (encoded ProPhoto).",
"#[cfg(test)]", f"pub const REF_V: [f64; {len(REF_V)}] = [", *wrap(map(exact, REF_V), " "), "];",
"#[cfg(test)]", f"pub const REF_PIX: [[f64; 3]; {len(REF_PIX)}] = [",
*wrap(("[" + ", ".join(map(exact, r)) + "]" for r in REF_PIX), " "), "];",
""]
for f in fits:
rows = []
for a, curve, apply in f["reference"]:
rows += [" Reference {", f" amount: {exact(a)},", " curve: &[",
*wrap(map(ref12, curve), " "), " ],"]
if apply is None:
rows.append(" apply: None,")
else:
rows += [" apply: Some(&[",
*wrap(("[" + ", ".join(map(ref12, r)) + "]" for r in apply), " "), " ]),"]
rows.append(" },")
out += [f"/// The family's own `curve` at [`REF_V`] and `apply` on [`REF_PIX`] for `{f['path']}` (12 significant",
"/// digits).", "#[cfg(test)]", f"pub const {f['name'].upper()}_REFERENCE: &[Reference] = &[", *rows,
"];", ""]
dest = Path(args.o) if args.o else OUT
text = "\n".join(out)
if args.check:
same = dest.exists() and dest.read_text() == text
print(f"{dest}: {'reproduced byte for byte' if same else 'DIFFERS from what the committed fits give'}")
return 0 if same else 1
dest.write_text(text)
for f in fits:
print(f"{f['name']}: {f['path']} ({f['fit']['fitted_as']['file']}) {f['fit']['mode']}"
f", {len(f['fit']['params'])} parameters")
def main():
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
sub = ap.add_subparsers(dest="cmd", required=True)
r = sub.add_parser("rust")
r.add_argument("-o"), r.add_argument("--check", action="store_true")
s = sub.add_parser("sanitize")
s.add_argument("fit"), s.add_argument("slider", choices=list(SLIDERS)), s.add_argument("-o")
args = ap.parse_args()
return rust(args) if args.cmd == "rust" else sanitize(args)
if __name__ == "__main__":
sys.exit(main())
+78
View File
@@ -0,0 +1,78 @@
"""Process V3's Light operator family (docs/light-v3.md), as the fitting tool defines it.
This is the part of the fitting tool (`fit_pointwise.py`, kept with the private fitting data) that
`light_v3_constants.py` needs to write the Rust tests' reference values: `Family.curve`, `Family.apply`,
`Family.law` and `Family.unpack` for Contrast and Blacks. `crates/pipeline/src/light_v3.rs` is the Rust port
of the same functions, and its tests compare the two.
F_a(v) = v + s(a) D+(v) for a > 0, max(0, v - s(a) D-(v)) for a < 0, with D piecewise linear on KNOTS (D(1) = 0;
signed shapes also D(0) = 0) and s(t) = ((1 - exp(-t / tau)) / (1 - exp(-1 / tau)))^q, t = |a| / 100. v is a channel value of linear ProPhoto RGB (D50) through the sRGB
transfer curve. Modes: pc (per channel), lum (on the encoded ProPhoto luminance, linear RGB scaled by the ratio),
mix (w pc + (1 - w) lum in linear light, a weight per sign).
"""
import numpy as np
PRO_Y = np.array([0.2880402, 0.7118741, 0.0000857])
KNOTS = np.array([0.0, 0.02, 0.05, 0.09, 0.14, 0.2, 0.28, 0.38, 0.5, 0.65, 0.82, 1.0])
def lin(e):
return np.where(e <= 0.04045, e / 12.92, ((e + 0.055) / 1.055) ** 2.4)
def enc(l):
l = np.clip(l, 0.0, None)
return np.where(l <= 0.0031308, 12.92 * l, 1.055 * np.power(l, 1 / 2.4) - 0.055)
class Family:
def __init__(self, mode, signed=False):
self.mode = mode
# Contrast moves tones both ways around a pivot: signed shapes, anchored at black and white
self.signed = signed
self.n_shape = len(KNOTS) - 1 # D(1) = 0
self.size = 2 * self.n_shape + 4 + (2 if mode == "mix" else 0)
def unpack(self, p):
n = self.n_shape
d_pos = np.append(p[:n], 0.0)
d_neg = np.append(p[n:2 * n], 0.0)
if self.signed:
d_pos[0] = d_neg[0] = 0.0
i = 2 * n
s_pos = (float(np.exp(p[i])), float(np.exp(p[i + 1]))) # (tau, q), positive amounts
s_neg = (float(np.exp(p[i + 2])), float(np.exp(p[i + 3]))) # negative amounts
i += 4
w = (1 / (1 + np.exp(-p[i])), 1 / (1 + np.exp(-p[i + 1]))) if self.mode == "mix" else None
return d_pos, d_neg, s_pos, s_neg, w
@staticmethod
def law(tq, a):
tau, q = tq
t = min(abs(a) / 100.0, 1.0)
tau = min(max(tau, 1e-3), 1e3)
return float(((1 - np.exp(-t / tau)) / (1 - np.exp(-1 / tau))) ** q)
def curve(self, p, a, v):
"""F_a on encoded values v (any shape)."""
if a == 0:
return v
d_pos, d_neg, s_pos, s_neg, _ = self.unpack(p)
if a > 0:
return v + self.law(s_pos, a) * np.interp(v, KNOTS, d_pos)
return np.maximum(v - self.law(s_neg, a) * np.interp(v, KNOTS, d_neg), 0.0)
def apply(self, p, a, v):
"""F_a applied to (n, 3) encoded ProPhoto pixels per the mode."""
if self.mode == "pc":
return self.curve(p, a, v)
yl = lin(v) @ PRO_Y
ye = enc(yl)
y2 = lin(self.curve(p, a, ye))
ratio = np.where(yl > 1e-6, y2 / np.maximum(yl, 1e-6), 1.0)
lum = enc(lin(v) * ratio[:, None])
if self.mode == "lum":
return lum
w = self.unpack(p)[4][0 if a > 0 else 1]
return enc(w * lin(self.curve(p, a, v)) + (1 - w) * lin(lum))
+629
View File
@@ -0,0 +1,629 @@
{
"slider": "light.blacks",
"mode": "mix",
"signed": false,
"knots": [
0.0,
0.02,
0.05,
0.09,
0.14,
0.2,
0.28,
0.38,
0.5,
0.65,
0.82,
1.0
],
"params": [
0.0016748697345088984,
0.032126630862752484,
0.07188512588294256,
0.09530584096821723,
0.12925288090794965,
0.12680972925019743,
0.10913227308994669,
0.10024857312175768,
0.0835198499581404,
0.05136152009684992,
0.02045048232256003,
0.00011845423640374467,
0.2706623236742467,
0.42355931120492346,
0.37893058797626605,
0.22045052169596244,
0.20955478047682013,
0.2107908996685734,
0.16685612159796198,
0.13055496600268582,
0.08667135921560576,
0.03499725744978859,
14.344979966519135,
0.1199976090379452,
6.829791928600096,
0.5956122696562978,
0.6007994346537187,
22.053184691621333
],
"amounts": {
"pos": [
1.0,
2.0,
10.0,
25.0,
50.0
],
"neg": [
1.0,
2.0,
10.0,
25.0,
50.0
]
},
"tune_pairs": 148,
"tune_photos": 19,
"check_pairs": 60,
"check_photos": 6,
"cost": 0.0008745122527803675,
"status": "`xtol` termination condition is satisfied.",
"fitted_as": {
"file": "v2-blacks-mix.json",
"sha256": "7a4eaf80f609bce82796255f2143379c2a861d9e4ad837d8b1cee13d8ee8bbbf"
},
"median_errors": {
"tune": [
{
"amount": -100.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 17,
"photos": 17,
"encoded_error": 0.003427741630935885,
"band_error": {
".03-.10": 0.2213629580750902,
".10-.25": 0.02608652782453921,
".25-.50": 0.01578410979952499,
".50-.90": 0.002808023738105474
},
"band_photos": {
".03-.10": 15,
".10-.25": 16,
".25-.50": 16,
".50-.90": 10
}
},
{
"amount": -50.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 17,
"photos": 17,
"encoded_error": 0.005919080768408077,
"band_error": {
"<.03": 2.540801442208995,
".03-.10": 0.08111268411041608,
".10-.25": 0.04438409233495842,
".25-.50": 0.020550565205089452,
".50-.90": 0.006222082011956415
},
"band_photos": {
"<.03": 13,
".03-.10": 15,
".10-.25": 16,
".25-.50": 16,
".50-.90": 10
}
},
{
"amount": -25.0,
"reference": 25.0,
"long_edge": 2048,
"pairs": 17,
"photos": 17,
"encoded_error": 0.0031214485072743755,
"band_error": {
"<.03": 0.16329115247026024,
".03-.10": 0.036668113073784654,
".10-.25": 0.022776150840884937,
".25-.50": 0.014843370759525187,
".50-.90": 0.0039038961386700737
},
"band_photos": {
"<.03": 15,
".03-.10": 15,
".10-.25": 16,
".25-.50": 16,
".50-.90": 11
}
},
{
"amount": -10.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 7,
"photos": 7,
"encoded_error": 0.0028229433114912773,
"band_error": {
"<.03": 0.13178410951728228,
".03-.10": 0.04196128224444614,
".10-.25": 0.01762880043633539,
".25-.50": 0.007293565839224106,
".50-.90": 0.002609491855638238
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 7,
".25-.50": 7,
".50-.90": 5
}
},
{
"amount": -2.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 7,
"photos": 7,
"encoded_error": 0.00041129347233050275,
"band_error": {
"<.03": 0.019017656661272694,
".03-.10": 0.005756775376322533,
".10-.25": 0.002565234930383287,
".25-.50": 0.001145782173166264,
".50-.90": 0.000382322002835805
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 7,
".25-.50": 7,
".50-.90": 6
}
},
{
"amount": -1.0,
"reference": 1.0,
"long_edge": 2048,
"pairs": 7,
"photos": 7,
"encoded_error": 0.0003722974487077393,
"band_error": {
"<.03": 0.018366070435347367,
".03-.10": 0.004089734153371508,
".10-.25": 0.0018553694269353212,
".25-.50": 0.0009593820885241899,
".50-.90": 0.0004271225438045706
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 7,
".25-.50": 7,
".50-.90": 5
}
},
{
"amount": 1.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 7,
"photos": 7,
"encoded_error": 0.0003760698824047078,
"band_error": {
"<.03": 0.017287292651452933,
".03-.10": 0.004092564163348587,
".10-.25": 0.0018455583699485529,
".25-.50": 0.0009623571483044081,
".50-.90": 0.0004186288558887353
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 7,
".25-.50": 7,
".50-.90": 5
}
},
{
"amount": 2.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 7,
"photos": 7,
"encoded_error": 0.00020040955093125052,
"band_error": {
"<.03": 0.013753116645338119,
".03-.10": 0.0007162453275012053,
".10-.25": 0.0003540900235241904,
".25-.50": 0.00038934971977656153,
".50-.90": 0.0002782855548532337
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 7,
".25-.50": 7,
".50-.90": 5
}
},
{
"amount": 10.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 7,
"photos": 7,
"encoded_error": 0.001783838738716413,
"band_error": {
"<.03": 0.05284982502051819,
".03-.10": 0.03724809716093273,
".10-.25": 0.019205512149578937,
".25-.50": 0.006917961002757063,
".50-.90": 0.0015806259646429421
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 7,
".25-.50": 7,
".50-.90": 5
}
},
{
"amount": 25.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 17,
"photos": 17,
"encoded_error": 0.003709389204943277,
"band_error": {
"<.03": 0.09494415640775108,
".03-.10": 0.0176749098453267,
".10-.25": 0.018947490336089716,
".25-.50": 0.013097052459767222,
".50-.90": 0.003511734102272039
},
"band_photos": {
"<.03": 13,
".03-.10": 15,
".10-.25": 16,
".25-.50": 16,
".50-.90": 11
}
},
{
"amount": 50.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 17,
"photos": 17,
"encoded_error": 0.002609444120265867,
"band_error": {
"<.03": 0.07482435736855328,
".03-.10": 0.013436692118006998,
".10-.25": 0.017886792958307664,
".25-.50": 0.009087796540733195,
".50-.90": 0.003603605087350397
},
"band_photos": {
"<.03": 13,
".03-.10": 15,
".10-.25": 16,
".25-.50": 16,
".50-.90": 10
}
},
{
"amount": 100.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 17,
"photos": 17,
"encoded_error": 0.0052279389117479615,
"band_error": {
"<.03": 0.06867116555034346,
".03-.10": 0.028802027760147397,
".10-.25": 0.03517066425047481,
".25-.50": 0.015005585548450773,
".50-.90": 0.005419520070429491
},
"band_photos": {
"<.03": 13,
".03-.10": 15,
".10-.25": 16,
".25-.50": 16,
".50-.90": 10
}
}
],
"check": [
{
"amount": -100.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 6,
"photos": 6,
"encoded_error": 0.0026036276924897854,
"band_error": {
".03-.10": 0.2724794859787279,
".10-.25": 0.032524388827564095,
".25-.50": 0.01623772080888221,
".50-.90": 0.001974081452192045,
">.90": 0.00327166522465544
},
"band_photos": {
".03-.10": 6,
".10-.25": 5,
".25-.50": 5,
".50-.90": 5,
">.90": 3
}
},
{
"amount": -50.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 6,
"photos": 6,
"encoded_error": 0.00630845958129503,
"band_error": {
"<.03": 2.937882639375302,
".03-.10": 0.08392136241031861,
".10-.25": 0.046410663700769156,
".25-.50": 0.020183223853684526,
".50-.90": 0.004274811360970359,
">.90": 0.0011760232124998261
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 6,
".25-.50": 5,
".50-.90": 5,
">.90": 3
}
},
{
"amount": -25.0,
"reference": 25.0,
"long_edge": 2048,
"pairs": 6,
"photos": 6,
"encoded_error": 0.0031592008349393005,
"band_error": {
"<.03": 0.14080623765681227,
".03-.10": 0.0318373066028957,
".10-.25": 0.03224211267963081,
".25-.50": 0.016030589604536166,
".50-.90": 0.0031808853864495733,
">.90": 0.00110274155996526
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 6,
".25-.50": 5,
".50-.90": 5,
">.90": 3
}
},
{
"amount": -10.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 4,
"photos": 4,
"encoded_error": 0.0032315112484176496,
"band_error": {
"<.03": 0.12510974742848963,
".03-.10": 0.05015845177052797,
".10-.25": 0.021326590472185665,
".25-.50": 0.008380427925365043,
".50-.90": 0.0016479323536602991,
">.90": 0.00011413404472121791
},
"band_photos": {
"<.03": 4,
".03-.10": 4,
".10-.25": 4,
".25-.50": 3,
".50-.90": 3,
">.90": 3
}
},
{
"amount": -2.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 4,
"photos": 4,
"encoded_error": 0.00045617733812925115,
"band_error": {
"<.03": 0.01925846038820568,
".03-.10": 0.0063834108841469995,
".10-.25": 0.003030159155055237,
".25-.50": 0.001279033505962499,
".50-.90": 0.0002698196294867122,
">.90": 2.7633406386833942e-05
},
"band_photos": {
"<.03": 4,
".03-.10": 4,
".10-.25": 4,
".25-.50": 3,
".50-.90": 3,
">.90": 3
}
},
{
"amount": -1.0,
"reference": 1.0,
"long_edge": 2048,
"pairs": 4,
"photos": 4,
"encoded_error": 0.00038314168156171563,
"band_error": {
"<.03": 0.0179409887964789,
".03-.10": 0.004554594316174306,
".10-.25": 0.0021860614907081508,
".25-.50": 0.0010348608044738427,
".50-.90": 0.00027134539581991134,
">.90": 2.327437207747032e-05
},
"band_photos": {
"<.03": 4,
".03-.10": 4,
".10-.25": 4,
".25-.50": 3,
".50-.90": 3,
">.90": 3
}
},
{
"amount": 1.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 4,
"photos": 4,
"encoded_error": 0.00038163643693189483,
"band_error": {
"<.03": 0.01789697865555805,
".03-.10": 0.0045282975606357224,
".10-.25": 0.002195762186994404,
".25-.50": 0.0009878774705477829,
".50-.90": 0.0002783038732938448,
">.90": 2.686083194581795e-05
},
"band_photos": {
"<.03": 4,
".03-.10": 4,
".10-.25": 4,
".25-.50": 3,
".50-.90": 3,
">.90": 3
}
},
{
"amount": 2.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 4,
"photos": 4,
"encoded_error": 0.0001803959147575279,
"band_error": {
"<.03": 0.01212475922937082,
".03-.10": 0.0009431699585146074,
".10-.25": 0.000355929836981769,
".25-.50": 0.0003440476619261129,
".50-.90": 0.00019109718572074783,
">.90": 1.9847289480291946e-05
},
"band_photos": {
"<.03": 4,
".03-.10": 4,
".10-.25": 4,
".25-.50": 3,
".50-.90": 3,
">.90": 3
}
},
{
"amount": 10.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 4,
"photos": 4,
"encoded_error": 0.002290357662922615,
"band_error": {
"<.03": 0.05709934188572894,
".03-.10": 0.0408071092493482,
".10-.25": 0.020792684426191338,
".25-.50": 0.007346519738751282,
".50-.90": 0.0010646491817687589,
">.90": 0.00026393508368777066
},
"band_photos": {
"<.03": 4,
".03-.10": 4,
".10-.25": 4,
".25-.50": 3,
".50-.90": 3,
">.90": 3
}
},
{
"amount": 25.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 6,
"photos": 6,
"encoded_error": 0.0030198740694812503,
"band_error": {
"<.03": 0.0725997864669866,
".03-.10": 0.022094528007660656,
".10-.25": 0.026543951558102536,
".25-.50": 0.01324388164672667,
".50-.90": 0.0026208880613337988,
">.90": 0.0010779135256942629
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 6,
".25-.50": 5,
".50-.90": 5,
">.90": 3
}
},
{
"amount": 50.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 6,
"photos": 6,
"encoded_error": 0.002475906570262025,
"band_error": {
"<.03": 0.061356997170475686,
".03-.10": 0.009863474631073559,
".10-.25": 0.01476986021053679,
".25-.50": 0.010247807139551512,
".50-.90": 0.0031242534323023554,
">.90": 0.002042051985148796
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 6,
".25-.50": 5,
".50-.90": 5,
">.90": 3
}
},
{
"amount": 100.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 6,
"photos": 6,
"encoded_error": 0.004946325387271203,
"band_error": {
"<.03": 0.08131887755018244,
".03-.10": 0.033910589363778845,
".10-.25": 0.02538659945793769,
".25-.50": 0.025997571830863868,
".50-.90": 0.007104110918209644,
">.90": 0.005182159260201775
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 5,
".25-.50": 5,
".50-.90": 5,
">.90": 3
}
}
]
}
}
+688
View File
@@ -0,0 +1,688 @@
{
"slider": "light.contrast",
"mode": "pc",
"signed": true,
"knots": [
0.0,
0.02,
0.05,
0.09,
0.14,
0.2,
0.28,
0.38,
0.5,
0.65,
0.82,
1.0
],
"params": [
9.797174393178826e-18,
-0.017053489024880908,
-0.04260284838408044,
-0.07195939270312468,
-0.09738651081071477,
-0.1088504066519633,
-0.10140378035603768,
-0.06947815571389163,
-0.007856500339789655,
0.08463087858854193,
0.1098534938016389,
0.30583740028604467,
-0.05850866310699469,
-0.07854274245013221,
-0.09074476735486797,
-0.0906596002773617,
-0.08429179542961336,
-0.07428102082426319,
-0.05004459522573259,
-0.00906946010144,
0.056653920573147026,
0.09818533983265328,
0.3070552562874873,
0.10657448975892592,
-0.13962415708911588,
0.37724097657204825
],
"amounts": {
"pos": [
1.0,
2.0,
10.0,
20.0,
25.0,
50.0
],
"neg": [
1.0,
2.0,
10.0,
25.0,
50.0
]
},
"tune_pairs": 155,
"tune_photos": 20,
"check_pairs": 61,
"check_photos": 6,
"cost": 0.007425023807942876,
"status": "`ftol` termination condition is satisfied.",
"fitted_as": {
"file": "v2-contrast-pc.json",
"sha256": "a3edbd6959efc611a62f77c35ec3d0228249a818e26d913a6813e966e245a218"
},
"median_errors": {
"tune": [
{
"amount": -100.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 17,
"photos": 17,
"encoded_error": 0.011121768451379337,
"band_error": {
"<.03": 0.06473831720828421,
".03-.10": 0.0930115027157312,
".10-.25": 0.10855335247607187,
".25-.50": 0.08458112931798814,
".50-.90": 0.04951305393020604
},
"band_photos": {
"<.03": 15,
".03-.10": 15,
".10-.25": 16,
".25-.50": 16,
".50-.90": 11
}
},
{
"amount": -50.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 17,
"photos": 17,
"encoded_error": 0.004286254992238507,
"band_error": {
"<.03": 0.08798561426579082,
".03-.10": 0.023395491074571718,
".10-.25": 0.04125160013916516,
".25-.50": 0.02813656219386674,
".50-.90": 0.01224863264329086
},
"band_photos": {
"<.03": 15,
".03-.10": 15,
".10-.25": 16,
".25-.50": 16,
".50-.90": 11
}
},
{
"amount": -50.0,
"reference": 50.0,
"long_edge": 6000,
"pairs": 3,
"photos": 3,
"encoded_error": 0.0056569939840179885,
"band_error": {
"<.03": 0.09798367558474397,
".03-.10": 0.130792624631025
},
"band_photos": {
"<.03": 3,
".03-.10": 3
}
},
{
"amount": -25.0,
"reference": 25.0,
"long_edge": 2048,
"pairs": 17,
"photos": 17,
"encoded_error": 0.006945703844995149,
"band_error": {
"<.03": 0.042459022563571834,
".03-.10": 0.06599006511649402,
".10-.25": 0.07119527732608275,
".25-.50": 0.06194452558952893,
".50-.90": 0.02380380595363875
},
"band_photos": {
"<.03": 15,
".03-.10": 15,
".10-.25": 16,
".25-.50": 16,
".50-.90": 12
}
},
{
"amount": -10.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 7,
"photos": 7,
"encoded_error": 0.0022531301423689854,
"band_error": {
"<.03": 0.03697373149772598,
".03-.10": 0.03971304167226704,
".10-.25": 0.022404234718419867,
".25-.50": 0.009058685811361137,
".50-.90": 0.010657569861098629
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 7,
".25-.50": 7,
".50-.90": 5
}
},
{
"amount": -2.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 7,
"photos": 7,
"encoded_error": 0.0003852393871073691,
"band_error": {
"<.03": 0.007012211524007572,
".03-.10": 0.0066646566763887746,
".10-.25": 0.00286755977345968,
".25-.50": 0.0017240802086141635,
".50-.90": 0.0018782060083671758
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 7,
".25-.50": 7,
".50-.90": 5
}
},
{
"amount": -1.0,
"reference": 1.0,
"long_edge": 2048,
"pairs": 7,
"photos": 7,
"encoded_error": 0.0006543633779320837,
"band_error": {
"<.03": 0.01886873284344166,
".03-.10": 0.010292594464825184,
".10-.25": 0.005632954367000359,
".25-.50": 0.002241935441265079,
".50-.90": 0.0031058898304381823
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 7,
".25-.50": 7,
".50-.90": 5
}
},
{
"amount": 1.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 7,
"photos": 7,
"encoded_error": 0.0006527385589234222,
"band_error": {
"<.03": 0.018817926083770614,
".03-.10": 0.010358472561087979,
".10-.25": 0.005616058982285934,
".25-.50": 0.0021934787509894807,
".50-.90": 0.0030850495726458984
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 7,
".25-.50": 7,
".50-.90": 5
}
},
{
"amount": 2.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 7,
"photos": 7,
"encoded_error": 0.0008095368298390367,
"band_error": {
"<.03": 0.02333747747697981,
".03-.10": 0.011422288253035966,
".10-.25": 0.00742974381498245,
".25-.50": 0.0038965317200995025,
".50-.90": 0.0034447363133185732
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 7,
".25-.50": 7,
".50-.90": 5
}
},
{
"amount": 10.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 7,
"photos": 7,
"encoded_error": 0.0018082128746201764,
"band_error": {
"<.03": 0.045326689844745194,
".03-.10": 0.011501487324692514,
".10-.25": 0.019129575064688376,
".25-.50": 0.0125055419250812,
".50-.90": 0.0044824579865754555
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 7,
".25-.50": 7,
".50-.90": 5
}
},
{
"amount": 20.0,
"reference": 0.0,
"long_edge": 6000,
"pairs": 5,
"photos": 5,
"encoded_error": 0.00309267216217087,
"band_error": {
"<.03": 0.048859278779928295,
".03-.10": 0.0445593256864193,
".10-.25": 0.037886311299740134,
".25-.50": 0.018012343705216413,
".50-.90": 0.0076965072545667045
},
"band_photos": {
"<.03": 5,
".03-.10": 5,
".10-.25": 5,
".25-.50": 5,
".50-.90": 3
}
},
{
"amount": 25.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 17,
"photos": 17,
"encoded_error": 0.007903821110042217,
"band_error": {
"<.03": 0.05150865439744394,
".03-.10": 0.07246865874385416,
".10-.25": 0.09144243025121834,
".25-.50": 0.06400970326100287,
".50-.90": 0.016674153313752264
},
"band_photos": {
"<.03": 15,
".03-.10": 15,
".10-.25": 16,
".25-.50": 16,
".50-.90": 10
}
},
{
"amount": 50.0,
"reference": -50.0,
"long_edge": 6000,
"pairs": 3,
"photos": 3,
"encoded_error": 0.006205513903254146,
"band_error": {
"<.03": 0.11470709333534655,
".03-.10": 0.118067402841938,
".10-.25": 0.2729320736520823
},
"band_photos": {
"<.03": 3,
".03-.10": 3,
".10-.25": 3
}
},
{
"amount": 50.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 17,
"photos": 17,
"encoded_error": 0.013146197515222533,
"band_error": {
"<.03": 0.09093522091940583,
".03-.10": 0.10255589841297505,
".10-.25": 0.14165315810252282,
".25-.50": 0.08784201480208256,
".50-.90": 0.02373075387210262
},
"band_photos": {
"<.03": 15,
".03-.10": 15,
".10-.25": 16,
".25-.50": 16,
".50-.90": 10
}
},
{
"amount": 100.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 17,
"photos": 17,
"encoded_error": 0.019644083854275383,
"band_error": {
"<.03": 0.14785079413511482,
".03-.10": 0.28522605929536815,
".10-.25": 0.2893249382631822,
".25-.50": 0.15281210908420345,
".50-.90": 0.02904286478459617
},
"band_photos": {
"<.03": 14,
".03-.10": 15,
".10-.25": 16,
".25-.50": 16,
".50-.90": 9
}
}
],
"check": [
{
"amount": -100.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 6,
"photos": 6,
"encoded_error": 0.00614368415261454,
"band_error": {
"<.03": 0.059928983720484864,
".03-.10": 0.03849443290379879,
".10-.25": 0.06826161779527672,
".25-.50": 0.06509598397385213,
".50-.90": 0.05217615569259957,
">.90": 0.031190911184747684
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 6,
".25-.50": 5,
".50-.90": 5,
">.90": 3
}
},
{
"amount": -50.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 6,
"photos": 6,
"encoded_error": 0.0023659145274087735,
"band_error": {
"<.03": 0.06470759304831414,
".03-.10": 0.009370845846563901,
".10-.25": 0.026351516593929925,
".25-.50": 0.019327549018610488,
".50-.90": 0.011562978286385712,
">.90": 0.005461528273139457
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 6,
".25-.50": 5,
".50-.90": 5,
">.90": 3
}
},
{
"amount": -25.0,
"reference": 25.0,
"long_edge": 2048,
"pairs": 6,
"photos": 6,
"encoded_error": 0.003398590038466944,
"band_error": {
"<.03": 0.03840228695869055,
".03-.10": 0.020796501758207908,
".10-.25": 0.040684964046721867,
".25-.50": 0.04701568701600178,
".50-.90": 0.019288472096135365,
">.90": 0.013499652156282174
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 6,
".25-.50": 5,
".50-.90": 5,
">.90": 3
}
},
{
"amount": -10.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 4,
"photos": 4,
"encoded_error": 0.0020376188455170567,
"band_error": {
"<.03": 0.03620494381244924,
".03-.10": 0.03208240175435808,
".10-.25": 0.010473635357755147,
".25-.50": 0.017871803195692943,
".50-.90": 0.010263293012151831,
">.90": 0.002715647895860737
},
"band_photos": {
"<.03": 4,
".03-.10": 4,
".10-.25": 4,
".25-.50": 3,
".50-.90": 3,
">.90": 3
}
},
{
"amount": -2.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 4,
"photos": 4,
"encoded_error": 0.00039351188188189697,
"band_error": {
"<.03": 0.008615997075480056,
".03-.10": 0.0061276905656996485,
".10-.25": 0.0016374797966802114,
".25-.50": 0.002600678552877267,
".50-.90": 0.0017840523386103938,
">.90": 0.0003802946498026381
},
"band_photos": {
"<.03": 4,
".03-.10": 4,
".10-.25": 4,
".25-.50": 3,
".50-.90": 3,
">.90": 3
}
},
{
"amount": -1.0,
"reference": 1.0,
"long_edge": 2048,
"pairs": 4,
"photos": 4,
"encoded_error": 0.0006805247753234763,
"band_error": {
"<.03": 0.018760298025893515,
".03-.10": 0.008662470862737264,
".10-.25": 0.00263534266805685,
".25-.50": 0.004147011742721331,
".50-.90": 0.0029838535914747215,
">.90": 0.0007237557973570842
},
"band_photos": {
"<.03": 4,
".03-.10": 4,
".10-.25": 4,
".25-.50": 3,
".50-.90": 3,
">.90": 3
}
},
{
"amount": 1.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 4,
"photos": 4,
"encoded_error": 0.0006726023263027637,
"band_error": {
"<.03": 0.01891795182475012,
".03-.10": 0.008848860673192677,
".10-.25": 0.0027310450646397463,
".25-.50": 0.0042898284968232525,
".50-.90": 0.0029359593356539817,
">.90": 0.0007228384571375645
},
"band_photos": {
"<.03": 4,
".03-.10": 4,
".10-.25": 4,
".25-.50": 3,
".50-.90": 3,
">.90": 3
}
},
{
"amount": 2.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 4,
"photos": 4,
"encoded_error": 0.0007419673662760145,
"band_error": {
"<.03": 0.02288867540873815,
".03-.10": 0.008542193659454047,
".10-.25": 0.0028634353466732527,
".25-.50": 0.005128283993017973,
".50-.90": 0.0033098642592463267,
">.90": 0.0008105193292430162
},
"band_photos": {
"<.03": 4,
".03-.10": 4,
".10-.25": 4,
".25-.50": 3,
".50-.90": 3,
">.90": 3
}
},
{
"amount": 10.0,
"reference": -1.0,
"long_edge": 2048,
"pairs": 4,
"photos": 4,
"encoded_error": 0.0011864056487623834,
"band_error": {
"<.03": 0.03999974952353827,
".03-.10": 0.005283445715065133,
".10-.25": 0.01467700568320757,
".25-.50": 0.009489447536394666,
".50-.90": 0.00398762454890003,
">.90": 0.0016691396424735546
},
"band_photos": {
"<.03": 4,
".03-.10": 4,
".10-.25": 4,
".25-.50": 3,
".50-.90": 3,
">.90": 3
}
},
{
"amount": 25.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 6,
"photos": 6,
"encoded_error": 0.0036202176280724597,
"band_error": {
"<.03": 0.04541808011087295,
".03-.10": 0.032641002299673386,
".10-.25": 0.04250708854059583,
".25-.50": 0.049747993323797084,
".50-.90": 0.015917120629692874,
">.90": 0.004955059580255294
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 6,
".25-.50": 5,
".50-.90": 5,
">.90": 3
}
},
{
"amount": 50.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 6,
"photos": 6,
"encoded_error": 0.005293621966822463,
"band_error": {
"<.03": 0.0887657367547818,
".03-.10": 0.03648056023382013,
".10-.25": 0.07667411207439194,
".25-.50": 0.06098566466448595,
".50-.90": 0.020046398187211347,
">.90": 0.005424273085440311
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 6,
".25-.50": 5,
".50-.90": 5,
">.90": 3
}
},
{
"amount": 100.0,
"reference": -25.0,
"long_edge": 2048,
"pairs": 6,
"photos": 6,
"encoded_error": 0.00927203928537906,
"band_error": {
"<.03": 0.11764958884120004,
".03-.10": 0.1451408972189724,
".10-.25": 0.10497093206952726,
".25-.50": 0.12045842741876807,
".50-.90": 0.023191055675967395,
">.90": 0.0075026383932912995
},
"band_photos": {
"<.03": 6,
".03-.10": 6,
".10-.25": 6,
".25-.50": 5,
".50-.90": 5,
">.90": 3
}
}
]
}
}
+3
View File
@@ -0,0 +1,3 @@
# Python packages for tools/light_v3_constants.py (crates/pipeline/src/light_v3_params.rs, docs/light-v3.md).
# python3 -m venv .venv-light-v3 && .venv-light-v3/bin/pip install -r tools/requirements-light-v3.txt
numpy==2.4.6
+69
View File
@@ -0,0 +1,69 @@
"""Synthetic publication checks. Run with python3 -m unittest discover -s tools."""
import contextlib
import io
import json
import tempfile
import unittest
from pathlib import Path
from types import SimpleNamespace
import light_v3_constants as constants
class SanitizeTests(unittest.TestCase):
def test_counts_distinct_photos_for_each_group_and_band(self):
fit = json.loads((constants.FITS / "contrast.json").read_text())
# Three repeated pairs from one photo must not qualify as three photos.
def row(photo, amount, bands):
return dict(photo=photo, a_tgt=amount, a_ref=0, long_edge=800,
encoded_error=0.25, cells={b: {"error": 0.5} for b in bands})
fit["check"] = [row("synthetic-a", 20, constants.BANDS) for _ in range(3)]
fit["check"] += [row(p, 40, constants.BANDS) for p in ("synthetic-a", "synthetic-b")]
fit["check"] += [row(p, 60, constants.BANDS[:2]) for p in ("synthetic-a", "synthetic-b", "synthetic-c")]
fit["check"] += [row("synthetic-a", 60, constants.BANDS) for _ in range(3)]
fit["check"] += [row("synthetic-b", 60, constants.BANDS[:3])]
fit["tune"] = fit["check"]
with tempfile.TemporaryDirectory() as temp:
source, dest = Path(temp) / "synthetic.json", Path(temp) / "public.json"
source.write_text(json.dumps(fit))
with contextlib.redirect_stdout(io.StringIO()):
constants.sanitize(SimpleNamespace(fit=source, slider="contrast", o=dest))
public = json.loads(dest.read_text())
self.assertEqual(public["params"], fit["params"])
self.assertEqual(public["check_photos"], 3)
for split in ("tune", "check"):
rows = public["median_errors"][split]
self.assertEqual([r["amount"] for r in rows], [60])
self.assertEqual(rows[0]["photos"], 3)
self.assertEqual(set(rows[0]["band_error"]), set(constants.BANDS[:2]))
self.assertEqual(rows[0]["band_photos"], {b: 3 for b in constants.BANDS[:2]})
def test_single_photo_fit_has_no_error_aggregates(self):
fit = json.loads((constants.FITS / "contrast.json").read_text())
fit["tune"] = [dict(photo="synthetic-a", a_tgt=20, a_ref=0, long_edge=800,
encoded_error=0.25, cells={})]
fit["check"] = []
with tempfile.TemporaryDirectory() as temp:
source, dest = Path(temp) / "synthetic.json", Path(temp) / "public.json"
source.write_text(json.dumps(fit))
with contextlib.redirect_stdout(io.StringIO()):
constants.sanitize(SimpleNamespace(fit=source, slider="contrast", o=dest))
public = json.loads(dest.read_text())
self.assertEqual(public["median_errors"], {"tune": [], "check": []})
self.assertIsNone(public["cost"])
def test_committed_aggregates_have_at_least_three_photos(self):
for path in sorted(constants.FITS.glob("*.json")):
fit = json.loads(path.read_text())
for rows in fit["median_errors"].values():
for row in rows:
with self.subTest(fit=path.name, amount=row["amount"], edge=row["long_edge"]):
self.assertGreaterEqual(row.get("photos", row["pairs"]), 3)
self.assertEqual(set(row["band_error"]), set(row.get("band_photos", {})))
self.assertTrue(all(n >= 3 for n in row.get("band_photos", {}).values()))
if __name__ == "__main__":
unittest.main()