Skip to content
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6d29e03
LR-BEHAV-RENDER-FIDELITY: process V8, Whites and the tone curves meas…
smi-leonivkovic Nov 10, 2026
b16fd0c
LR-BEHAV-RENDER-FIDELITY: doc comments for the V8 curve stage, Gap 3 …
smi-leonivkovic Nov 11, 2026
6cb4e5b
Merge remote-tracking branch 'origin/main' into lr-v8-tone
smi-leonivkovic Nov 11, 2026
815ebe6
LR-BEHAV-RENDER-FIDELITY: what's new names process 9 (#523)
smi-leonivkovic Nov 11, 2026
fc55dde
LR-BEHAV-RENDER-FIDELITY: review fixes: neutral-render claims, Whites…
smi-leonivkovic Nov 11, 2026
5154467
LR-BEHAV-RENDER-FIDELITY: review fixes: measured curve tables only at…
smi-leonivkovic Nov 11, 2026
b1f6a66
LR-EDIT-LIGHT-CURVE-PARAM: the parametric graph draws and drags the c…
smi-leonivkovic Nov 11, 2026
0bbd0fc
LR-BEHAV-RENDER-FIDELITY: review fixes: the chart tool refuses render…
smi-leonivkovic Nov 11, 2026
b0e9b29
Merge branch 'lr-v8-tone' into lr-v9-curve-graph
smi-leonivkovic Nov 11, 2026
6f565fe
LR-EDIT-LIGHT-CURVE-PARAM: review fixes: a graph drag searches the cu…
smi-leonivkovic Nov 11, 2026
a8b4d7e
LR-BEHAV-RENDER-FIDELITY: review fixes: the measured tables are read …
smi-leonivkovic Nov 11, 2026
0b26397
Merge branch 'lr-v8-tone' into lr-v9-curve-graph
smi-leonivkovic Nov 11, 2026
8bec5c5
LR-EDIT-LIGHT-CURVE-PARAM: review fixes: doc comments on the graph's …
smi-leonivkovic Nov 11, 2026
3437e59
Merge remote-tracking branch 'origin/main' into lr-v8-tone
smi-leonivkovic Nov 14, 2026
5ba1722
Merge branch 'lr-v8-tone' into lr-v9-curve-graph
smi-leonivkovic Nov 14, 2026
14909c4
curve_stage: say in apply's doc that values above white are added bac…
smi-leonivkovic Nov 18, 2026
f54fd34
LR-EDIT-LIGHT-CURVE-PARAM: the parametric graph's fix from #4126 land…
smi-leonivkovic Nov 20, 2026
03de271
Merge origin/main into lr-v8-tone
smi-leonivkovic Nov 20, 2026
789c1a0
LR-BEHAV-RENDER-FIDELITY: Whites and the parametric regions are a fit…
smi-leonivkovic Nov 24, 2026
7c0e8ea
Merge main into lr-v8-tone (#523)
smi-leonivkovic Dec 2, 2026
be29de8
Merge remote-tracking branch 'origin/main' into lr-v8-tone
smi-leonivkovic Dec 3, 2026
1f53475
test(curve): the drag test allows the framework's drag threshold, not…
smi-leonivkovic Dec 3, 2026
ff7529a
Merge main into lr-v8-tone: the series moves to process V18 (#523)
smi-leonivkovic Dec 3, 2026
a85845d
test(proraw): V18's curve stage leaves Whites to the ProRAW chain; V1…
smi-leonivkovic Dec 3, 2026
2722f97
fix(curve_stage): Refine Saturation restores the colour after Whites …
smi-leonivkovic Dec 3, 2026
5a58233
fix(curve_input): under V18 sample where the curve stage reads (#523)
smi-leonivkovic Dec 3, 2026
de0c5a8
fix(tools): the tone charts' manifest carries the tool's prefix and f…
smi-leonivkovic Dec 3, 2026
023c93c
test(gpu): the curve-input prefix test names V17, where the sample is…
smi-leonivkovic Dec 3, 2026
a8872ab
fix(curve_input): on ProRAW the sample's curve stage leaves Whites to…
smi-leonivkovic Dec 3, 2026
587ed53
docs: V17's Apple ProRAW uses its chain's fitted Whites, not V2 White…
smi-leonivkovic Dec 3, 2026
e382eef
docs(parity): the point curves keep LightCraft's spline shape; only h…
smi-leonivkovic Dec 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions crates/develop/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,17 @@ pub enum Process {
/// V16, with Apple ProRAW's tone sliders running in Lightroom's fitted tone chain
/// (`lightcraft_pipeline::proraw`).
V17,
/// V17, with Whites and the parametric curve from a fitted model, and the tone curves applied
/// hue-preserving: Whites, the parametric and point curve in linear ProPhoto RGB, then the red, green and
/// blue curves per channel, before the colour stage (`lightcraft_pipeline::curve_stage`,
/// `docs/curve-stage.md`).
V18,
}

impl Process {
/// Every process, oldest first (`ProcessVersion(9)` names none and renders as V8; 11 and 12 name none and
/// render as V10).
pub const ALL: [Process; 14] = [
pub const ALL: [Process; 15] = [
Process::V1,
Process::V2,
Process::V3,
Expand All @@ -147,8 +152,9 @@ impl Process {
Process::V15,
Process::V16,
Process::V17,
Process::V18,
];
pub const LATEST: Process = Process::V17;
pub const LATEST: Process = Process::V18;

pub const fn version(self) -> ProcessVersion {
match self {
Expand All @@ -166,6 +172,7 @@ impl Process {
Process::V15 => ProcessVersion(15),
Process::V16 => ProcessVersion(16),
Process::V17 => ProcessVersion(17),
Process::V18 => ProcessVersion(18),
}
}
}
Expand Down
38 changes: 24 additions & 14 deletions crates/gpu/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const FIELDS: &[(&str, usize)] = &[
("SRGB_OFF", 1),
("CURVE_OFF", 1),
("CURVES", 1),
("STAGE", 1),
("STAGE_OFF", 1),
("STAGE_REFINE", 1),
("STAGE_WHITES", 1),
("GAIN", 1),
("EV", 1),
("AIR", 1),
Expand Down Expand Up @@ -296,21 +300,23 @@ pub fn finish_block(fp: &FinishParams, masks: &[[f32; MASK_TERMS]], present: &Pr
let srgb_off = aux.len();
aux.extend_from_slice(&srgb_lut()[..]);
let curve_off = aux.len();
if let Some(c) = &fp.curves {
for l in c {
if l.v.len() != CURVE_N as usize {
// a wrong-length curve would shift every later aux offset (CURVE_OFF, MASK_OFF and
// the mask terms that follow) and make the kernel read the wrong data. `fail()`
// records the failure on this thread so the render falls back to the CPU; the
// partial `(p, aux)` returned here is never bound to a pipeline.
fail(FailKind::Fatal, format!("curve table has {} entries, expected {}", l.v.len(), CURVE_N));
// `p` is only assembled below the curve loop, so an empty block is as good as any:
// the caller (render.rs) gates on `failed()` right after this returns and bails to
// the CPU fallback before indexing `p` or uploading `aux`.
return (Vec::new(), aux);
}
aux.extend_from_slice(&l.v);
let stage_off = curve_off + fp.curves.as_ref().map_or(0, |c| c.len() * CURVE_N as usize);
// process V18's stage (red, green, blue, then the base table) or the earlier processes' curves
// (and Whites alone after the base table, when Refine Saturation needs it)
let tables = fp.curves.iter().flatten().chain(fp.curve_stage.iter().flat_map(|c| c.chan.iter().chain([&c.base]).chain(c.whites.iter())));
for l in tables {
if l.v.len() != CURVE_N as usize {
// a wrong-length curve would shift every later aux offset (CURVE_OFF, MASK_OFF and
// the mask terms that follow) and make the kernel read the wrong data. `fail()`
// records the failure on this thread so the render falls back to the CPU; the
// partial `(p, aux)` returned here is never bound to a pipeline.
fail(FailKind::Fatal, format!("curve table has {} entries, expected {}", l.v.len(), CURVE_N));
// `p` is only assembled below the curve loop, so an empty block is as good as any:
// the caller (render.rs) gates on `failed()` right after this returns and bails to
// the CPU fallback before indexing `p` or uploading `aux`.
return (Vec::new(), aux);
}
aux.extend_from_slice(&l.v);
}
let mask_off = aux.len();
for m in masks {
Expand Down Expand Up @@ -358,6 +364,10 @@ pub fn finish_block(fp: &FinishParams, masks: &[[f32; MASK_TERMS]], present: &Pr
p.u("SRGB_OFF", srgb_off as u32);
p.u("CURVE_OFF", curve_off as u32);
p.b("CURVES", fp.curves.is_some());
p.b("STAGE", fp.curve_stage.is_some());
p.u("STAGE_OFF", stage_off as u32);
p.f("STAGE_REFINE", fp.curve_stage.as_ref().map_or(1.0, |c| c.refine));
p.b("STAGE_WHITES", fp.curve_stage.as_ref().is_some_and(|c| c.whites.is_some()));
p.f("REFINE_SAT", fp.refine_sat);
p.f("GAIN", fp.gain);
p.f("EV", fp.ev);
Expand Down
85 changes: 85 additions & 0 deletions crates/gpu/src/wgsl/finish.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,86 @@ fn light_ops(d: vec3<f32>) -> vec3<f32> {
return mul3(PRO_TO_2020, p);
}

// A table of process V18's curve stage (`Lut1::eval`) at offset `o` in `aux`.
fn stage_lut(o: u32, x: f32) -> f32 {
let f = clamp(x, 0.0, 1.0) * f32(CURVE_N - 1u);
let i = min(u32(f), CURVE_N - 2u);
let t = f - f32(i);
return aux[o + i] + (aux[o + i + 1u] - aux[o + i]) * t;
}

// `CurveStage::apply`: the base table on the largest and smallest channel of sRGB-encoded linear ProPhoto, the
// middle one keeping its place between them in linear light, then the red, green and blue curves per channel.
// `curve_stage::hue_preserving`: the table at `o` on the largest and smallest channel of `e`, the middle one keeping
// its place between them in linear light (`pc`). Linear, in [0, 1].
fn stage_hue_preserving(o: u32, e: vec3<f32>, pc: vec3<f32>, hi: u32, lo: u32) -> vec3<f32> {
let la = srgb_linear(stage_lut(o, e[hi]));
let lb = srgb_linear(stage_lut(o, e[lo]));
let pa = pc[hi];
let pb = pc[lo];
var out = vec3<f32>(0.0);
for (var k = 0u; k < 3u; k++) {
var t = 1.0;
if (pa > pb) {
t = (pc[k] - pb) / (pa - pb);
}
out[k] = clamp(lb + (la - lb) * t, 0.0, 1.0);
}
return out;
}

fn curve_stage(d: vec3<f32>) -> vec3<f32> {
let p = mul3(PRO_FROM_2020, d);
var pc = clamp(p, vec3<f32>(0.0), vec3<f32>(1.0));
var e = vec3<f32>(srgb_exact(pc.x), srgb_exact(pc.y), srgb_exact(pc.z));
var hi = 0u;
var lo = 0u;
for (var k = 1u; k < 3u; k++) {
if (e[k] > e[hi]) {
hi = k;
}
if (e[k] < e[lo]) {
lo = k;
}
}
let off = pu(F_STAGE_OFF);
let base = stage_hue_preserving(off + 3u * CURVE_N, e, pc, hi, lo);
var curved = vec3<f32>(0.0);
for (var k = 0u; k < 3u; k++) {
curved[k] = stage_lut(off + k * CURVE_N, srgb_exact(base[k]));
}
var q = vec3<f32>(0.0);
for (var k = 0u; k < 3u; k++) {
q[k] = srgb_linear(clamp(curved[k], 0.0, 1.0));
}
let rs = pf(F_STAGE_REFINE);
if (rs < 1.0) {
// the saturation back towards the input's after Whites, at the curves' luminance
var reference = e;
if (pu(F_STAGE_WHITES) != 0u) {
let w = stage_hue_preserving(off + 4u * CURVE_N, e, pc, hi, lo);
reference = vec3<f32>(srgb_exact(w.x), srgb_exact(w.y), srgb_exact(w.z));
}
let rr = refine_saturation(reference, curved, rs);
var r = vec3<f32>(0.0);
for (var k = 0u; k < 3u; k++) {
r[k] = srgb_linear(clamp(rr[k], 0.0, 1.0));
}
let yq = dot(q, PRO_Y);
let yr = dot(r, PRO_Y);
q = r;
if (yr > 1e-6) {
q = r * (yq / yr);
}
}
for (var k = 0u; k < 3u; k++) {
if (p[k] > 1.0) {
q[k] += p[k] - 1.0;
}
}
return mul3(PRO_TO_2020, q);
}

// `proraw::tone_rgb`: the table at `o` on linear ProPhoto `p`, hue-preserving (the largest and
// smallest channel go through it, the middle one keeps its relative position between them).
fn tone_rgb_at(o: u32, p: vec3<f32>) -> vec3<f32> {
Expand Down Expand Up @@ -811,6 +891,11 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
d = light_ops(d);
}

// --- process V18: Whites and the tone curves
if (pu(F_STAGE) != 0u) {
d = curve_stage(d);
}

// --- colour
d = color_ops(d, lt[11], lt[12]);
if (tint_on) {
Expand Down
48 changes: 47 additions & 1 deletion crates/gpu/tests/it/equivalence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ fn curve_input_matches_the_gpu_prefix_and_keeps_later_operations_out() {
let v = 0.01 + x as f32 / 500.0;
[v, v * (0.25 + y as f32 / 100.0), v * 0.4]
}));
let mut s = DevelopSettings::default();
// up to V17 the curves act on the encoded output, so a curve's input is the output of its predecessors; V18 samples
// where its curve stage reads (`lightcraft_pipeline` `v18_samples_where_the_curve_stage_reads_not_after_the_colour_tools`)
let mut s = DevelopSettings { process: Process::V17.version(), ..DevelopSettings::default() };
s.light.exposure = 0.5;
s.curve.shadows = 45.0;
s.curve.master = vec![Point::new(0.0, 0.04), Point::new(0.25, 0.65), Point::new(1.0, 0.95)];
Expand Down Expand Up @@ -988,6 +990,50 @@ fn light_v3_operators_match() {
}
}

/// Process V18's curve stage: Whites, the parametric curve, the point curves and Refine Saturation, on a camera curve
/// and without one, in SDR and HDR.
#[test]
fn curve_stage_matches() {
if !gpu() {
return;
}
use lightcraft_geom::Point;
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();
let raw = SourceInfo { raw: true, camera_tone: Some(curve), ..Default::default() };
let req = RenderRequest::fit(720, 720);
let v18 = || DevelopSettings { process: Process::V18.version(), ..Default::default() };
for v in [-100.0, -30.0, 40.0, 100.0] {
let mut s = v18();
s.light.whites = v;
check(&format!("V18 Whites {v}"), &src, &raw, &s, &req);
}
let mut s = v18();
s.curve.highlights = -40.0;
s.curve.lights = 25.0;
s.curve.darks = -15.0;
s.curve.shadows = 30.0;
check("V18 parametric", &src, &raw, &s, &req);
s.curve.master = vec![Point { x: 0.0, y: 0.05 }, Point { x: 0.5, y: 0.55 }, Point { x: 1.0, y: 0.95 }];
s.curve.red = vec![Point { x: 0.0, y: 0.0 }, Point { x: 0.4, y: 0.5 }, Point { x: 1.0, y: 1.0 }];
s.curve.blue = vec![Point { x: 0.0, y: 0.1 }, Point { x: 1.0, y: 0.9 }];
s.light.whites = -25.0;
check("V18 curves", &src, &raw, &s, &req);
s.curve.refine_saturation = 30.0;
check("V18 Refine Saturation", &src, &raw, &s, &req);
check("V18 curves, no camera curve", &src, &SourceInfo::default(), &s, &req);
s.curve.split_mid = 40.0;
check("V18 other splits", &src, &raw, &s, &req);
s.curve.split_mid = 50.0;
s.hdr.enabled = true;
s.hdr.max_ev = 2.0;
check("V18 HDR preview", &src, &raw, &s, &req);
}

/// Issue #632: the Highlights / Shadows base of each process (V1: the edge-aware filter of log
/// luminance; V2 to V7: of its fine median, V8 on: of its detail-free plane, a radius that grows with the render) matches the CPU's, and
/// a warm cache never hands one process the other's base.
Expand Down
3 changes: 3 additions & 0 deletions crates/pipeline/src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use lightcraft_develop::ToneCurve;
pub use craft_develop::curve::{PARAM_AMOUNTS, PARAM_LUT};

/// The parametric (region) curve of a [`ToneCurve`], backed by `craft_develop::curve::ParametricCurve`.
///
/// Processes V1 to V17 render it, and V18 renders it when the splits are moved. The curve editor draws it
/// through [`crate::curve_stage::ParametricGraph`], which picks the measured regions where V18 renders those.
#[derive(Clone, Debug)]
pub struct ParametricCurve(craft_develop::curve::ParametricCurve);

Expand Down
12 changes: 9 additions & 3 deletions crates/pipeline/src/curve_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! The normal renderer is unchanged. A small, separate render shares its spatial stages and
//! per-pixel code, stopping before the selected curve and everything that follows it.

use lightcraft_develop::{DevelopSettings, ToneCurve};
use lightcraft_develop::{DevelopSettings, Process, ToneCurve};
use lightcraft_raster::{Histogram, Rgb32f, Rgba8};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
Expand Down Expand Up @@ -107,15 +107,21 @@ pub(crate) fn finish(
if let Some(display) = &request.display {
fp.for_display(display, request.proof);
}
fp.curves = crate::finish::curve_luts(&input.predecessors(&settings.curve));
// only the predecessors, wherever the process applies its curves (encoded output, or V18's curve stage)
let predecessors = DevelopSettings { curve: input.predecessors(&settings.curve), ..settings.clone() };
fp.curves = if settings.process.process() < Process::V18 { crate::finish::curve_luts(&predecessors.curve) } else { None };
fp.curve_stage = crate::finish::curve_stage_for(&predecessors, fp.proraw.is_some());
// V18's curves read sRGB-encoded linear ProPhoto after the tone map: sample there, not after the colour tools
fp.sample_at_curve_stage = settings.process.process() >= Process::V18;
fp.refine_sat = 1.0;
// the samples, and the 8-bit pixels as `finish` dithers them at the same place in the output
let samples = crate::finish::finish_with(p, &fp, false, true, |x, y, e| {
let d = crate::finish::bayer_dither_offset(x, y);
(e, [crate::finish::enc(e[0], d), crate::finish::enc(e[1], d), crate::finish::enc(e[2], d), 255])
});
let (samples, data): (Vec<[f32; 3]>, Vec<[u8; 4]>) = samples.into_iter().unzip();
let histogram = of_encoded(&samples, fp.out_luma);
let weights = if fp.sample_at_curve_stage { crate::light_v3::PRO_Y } else { fp.out_luma };
let histogram = of_encoded(&samples, weights);
let image = Rgba8 { width: w, height: h, data };
Rendered { image, histogram, deep: None }
}
Expand Down
42 changes: 39 additions & 3 deletions crates/pipeline/src/curve_input_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ fn input_follows_exposure_but_not_its_own_curve_or_later_curves() {
assert_ne!(a.image, b.image);
}

/// Up to V17 the curves act on the encoded output, so a curve's input is the output of its predecessors. (V18:
/// `v18_samples_where_the_curve_stage_reads_not_after_the_colour_tools`.)
#[test]
fn each_curve_sees_exactly_its_predecessors_including_profile_contributions() {
let mut s = DevelopSettings::default();
let mut s = DevelopSettings { process: lightcraft_develop::Process::V17.version(), ..DevelopSettings::default() };
s.profile.id = "lc.film.golden-hour".into();
s.curve.shadows = 45.0;
s.curve.master = bent();
Expand Down Expand Up @@ -171,7 +173,8 @@ fn diagnostic_and_normal_renders_share_spatial_cache_without_changing_pixels() {
fn input_uses_the_display_primaries_and_effective_edit() {
let src = source();
let info = SourceInfo::default();
let mut s = DevelopSettings::default();
// up to V17 the curves act on the encoded output, in the display's primaries (V18's read ProPhoto)
let mut s = DevelopSettings { process: lightcraft_develop::Process::V17.version(), ..DevelopSettings::default() };
s.light.exposure = 1.0;
s.curve.lights = 55.0;
s.curve.master = bent();
Expand All @@ -181,7 +184,7 @@ fn input_uses_the_display_primaries_and_effective_edit() {
let mut effective = s.effective().into_owned();
effective.curve = CurveInput::Red.predecessors(&effective.curve);
assert_eq!(disabled.image, crate::render(&src, &info, &effective, &req).image);
let mut previous = DevelopSettings::default();
let mut previous = DevelopSettings { process: lightcraft_develop::Process::V17.version(), ..DevelopSettings::default() };
previous.curve.lights = 45.0;
let srgb = render(&src, &info, &previous, &req, None, CurveInput::Red).unwrap();
for space in [OutputSpace::DisplayP3, OutputSpace::Rec2020] {
Expand Down Expand Up @@ -220,3 +223,36 @@ fn an_over_budget_brush_mask_fails_the_sample_instead_of_dropping_strokes() {
s.masks.push(brush(vec![stroke(0.2, 0.6)]));
assert!(render(&source(), &SourceInfo::default(), &s, &full_size, None, CurveInput::Master).is_ok());
}

/// Under V18 the curves read the colour where the curve stage runs, after the tone map and before the colour tools:
/// Saturation, which comes after them, leaves every curve's input alone; on V17 it is part of it (review on #4076).
#[test]
fn v18_samples_where_the_curve_stage_reads_not_after_the_colour_tools() {
use lightcraft_develop::Process;
for ch in [CurveInput::Parametric, CurveInput::Master, CurveInput::Red] {
let on = |p: Process, saturation: f64| {
let mut s = DevelopSettings { process: p.version(), ..DevelopSettings::default() };
s.color.saturation = saturation;
sample(&s, ch).histogram
};
assert_eq!(on(Process::V18, -100.0), on(Process::V18, 0.0), "V18 {ch:?}: Saturation is after the curves");
assert_ne!(on(Process::V17, -100.0), on(Process::V17, 0.0), "V17 {ch:?}: the curves read the encoded output");
}
}

/// On Apple ProRAW the chain applies Whites, so the curve stage the sample is built with leaves it out, as the render's
/// does: Whites alone gives no stage, a curve a stage of its own (review on #4076).
#[test]
fn proraw_curve_input_applies_whites_once() {
use lightcraft_develop::Process;
let mut s = DevelopSettings { process: Process::V18.version(), ..DevelopSettings::default() };
s.light.whites = 40.0;
assert!(crate::finish::curve_stage_for(&s, false).is_some(), "elsewhere the stage applies Whites");
assert!(crate::finish::curve_stage_for(&s, true).is_none(), "on ProRAW the chain does");
s.curve.master = bent();
let with_curve = crate::finish::curve_stage_for(&s, true).expect("the curve");
let mut alone = s.clone();
alone.light.whites = 0.0;
let curve_only = crate::finish::curve_stage_for(&alone, false).expect("the curve");
assert_eq!(with_curve.base.v, curve_only.base.v, "the ProRAW stage is the curve without Whites");
}
Loading