Main split the app's main.rs, the engine and ui-egui tests and the frame loop into modules; the lens-database hunks now live in apps/lightcraft/src/session.rs, crates/ui-egui/src/app/frame.rs and crates/engine/src/tests/lens_refresh.rs. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5.2 KiB
Lens profiles from a lens database
Raws that carry no lens correction of their own (DNG OpcodeList3, or a camera correction a raw reader converts,
see sony-lens-corrections.md and nikon-lens-corrections.md) are corrected from a lens database in the lensfun
XML format. The app does not ship any lens database: lensfun's data is licensed CC BY-SA 3.0 and is downloaded at
run time, never bundled and never committed. Adobe LCP profiles are never used.
Setup: none
- On first run the desktop app downloads lensfun's
data/db(56 XML files, about 5 MB) into its data folder (<config dir>/lensfun, beside the face and denoise models; seecrates/engine/src/config.rs), with a row in the activity stack (its ✕ stops it; the next start resumes). The files are pinned to one lensfun commit by name, size and SHA-256 (crates/engine/src/lensfun_download.rs); a file that differs is thrown away. A later build with a newer pin replaces them once.SOURCE.txtin the folder names the commit and the licence. - By default the files come from lensfun's GitHub repository at the pinned commit.
LIGHTCRAFT_LENSFUN_URLlists other places serving the same files (base URLs, tried first), e.g. a copy on LightCraft's own server. LIGHTCRAFT_LENSFUN_DIRpoints at a database of your own instead (lensfun'sdata/db, or a Linux distribution's/usr/share/lensfun/version_1/); then nothing is downloaded.
When the database arrives (or changes), every library raw without a profile whose lens it knows is read again in the
background and gets its profile; a photo still as imported gets the correction switched on, as import would, and an
edited one keeps its settings. Ticking Enable Lens Corrections on a photo without a profile looks it up again
too. library.refreshLensProfiles, lens.downloadDatabase and lens.databaseStatus do the same for agents.
The Optics panel says which profile is loaded: "Profile: from the file", "Profile: (lens database)", or
"No lens profile found for ". A profile is never copied between photos: presets, Copy / Paste, Sync and Auto
Sync carry Enable Lens Corrections and its amounts, and each photo keeps the profile of its own lens
(crates/engine/src/tests/lens_refresh.rs).
Files are read once per folder and again after a download. Invalid files are skipped with a warning in the log.
What is applied
The lens is identified from EXIF: camera make / model (for the mount and crop factor; the 35 mm equivalent focal length is used when the camera isn't listed) and the lens model string. Lens names match on their words; every number (focal lengths, apertures) in the database name must appear in the EXIF name, and the lens maker must agree when the file names one.
Some cameras record no lens model at all, only the lens specification: Nikon DSLRs write the lens's focal range and
maximum apertures in their maker note (tag 0x0084) and no Exif LensModel, whatever lens is mounted. For such a
file the lens is looked up by a name built from the specification, 24-70mm f/2.8 (18-55mm f/3.5-5.6,
85mm f/1.8), and a profile is used only when one of its names is exactly that (ignoring case and punctuation).
The specification fits every maker's lens with that range (a Nikkor, a Sigma, a Tamron), so neither a partial match
nor a name with a maker in it ("Samyang 85mm f/1.4" for "85mm f/1.4") is taken; a database that should correct such
files names its profile that way, e.g. a lensfun entry with an extra <model>24-70mm f/2.8</model> for the one
24-70 f/2.8 the photographer owns. lensfun's own database has no such names, so it doesn't correct these files.
| Correction | Models | Interpolated over |
|---|---|---|
| Distortion | poly3, poly5, ptlens |
focal length |
| Lateral CA (TCA) | linear, poly3 |
focal length |
| Vignetting | pa |
focal length, aperture (in stops), focus distance (nearest calibrated, by 1/d; infinity when unknown) |
Fisheye and other non-rectilinear lenses get no distortion correction. The profile is converted by least squares
into the DNG WarpRectilinear / FixVignetteRadial polynomials, so it goes through the same path as embedded
corrections: Enable Profile Corrections and its Distortion / Vignetting amounts, the CPU and GPU geometry
stage (one resample), orientation handling and DNG export. A conversion whose radial error exceeds 0.001 of the
half diagonal, or that would fold the image, is not applied.
Normalisation follows lensfun's documentation: distortion and TCA radii are 1 at half the shorter side of the
calibration frame (its cropfactor and aspect-ratio), vignetting radii 1 at its corner; the optical centre is
the image centre (lensfun's <center> offsets are not read).
Limits
- Only raws: rendered images (JPEG, HEIF, TIFF) are often already corrected in camera.
- The focus distance is not read from maker notes yet: vignetting uses the farthest calibrated distance.
- No manual make / model picker and no choice between sources (in the file, lens database, an own calibration) yet; matching is automatic, the file's own correction wins.
- Not yet validated against real photos and another renderer; the tests use synthetic profiles and grids.