Skip to content

Match the default raw tone curve to Lightroom's - #514

Open
AER00 wants to merge 17 commits into
storytold:mainfrom
AER00:fix/default-tone-curve
Open

AER00 wants to merge 17 commits into
storytold:mainfrom
AER00:fix/default-tone-curve

Conversation

@AER00

@AER00 AER00 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Match the default raw rendering to Lightroom (tone and colour)

The default raw look was tuned by eye. These commits measure it against Lightroom Adobe
Standard instead: the tone curve first, then the colourfulness that curve was throwing away.
References are Lightroom output on raws we own, kept locally and never committed.

Tone

The curve was about a stop dark, had a lifted toe and clipped highlights. It now uses a logistic
shoulder, with BASE_SLOPE = 1.56 / BASE_WHITE_EV = 1.30 fitted to 0.045 stops RMS by
exposure ladder — a pixel's percentile rank is invariant down a ladder, which reconstructs each
engine's scene→display curve on one absolute axis without assuming anything about either.
Whites split into WHITES_UP / WHITES_DOWN: one symmetric coefficient made it 2.4× too
strong downward, and that slider's mean error drops 19.6 → 8.5 per 255. ARW renders come back
bit-identical, since they take tone from a per-photo fit rather than this curve.

Color

With tone matched, the render was still ~19 % under the reference in chroma over saturated
pixels, worse the darker the pixel. It is not the camera profile: the embedded
ProfileHueSatMap and ProfileLookTable are applied faithfully (perturbing either table in
the file
moves both engines by the same factor), neutralising both leaves the deficit
unchanged, and the data is md5-identical to Adobe's own DCP.

ToneMap::new mapped luminance and rescaled the colour with it, which preserves saturation
exactly, where the reference's baseline curve acts on the channels. DEFAULT_CHROMA multiplies
the colour back about the mapped luminance — the mechanism CameraTone::chroma already had for
file-local looks, which the default curve passed as NO_CHROMA. Derived by measurement, and it
avoids a per-channel curve's hue shifts and clipping.

Results

The 5 DNGs embedding a single Adobe Standard profile (the rest are off-target by construction),
mean over the frame: ΔE 6.30 → 3.49, chroma 0.81 → 1.01, lightness unchanged. Verified
independently on a raw.pixls.us sample set — other bodies, other converter, unedited files:

camera chroma LC/LR whole-image ΔE
Canon EOS 5D Mark III 0.814 → 1.007 6.05 → 1.61
Canon EOS 5D Mark III, 2nd scene 0.819 → 1.001 5.87 → 1.49
Canon EOS-1D X (linear raw) 0.791 → 0.990 2.83 → 2.31
Google Pixel 4a 0.797 → 1.027 4.18 → 3.11
Fujifilm X100S 0.936 → 0.969 2.40 → 2.40

The "before" column is the point: 0.79–0.82 across four bodies from three manufacturers, so
it was a property of our render rather than of any one test set.

An earlier revision of this description quoted "mean ΔE 10.02 → 5.09 over 17 raws". That
harness forced Adobe Standard on files embedding Camera Standard, mixing targets. The figures
above supersede it.

Notes

  • ToneMap::display (file-referred sources) and ToneMap::camera (file-local fitted looks) are
    untouched; only raws with no file-local look change. CPU and GPU paths agree to the digit.
  • Bumps RENDER_CACHE_VERSION, which the tone commits needed and missed.
  • Still wrong: the top luminance bin sits at ~0.33 whatever the curve — that is highlight
    roll-off, not chroma; Blacks is wrong in kind (a constant toe lift where the reference has a
    weighted bump near −4.8 EV); every other slider and the presets are still tuned by eye.
  • One sample read worse: a Canon 7D Mark II "Enhanced-NR" DNG (chroma 1.10 → 1.28). Its
    whole-image ΔE is 6.0 → 7.2 where clean files sit at 1.5–3.1, and it was already above 1.0
    before this change — its base rendering is off for a reason not yet found.

@AlexChambers

Copy link
Copy Markdown
Contributor

