Repository navigation
M11.4: raws from 52 camera models start from matrices fitted to measured spectral sensitivities - #560
Conversation
…red spectral sensitivities A raw without colour matrices of its own now gets DNG ColorMatrix1/2 and ForwardMatrix1/2 for its model when the model is one of the 52 cameras in rawtoaces-data (Academy Software Foundation, Apache-2.0): 22 Canon, 11 Nikon, 11 Sony, 3 Fujifilm and 5 others, plus the other names its alias list gives (Rebel T3i and Kiss X5 for the EOS 600D; bodies it lists as sharing a sensor). tools/spectral_camera_table.py fits, under Standard Illuminant A and D65, a white-preserving 3x3 to the measured spectral sensitivities over rawtoaces-data's 190 training reflectances and writes crates/raw/src/spectral_table.rs. No number comes from Adobe or from a raw decoder. lightcraft_raw::spectral looks a camera up by Exif make and model; the DNG colour model does the rest. camera_preview::starting_colour takes the first available of: the file's own matrices, a camera profile for the model (fitted to the JPEG for tone), the spectral matrices, the file-local JPEG fit, the neutral fallback. A profiled model whose profile fit fails takes its spectral matrices. White balance stays relative to the as-shot look for every raw without matrices of its own, so Photo::relative_wb and the controls are unchanged; calibrate still pools covered models. Tests: one per precedence step (synthetic), the table's lookup, aliases and DNG shape, and a corpus test of the order on ILCE-7M4 (profile), EOS 5D Mark III and D5100 (spectral), EOS 7D (own fit) and a DNG. The ILCE-7RM2 and GFX100S corpus tests now expect the spectral matrices. Attribution in assets/ATTRIBUTION.md and NOTICE. RENDER_CACHE_VERSION 23. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you @rossaai! Licensing is clean: rawtoaces-data is Apache-2.0 per file, the training set is too, the CMFs are CC-BY-4.0, and NOTICE and ATTRIBUTION are in place. Thanks for documenting that so carefully. The ordering stops me from landing it.
#657 also landed #528, #583, #568 and #616, which refactor Please join our Discord if you haven't already: https://discord.gg/artcraft |
Merge origin/main into storytold#560 (fit_preview / camera-look refactors of storytold#528, storytold#583, storytold#568, storytold#616). `starting_colour` now tries the per-file camera-JPEG fit (with the camera profile when there is one) first and uses the spectral-sensitivity matrices only when that fit fails, before the neutral fallback, so no photo with an accepted JPEG fit changes. Tests pin the order through an injectable fit; docs, parity, ROADMAP and what's new describe it. RENDER_CACHE_VERSION 37 -> 38. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… by mistake) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you @rossaai! This landed in #692. I merged main into your branch and reordered the starting colour: the file's own matrices, then the per-file JPEG fit, then your spectral matrices, then neutral. So photos with an accepted JPEG fit render exactly as before, and your matrices replace the neutral fallback for 52 bodies. A test pins that order. A ΔE comparison of the spectral start against the camera JPEGs would still be very welcome. Please join our Discord if you haven't already: https://discord.gg/artcraft |
…emory Photo Merge: refuse inputs beyond the memory budget (upstream storytold#2073)
What it does
A raw that carries no colour matrix now gets DNG
ColorMatrix1/2andForwardMatrix1/2for its model, when the model is one of the 52 cameras in rawtoaces-data (Academy Software Foundation, Apache-2.0, tag v1.1.0, commit5cfa5370). That is 22 Canon, 11 Nikon, 11 Sony, 3 Fujifilm and 5 other bodies, plus the 23 other names in rawtoaces-data'sdata/aliases.json(Rebel T3i and Kiss X5 for the EOS 600D, for example, and bodies it lists as sharing a sensor, such as the GFX100S with the GFX 100).tools/spectral_camera_table.pyfits, under CIE Standard Illuminant A and D65, a white-preserving 3x3 from white-balanced camera RGB to XYZ, by least mean CIE76 error over rawtoaces-data's 190 training reflectances. It writescrates/raw/src/spectral_table.rs. The method follows the description in Academy P-2013-001. No rawtoaces code is used. Run on rawtoaces-data v1.1.0 with the pinned packages, it reproduces the committedspectral_table.rsbyte for byte.lightcraft_raw::spectral::findlooks a camera up by Exif make and model, thenCamera::fillwrites the matrices intoColorData. The existing DNG colour model incrates/raw/src/color.rsdoes the rest.camera_preview::starting_colourtakes the first available of these:If a profiled model's profile fit fails, the model gets its spectral matrices.
White balance stays relative to the as-shot look for every raw without matrices of its own.
Photo::relative_wb, the WB controls and old catalogs are unchanged.lightcraft-cli calibratestill collects pairs from covered models, so a profile fitted later takes precedence.RENDER_CACHE_VERSIONgoes to 23.No number in this change comes from Adobe, from a DNG Converter matrix or from dcraw, LibRaw, rawspeed, darktable, RawTherapee, rawloader or rawler. The only inputs are rawtoaces-data's measured spectral sensitivities, its training reflectances, its alias list and the CIE 1931 colour-matching functions it ships. This follows the clean-room rule in
AGENTS.md. Attribution is inassets/ATTRIBUTION.mdandNOTICE.Why an embedding app needs it
An app that embeds the engine renders CR2, NEF, ARW and RAF files from these bodies with a colour model that has the same values on every photo of a body. The values do not depend on the embedded JPEG, the picture style or the scene. Before this change, colour came from a per-file JPEG fit when the fit passed its gates. Otherwise it came from the neutral fallback. This also addresses the first step named in #380 ("per-camera calibration comes first") for the 52 bodies.
What changes for bodies in the table
For a body in the table without an accepted profile fit, the spectral matrices now come before the file-local JPEG fit. Such a raw starts from the spectral matrices and LightCraft's default tone curve, and no longer from a colour and tone curve fitted to its own JPEG. Two corpus files show this.
raf-fuji-gfx100s-4503.rafreaches the GFX 100 row through the alias list, andarw-sony-a7rm2-12bit-uncompressed.arw(#232) has its own row. Both had an accepted JPEG fit before this change, and their tests now expect the spectral matrices.No colour-difference measurement of the spectral matrices against the camera JPEG, or against the file-local fit, is part of this change. The order of steps 3 and 4 is therefore a choice, not a measured result. If you want the JPEG fit to come first, moving step 3 after step 4 is a one-line change in
starting_colour, and the corpus tests above would then expect the JPEG fit again.How it was tested
The tests ran on macOS arm64 with rustc 1.99.0, at
88ea1a8plus this commit.LIGHTCRAFT_CORPUSpointed at a folder whoseraw/held these CC0 corpus files, downloaded from the URLs inxtask/src/main.rs:arw-sony-a7m4-14bit.arw,arw-sony-a7rm2-12bit-uncompressed.arw,cr2-canon-5d3.cr2,cr2-canon-5d2.cr2,cr2-canon-7d.cr2,cr3-canon-r100-raw.cr3,dng-canon-5d3-16bit.dng,nef-nikon-d5100-lossless.nef,nef-nikon-d7500-lossless14.nef,raf-fuji-gfx100s-4503.raf,raf-fuji-xt2-865.rafandraf-fuji-xt20-compressed.raf.With these files present,
corpus_colour_precedence,corpus_raf_colour_and_white_balanceandcorpus_arw_with_a_lens_corrected_preview_gets_a_camera_lookread their files and skipped none.The full
cargo xtask ciwas not run. It covers the whole workspace, and this change toucheslightcraft-rawandlightcraft-engineinternals, plus one new public module,lightcraft_raw::spectral.New tests:
crates/raw/src/spectral.rs: Exif names find their rows (Canon EOS-1Ds, the DIGITAL suffix, NIKON CORPORATION, PowerShot), every alias reaches its target, other bodies and other makes find nothing, every row is a finite and invertible DNG profile whose forward matrices map white to D50, andfillkeeps a file's own matrices.crates/engine/src/camera_preview.rs, one test per precedence step:a_files_own_matrices_come_firsta_camera_profile_is_tried_before_the_spectral_matrices(ILCE-7M4, bundled profile, no JPEG, so the spectral matrices follow)spectral_matrices_come_before_the_photos_own_fita_camera_outside_the_table_keeps_the_fit_or_the_fallbackcorpus_colour_precedencechecks the order on real files:As a control, removing the profile step from
starting_colourmakes this test fail on the ILCE-7M4.Each of these eight changes to the new code made at least one new or changed test fail: not filling the spectral matrices, removing the profile step, putting the JPEG fit before the spectral matrices, overwriting a file's own matrices, deriving relative white balance from the transform, ignoring the alias list, keeping a leading
EOSin the model name, and ignoring the make.corpus_arw_with_a_lens_corrected_preview_gets_a_camera_look(Odd colors when importing photos into LightCraft. #232) still checks that the away-from-edges fit is accepted on the ILCE-7RM2, now by calling the fit directly. It also asserts that loading the file now uses the spectral matrices.corpus_raf_colour_and_white_balancenow expects the GFX100S to use the spectral matrices.What it does not change
lightcraft-cli calibrate.crates/merge) and DNG conversion and export, which readlightcraft_raw::decodedirectly and still see the file's own colour data.Licence
The table is derived from Apache-2.0 data. This change keeps
lightcraft-rawunder the workspace licence and meets Apache-2.0 §4 throughLICENSE-APACHE, the file header,NOTICEandassets/ATTRIBUTION.md. If you prefer to mark derived data the waycrates/segmentis marked, as Apache-2.0 only, say so and I will change it. The CIE 1931 colour-matching functions that rawtoaces-data ships are marked CC-BY-4.0, and they are credited in both places.Issues
Refers to #380 and the LR-PROF-CAMERACOLOR row in
docs/parity.md. Follows #310. No open issue asks for exactly this change, so it closes none.🤖 Generated with Claude Code