Repository navigation
Description
Summary
Three unedited ILCE-7M3 ARWs (lossy compressed, ISO 800, FE 55 mm F1.8 ZA at f/1.8, tungsten light, DRO on, a subject on a white sheet that fills half the frame) render posterised on 0.17.0 and on main (ebe2477). The sheet is a flat grey that never reaches white, with contour bands and a dark ring around the subject, and a pale cream pacifier turns into an orange blob.
The cause is the per-file camera look (crates/engine/src/camera_preview/). On these frames, the camera JPEG is about 1.4 EV darker than the raw at the frame's long edges than in its middle, and the sheet is brightest in the raw at those edges. So above scene luminance 0.21, the JPEG's median per scene bin falls as the scene gets brighter.
- The quantile fit (LR-PROF-CAMERACOLOR: fit the starting tone curve by quantile matching (no flat steps), old fit as fallback #499) misses the gates by 0.02–0.05.
- The conditional-median fallback (
fit_tone_conditional) passes them. Its isotonic pooling turns the falling medians into a curve that holds knots 12–31 (1.2 stops of scene) at one level and knots 3–8 (0.5 stops) at another.
#499 already recorded this case as a known gap: "A follow-up could remove the steps from the fallback curve". No issue was ever filed for it.
Proposed fix: refuse a conditional-median curve when one pooled block covers more than half a stop of the scene. On the 431 pinned raw.pixls.us files it changes one render (an Olympus E-10 sample whose fallback curve is posterised as well) and leaves the other 430 byte-identical. #3618 has the test and the fix.
Reproduction without the private frames
The frames are family photos and can't be shared. The mechanism reproduces on a synthetic 96×64 proxy (edge_brightened_sheet in camera_preview/tests.rs on the branch):
- A sheet whose sensor luminance rises from 0.18 in the middle to 0.41 at the corners, around a darker subject.
- A camera JPEG that is the known matrix and curve of the other tests, darkened by 2.3 EV toward the corners.
On main the quantile look misses MIN_IMPROVEMENT at 0.737 (held-out RMS 0.096, under MAX_HOLDOUT_RMS), and the conditional-median look is accepted at 0.052 with knots 6–31 at one level. That is the same pattern as the real frames.
On the real frames (LIGHTCRAFT_PROFILE=1 lightcraft-cli render DSC08512.ARW -o x.png, with LIGHTCRAFT_CAMERA_PROFILES pointing at an empty folder):
| Frame | Quantile, all pixels: RMS (ratio) | Quantile, away from edges: RMS (ratio) | Conditional median, accepted: RMS | Flat runs of the accepted curve (knots, stops) |
|---|---|---|---|---|
| DSC08511 | 0.1027 (0.72, RMS > 0.10) | 0.1029 (0.70, RMS > 0.10) | 0.0775 | 3–8 (0.55), 11–31 (1.33) |
| DSC08512 | 0.0982 (0.745) | 0.0995 (0.726) | 0.0751 | 3–8 (0.53), 12–31 (1.19) |
| DSC08514 | 0.0888 (0.747) | 0.0911 (0.751) | 0.0710 | 4–10 (0.64), 14–31 (1.01) |
| DSC08510/13/15/16 (control, same session) | accepted at 0.52–0.69 | – | – | none |
The control frames go through the same spatial mismatch (below), but there the quantile look clears the gate.
Why the pooling comes out flat (DSC08512)
I dumped the 6,144 proxy pairs that go into the fit (scene luminance through the fitted matrix, against JPEG luminance) and tested four hypotheses.
| Hypothesis | Verdict | Evidence |
|---|---|---|
(a) Truncation bias from leaving out JPEG luminance ≥ 0.85 (collect_pairs, fit_tone_with_shadows) |
No | No proxy pixel reaches 0.85: the JPEG's maximum is 0.47 (0.49 and 0.45 on the other two frames), so the filter removes nothing. |
| (c) Vignetting or geometry between the sensor proxy and the JPEG | Yes, as a spatial term. No correction comes from LightCraft's side. | Relative to the raw, the JPEG falls about 1.4 EV from the middle to the long edges (table below). The proxy gets no vignetting correction here: lensfun has no match (identical results with and without LIGHTCRAFT_LENSFUN_DIR), and the ILCE-7M3's Sony shading table isn't applied (docs/sony-lens-corrections.md). The file has Shading Comp Auto, Distortion Comp Auto and DRO on. |
| (b) Sony's DRO (local tone) in the camera JPEG | Can't be separated from (c) with these frames | DRO is on in all seven frames. The pattern is about the same on frames with different content (DSC08510, DSC08513), which points to a fixed spatial term more than a content-dependent operator. Untested. |
| (d) The sheet is nearly uniform in the JPEG | Yes, as a consequence of (b)/(c) | In the bins the pooling flattens, the scene spans 0.18–0.41 (1.2 stops) and the JPEG medians span 0.30–0.41. |
log2(JPEG / scene) by distance from the centre (r/rmax), within scene-luminance bands. DSC08512, 96×64 proxy, median (pixel count):
| r/rmax | scene 0.05–0.09 | 0.09–0.14 | 0.14–0.20 | 0.20–0.26 | 0.26–0.50 |
|---|---|---|---|---|---|
| 0.0–0.2 | +1.09 (288) | +1.29 (27) | |||
| 0.2–0.4 | +0.92 (363) | +0.96 (160) | +1.15 (426) | +1.05 (215) | |
| 0.4–0.6 | +0.33 (168) | +0.45 (357) | +0.70 (132) | +0.79 (1020) | +0.64 (257) |
| 0.6–0.8 | −0.47 (81) | −0.18 (301) | −0.17 (151) | +0.20 (431) | +0.20 (756) |
| 0.8–1.0 | −0.82 (55) | −0.59 (65) | −0.36 (95) | −0.37 (600) |
The conditional-median bins (32 equal-population bins of the 4,093 training pairs) show what that does to the fit:
| Knot | Scene median | JPEG median | After pooling | Median r/rmax |
|---|---|---|---|---|
| 3 | 0.077 | 0.141 | 0.141 | 0.29 |
| 5 | 0.088 | 0.155 | 0.141 | 0.35 |
| 8 | 0.111 | 0.122 | 0.141 | 0.61 |
| 9 | 0.126 | 0.121 | 0.141 | 0.66 |
| 11 | 0.164 | 0.328 | 0.328 | 0.38 |
| 15 | 0.210 | 0.408 | 0.361 | 0.42 |
| 21 | 0.243 | 0.329 | 0.361 | 0.62 |
| 28 | 0.323 | 0.305 | 0.361 | 0.77 |
| 31 | 0.409 | 0.304 | 0.361 | 0.90 |
The brightest scene bins are the frame's edges, which the JPEG renders darker. Both flat runs are bins whose pixels move outward as the scene gets brighter. On held-out pixels the fallback beats the quantile curve by a wide margin (RMS 0.075 against 0.098), because it follows that spatial difference. That is why it passes the gates.
Why the gates let it through
MIN_IMPROVEMENT(0.7) is a ratio against the neutral fallback, which is also far from this JPEG. Quantile matching reaches 0.72–0.75. The conditional median reaches 0.41–0.48, because it fits the spatial term.highlights_holdonly checks curves narrower thanNARROW_TONE_RANGE(1.5); these span 9–11×. It would not catch these frames even if it ran on every curve: it compares pixels with JPEG luminance ≥ 0.85, and these frames have none (checked by forcing it on conditional-median curves: "highlight check on 0 pixels", nothing changes).limit_elasticity(LR-PROF-CAMERACOLOR: limit tone-curve steps between pixel populations (#1904) #2656) bounds steep segments only. Nothing bounds flat ones.
Fixes compared
All renders are full-size PNGs from main plus the change. The patch is my sheet patch (x 2700–3200, y 700–1200 of the 4000×6000 portrait render, G channel, 8-bit). CIEDE2000 is against the embedded camera JPEG, over 200×300 cells. Corpus counts are over the 431 pinned raw.pixls.us files that go through the per-file fit (cargo xtask corpus --download, every sha256 checked).
| Variant | DSC08512 ends up with | Sheet patch: G levels | Identical neighbours | dE00 mean (sheet) | Corpus renders changed |
|---|---|---|---|---|---|
main |
conditional median, flat 3–8 and 12–31 | 10 | 59.5 % | 5.41 (3.09) | – |
| 1. Refuse a pooled block over 0.5 stops | no full look; the partial look misses the gate at 0.745 → ILCE-7M3 spectral matrices | 27 | 29.8 % | 8.28 (5.89) | 1 of 431 (Olympus E-10) |
| 1 + #3587 | the same: the partial look with measured colour misses at 0.747. (DSC08511 passes away from edges at 0.695 and gets it: 18 levels, 46 %.) | 27 | 29.8 % | 8.28 (5.89) | not run |
2. highlights_hold on every conditional-median curve |
unchanged (no pixels ≥ 0.85) | 10 | 59.5 % | 5.41 | 0 of 242 tried |
3. Minimum elasticity 0.25, windowed like limit_elasticity |
conditional median without flat runs; the top rises at 0.25 | 12 | 56.4 % | 5.98 (4.65) | 9 of 242 tried, all within ±0.04 dE00 |
| Control DSC08510 (quantile look accepted) | – | 18 | 52.5 % | – | – |
Fix 3 removes the exact flats but keeps the curve that learned the spatial term: the sheet stays nearly flat, and the pacifier stays orange, because that comes from the look's colour, not its tone. Fix 1 drops the look, and the frames render the way the same model does without a camera JPEG (an ARW copy with its embedded JPEGs zeroed: no banding, smooth skin, more pink than Lightroom). That render is darker and cooler than the camera JPEG, hence the higher dE00 against it, but it no longer posterises.
For reference, measured on JPEG exports, so not directly comparable with the PNG numbers above: Lightroom's export of this frame has 34 levels and 13 % identical neighbours, and LightCraft on Adobe's DNG without a preview has 32 levels and 20 %.
Corpus
I rendered the 431 pinned raw.pixls.us files that take the per-file fit (cargo xtask corpus --download, sha256-checked) at 1600 px, with LIGHTCRAFT_PROFILE=1 and an empty LIGHTCRAFT_CAMERA_PROFILES.
| Files | |
|---|---|
| Quantile look accepted | 340 (+47 DNG tone fits) |
| Reach the conditional-median fallback | 3 |
| Accept it today | 2 |
| Of those, with a flat run of more than 2 knots | 2 (G7 X Mark III: one run of 0.14 stops; E-10: six runs, the widest 1.81 stops over knots 0–2 and 0.96 stops over knots 4–9) |
| Partial look / spectral matrices / neutral fallback | 7 / 4 / 30 |
With fix 1, one render changes. The Olympus E-10's base render is posterised the same way: its background is painted flat patches with hard edges, and its toe is pooled over 1.8 stops. Its partial look misses the gate and the body has no spectral matrices, so it falls to the neutral fallback, which is smooth but much duller: CIEDE2000 to the camera JPEG 13.87 → 18.67, mean ΔC* +1.1 → −21.8. The G7 X Mark III keeps its look. The other 429 renders are byte-identical; two GFX 100S files differed in the first sweep only because the GPU ran out of memory and they were rendered on the CPU, and re-rendered alone they are identical.
The archive count in docs/camera-preview-colour.md (7 of 1,781 files accept the fallback, 6 with flat segments, 35 in total) is for the whole raw.pixls.us archive. I only have the 431 pinned files, so the other 5 aren't measured here: those would be the ones to check before merging.
Not covered here
- The spatial difference itself (Sony shading compensation and/or DRO in the camera JPEG). A global matrix and curve can't follow it. Fitting on the middle of the frame only, or a radial term, would be a separate change.
- The DNG path. Adobe DNG Converter's DNG with a full-size preview (
-p2) getsDNGTONE accepted, and its chroma curve (up to 1.55× in the darker tones) mottles the skin. With-p0the fit is refused and the render is smooth, about 1.2 EV darker. That is a different gate.
Related
- LR-PROF-CAMERACOLOR: fit the starting tone curve by quantile matching (no flat steps), old fit as fallback #499: introduced the quantile-first order and this fallback, and noted the gap.
- Nikon Z 6_2 NEF (14-bit lossless): default render turns fine texture into flat, hard-edged "painted" patches at 100% (camera JPEG stays smooth) #475: flat steps from the old fit. Posterization in NEF files. #1904 / LR-PROF-CAMERACOLOR: limit tone-curve steps between pixel populations (#1904) #2656: the steep-step counterpart (
limit_elasticity). - LR-PROF-CAMERACOLOR: smooth fitted tone curves; DRO lowering follows Sony's curve between knots #2188 (open): smooths fitted curves. Its mirrored blur keeps the last knot, so the flat top stays (only its corner rounds), and it adds no gate.
- LR-PROF-CAMERACOLOR-CHOICE: Calibrated camera colour, a per-photo choice of a raw's starting colour #2222 (open): opt-in "Calibrated camera colour". It avoids this frame per photo; the default is unchanged.
- LR-PROF-CAMERACOLOR: night and LED raws no longer open washed out when the camera-JPEG match fails #3587 (open): changes
fit_partialonly. With the conditional-median look accepted,fit_partialis never reached. With fix 1 it is, but DSC08512 still misses its gate. - LR-EDIT-OPTICS-PROFILE: enable Sony ILCE-7M3 embedded distortion correction (rebase of #1384) #3144 (open): ILCE-7M3 embedded distortion. It might bring the quantile ratio under 0.7 by aligning the pairs better; it does nothing to the fallback curve.
- Sony A7 (ILCE-7) ARWs render posterized with a cold colour cast at default settings #454, LightCraft v0.7.1 - Sony A7IV - Raw - Colors washed out and odd color transitions/pixelation #1369, Ricoh GR IIIx DNG renders with harsh, blotchy tonal transitions compared to Lightroom Classic #3458: posterised or blotchy transitions on other bodies (ILCE-7, A7 IV, GR IIIx DNG); each is worth a
LIGHTCRAFT_PROFILEcheck for this pattern. - # Profile generated by
lightcraftCLI crushes colour on tungsten-lit frames #3602: tungsten Sony frames greyed by acalibrateprofile. That is a different path; this one reproduces with no camera profile.
I can run any diagnostic build against the three frames and the four control frames of the same burst.
Activity
ticket-craft commentedon Nov 2, 2026
Possibly related: #454, #475 and #631.
alexdrl commentedon Nov 2, 2026
Follow-up: the other four frames of the same burst accept the quantile look and compress the same sheet; tracked in #3631.