Two notes from measuring Lightroom on my own camera (details in #146 and #523):

  1. This changes how existing edits render on every raw that uses the default curve: DNGs, and photos without an accepted camera-look fit. LRC-DEV-PROCESS: process versions, so a look change can ship without changing existing edits (#146) #533 adds process versions, so a change like this can land as process 2. Photos edited before it keep V1, new photos get the new curve, and "Update to Current Process" moves old ones over on request. It's a one-arm match in finish::base_tone today, which is where this curve would branch.
  2. Matching by percentile rank down an exposure ladder is a neat way to recover the base curve, and it relies on Exposure being a pure gain before the curve, which my measurements confirm. The same method can't see local operators, though. Lightroom's Highlights is local and edge-aware, with strength set by how much of the frame is dark, so "Highlights already matches (rms 1.8 to 3.9/255)" may hold for the whole histogram and still miss in skies next to dark foregrounds (see Same Light-panel values render brighter/darker than Lightroom (Exposure, Whites/Blacks, Highlights/Shadows; worse for PV 11) #523's bird and leopard examples).

…ourfulness

ToneMap::new mapped luminance and rescaled the colour with it, which preserves
saturation exactly, where the reference developer's channel-wise baseline curve
saturates the shadows and bleaches the highlights toward white; an otherwise-correct
raw render therefore came out flat, ~19 % under the reference in chroma over saturated
pixels (mean dE 6.3 against 1.8 on an independent Canon sample, and the same 0.79-0.82
ratio across four manufacturers).
DEFAULT_CHROMA restores that per display luminance -- the mechanism CameraTone::chroma
already used for file-local camera looks, which the default curve passed as NO_CHROMA --
without the hue shifts or channel clipping a per-channel curve would bring.
It also bumps RENDER_CACHE_VERSION, which the earlier tone commits on this branch needed
and missed.
@AlexChambers

Copy link
Copy Markdown
Contributor

Nice work on the chroma. Three measurements of mine (Lightroom 9.5.1, process 2012, my own A7CR raws; exports only) bear on it and on your open Blacks item:

  • The base curve is applied per channel in linear ProPhoto. On a patch probe, per-channel in linear ProPhoto fits to 0.009 encoded, against 0.024 per channel in sRGB. That's where the extra colourfulness comes from, so a DEFAULT_CHROMA multiplier about luminance can match the average and still miss by hue and brightness: per-channel curves shift hue near the shoulder, and Lightroom shows those shifts too.
  • Contrast is per channel as well. The best-fitting space was ProPhoto primaries with the sRGB transfer (held-out chroma error 0.003–0.005, against 0.005–0.010 in sRGB and 0.02 luma-only). Chroma scales ×1.35 at +100 and ×0.69 at −100.
  • Whites and Blacks mix per channel and luma by direction. Negative Whites is luma-only at every amount. Positive Whites and negative Blacks are per channel. Positive Blacks is per channel at +25 and about 0.4 per channel at +100 (0.55 at +50). As fixed curves: Blacks −100 moves the black point to about 0.21 encoded with a soft toe (−50 → 0.075, −25 → 0.037), and +100 lifts the deep shadows by about 0.10 with the black end anchored. The spread across 24 photos was under 0.02. That may be the "weighted bump" you're seeing.

AER00 added 2 commits October 9, 2026 20:29
dng_tone_curve built the finish stage's camera tone from a DNG
ProfileToneCurve with NO_CHROMA, so every DNG carrying one -- i.e. every
DNG converted with a camera-matching profile -- was rendered with the
reference's tone curve but none of the colourfulness that goes with it.
That is the same defect as the default curve's, on the path the default
curve's fix does not reach: a ProfileToneCurve acts on the reference's
channels, and the tone map here only carries luminance.

Only files with a ProfileToneCurve change; a camera look fitted from a
JPEG (ARW/NEF/RAF) supplies its own fitted chroma curve and still wins,
and ToneMap::display is untouched.

On the two-profile DNGs (Camera Standard in IFD0, Adobe Standard in an
ExtraCameraProfiles IFD), against Lightroom Camera Standard:
  DSC00931  dE 23.28 -> 13.91, chroma 0.659 -> 0.812
  DSC00950  dE 15.99 -> 12.85, chroma 0.518 -> 0.665
and against Lightroom Adobe Standard the two-profile set goes chroma
0.78 -> 1.00. The single-profile Adobe Standard set is unchanged.
LightCraft's Blacks added a constant in display-linear. The reference runs a
second curve over the tone-mapped value, `((x - t)/(1 - t))^p`, per channel:
a black point `t` that exists only below zero, and a curvature `p`.

Measured per channel (binned by that channel's own value in the render at
Blacks = 0) on a Canon 5D Mark III, a Pixel 4a and a Fujifilm X100S, whose
fitted parameters agree to ~2 %. An exposure-shift test fixes the domain: the
transfer is the same curve at Exposure 0 and +1 EV, which a scene-domain
offset would not be. The per-channel share is 1 up to +25 and falls to 0.4 at
+100, reproducing the asymmetry reported in review.

At +100 the old model lifted a level rendering at 0.05 up to 0.20 where the
reference gives 0.11; at -100 it left one at 0.25 at 0.13 where the reference
crushes it to 0.03. Whole-render dE against the reference (1.8 at Blacks = 0)
goes 4.98 -> 2.12 at -50, 13.80 -> 3.06 at -100, 5.66 -> 2.36 at +100.

The step runs after the tone map on both paths; for display-referred sources
it is the identity, so JPEG rendering is unchanged.
@AER00

AER00 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Blacks

Measured the same way - per channel, binned by that channel's own value in the render at
Blacks = 0 — the reference's Blacks is not a lift at all. It is a second curve over the
tone-mapped value, ((x − t)/(1 − t))^p in display linear: a black point t that exists only
below zero, and a curvature p. An exposure-shift test fixes the domain — the transfer is the
same curve at Exposure 0 and +1 EV (0.181 vs 0.191, 0.576 vs 0.578 at +100), which a scene-domain
offset would not be — and the fitted parameters agree to ~2 % across a Canon 5D Mark III, a
Pixel 4a and a Fujifilm X100S, so they belong to the slider rather than to a photo. It is applied
per channel rather than to luminance, though not uniformly: fully per-channel up to +25, a share
of 0.4 at +100 — the same asymmetry reported in review, arrived at independently.

Ours was a constant added in display-linear. At +100 it lifted a level rendering at 0.05 up to
0.20 where the reference gives 0.11; at −100 it left a level at 0.25 at 0.13 where the reference
crushes it to 0.03. Blacks now carries the measured table and the finish stage applies it, on
the CPU and in the WGSL kernel alike — the one finish step passed as numbers rather than a table.
Whole-render ΔE against the reference, where Blacks = 0 already sits at 1.8:

−50 +50 −100 +100
before 4.98 3.32 13.80 5.66
after 2.12 2.05 3.06 2.36

(Canon 5D Mark III; −100 goes 8.63 → 3.82 and 12.73 → 4.52 on the Pixel 4a and the X100S.) The
slider no longer degrades the match at all: moving it now costs about what the baseline error
already is.

LightCraft's Whites moved the shoulder alone, through a pair of coefficients
(WHITES_UP / WHITES_DOWN). The reference moves the white point and the
log-slope together, and the two are tied: fitting the slope as a fixed
multiple of the EV matches the free two-parameter fit to four decimals.
Nor is it a linear pair -- per unit the move is 0.0042 EV at -100 against
0.0175 at +100 -- so WHITES_KNOTS carries the measured EV per notch.

The evidence is the same family comparison used for Blacks, with a control:
fitting a shoulder to LightCraft's own Whites recovers the old coefficients
to 0.02 EV at a residual of 0.004, so the family is identified. Against the
reference the tied shoulder-and-slope fit has a residual of 0.019 in encoded
sRGB at +100 where the shoulder alone has 0.062. Rendered, the transfer is
within 0.002-0.016 encoded over -50..+50 (was 0.009-0.035).

Unlike Blacks this one is scene-domain, and provably so: rendering one file
under two camera profiles, which have different tone curves, gives different
transfers for a positive Whites (+100 at display 0.35: 0.566 against 0.660),
so the op sits before the output curve. That test cannot separate the two
domains for Blacks -- an exposure shift scales the same variable both the
curve and the op act on -- and the Blacks commit's claim to the contrary is
corrected here, along with the family comparison that does settle it.

Whole-render dE against the reference (1.8 at Whites = 0): 4.26 -> 2.51 at
-100, 2.35 -> 2.02 at -50, 6.24 -> 4.95 at +50. At +100 it barely moves,
because that error is colour rather than lightness: the reference clips per
channel where the tone stage maps luminance, so DEFAULT_CHROMA, fitted to the
neutral curve, over-desaturates once the curve is steepened (chroma 0.64).
That needs a per-channel tone stage, which is not this commit.
@AER00

AER00 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Whites

Whites had already been split into WHITES_UP / WHITES_DOWN, which fixed the 2.4× over-strength
downwards — but it still moved the shoulder alone, and that misses the reference's transfer by
2–3× at every notch. The reference moves the white point and the log-slope, and the two are
tied: fitting the slope as a fixed multiple of the EV (WHITES_SLOPE = 0.425) matches the free
two-parameter fit to four decimals and cuts the residual from 0.062 to 0.019 in encoded sRGB at
+100. Nor is it a linear pair — per unit the move is 0.0042 EV at −100 against 0.0175 at +100.

Whites is scene-domain, and that is provable where it is not for Blacks: rendering one file
under two camera profiles, which have different tone curves, gives different transfers for a
positive Whites (+100 at display 0.35: 0.566 under one, 0.660 under the other), and no
display-domain family comes close (0.019 against 0.085).

Whites −100 −50 +50 +100
dE before 4.26 2.35 6.24 16.79
dE after 2.51 2.02 4.95 15.36

The +100 row barely moves, and the reason is worth stating: that error is colour, not
lightness.
The reference's tone stage clips per channel where ours maps luminance, so once the
curve is steepened DEFAULT_CHROMA — which was fitted to the neutral curve — over-desaturates
(chroma 0.64 against the reference). Simulating the same model applied per channel instead gives
dE 9.3 against LightCraft's 15.4. Fixing that means making the tone stage per channel

@AlexChambers

Copy link
Copy Markdown
Contributor

One more data point on Whites, since it may explain part of the remaining +100 gap. Across 24 photos, my measurements found positive Whites is scene-adaptive. It stretches toward a white point set by each photo's 99th percentile: at +100, w = 1.394 × p99 − 0.553 (r 0.95; p98 works as well, the maximum doesn't, r 0.55). Strength goes as (amount/100)^1.85, the same non-linearity as your 0.0042 vs 0.0175 EV per unit. The useful check: curves with equal w agree across photos and amounts to 0.012, while curves for the same slider value differ by photo. So a single fitted slope can match a few reference images and still miss photos with a different p99. Negative Whites, by contrast, behaved as one fixed curve on luma (out = in − 0.1·in² at −100).

brahimforbladi-blip pushed a commit to brahimforbladi-blip/lightcraft that referenced this pull request Oct 10, 2026
…ults (storytold#318, storytold#209)

Auto was a percentile rule that set Exposure about 1.4 EV higher than
Lightroom's Auto on the same photos (mean +1.81 against +0.44 EV) and
barely used Shadows: on 24 Sony raw photos its results were further from
Lightroom's Auto results (median dE76 22.0) than leaving the photo
unedited (7.9), about 18 L* too bright.

Auto is now Lightroom's shape of rule with values chosen for our results:
- Exposure = -0.58 - 0.41 * the scene's log-average luminance (EV from
  middle grey, scene-linear, under the photo's white balance, so it does
  not depend on the base tone curve), clamped to -2..3 EV. The slope is
  Lightroom's: its Auto's chosen Exposure against our log average, r -0.92;
- Highlights -66 and Shadows +52: Lightroom's own average Auto values;
- Contrast +68 and Vibrance +30 (our scales; our base tone is flatter);
  Whites, Blacks and Saturation 0.
The exposure offset, Contrast and Vibrance were fitted jointly so our
renders match Lightroom's Auto exports on the 16 photos whose starting
look Sony's DRO doesn't brighten (storytold#568 changes the other 8). Held out one
photo at a time, each fold fitted from its own training photos only:
median dE76 6.38 on those 16 (8.28 unedited, 18.81 with the old rule),
12 of 16 closer than unedited; 7.70 on all 24 (7.92 unedited); on the 8
DRO photos 9.39 (7.00 unedited), their brighter start showing through.
Freeing Highlights and Shadows too (5 fitted values) did no better held
out (6.51) and left them poorly determined across folds.

The log average skips pixels that aren't finite (a damaged decode) through
the proxy's resampling and white balance; with no valid pixel, Exposure 0.

Values are black-box observations of Lightroom (the settings its Auto
chose and its exports), as in storytold#514. Auto only applies when asked for, so
existing edits keep their look; HDR merges with Auto Settings use the
same rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream moved 497 commits ahead while still carrying the original tone curve:
`ToneMap::hdr` with `slope = 1.0 + 0.55c` and `white_ev = 2.9 − 1.6·(whites/100)`, Blacks as a
toe inside `ToneMap`, plus HDR (`peak`) and process versions. This branch replaces that curve
with the measured one, so the merge is a port rather than a conflict resolution:

- `ToneMap::new`/`hdr`/`camera` carry the measured logistic shoulder (`BASE_SLOPE`,
  `WHITES_KNOTS`) and no longer take `blacks`; `Blacks` is applied by the finish stage as
  before. `base_tone` keeps upstream's HDR / process-version dispatch and drops `blacks` from
  its raw arms.
- The HDR highlight lift is kept and composes with the measured curve; the toe went with the
  rest of the old Blacks model (Blacks owns that now, per channel, after the tone map).
- `RENDER_CACHE_VERSION` 42 → 43: both sides changed the rendered output.
- The HDR test asserted SDR-equality below a fixed scene level, a bound calibrated to the old
  slope. It now states the boundary in the curve's own terms, since the measured slope moves
  with Contrast and Whites.

cargo xtask ci: all 8 steps pass (fmt, clippy, heif, test, parity, layers, assets, wasm).
AER00 added 4 commits October 10, 2026 15:19
Whites was one fixed table on one code path. Both were wrong.

The camera path never ran the measured model. `ToneMap::camera` composed its tone with
`ToneMap::display`, a display-domain lift whose reach is a fraction of a stop, so on any file
carrying a camera look -- every ARW, and DNGs with an embedded look -- Whites was nearly inert:
measured, the reference moves the white point +2.60 EV at +100 where this engine managed +0.26,
which is most of the error on such files. The reference's transfer there is described by the same
family as on the default curve, at the same residual (0.013-0.033 against 0.019 over the corpus),
so `whites_display` applies that move over the camera curve's output.

Positive Whites is per-photo, not one table. Across ten bodies the white-point move fitted per
photo spans 0.66-4.15 EV at +100 and the fixed 1.753 is off by more than 0.35 EV on nine of them.
Negative Whites is the opposite -- spread 0.04-0.08 EV, one curve -- and is untouched. The scale
comes from the frame's own highlight level, the 99th percentile of the *encoded* display luma of
a ~384 px proxy render at Whites 0 (`local::frame_highlight`, computed once per plan exactly as
the whole-frame dehaze airlight is). It correlates -0.41/-0.65/-0.79/-0.84 with the amount the
reference asks for at +25/50/75/100, and removes 6/15/26/36 % of the transfer error there, held
out by whole camera body.

The percentile must be taken encoded. A percentile does not commute with the transfer curve, and
the first attempt at this fed a display-linear proxy to a relation fitted on an encoded feature:
that shifted every reading by ~0.2, dropped the +100 correlation to -0.66 and applied roughly a
third too much. `LIGHTCRAFT_WHITES=1` now prints what was measured, so the two can be checked
against each other rather than assumed equal.

On twelve raws from two bodies at +100, whole-render dE against Lightroom falls 178.5 -> 123.3
(-31 %), ten of twelve improving; at -100 nothing changes, as intended. What remains at +100 is
dominated by colour, not lightness -- the tone stage maps luminance where the reference's is per
channel -- which is not in this change.

RENDER_CACHE_VERSION 43 -> 44. cargo xtask ci: all 8 steps pass.
… grey

Contrast was a log-slope change about grey, which is a different operation. Measured through the
same pipeline -- our engine and the reference, same files, same binning -- ours fitted at g 0.760
with an effective pivot of 0.596 where the reference is 0.634 about 0.507. So it pivoted 0.09 too
high, moving the shadows more than it should and the highlights less, and its S was too shallow.

The reference's Contrast is an odd-symmetric power about a fixed display pivot. Fitting its own
transfer at seven slider values over twenty-four bodies gives a pivot that does not move (0.4934,
sd 0.05) and an exponent table that is a clean exponential: g = exp(-0.004537 * contrast), within
1 % at every measured point and exactly 1 -- the identity -- at neutral. One constant, not a table.

The shipped coefficients are calibrated rather than taken from that table, because the fit
compresses the exponent: applying the fitted value and re-measuring came back shallower than asked
(g 0.692 against the reference's 0.634 at +100). The two arms compress differently -- 0.832
positive, 0.912 negative, since an S and an inverse S do not fit alike -- so there are two
constants, each verified by re-measuring rather than assumed.

With them, the fitted g matches the reference within 1 % at every notch and the pivot within 0.01.

Applied in the encoded domain over both the default curve and a camera look, for the same reason
`whites_display` is: a display-domain operation cannot be applied to a scene-domain curve directly.

Exposure was measured the same way and deliberately left alone: the reference fits at ~1.068 stops
per unit against our exact 1.0, but our own Exposure -- exactly 1.0 by construction -- reads 1.053
through the same pipeline, and the paired ratio is 1.026 +/- 0.017. Most of that 6.8 % is bias in
the fit, so changing it would be fitting noise.

cargo xtask ci: all 8 steps pass.
The reference's tone curve runs on the three channels, so a bright colour bleaches as its
channels clip one by one. Ours mapped luminance and rescaled the colour, and DEFAULT_CHROMA --
one fitted multiplier -- was putting back the saturation a luminance map loses. But it was
fitted to the *neutral* curve, so once the curve steepened it over-corrected: at Whites +100 the
render was left at chroma 0.70 against the reference's 1, the largest remaining term.

ToneMap now records whether the curve is per channel. The default raw curve is, and no longer
takes a chroma curve at all -- the mechanism it needed is gone. A camera look is not: it is a
per-file fit of the whole image, so it stays on luminance, and a file-carried ProfileToneCurve
still shares that stage (unmeasured there, noted in the code). File-referred sources are
untouched, so JPEG rendering is bit-identical. The finish stage branches on it on the CPU and in
the WGSL kernel alike, the kernel taking a new PER_CHANNEL uniform.

Twelve bodies, whole-render dE and chroma against Lightroom:

  dE neutral      3.49 -> 3.13   (8/12 better)
  dE Whites +100  9.36 -> 7.65   (10/12 better)
  chroma +100     0.70 -> 0.88

The +100 wins are large where the colour error was (Canon 9.92 -> 5.40, Adobe DNG Converter
15.22 -> 8.55, Blackmagic Design 13.59 -> 11.12); the two regressions are at neutral and under
0.9 dE. The base curve and Contrast both run through this path, so both are per channel now.

Bumps RENDER_CACHE_VERSION, which the Contrast commit needed and missed.

cargo xtask ci: all 8 steps pass.
The "Colour & image quality" row still listed tone among the things tuned by eye, which the
per-channel tone commit and the Whites/Blacks/Contrast work before it made false -- and which
contradicted the look-parity bullet further down that already says tone and colour are measured.
@AER00

AER00 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

The tone stage is per channel

The reference's tone curve runs on the three channels, not on luminance 0 that is why it bleaches a
saturated colour as its channels clip one by one, and it is where the +100 colour error lived. Ours
mapped luminance and rescaled the colour, and DEFAULT_CHROMA (one fitted multiplier) was making
up the saturation a luminance map loses; but it was fitted to the neutral curve, so once the
curve steepened it over-corrected, leaving chroma 0.70 against the reference at +100.

ToneMap now records whether it is per channel. The default raw curve (hdr_scaled) is, and takes
NO_CHROMA — the mechanism it needed is gone. A camera look (camera_scaled) is not: it is a
whole-image curve fitted as one, and stays on luminance; file-referred display_hdr likewise, so
JPEG rendering is untouched. The finish stage branches on it on the CPU and in the WGSL kernel
alike, the kernel taking a PER_CHANNEL uniform.

Twelve bodies, native rendering, whole-render ΔE and chroma against Lightroom:

luminance per channel bodies better
ΔE, neutral 3.49 3.13 8/12
ΔE, Whites +100 9.36 7.65 10/12
chroma, Whites +100 0.70 0.88 —

The +100 wins are large where the colour error was - Canon 9.92 → 5.40, Adobe DNG Converter
15.22 → 8.55, Blackmagic Design 13.59 → 11.12 - and the two regressions (both at neutral, both
under 0.9 ΔE) are the cost. This is also what the base curve and Contrast needed; both run through
this path.

Positive Whites is per-photo

A fixed table cannot be right at the top of the slider. Binning the reference's own render at
Whites = V by its render at 0, per channel, across ten camera bodies, the white-point move fitted
per photo spans 0.66–4.15 EV at +100, and the fixed 1.753 is off by more than 0.35 EV on nine
of the ten
. Negative Whites is the opposite — spread 0.04–0.08 EV, one curve — so it is
untouched.

The reference stretches toward a white point the photo's own highlights set, so a frame that
already has highlights needs a smaller move. One statistic carries it: the 99th percentile of the
sRGB-encoded display luma of a ~384 px proxy render of the frame at Whites = 0, which the plan
computes once (local::frame_highlight → Plan::whites_scale) exactly as the existing whole-frame
dehaze airlight is. Against the amount the reference asks for it correlates −0.41 at +25, −0.65 at
+50, −0.79 at +75 and −0.84 at +100 — strongest where the term matters most. Held out by whole
camera body, it removes 6 / 15 / 26 / 36 % of the transfer error at +25/50/75/100.

The percentile must be taken in the encoded domain. A percentile does not commute with the
transfer curve, and this is not a theoretical point: the first attempt fitted the relation against
a full-resolution feature and then fed it a display-linear proxy, which shifted every reading by
~0.2 (0.58 against 0.78 on one body), dropped the +100 correlation to −0.66 and applied roughly a
third too much. frame_highlight now encodes before taking the percentile, and LIGHTCRAFT_WHITES=1
prints what it measured, so the two can be checked against each other.

Whites on a file with a camera look

Any raw carrying a camera tone curve — every ARW, and DNGs with an embedded look — never ran the
measured model at all: ToneMap::camera composed its tone from ToneMap::display, a
display-domain lift whose reach is a fraction of a stop, which left Whites nearly inert there.
Measured on one body, the reference moves the white point +2.60 EV at +100 where this engine
managed +0.26 — most of that file's error. The reference's transfer on such files is described by
the same family as on the default curve, at the same residual (0.013–0.033 against 0.019 over the
corpus), so whites_display applies that move over the camera curve's output directly. On the
owner's files at +100 that is 26.6 → 12.7 ΔE on the worst body.

Both together, on real files

Twelve raws from two bodies (a6400, a6700), ±100, whole-render ΔE against Lightroom. At +100,
ten of twelve improve and the total falls 178.5 → 123.3 (−31 %); at −100 nothing changes, as
intended. The two exceptions are marginally worse (4.78 → 5.10 and 3.64 → 4.60) — both bodies whose
reference move at +100 is small (+0.63/+0.81 EV), where the per-photo scale pulls back but not all
the way. What remains at +100 is dominated by colour, not lightness: the per-channel tone stage
above.

Contrast

Contrast was a log-slope change about grey. The reference's is not a slope at all: it is an
odd-symmetric S-curve about a fixed display pivot, and measuring it through the same pipeline —
our engine and the reference, same files, same binning — showed ours wrong in two ways at once.
Ours fitted at g 0.760 with an effective pivot of 0.596; the reference is 0.634 about 0.507. So it
pivoted 0.09 too high, moving the shadows more than it should and the highlights less, and its S
was too shallow.

Fitting the reference's transfer at seven slider values over twenty-four bodies gives a pivot that
does not move (0.4934, sd 0.05) and an exponent table that turns out to be a clean exponential —
g = exp(−0.004537·contrast), within 1 % at every measured point and exactly 1 (the identity) at
neutral. That is one constant, not a table.

The coefficients that ship are calibrated rather than taken from that table, because the fit
compresses the exponent: applying the fitted value and measuring the result came back shallower
than asked (g 0.692 where the reference reads 0.634 at +100). The two arms compress differently —
0.832 positive, 0.912 negative, since an S and an inverse S do not fit alike — so there are two
constants, each checked by re-measuring rather than assumed.

With them, the match is within 1 % at every notch and the pivot within 0.01:

Contrast −100 −50 −25 +25 +50 +100
ours g 1.5679 1.2437 1.1105 0.8845 0.7912 0.6381
reference g 1.5642 1.2445 1.1107 0.8842 0.7880 0.6337
error +0.2 % −0.1 % −0.0 % +0.0 % +0.4 % +0.7 %

The chroma curve composited over a file's own ProfileToneCurve was fitted against the *default*
render curve, and over-saturates this one. On the owner's ProfileToneCurve DNGs at neutral against
Lightroom Adobe Standard, the bare luminance map reads dE 5.5/4.9 where the chroma curve reads
7.8/7.9, and applying the curve per channel instead reads 7.9/8.4 -- the reference is *less*
saturated than a luminance map here, so neither repairs it and the residual is not in the tone
stage. Neutral dE 7.33/7.22/7.78 -> 6.15/5.87/5.61, dL* unchanged.

DEFAULT_CHROMA had no caller left, so it goes with the call, along with the unreachable unwrap_or
fallback and the test that asserted the opposite. Bumps RENDER_CACHE_VERSION (46).

cargo xtask ci: all 8 steps pass.

Copy link
Copy Markdown
Member

Thanks for fitting the tone curve. Getting the default raw look closer to Lightroom matters a lot. As written, though, it changes every existing raw edit in place on V1: the base curve constants (BASE_SLOPE, BASE_WHITE_EV), per-channel tone, Blacks as a separate per-channel curve, and per-photo Whites. docs/process-versions.md requires a new rendering to go behind a process version, so that existing edits keep their look until the user updates them.

Could you put it on a new arm of finish::base_tone / the finish stage? #645 (Process V2) is landing now, and #762 is moving sharpening onto a version as well, so please coordinate the number. Please also say in the docs that the constants were fitted to observed Lightroom output. Observing behaviour is fine under our clean-room rules; it just needs to be recorded. If you haven't already, come and join us on Discord: https://discord.gg/artcraft


Generated by Claude Code

AER00 added 3 commits October 11, 2026 15:24
Measured on the owner's own seventeen default-path DNGs by binning the reference's render at V by
its render at 0, per channel: our transfer is short by 0.066 encoded in the midtones at +100 while
the highlights already match, i.e. the reference lifts the whole image and we move the white point
and leave the midtones behind. The extra 1.3x was measured before and declined as "as likely to be
this engine's profile error on unusual bodies as the reference's true level"; on files whose
profile is not in question it reproduces at 1.25-1.3.

  transfer error, +50/+75/+100      0.0341 -> 0.0247
  midtone term at +100              -0.066 -> +0.004
  whole-render dE at +100 (17 DNGs)   8.16 -> 6.71
  whole-render dE at +75              5.42 -> 4.72

Negative Whites is untouched (its per-body spread is 0.04-0.08 EV, one curve). The golden table
in whites_curve_matches_the_reference_transfer is re-pinned from the binary -- its old values were
stale by up to 0.031, inside their 0.035 tolerance -- and the knot assertion moves to 2.279.
Bumps RENDER_CACHE_VERSION (47).

cargo xtask ci: fmt, clippy and heif pass. The test step stops on export_progress_and_cancel
(crates/mcp/tests/e2e.rs:237), a pre-existing load-sensitive race that passes 6/6 in isolation and
failed the same way earlier today before this change; nothing else is red.
… exponent fit

The S was already right -- its exponent matches the reference within 1% at every notch -- but the
pivot it pivots about was taken from the fit that produced those exponents, whose own scatter is
+-0.05. Searched against the reference's transfer on the owner's seventeen default-path DNGs, the
optimum is 0.4700 rather than 0.4934, and it is not a couple of files carrying a mean: 12 of 17
improve at -100 (-0.29 dE) and 12 of 17 at +100 (-0.21), even at +-50, and no notch is worse. The
gain is concentrated at the extremes and vanishes in the middle, which is where a pivot acts and
where it must not -- the signature of a real parameter effect rather than of the search.

  Contrast  mean dE over eight notches   4.03 -> 3.92
            -100                          4.37 -> 4.08
            +100                          6.05 -> 5.83

Bumps RENDER_CACHE_VERSION (48). The same caveat on the gate as the Whites commit above: fmt,
clippy and heif pass, the test step stops on the pre-existing load-sensitive export test.
It was false when written -- the shipped pivot and the reference's measured one differ by 0.0136 --
and the row now states which pivot ships and how it was chosen, so the claim is redundant as well.
The tone work from storytold#146/storytold#196 changes how every existing raw edit renders, so
it goes behind a process version (docs/process-versions.md): V2 is the measured
rendering and LATEST; V1 keeps the pre-branch rendering exactly.

- Process::V2 added, LATEST; ALL is [V1, V2]. V2 is shared with the
  Highlights/Shadows base (storytold#645) and the sharpening (storytold#762) landing in the same
  batch, so a photo that updates to V2 gets the whole measured look at once.
- finish::base_tone: V1's arm calls tone::ToneMap::{camera_v1, hdr_v1}, the old
  model restored verbatim (neutral base curve, extended-Reinhard shoulder,
  Blacks as the curve's toe, Whites as a display-domain lift); V2's arm is the
  measured model. A display-referred source uses display_hdr in both.
- FinishParams::blacks is Blacks::IDENTITY for V1, and the per-photo Whites
  statistic is measured only for V2 (Process::is_measured_tone) -- V1 pays for
  neither.
- RENDER_CACHE_VERSION 48 -> 49.
- docs: process-versions.md describes V1/V2 and records that the V2 constants
  are fitted to the reference developer's observed output only (its rendered
  images; no bundle, profile, preset or Adobe asset); parity.md, ROADMAP.md and
  gpu-pipeline.md name V2 / F_PER_CHANNEL.

Tests: v2_is_not_v1 pins the default curve apart; the v1_* golden tests pin the
frozen model; stored_process_numbers_render_with_a_known_process now asserts
the two arms render a raw differently and a rendered source alike.

cargo xtask ci: all 8 steps green (fmt, clippy, heif, test, parity, layers,
assets, wasm).
@AER00

AER00 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Same develop settings (Lightroom export vs Lightcraft)
Before:
image

Process V2:

image

Second example:
image

Process V2:
image

Takes the branch onto the 346 commits main landed since b70ae17, including its
own Process::V2 (storytold#632: Highlights and Shadows keep the local contrast of the
tones they move) and the progress-doc restructure (parity.md ->
parity-checklist.md, "Where we stand" -> target-app-parity.md, milestones and
risks -> roadmap.md).

Resolutions:

- Process: main's V2 and this branch's measured tone model share one V2, as
  agreed with the Highlights/Shadows (storytold#645) and sharpening (storytold#762) work. The
  Process::V2 doc comment and docs/process-versions.md say so.
- finish::base_tone keeps V1 frozen (main's tone map) and gives V2 the measured
  model, now HDR-aware on the camera path too (ToneMap::camera_scaled_hdr), so
  an HDR render keeps the file's camera look. Process::is_measured_tone gates
  the Blacks curve and the per-photo Whites statistic; local::tone_base_detail
  gates storytold#632's median base.
- The camera-look fitter keeps scoring its candidates with the frozen V1 tone
  map (ToneMap::{camera_v1, hdr_v1}). The model a fit is scored with decides
  which files accept a look -- the source stage, which the process version does
  not reach; the fit's own test (a_black_and_white_jpeg_gives_its_tone_curve)
  asserts the default curve is darker, which V2's measured curve is not.
- crates/pipeline/src/spots.rs: chunks_exact(3) -> as_chunks::<3>() for the
  clippy lint rustc 1.98 added (main's new line; the local gate is -D warnings).
- RENDER_CACHE_VERSION 60 -> 61 (the branch's look changes on top of main).
- Docs merged: parity-checklist.md (the five Light rows, the storytold#632 note on
  Highlights/Shadows, LR-PROF-CAMERACOLOR and LR-BEHAV-RENDER-FIDELITY),
  process-versions.md (V1/V2 as one batch), roadmap.md (Look parity bullet),
  gaps.md (gap 3 is no longer "render fidelity unmeasured").

cargo xtask ci: all 8 steps green (fmt, clippy, heif, test, parity, layers,
assets, wasm).
@AER00

AER00 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for fitting the tone curve. Getting the default raw look closer to Lightroom matters a lot. As written, though, it changes every existing raw edit in place on V1: the base curve constants (BASE_SLOPE, BASE_WHITE_EV), per-channel tone, Blacks as a separate per-channel curve, and per-photo Whites. docs/process-versions.md requires a new rendering to go behind a process version, so that existing edits keep their look until the user updates them.

Could you put it on a new arm of finish::base_tone / the finish stage? #645 (Process V2) is landing now, and #762 is moving sharpening onto a version as well, so please coordinate the number. Please also say in the docs that the constants were fitted to observed Lightroom output. Observing behaviour is fine under our clean-room rules; it just needs to be recorded. If you haven't already, come and join us on Discord: https://discord.gg/artcraft

Generated by Claude Code

Done, should be ready to merge. If you have any more requests, let me know

@AlexChambers AlexChambers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a fellow contributor, not a maintainer. I'm using Codex to help review PRs and checking potential findings with focused tests where possible.

Reviewed head 330675c4d920964e145339ac528338165072fb3d against target base and merge base 995d5ea49b12b1b0adb6d08e177ac32a8e7b3a7f.

P2: Keep HDR highlights when Blacks changes

A one-notch Blacks adjustment removes HDR headroom. The new curve clamps every channel to 1 even when the finish stage is rendering above SDR white. On the original 32 by 8 grayscale ramp below, three stops of HDR headroom give a neutral maximum of 7.9996. Blacks -1, +1 and +25 each reduce the maximum to 1, with no samples above white. At the exact base, all three retain a maximum of 8 and 552 channel samples above white.

This affects V2 raw HDR rendering, including the float render used for HDR exports. Preserve the HDR range when applying the Blacks curve. Changed clamp.

P2: Keep positive Whites consistent across render sizes

A flat part of the same photo changes brightness with thumbnail size. The new statistic uses the requested output dimensions when they are below 384 pixels. The same small bright pattern then occupies a different share of the proxy, changing the photo's global Whites strength.

At Whites +100, the original 384 by 96 fixture below produces middle-patch byte 159 at full size and 88 at 128 by 32. LIGHTCRAFT_WHITES=1 reports p99 0.2524 and scale 2.0000 for the full render, versus p99 0.9047 and scale 0.8257 for the thumbnail. At Whites 0 both are 64; at -100 both are 61. The exact base gives 74 at both sizes at +100. Use a fixed frame-wide measurement resolution independent of the requested render size. Changed proxy dimensions.

Portable public-API reproduction for both findings

Save this as crates/pipeline/tests/review514.rs, then run cargo test -p lightcraft-pipeline --test review514 -- --nocapture. Both assertions fail at the reviewed head and pass at the exact base. No external media or GPU is used.

use lightcraft_develop::{DevelopSettings,ProcessVersion};
use lightcraft_pipeline::{render,DeepSamples,OutputDepth,RenderRequest,SourceInfo};
use lightcraft_raster::Rgb32f;

fn hdr_render(blacks:f64)->Vec<f32> {
    let src=Rgb32f::from_fn(32,8,|x,_|[0.18*2f32.powf(x as f32/4.0);3]);
    let mut s=DevelopSettings::default();s.process=ProcessVersion(2);
    s.hdr.enabled=true;s.hdr.max_ev=3.;s.light.blacks=blacks;
    let req=RenderRequest{depth:OutputDepth::F32Hdr,..RenderRequest::fit(32,8)};
    let out=render(&src,&SourceInfo{raw:true,..Default::default()},&s,&req);
    match out.deep.unwrap().samples {DeepSamples::F32(v)=>v,_=>panic!("expected float")}
}
#[test]
fn review514_blacks_keeps_hdr_headroom() {
    let neutral=hdr_render(0.);let max0=neutral.iter().copied().fold(0f32,f32::max);
    assert!(max0>4.,"HDR fixture must exceed white: {max0}");
    let mut minima=f32::INFINITY;
    for b in [-1.,1.,25.] {
        let out=hdr_render(b);let max=out.iter().copied().fold(0f32,f32::max);
        let above=out.iter().filter(|v|**v>1.01).count();
        println!("Blacks={b}: neutral maximum {max0}, edited maximum {max}, samples above white {above}");
        minima=minima.min(max);
    }
    assert!(minima>2.,"moving Blacks removed HDR headroom, lowest maximum={minima}");
}

#[test]
fn review514_whites_statistic_does_not_depend_on_thumbnail_size() {
    let src=Rgb32f::from_fn(384,96,|x,y|if x>=378 && y%3==0 {[2.;3]}else{[0.04;3]});
    let info=SourceInfo{raw:true,..Default::default()};
    let mut s=DevelopSettings::default();s.process=ProcessVersion(2);s.light.whites=100.;
    for control in [0.,-100.] {
        let mut c=s.clone();c.light.whites=control;
        let a=render(&src,&info,&c,&RenderRequest::fit(384,96)).image.get(192,48)[0];
        let b=render(&src,&info,&c,&RenderRequest::fit(128,32)).image.get(64,16)[0];
        println!("Whites={control}: full={a}, thumbnail={b}");
        assert!(a.abs_diff(b)<=1,"control patch must be constant");
    }
    let full=render(&src,&info,&s,&RenderRequest::fit(384,96)).image;
    let small=render(&src,&info,&s,&RenderRequest::fit(128,32)).image;
    let a=full.get(192,48)[0];let b=small.get(64,16)[0];
    println!("uniform middle full={a} thumbnail={b}; difference={}",a.abs_diff(b));
    assert!(a.abs_diff(b)<=1,"the same flat patch changes brightness with output size");
}

Verification limits: 29 focused existing CPU tests pass, including tone, HDR and stored-process tests. These reproductions compare the stated behavior at head and base, not byte equality between the old and new V2 looks. I did not run an actual GPU, native UI, encoded HDR export or Lightroom comparison. The earlier process-version feedback is not repeated.

@wanikhawar

Copy link
Copy Markdown
Contributor

This changes existing process-V1 renders in place, which docs/process-versions.md doesn't allow. Please rebase and put it behind a process version, or close it in favour of #4099 / #4076. The earlier review points (Blacks clamped to 1 at crates/pipeline/src/tone.rs:392, and the Whites statistic changing with proxy size under 384 px) are still open.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants