Repository navigation
Description
Updated 2026-12-01. The original guess (the plateau after the step, missed by
limit_elasticity) was incomplete. The step and the plateau are one artefact with one cause: the saturated LED wall takes part in the tone fit. Details and measurements below.
What happens
On Nikon D90 NEFs shot on a stage in front of a saturated red/blue LED wall (flash on), the default render posterises skin, clothing and hair: faces and a beige jacket become a flat orange/yellow fill, and dark hair and stubble break into black blotches. The camera JPEG embedded in the same NEF, and an independent raw converter's render of the same file, show normal skin and fabric texture.
Hall shots from the same body and session (no LED wall in frame) render fine.
Columns: main (84b296e) | with saturated pixels left out of the tone fit (experiment below) | camera JPEG. Rows: frame A, frame B (faces cropped).
A synthetic repro that needs no private photos, the experimental patch and open questions for maintainers are in this comment.
Version and repro
- Still present on
mainat 84b296e (first seen on 0.22.0, e4b6735; also on 543b94a). Camera look: refuse a fitted matrix led by another channel (#3973) #3992 does not change it. - Linux (Mint 22.3), built from source. Default settings, WB As Shot, profile Color.
lightcraft-cli render DSC_2782.NEF -o out.png --size 1072, cleanHOME, no sidecar: same result. Same on GPU (GTX 1080 Ti) andLIGHTCRAFT_GPU=0.- Raw values on the face are far from clipping (max 881 of 4095).
Cause
The per-photo tone curve is fitted by quantile matching of scene luminance to JPEG luminance over all training pixels. That assumes the JPEG's luminance depends on scene luminance alone. It doesn't for saturated colours: the camera renders the red LED wall much brighter than skin or hair of the same scene luminance. Quantile matching sorts the two populations apart and joins them with a steep step followed by a plateau (the curves in the first version of this issue: elasticity ~3.6 over 5–8 knots, then 0.1–0.2 over more than 1 EV of mid-tones). Hair falls on the step, skin and fabric on the plateau.
The mechanism is the one #1904 describes (two pixel populations rendered at different brightness for the same scene luminance), but limit_elasticity can't catch it here: no single segment is over the bound, and smoothing the step leaves the plateau.
Measurements
Metric: gradient spread (p99/p50 of the log-luminance gradient) in a hair + skin box, render at --size 1072. Posterisation pushes it up. A dcraw reference scores 3.9 / 4.8 and the camera JPEG 5.0 / 5.2.
Experiment (on main 84b296e) |
Frame A | Frame B |
|---|---|---|
main |
21.4 | 15.3 |
| plateaus lifted to a minimum elasticity of 0.35 | 16.4 | 12.1 |
| last segment's elasticity capped at 1.0–1.5 (the extrapolation) | 21.4 | 15.6–15.8 |
| fitted colour matrix refused | 21.4 | 18.8 |
conditional-median tone fit (fit_tone_conditional) instead of quantile |
3.8 | 13.7 |
JPEG pixels with saturation > 0.9 left out of the tone training (fit_tone_with_shadows, both the original and the shadow pairs) |
5.7 | 4.9 |
Thresholds from 0.6 to 0.9 all give 3.8–5.9. A synthetic test (neutral subject on a known camera curve, 40% of the frame a red wall whose sensor RGB is [1, 0.25, 0.2] and JPEG [1, 0.03, 0.03] at 1.6× the subject's brightness) reproduces it: main puts subject tones off the camera curve by 0.084 in display gamma (≈ 21 levels of 255).
Side effect, from 47 NEFs (16 from this event, 31 D90 frames from other shoots): 23 render identically, the non-stage ones change by at most 0.5/255. Five stage frames change visibly, all through the LED wall: it renders darker and a deeper red than in the camera JPEG, because the brightness the camera gave it is no longer learned anywhere.
Possible fix
Leaving saturated pixels out of the tone fit fixes the posterisation, but as a hard cutoff it drops the wall's extra brightness. A more complete fix would fit the tone curve on near-neutral pixels and let the colour model carry the hue-dependent brightness, so the subject's curve stays clean and the wall keeps the camera JPEG's brightness. Today the colour model can't: HueSat changes hue and saturation only and restores luminance ("the camera tone curve owns it"). DCP profiles separate the two this way, with a single tone curve plus per-hue value scales in their HueSatMap/LookTable; doing the same here would mean giving the table a luminance gain per hue and saturation.
Related
- Posterization in NEF files. #1904 (closed): posterisation in NEFs, steep tone segments.
- Camera look: the conditional-median fallback learns a camera JPEG that is darker at the frame's edges as a flat tone curve, and posterises unedited ILCE-7M3 frames #3619, Camera look: the quantile tone fit also absorbs the camera JPEG's darker edges, and compresses the mid-tones of the rest of the ILCE-7M3 burst #3631 (open): quantile / conditional-median tone fits that compress mid-tones on Sony frames, from a different cause (darker JPEG edges).
Sample
The frames show people at a private event, so I won't post them publicly. I can send one or two NEFs privately to a maintainer.
Activity
Amarows commentedon Dec 1, 2026
Updated the description with a corrected root cause: the step and plateau come from the saturated LED wall taking part in the quantile tone fit, not from a gap in
limit_elasticity. Leaving JPEG pixels with saturation > 0.9 out of the tone training brings both frames to the camera JPEG's level (measurements and side effects in the description). A before/after image follows.Amarows commentedon Dec 1, 2026
Before/after and a synthetic repro – handing this over
I've taken this as far as I can as a reporter. Below: what the experimental change does on the real frames, a synthetic repro that needs none of my photos, the patch, and questions where I need your judgement.
Real frames (faces cropped)
Columns:
main(84b296e) | experimental patch below | camera JPEG embedded in the NEF. Rows: frame A, frame B.On
main, skin is a flat fill with a hard edge (A) or a contoured highlight (B), and hair breaks into black specks. With the patch both look like the camera JPEG in texture. The LED wall comes out darker and a deeper red than in the JPEG (see the trade-off below).Synthetic repro (no private photos)
A 960×640 stage: a textured "head" (skin + dark hair) in front of a red LED wall. Sensor RGB of the wall
[1, 0.25, 0.2], its JPEG[1, 0.03, 0.03]at 1.6× the subject's brightness for the same scene luminance; the subject follows a known camera curve. The tone curve is fitted withcollect_pairs+fit_tone_with_shadowson a 96×64 box-averaged proxy, then applied to the full frame. To isolate the tone curve, colour is taken from the JPEG and only brightness comes from the fitted curve.Columns:
main| patch | camera JPEG.On
mainthe hair's texture is flattened and lifted to grey (it lands on the plateau); with the patch it matches the JPEG, and the wall is darker than in the JPEG.Unit test that fails on
main(subject tones off the camera curve by 0.084 in display gamma) and passes with the patch:Test (crates/engine/src/camera_preview/tests.rs)
Experimental patch
JPEG pixels with HSV saturation above 0.9 are left out of the tone training, in both pair sets of
fit_tone_with_shadows. The held-out split is kept: the index still advances for a skipped pixel.Diff (crates/engine/src/camera_preview/pairs.rs)
Checks:
cargo fmtand clippy clean; 114/114camera_previewtests pass; full engine suite 2029/2030. The one failure,smart_previews_from_an_older_look_fit_are_refreshed("lens database changed while decoding the smart preview"), passes when run alone, 3/3 on bothmainand the patch. It looks like a race under the parallel suite.Effect on 47 D90 NEFs (16 from this event, 31 from other shoots): 23 render identically, non-stage frames change by at most 0.5/255, five stage frames change visibly, all through the LED wall.
Questions
HueSatrestores luminance ("the camera tone curve owns it").HueSat::apply, pooled profiles andLOOK_VERSION.fit_tone_conditionaland the pooled tone ofcalibrate(fit_profile_tone): a camera profile pooled from stage photos would learn the same step.Amarows commentedon Dec 1, 2026
@radialmonster, since you worked on #1904 (same two-population mechanism in NEFs), could you take a look at the questions in the comment above when you have time? @r3d42-git, cc as you've been working in camera_preview recently. I'm happy to test builds against these frames.
r3d42-git commentedon Dec 1, 2026
@Amarows, thanks for tracing this to the LED wall and sharing the patch and regression test. PR #4975 is ready for review. The GitHub checks passed and CodeRabbit completed its review.
The PR keeps the existing tone curve if too few midtones remain or if the filtered curve gives no measurable improvement on held-out subject pixels. In the 462-entry RAW corpus, three native renders changed. Two moved closer to the camera JPEG overall and the Canon R100 C-RAW moved slightly farther away.
Could you try commit
3aa75ce9fon your original D90 frames A and B at 1,072 px? It would help to know whether the hair and skin gradients recover on both and how bright the LED wall looks against the camera JPEG. The frames can stay private.If it's handy, you can build the PR in a separate worktree alongside your existing LightCraft checkout. From the root of that checkout, run:
With Cargo's default target directory, you can use
../lightcraft-pr4975/target/release/lightcraft-cliin your originalrender … --size 1072command for frames A and B.Amarows commentedon Dec 1, 2026
@r3d42-git, thanks for picking this up. I tested
3aa75ce9fon frames A and B, rendered withlightcraft-cli render … --size 1072, a cleanHOMEand no sidecar.Hair and skin recover on both frames. Gradient spread (p99/p50) in the hair + skin box (before vs patch, before vs Camera JPEG):

main84b296e3aa75ce9fOn both frames the filtered curve is selected. The log shows
filtered true, and the held-out subject error drops from 17.5 to 4.4 codes on A and from 9.5 to 3.3 on B. Both renders are pixel-identical to my experimental patch, so the before/after crops in my earlier comment also show this PR.The LED wall is darker than in the camera JPEG. Mean display luma (0–255) over the saturated-red wall pixels (JPEG saturation > 0.85, 22% of frame A, 30% of frame B):
mainThat's about 15–19 levels below the JPEG, about 0.5 stop in display terms. The wall still reads as a deep red stage backdrop, and I find that acceptable for these photos: the subject matters more than the wall.