Skip to content

LR-EDIT-OPTICS-PROFILE: apply embedded A7R IVA distortion corrections - #498

Merged
echelon merged 5 commits into
storytold:mainfrom
QuirkyTurtle94:sony-embedded-lens-corrections
Oct 10, 2026
Merged

echelon merged 5 commits into
storytold:mainfrom
QuirkyTurtle94:sony-embedded-lens-corrections

Conversation

@QuirkyTurtle94

@QuirkyTurtle94 QuirkyTurtle94 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Sony A7R IVA RAWs can contain per-image lens distortion data while LightCraft reports no embedded correction. Decode the signed 16-sample raw-IFD table (0x7037) into the existing WarpRectilinear path. The existing Optics control can disable or adjust the correction, and DNG export preserves it.

The merged implementation is restricted to exact ILCE-7RM4A Bayer ARWs, independently checked with the FE 24–105mm F4 G OSS and FE 200–600mm F5.6–6.3 G OSS. Other Sony models remain uncorrected. Preserve main's image crop order: Sony crop tags → DefaultCrop → recorded image size. The warp independently uses DefaultCrop for its centre/normalization.

This PR merged at 7962c78 through #692. It includes the original 11-file model-boundary test and synthetic geometry/header/full/DNG checks. Distortion only; vignetting, lateral CA, other table layouts and unvalidated bodies remain outside scope. No private photos or reference exports are committed.

Post-merge follow-up: #695. Full-corpus validation, expansion to 23 Sony files across 17 models, an additional image-aspect guard and fresh reference measurements are submitted there. Those follow-up changes were pushed after #498 merged and are not part of this PR's merged diff. Detailed review response: #498 (comment)

Related to #329; this does not close the broader lens-profile request. Optional solve4 sharing remains deferred because the Sony and RW2 implementations have different singular-pivot thresholds.

…n is at 21)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@echelon

echelon commented Oct 9, 2026

Copy link
Copy Markdown
Member

Thank you @QuirkyTurtle94! Following the RW2 approach for embedded Sony distortion is the right design, and I merged main into your branch to clear a conflict. Before it can land:

  1. Validation beyond one body. As written, the warp is on by default for every Bayer ARW with a 16-entry table at 3:2. On the corpus the A7M3 now gets about 2.5% corner warp where main applied none, and the table's meaning for bodies other than the ILCE-7RM4A is unverified. RW2 was checked on 35 held-out photos against their embedded JPEGs. Please do a similar check on a few corpus bodies (cargo xtask corpus --download), or limit the warp to validated models.
  2. Update the default_crop doc comment, which is stale now that DefaultCrop takes precedence over Sony's 0x74c7/0x74c8.
  3. Optionally, share solve4 with rw2 instead of duplicating it.

If you haven't already, please join our Discord: https://discord.gg/artcraft

@QuirkyTurtle94 QuirkyTurtle94 changed the title LR-EDIT-OPTICS-PROFILE: apply embedded Sony ARW distortion corrections LR-EDIT-OPTICS-PROFILE: apply embedded A7R IVA distortion corrections Oct 9, 2026
@QuirkyTurtle94

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I have taken the validated-model restriction option and resolved the conflicts with current main.

  • The embedded Sony warp is now enabled only for exact model ILCE-7RM4A (Bayer, native 3:2, supported 16-entry layout). A7 III, A7R IV without the A suffix, unknown models and other Sony bodies remain uncorrected.
  • Added a real-file regression covering 11 CC0 samples across seven bodies. It fails with the model guard removed and passes with it restored. Synthetic tests cover both TIFF byte orders, exact model boundaries, crop normalization and accepted/rejected correction preservation through DNG export. These exclusion checks are not claimed as geometry validation of other bodies.
  • Fixed the default_crop doc comment and documented the coverage boundary and requirements for adding models.
  • Resolved the corpus-manifest conflict using main's new SHA-256 tuple format; both new samples have actual checksum fields, and all 11 local Sony corpus files match their pinned hashes. Advanced the render-cache version to 24 to invalidate results from either earlier branch.
  • Left optional solve4 sharing for a separate cleanup because the existing Sony and RW2 implementations use different singular-pivot thresholds.

Validation after merging main (03b3d60): fmt, Clippy and HEIF pass. Full cargo xtask ci still stops at the two existing Metal denoise failures tracked in #479 / separate PR #500. With only those two tests skipped, all 1,955 remaining workspace tests pass; parity, layering, assets and all wasm checks pass as well. No GPU fix is bundled here.

