Use coincident interpolation bounds at integer pixel centres so only contributing neighbours can propagate NaN. Clarify when a LensDB reload invalidates fitted Smart Previews.
Apply the measured database vignetting at sensor coordinates when an external warp is accepted. Carry aligned colour and tone samples into pooled calibration. Preserve the CR3 framing and Smart Preview source identity, and advance look and render cache versions.
Conflicts:
crates/engine/src/camera_preview.rs
crates/engine/src/camera_preview/look_fit.rs
crates/engine/src/media/source.rs
Ported: the camera_preview.rs and look_fit.rs imports keep both sides' names. LOOK_VERSION stays 26, as coordinated by @AlexChambers, with main's 14-18 history kept above it. RENDER_CACHE_VERSION becomes 87 rather than the reserved 83, because main has reached 86: going back to 83 would let the next bump (84) match old caches.
Conflicts:
crates/engine/src/media/source.rs
docs/parity-checklist.md
Delta since approval (2630748a..91620b0f: doc cites, panic! in a test, render-cache bump) reviewed. Conflict: RENDER_CACHE_VERSION goes to 86 (main is at 85, 83 reserved by #3943), documented in main's version list.
Switch unbinned RAW development onto craft-develop's develop_balanced_masked
(craft-libs#3042, already pinned by #4670). Bump RENDER_CACHE_VERSION to 84
and stamp smart previews with SOURCE_VERSION so raw proxies refresh once.
Fixes#1328.
Part of storytold/craft-libs#778.
Co-authored-by: Alex Chambers <[email protected]>
Co-authored-by: Dylan M. Taylor <[email protected]>
Exclude unsaved external vignette gains from non-CR3 DNG colour fitting while retaining correspondence geometry and the vignette carried by the file's own opcodes. Preserve file-local and pooled calibration.
Add causal procedural DNG coverage and retain the file-owned correction assertions in bounded test helpers. Clarify that the five-photo fixed-mount validation is historical and was not rerun on the synchronized source. Full cargo xtask ci passes with Rust 1.95.0, actual Metal and WASM; capability skips are separate.
Co-authored-by: Codex <[email protected]>
The sensor clip mask misses highlights the JPEG clips and the raw doesn't; their
JPEG brightness no longer follows the scene, so they skewed the measured share.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- LOOK_VERSION 26 and RENDER_CACHE_VERSION 83: open PRs already take
14/77 (#758, #3902), up to 25/82 (#1206).
- look_proxies: say why a CR3's framing is now estimated on the
uncorrected sensor, and that it came out the same as on the corrected
one on all 22 corpus CR3s with a database profile.
- camera-preview-colour.md: the 22 corpus CR3s this changes, measured
against their camera JPEGs.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review follow-ups for #3941:
- camera_vignetting_amount ranks luminance within classes of similar sensor
chromaticity (near-neutral and eight hue sectors), weighted by pixel count,
so a camera that renders some hues brighter, gathered toward the corners,
no longer reads as vignetting.
- A CR3 proxy moved to its JPEG's framing gets the vignetting gain of the
position each pixel shows (framed_proxies returns the framing).
- fit_dng_tone takes a lens database profile in the share the preview shows,
as the other raws' fits do; a file's own correction stays whole.
- Tests: hue classes, CR3 framing gains, the DNG share, a tinted fully
corrected JPEG with and without the profile, and an informative tiny image
for the too-few-pixels fallback.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes#3941
## Problem
With the downloaded lensfun database, raws whose look LightCraft fits to
their own camera JPEG (Sony ARW and the other makes without a colour matrix)
render too dark, with colour skewed, when lensfun has a vignetting profile
for their lens: in the loupe, the thumbnails and exports alike. Without the
database the same files match their camera JPEG more closely. On the 11
affected photos measured below, the bug darkened the render by 0.4 to 17 L*
(one unchanged); its colour shifts are scene-dependent, mostly a little lost
chroma. On the ILCE-7M3 / FE 28mm F2 photo from #3941 (f/2, the worst
case) the yellow CRT text turns orange and the frame 17 L* darker.
`git bisect` (rendering each commit with and without the lens database)
points to 001a58e9 "RAW.colour: fit the per-file look on the
vignetting-corrected sensor" (LOOK_VERSION 13). Since then every per-file
fit multiplies the sensor proxy by the whole embedded vignetting correction,
on the assumption that the camera JPEG has it applied. That holds for the
file's own data (Fujifilm maker notes, DNG opcodes), but
`lens_profiles::for_raw` hands the fit a lensfun profile the same way, and a
lens database describes the lens, not what this camera did to its JPEG
relative to the raw. The #3941 JPEG shows none of the profile's correction
relative to its raw, although its maker note says vignetting correction
Auto (as with the A7CR's shading Auto JPEGs in
docs/sony-lens-corrections.md). So the fit saw corners far brighter than
the JPEG's: its held-out RMS went from 0.027 (without lensfun) to 0.062,
accepted only on the "away from edges" retry, the tone curve darkened to
compensate and the colour matrix bent. How far depends on how much of the
profile the JPEG lacks and what the scene puts in the corners.
## Change
`look_proxies` (crates/engine/src/camera_preview/look_fit.rs) keeps the
whole correction for the file's own data (`LensSource::File`, unchanged).
For a `LensSource::Database` profile it measures the share of the
correction the camera JPEG shows (`camera_vignetting_amount`) and applies
that share to the sensor proxy, scaled as the Vignetting amount slider
scales it (`1 + (gain - 1) * amount`). The camera's tone curve is monotone,
so with the share the camera applied, the corrected sensor orders its pixels
by luminance as the JPEG does: of 0 to 100 % in 5 % steps, the share with
the highest rank correlation (`rank_correlation_ties`) wins. Clipped and
non-finite pixels are left out; with fewer than 256 usable pixels, or with a
lens warp on the proxy (which a file with a database profile doesn't have),
the whole correction is kept, as before.
LOOK_VERSION 14, RENDER_CACHE_VERSION 77. Docs: camera-preview-colour.md,
lens-profiles.md, raw-parity.md (with a revision row).
**Not in this PR:**
- The render still applies a lensfun profile's vignetting correction in full
while Enable Profile Corrections is on, so the #3941 photo's corners come
out much brighter than in its camera JPEG (lensfun: about 2.6 EV at the
extreme corner of this lens at f/2; the Vignetting amount slider lowers
it). If Sony applies part of its shading correction to the raw samples (an
open question in docs/sony-lens-corrections.md), that is a double
correction of its own; it needs flat-field measurements, and the ARW's
recorded shading setting and table (`0x7031`/`0x7032`) could then decide
it.
- Sony's DRO brightens the camera JPEG's shadows locally, which could bias
the measured share; CR3 proxies are measured in the oriented frame without
their small framing alignment.
## How it was checked
- [x] `cargo xtask ci` on this branch, rebased on current `main` (macOS
aarch64): fmt, clippy, heif, parity, layers, assets, roots and wasm pass;
the tests pass except two that fail identically on unchanged `main` on
this machine: `tests_light::v1_and_v2_render_as_before_v3` (#3788) and
`tests::titlebar::double_click_on_the_empty_bar_zooms_then_restores`.
The engine's corpus tests pass with the files above.
- [x] A test that fails without this change:
`a_lens_database_vignetting_reaches_the_fit_as_far_as_the_camera_jpeg_shows_it`
(synthetic ARW and camera JPEG, `grey_raw_with_jpeg`): with an uncorrected
JPEG the grey and the colour fit keep the curve fitted without the
profile, and with a fully corrected JPEG the whole correction applies.
Without the change it fails: the curve at 0.25 is 0.460 instead of the
camera's 0.528. Plus `camera_vignetting_amount_measures_the_share_the_jpeg_shows`
(0, 40 and 100 % measured within 5 %).
- [x] User-visible change: `lightcraft-cli snapshot` of the loupe and
`lightcraft-cli render`, with `LIGHTCRAFT_LENSFUN_DIR` set to the
downloaded database and to an empty folder; `LIGHTCRAFT_PROFILE=1` prints
the measured share.
Against the camera JPEG, with the downloaded lensfun database: the look
fit's held-out RMS, and the mean CIEDE2000 of the central half of the
render (profile distortion off so the two line up):
| Photo | share | RMS main → this | ΔE00 main → this |
|---|---|---|---|
| #3941: ILCE-7M3, FE 28mm F2, f/2 | 0 % | 0.0625 → 0.0268 | 7.47 → 5.11 |
| corpus: ILCE-9M2 | 0 % | 0.0452 → 0.0149 | 6.84 → 3.39 |
| corpus: ILCE-7RM2 | 45 % | 0.0561 → 0.0556 | 9.14 → 8.96 |
| corpus: SLT-A33 | 0 % | 0.0614 → 0.0341 | 4.70 → 4.82 |
| corpus: ILCE-7SM2 | 0 % | 0.0483 → 0.0449 | 5.29 → 5.28 |
| corpus: ZV-E10M2 | 0 % | 0.0413 → 0.0230 | 7.24 → 5.45 |
| corpus: DSC-RX1RM3 | 0 % | 0.0480 → 0.0396 | 3.91 → 2.90 |
| corpus: ILCE-6400 | 10 % | 0.0350 → 0.0322 | 3.38 → 2.80 |
| corpus: E-M5 Mark II | 30 % | 0.0185 → 0.0178 | 1.76 → 1.74 |
| corpus: PEN-F | 10 % | 0.0218 → 0.0219 | 1.69 → 1.66 |
| corpus: D780 | 35 % | 0.0287 → 0.0188 | 2.93 → 2.57 |
The corpus rows are the CC0 raw.pixls.us files `cargo xtask corpus
--download` pins: of 91 checked (all 37 ARWs, 19 ORFs, 15 PEFs, the first
20 NEFs), these 10 get a lens database vignetting profile into their fit;
the other 81 take the same code path as before. Corpus mean ΔE00 4.69 →
3.96: 6 better, 3 within 0.05, one 0.12 worse; held-out RMS lower on 9 of
10 (PEN-F +0.0001). Script: render each file with both builds under
`LIGHTCRAFT_PROFILE=1` (`--set optics.profileDistortion=0`), read the
measured share and the accepted fit's held-out RMS from stderr, and compare
the central half with the largest embedded JPEG.
## Merging
- **Overlap:** none found fixing #3941. Open pull requests that also touch
`camera_preview` and bump the shared numbers: #3587 and #2092 (also
`look_fit.rs`, other functions), #3902, #3635, #2188, #2854.
- **Existing edits and libraries:** photos with a lens database vignetting
profile get a new camera look (LOOK_VERSION 14) and render closer to their
camera JPEG; edits and settings are unchanged. A bug fix in the camera
colour a file gets, which changes the source, not how settings are
interpreted (docs/process-versions.md), as 001a58e9 landed.
- **Shared numbers taken:** LOOK_VERSION 14, RENDER_CACHE_VERSION 77.
- **Where it came from:** own measurements on the #3941 photo and the CC0
raw.pixls.us corpus (`cargo xtask corpus`); no lens or camera data added.
- **New dependencies, `unsafe`, build scripts, network access, spawned
processes, deleted files, CI or `xtask` gate changes:** none.
Merge current upstream main without rewriting the published branch. Keep
non-CR3 geometry and fixed-lens resolution, required pooled/DNG consistency and the
loaded-LensDB/Smart-preview producer provenance as an independent proposal.
The other feature PR is not a prerequisite or merge parent.
Restore current main for general UI/task runtime code, GPU equivalence tests
and Cull benchmark whitespace. Preserve geometry and source-identity gates.
Two bounded CI fixtures remain: stale V1/V2 golden constants aligned to exact
unmodified-main output, and decoded-source isolation before a Find Similar
retry. Main independently reproduced both failures. Assertions, signature
caches, expected counts, production UI and renderer remain unchanged.
Adapt the shared test-directory helper to main's new no-panic lint contract.
Final cargo xtask ci passes all nine gates with Rust1.95.0, actual Metal and
WebAssembly. Tested, staged and committed trees match. Capability skips are
recorded separately. No current real-photo acceptance or product install.
Co-authored-by: Codex <[email protected]>
Merge upstream main 89725652 without rewriting published history.
Retain imported camera-profile loader contracts and fresh-original smart
preview provenance, including the existing offline-original guard.
Reconcile independently assigned render75 as combined render76/look14.
Preserve upstream history and external-profile proposal scope. Adapt
upstream GPU and pipeline fixtures to bounded output dithering without
changing rendering code or weakening colour/equivalence bounds. Confirm
new V1/V2 golden hashes independently on exact main; the old quantizer
reproduces the historical hashes. Isolate resumed Find Similar signature
reuse from incidental UI decoded-source caches.
Full macOS CI passes all eight gates with Rust 1.95.0, Metal and WASM.
Co-authored-by: Codex <[email protected]>
Merge upstream main ae7ac42a without rewriting published history.
Preserve upstream lens download/refresh, optional crop and mask geometry.
Resolve lens documentation limits without dropping the feature scope.
Follow loaded Arc snapshots in lens/camera cache identities; hash optional
crop values without assuming full frame. Build smart previews from fresh
originals with captured database provenance, reject reloads during decoding,
and never mark a replacement database checked by an earlier scan.
Cover reload/replacement, stale/damaged/missing proxies and cached-source
bypass in isolated synthetic regressions. Make the older offline fixture
loader reject a missing original, matching the production loader. Advance combined render cache
to 75 against upstream 74; camera-look version remains 14.
Co-authored-by: Codex <[email protected]>
Merge upstream main b4757824b without rewriting the published PR history.
Resolve docs/gaps.md by retaining upstream documentation and the bounded
external-profile geometry proposal. Preserve automatic upstream code changes.
Advance the combined render cache version to 74 because both branches had
independently used 73; camera-look version remains 14. Update its documentation.
Co-authored-by: Codex <[email protected]>
* CRW-LIB: decode Canon CRW through the shared craft-crw crate
LightCraft decodes Canon CRW (the CIFF raws of the EOS D30, D60, 10D, 300D and the
PowerShot G1/G6) through craft-libs' `craft-crw`, the clean-room decoder derived and
verified on the `clean-room-crw-format-decode` branch and moved there with its frozen
tables and derivation record. `crates/raw/src/vendor/crw.rs` is now the adapter: it maps
the crate's header and samples onto `RawImage` (CFA, levels, active area, orientation,
as-shot white balance, the make/model/time records a CRW keeps instead of Exif) and
converts the capture time through chrono. The dependency is a local path
(`../craft-libs/crates/crw`) until the craft-libs branch merges; then it becomes a git
revision.
Everything LightCraft-side from that branch comes along unchanged: `probe_bytes` fills
metadata gaps from the decoder's records so CRW imports name their camera; the EOS D60
bundled camera profile and its chart-measured dual-illuminant matrices (`chart_table.rs`,
`spectral::Camera` carries its illuminant pair) give the D60 a Kelvin white-balance scale;
CRW joins the JPEG-fitted starting look, the catalog's raw formats and `lightcraft-cli
calibrate`; `RENDER_CACHE_VERSION` 71; the CC0 CRW corpus entries for `cargo xtask corpus`;
coverage, parity, gaps, raw-parity, target-app-parity and ROADMAP updates. The G5 stays
preview-only (the crate refuses it with the reason) and the robustness test keeps its CRW
sample.
What does not come along: the decoder, its tables and `crw_oracle.rs` (now craft-crw's
digest-pinned sample test) and the derivation record, which lives in craft-libs
`crates/crw/clean-room/`. `clean-room/crw/` here keeps only the EOS D60 chart-calibration
document and its capture list, with a README pointing at the record.
Gates: fmt, clippy -D warnings (raw all targets; engine, catalog, cli), lightcraft-raw tests
(475 + 134, the corpus files decoding through the adapter), catalog tests, engine lib tests
(1,300 pass; the two failures, `tests_import::recursive_discovery_…` and
`originals::tests::write_targets_pin_absent_paths_…`, are in files unchanged from main),
`cargo xtask parity`, `assets`, `layers`, `coverage.py --check`.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
* no message
* no message
* Update documentation after moving code to craft-libs
* Review coment fixes
* CRW: pin craft-crw f3b62ec, a truncated entropy stream is Corrupt
craft-libs #472 makes craft_crw::decode refuse a stream that ends more than
Limits::max_stream_end_fill (64 samples, one block) before the frame does,
instead of filling the rest with predictor values and returning success.
The adapter already maps craft_crw::Error::Corrupt to RawError::Corrupt;
a regression test proves a truncated CRW now fails at this boundary (it
decoded as a flat frame on the old pin) while its header still reads.
Only craft-crw moves; craft-ui/docpath/update/window stay on c5a1cbf.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* Code review comment fix
* Add some tests
---------
Co-authored-by: Robert Woldberg <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
Resolve file corrections before DNG and merge colour fitting removes lens opcodes. Include the loaded lens database identity in camera render keys and smart-preview staleness/scan markers. Cover real lookup wiring, file-warp precedence, cache transitions, finite support and clipped masks; retain geometry gates and newer/offline proxy handling.
Validated with focused regressions and full cargo xtask ci (8/8, Rust 1.95.0, Apple M5 Max Metal and WASM). DNG/merge regressions fail against the previous ordering. Synthetic headless demo smoke passed; historical photo comparisons were not rerun.
Co-authored-by: Codex <[email protected]>
Compare original and profile proposal on shared valid edges during search and held-out validation. Keep thresholds, bounded search and existing CR3 framing behavior.
Co-authored-by: Codex <[email protected]>
Merge upstream main at 496524ced5 without rewriting published history. Preserve current upstream fixes and retain only the independent feature change in the resulting PR diff.
Co-authored-by: Codex <[email protected]>
Conflicts: crates/engine/src/camera_preview.rs: LOOK_VERSION stays 13, all three version notes kept; docs/raw-parity.md header merged (newer date, both changes)
Review follow-up to the vignetting fit fix:
- `proxies` applies the embedded vignetting gain before it moves the sensor
into the camera JPEG's lens geometry, so a warped proxy pixel gets the gain
of the position it samples, as the render applies it.
- `alignment` reads NaN pixels (outside a lens-warped proxy) as missing. The
`max(1e-4)` turned them into black, a false edge along the border, and the
warped candidate lost on wide-angle RAFs with barrel distortion.
- Tests: the colour fit gets the embedded lens, the vignetting is applied
before the warp, and alignment ignores missing pixels.
27 + 60 X-S10 RAFs: mean ΔE00 unchanged (3.06, 2.55 -> 2.54), none worse by
more than 0.02.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The RAF look fit compared the uncorrected sensor proxy with the camera
JPEG, which is already corrected for vignetting, so the tone curve learned
the brightening and the render then applied the embedded vignetting
correction a second time. Shadows and midtones came out up to 0.6 / 0.3 EV
too light on X-S10 files.
`look_proxies` applies the embedded correction to the sensor proxy of
every per-file fit (colour, monochrome, near-black fallback), as
`fit_dng_tone` already did. LOOK_VERSION 13, RENDER_CACHE_VERSION 71.
60 held-out X-S10 RAFs: mean ΔE00 2.71 -> 2.55, 32 better, none worse by
more than 0.05.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- X-S20 lens distortion and vignetting scale fixes
- X-S20 / X-S10 / X-M5 spectral sensor mappings
- Add Samuel Li to contributors/people.toml
Co-Authored-By: Antigravity <[email protected]>
- address review concerns
- update RENDER_CACHE_VERSION value in docs/camera-preview-colour.md
- made sure diagonal scales are exact match
X-T20, X-T2, X-Pro2, X-E3, X-H1 and X100F have no measured colour matrix, so
As Shot showed on the relative scale. Their RAFs store the camera's own
neutral multipliers for Illuminant A and D65 (tag 0xf00c). Two points
give a line in (ln R/G, ln B/G); mired is linear along it, isotherms are
perpendicular, tint is scaled by the CIE locus spacing. Only the file's pair
and CIE colorimetry are used. Bodies with matrices are unchanged. The look
stays the per-file JPEG fit.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014ti8KemZbjE2ZgHgV1q1BM
Retain upstream module extractions and move calibration changes into their current owners. Advance render cache 70 to 71 and include the same explicit CI prerequisite as PR3136.
Co-authored-by: OpenAI Codex <[email protected]>
Use resolved lens geometry and independently gated framing alignment for RAW/camera-JPEG calibration pairs, including pooled calibration and DNG color tags. Resolve unnamed fixed-lens profiles only through a unique exact fixed mount. Invalidate cached looks and previews.
Add synthetic geometry, mask, orientation and fixed-mount regressions. Validate actual RAW renders against the previously tested fix, and run all eight cargo xtask ci gates on the separate Clippy prerequisite.
docs/parity-checklist.md: header keeps the newer date; LR-IMP-FORMATS row keeps both sides' changes.
docs/raw-parity.md: header change note names both sides' changes.
docs/raw/coverage.tsv: merged cleanly; same rows as both sides, no duplicates (regenerated on the combined branch).
crates/engine/src/camera_preview.rs: LOOK_VERSION keeps both history lines and the higher value.
crates/engine/src/media.rs: RENDER_CACHE_VERSION keeps the higher value.
crates/engine/src/camera_preview.rs: LOOK_VERSION keeps the higher value; fit_tone_only_pairs (from #1616) takes the HighlightCheck of #699 from fit_tone_only_on, and fit_dark_tone passes its frame's (empty, as no JPEG pixel reaches 0.85) check.
crates/engine/src/media.rs: RENDER_CACHE_VERSION keeps the higher value.
docs/parity-checklist.md: LR-PROF-CAMERACOLOR row keeps both sides' changes.
crates/engine/src/camera_preview.rs: LOOK_VERSION keeps both history lines and the higher value.
crates/engine/src/media.rs: RENDER_CACHE_VERSION keeps the higher value.
To make room for the pooled extension in the curve's 32 knots, extend_tone kept every
n-th knot of the photo's own curve, which could move the curve inside the range its JPEG
showed (a sharp toe most). It now drops the knots the curve needs least, one at a time,
within one 8-bit code (thinned_knots); with fewer extension knots if needed, or the
photo's curve as fitted when even two don't fit. On a D750 bracket renders move by at
most dE 0.09. LOOK_VERSION 13. Found by CodeRabbit on #2093.
profile_samples returned nothing when collect_pairs found no colour pairs, so the darkest
photos, the ones that show the camera's toe, never reached the pooled tone curve. Their
tone samples are now kept; Pool counts them apart from the colour fit's photos and
calibrate reports them as tone only. A black-and-white camera JPEG (a monochrome picture
style's own mix and curve) gives nothing, as before. Found by CodeRabbit on #2093.
The pooled curve maps luminance through the profile's matrix. A photo whose own fit
rejected the profile's colour renders through its own matrix, so continuing its curve
along the pooled one gave it a highlight mapping fitted to other colours. Such a look now
keeps its curve as fitted (with_pooled_tone). LOOK_VERSION 12. Found by CodeRabbit on #2093.
lightcraft-cli calibrate also pools tone samples (camera RGB -> camera JPEG
luminance, dark pixels included) and fits one curve per camera by quantile
matching; profiles store it as an optional `tone` field (older profiles and
builds still load). A photo keeps its own curve as far as its JPEG showed it and
follows the pooled curve past that, faded over 1 EV (extend_tone), instead of
the bounded shoulder that rendered underexposed photos pushed back up 4-7 L*
too dark; a photo no look fits takes the pooled curve whole.
On NIKON D780 brackets, pushed frames now match the properly exposed frame
within 0.5 L*; on 120 held-out D780/D750/D90 photos rendered as shot the curve
changes mean dE against the camera JPEG by at most 0.03.
LOOK_VERSION 11.