Re-exported the three A7R IVA reference files on the merged build: corrected geometry against Sony Imaging Edge remains within median residuals of 0.35, 0.14, 0.09 px at 24, 200 and 600 mm respectively (2376 px output width).

Private photographs and Sony reference exports remain local; only source, tests, documentation and public corpus URLs/checksums are included.

@echelon

echelon commented Oct 10, 2026

Copy link
Copy Markdown
Member

Thank you @QuirkyTurtle94! Limiting the embedded warp to the ILCE-7RM4A was the right call, and the solver is bounded nicely.

I couldn't land it this round. #575 and #580, which landed in #657, rewrite default_crop in crates/raw/src/vendor/arw.rs: #580 adds the recorded-size crop for 16:9 shots on pre-crop-tag bodies, and Sony's own crop tags still come first. This PR moves those crop tags inside default_crop and prefers DefaultCrop over them for every Sony body, not only the 7RM4A. That changes framing on bodies this PR doesn't validate.

Could you rebase onto main, and:

  1. keep the crop precedence as main has it (Sony crop tags, then DefaultCrop, then LR-IMP-CAMERA-COVERAGE: Sony 16:9 crop on pre-crop-tag bodies #580's recorded size), or limit the change to the bodies you checked;
  2. re-run cargo test -p lightcraft-raw --test corpus with the full Sony corpus (cargo xtask corpus --download).

Please join our Discord if you haven't already: https://discord.gg/artcraft

Main (storytold#575, storytold#580) rewrote default_crop. The image crop now keeps main's
order for every Sony body (Sony's crop tags, then DefaultCrop, then the
recorded-size crop), so framing does not change. Only the ILCE-7RM4A
distortion warp takes its centre and normalization from DefaultCrop when
the file has one, which keeps the geometry validated against Sony's
exports (centre x 4783.5 on the A7R IVA sample). The DNG round-trip test
now checks both: Sony's crop on the image, the warp centred on the
default crop. RENDER_CACHE_VERSION 38.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@echelon

echelon commented Oct 10, 2026

Copy link
Copy Markdown
Member

Thank you @QuirkyTurtle94! This landed in #692. I merged main into your branch and kept main's crop order (Sony crop tags, then DefaultCrop, then the recorded size) for every body. Your warp still takes its centre from DefaultCrop on the ILCE-7RM4A only, and it's still limited to that body.

Please join our Discord if you haven't already: https://discord.gg/artcraft

mysbryce pushed a commit to mysbryce/lightcraft that referenced this pull request Oct 10, 2026
…ultCrop helper side by side (merge put the flag on the wrong function)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@QuirkyTurtle94

QuirkyTurtle94 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Merge timing update: #498 landed in #692 at 7962c78 while this validation was running. The original results below are for 16d09e8a, which was pushed after that merge. The remaining fix and validation changes are now submitted separately in #695, based on current main (b70ae174), commit 9682caae.

Current-main follow-up results: all eight cargo xtask ci stages pass again, including all 20 corpus tests and both former GPU failures. All 103 corpus files are checksum-verified, including 23 Sony files across 17 models after adding main's new A900 fixture to the boundary test. The new cache version is 43, following main's 42. Fresh Sony-reference residuals remain 0.36/1.12 px at 24 mm, 0.13/0.35 px at 200 mm and 0.10/0.37 px at 600 mm, after removing the documented approximately 8 px framing translation. #695 contains the additional aspect guard, expanded tests and updated documentation; these were not part of the original #498 merge.


Thanks for the follow-up and for the crop-precedence merge. I kept your 7962c78 commit and pushed 16d09e8 with the remaining validation and a regression found during that work.

  1. Crop precedence remains exactly as requested: Sony crop tags → DefaultCrop → recorded image size. The distortion centre/normalization still comes from DefaultCrop; this does not change another body's image framing.
  2. Full corpus downloaded and checked: cargo xtask corpus --download completed, and all 102 manifest files match their pinned SHA-256 hashes. I expanded the model-boundary test from 11 to all 22 Sony files across 16 bodies, including A7CR variants, A7R IV without the A suffix, older Sony bodies, and the A7S II/A580 16:9 samples. Only the validated ILCE-7RM4A receives a warp; header/full decode agree for all 22. These are exclusion/regression checks, not a claim that other bodies' lens geometry is validated.
  3. One aspect-crop edge case fixed: a Sony image crop could be non-3:2 while DefaultCrop remained 3:2, bypassing the intended scope restriction. The extended header/full/DNG regression failed on the previous head (one unexpected warp) and passes with an additional image-framing guard. Both TIFF byte orders are covered, and the render cache is bumped to 39.
  4. All required checks are green: cargo test -p lightcraft-raw --test corpus -- --nocapture passes all 19 tests with the complete corpus present. cargo xtask ci passes all eight stages: fmt, Clippy, HEIF, workspace tests, parity, layers, assets and wasm. Both formerly failing Metal denoise tests now pass; no tests were manually excluded. The test harness ran with RUST_TEST_THREADS=1.

I also repeated the Sony-reference comparisons at 2376 px wide. Corrected median/p95 feature residuals are 0.36/1.12 px at 24 mm, 0.13/0.36 px at 200 mm, and 0.10/0.37 px at 600 mm. These subtract translation only: the retained crop origin introduces approximately 8 px horizontal framing difference from Sony, which is now explicitly documented rather than hidden by the old alignment figures. All six corrected/uncorrected reference renders are byte-identical between the measured build and the final executable. Headless checks also show the A7R IVA profile controls present, A7 III controls absent, and completed renders with no notices.

The PR description and docs/sony-lens-corrections.md now reflect these results. Support remains restricted to ILCE-7RM4A; the A6700 samples in #653 should be a separately validated extension. Optional solve4 sharing remains deferred because the existing pivot thresholds differ. No private photos or reference exports were committed or uploaded.

dev-null-undefined added a commit to dev-null-undefined/lightcraft-fork that referenced this pull request Oct 11, 2026
…ded table

New vendor::arw_lens_rm6 reads the raw IFD's lens tables (0x7037 distortion,
0x7032 vignetting, 0x7035 lateral CA, their flags) and turns the distortion
table into a one-plane WarpRectilinear in OpcodeList3, with the conventions
measured on 54 ILCE-7RM6 photos: knots at i/15 of the full-frame crop half
diagonal, S(r) = r (1 + v(r)/15000), frame-filling zoom, centred on the
default crop. Only the ILCE-7RM6 is enabled; vignetting is read, not applied.
The radial least-squares fit is split out as vendor::fit_radial_warp (RW2
results unchanged); its error gate can be limited to the radii the crop
shows, so a padded active area (lossless files) doesn't refuse a fit over
pixels that are never rendered.

It sits next to main's vendor::arw_lens (storytold#498), which holds the ILCE-7RM4A
conventions measured against Sony's exports (unit 16384, table indexed at the
output radius); the two are selected by camera model (disjoint allowlists).
arw::decode chains this module's opcodes after arw_lens::distortion, with the
same active area and the same crop (the DNG-style default crop when the file
has one, which on the ILCE-7RM6 equals Sony's crop tags), and like it only
for CFA data (not the downsized linear-RGB lossless sizes, where the knot
spacing in full-frame pixels would not hold).

The corpus test checks the conversion on the two lossless RawDB files (CC0).
The APS-C one is pinned in xtask RAW_SAMPLES with its sha256; the full-frame
one is not (at most two pins per PR, and storytold#625 pins two Compressed ARW 6.0
files), so its case runs only where the file is present.

RENDER_CACHE_VERSION 43 (main is at 42). PR storytold#625 also bumps to 43: whichever
of the two merges second bumps to 44.

Co-Authored-By: Claude <noreply@anthropic.com>
dev-null-undefined added a commit to dev-null-undefined/lightcraft-fork that referenced this pull request Oct 11, 2026
…M6; docs and tracker

docs/sony-ilce7rm6-lens-corrections.md records the three Sony tables, the
measured conventions with their residuals, the conversion to
WarpRectilinear and its fit gate, the model allowlist and how to extend
it, the measurement method, the verification and the limits.

Verified locally on 54 ILCE-7RM6 photos with four lenses. The corrected
render lines up with the camera JPEG within 0.679 px at 1440 px at the
corners and edge midpoints of the 33 measurable photos shot with
in-camera correction on (up to 17.3 px uncorrected). The 13 controls show
the model's own shift. Every fit passes the 0.25 px gate (margin 0.075).
Lateral CA stays within 0.3 px, but applied after demosaic it raises the
render's corner CA (rms 0.032 -> 0.052 px); the doc and tracker say so.

Its "Two conventions" section sets these conventions next to the
ILCE-7RM4A's (vendor::arw_lens, docs/sony-lens-corrections.md, storytold#498):
on the 34 measurable ILCE-7RM6 photos that formula gives 1.429 / 0.319 px
(max / rms) against 0.596 / 0.143, failing only on the 24-70 GM II and
fitting the 100 mm and 200-600 better; no single unit fits every lens
under either, and what would settle it (Sony On/Off exports of a wide
zoom, more lenses). docs/sony-lens-corrections.md gains a pointer to it.

Tracker rows LR-EDIT-OPTICS-PROFILE (one note for both bodies) and
LR-IMP-CAMERA-COVERAGE in docs/parity-checklist.md, gap 8 in
docs/gaps.md, the lens-profile section of docs/raw-parity.md (lens score
unchanged), whats-new (lossless ARWs now; Compressed / Compressed HQ once
the ARW 6.0 decoder, storytold#625, lands) and the colour-fit follow-up note are
updated.

Co-Authored-By: Claude <noreply@anthropic.com>
dev-null-undefined added a commit to dev-null-undefined/lightcraft-fork that referenced this pull request Oct 11, 2026
…ded table

New vendor::arw_lens_rm6 reads the raw IFD's lens tables (0x7037 distortion,
0x7032 vignetting, 0x7035 lateral CA, their flags) and turns the distortion
table into a one-plane WarpRectilinear in OpcodeList3, with the conventions
measured on 54 ILCE-7RM6 photos: knots at i/15 of the full-frame crop half
diagonal, S(r) = r (1 + v(r)/15000), frame-filling zoom, centred on the
default crop. Only the ILCE-7RM6 is enabled; vignetting is read, not applied.
The radial least-squares fit is split out as vendor::fit_radial_warp (RW2
results unchanged); its error gate can be limited to the radii the crop
shows, so a padded active area (lossless files) doesn't refuse a fit over
pixels that are never rendered.

It sits next to main's vendor::arw_lens (storytold#498), which holds the ILCE-7RM4A
conventions measured against Sony's exports (unit 16384, table indexed at the
output radius); the two are selected by camera model (disjoint allowlists).
arw::decode chains this module's opcodes after arw_lens::distortion, with the
same active area and the same crop (the DNG-style default crop when the file
has one, which on the ILCE-7RM6 equals Sony's crop tags), and like it only
for CFA data (not the downsized linear-RGB lossless sizes, where the knot
spacing in full-frame pixels would not hold).

The corpus test checks the conversion on the two lossless RawDB files (CC0).
The APS-C one is pinned in xtask RAW_SAMPLES with its sha256; the full-frame
one is not (at most two pins per PR, and storytold#625 pins two Compressed ARW 6.0
files), so its case runs only where the file is present.

RENDER_CACHE_VERSION 43 (main is at 42). PR storytold#625 also bumps to 43: whichever
of the two merges second bumps to 44.

Co-Authored-By: Claude <noreply@anthropic.com>
dev-null-undefined added a commit to dev-null-undefined/lightcraft-fork that referenced this pull request Oct 11, 2026
…M6; docs and tracker

docs/sony-ilce7rm6-lens-corrections.md records the three Sony tables, the
measured conventions with their residuals, the conversion to
WarpRectilinear and its fit gate, the model allowlist and how to extend
it, the measurement method, the verification and the limits.

Verified locally on 54 ILCE-7RM6 photos with four lenses. The corrected
render lines up with the camera JPEG within 0.679 px at 1440 px at the
corners and edge midpoints of the 33 measurable photos shot with
in-camera correction on (up to 17.3 px uncorrected). The 13 controls show
the model's own shift. Every fit passes the 0.25 px gate (margin 0.075).
Lateral CA stays within 0.3 px, but applied after demosaic it raises the
render's corner CA (rms 0.032 -> 0.052 px); the doc and tracker say so.

Its "Two conventions" section sets these conventions next to the
ILCE-7RM4A's (vendor::arw_lens, docs/sony-lens-corrections.md, storytold#498):
on the 34 measurable ILCE-7RM6 photos that formula gives 1.429 / 0.319 px
(max / rms) against 0.596 / 0.143, failing only on the 24-70 GM II and
fitting the 100 mm and 200-600 better; no single unit fits every lens
under either, and what would settle it (Sony On/Off exports of a wide
zoom, more lenses). docs/sony-lens-corrections.md gains a pointer to it.

Tracker rows LR-EDIT-OPTICS-PROFILE (one note for both bodies) and
LR-IMP-CAMERA-COVERAGE in docs/parity-checklist.md, gap 8 in
docs/gaps.md, the lens-profile section of docs/raw-parity.md (lens score
unchanged), whats-new (lossless ARWs now; Compressed / Compressed HQ once
the ARW 6.0 decoder, storytold#625, lands) and the colour-fit follow-up note are
updated.

Co-Authored-By: Claude <noreply@anthropic.com>
dev-null-undefined added a commit to dev-null-undefined/lightcraft-fork that referenced this pull request Oct 13, 2026
…ded table

New vendor::arw_lens_rm6 reads the raw IFD's lens tables (0x7037 distortion,
0x7032 vignetting, 0x7035 lateral CA, their flags) and turns the distortion
table into a one-plane WarpRectilinear in OpcodeList3, with the conventions
measured on 54 ILCE-7RM6 photos: knots at i/15 of the full-frame crop half
diagonal, S(r) = r (1 + v(r)/15000), frame-filling zoom, centred on the
default crop. Only the ILCE-7RM6 is enabled; vignetting is read, not applied.
The radial least-squares fit is split out as vendor::fit_radial_warp (RW2
results unchanged); its error gate can be limited to the radii the crop
shows, so a padded active area (lossless files) doesn't refuse a fit over
pixels that are never rendered.

It sits next to main's vendor::arw_lens (storytold#498), which holds the ILCE-7RM4A
conventions measured against Sony's exports (unit 16384, table indexed at the
output radius); the two are selected by camera model (disjoint allowlists).
arw::decode chains this module's opcodes after arw_lens::distortion, with the
same active area and the same crop (the DNG-style default crop when the file
has one, which on the ILCE-7RM6 equals Sony's crop tags), and like it only
for CFA data (not the downsized linear-RGB lossless sizes, where the knot
spacing in full-frame pixels would not hold).

The corpus test checks the conversion on the two lossless RawDB files (CC0).
The APS-C one is pinned in xtask RAW_SAMPLES with its sha256; the full-frame
one is not (at most two pins per PR, and storytold#625 pins two Compressed ARW 6.0
files), so its case runs only where the file is present.

RENDER_CACHE_VERSION 62 -> 63.

Co-Authored-By: Claude <noreply@anthropic.com>
dev-null-undefined added a commit to dev-null-undefined/lightcraft-fork that referenced this pull request Oct 13, 2026
…M6; docs and tracker

docs/sony-ilce7rm6-lens-corrections.md records the three Sony tables, the
measured conventions with their residuals, the conversion to
WarpRectilinear and its fit gate, the model allowlist and how to extend
it, the measurement method, the verification and the limits.

Verified locally on 54 ILCE-7RM6 photos with four lenses. The corrected
render lines up with the camera JPEG within 0.679 px at 1440 px at the
corners and edge midpoints of the 33 measurable photos shot with
in-camera correction on (up to 17.3 px uncorrected). The 13 controls show
the model's own shift. Every fit passes the 0.25 px gate (margin 0.075).
Lateral CA stays within 0.3 px, but applied after demosaic it raises the
render's corner CA (rms 0.032 -> 0.052 px); the doc and tracker say so.

Its "Two conventions" section sets these conventions next to the
ILCE-7RM4A's (vendor::arw_lens, docs/sony-lens-corrections.md, storytold#498):
on the 34 measurable ILCE-7RM6 photos that formula gives 1.429 / 0.319 px
(max / rms) against 0.596 / 0.143, failing only on the 24-70 GM II and
fitting the 100 mm and 200-600 better; no single unit fits every lens
under either, and what would settle it (Sony On/Off exports of a wide
zoom, more lenses). docs/sony-lens-corrections.md gains a pointer to it.

Tracker rows LR-EDIT-OPTICS-PROFILE (one note for both bodies) and
LR-IMP-CAMERA-COVERAGE in docs/parity-checklist.md, gap 8 in
docs/gaps.md, the lens-profile section of docs/raw-parity.md (lens score
unchanged), whats-new (lossless ARWs now; Compressed / Compressed HQ once
the ARW 6.0 decoder, storytold#625, lands) and the colour-fit follow-up note are
updated.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants