Skip to content

Commit ac55490

Browse files
authored
Merge pull request storytold#3144 from janickm/dev/janickm/a7m3-distortion
LR-EDIT-OPTICS-PROFILE: enable Sony ILCE-7M3 embedded distortion correction (rebase of storytold#1384)
2 parents b28661a + 5d97498 commit ac55490

10 files changed

Lines changed: 546 additions & 21 deletions

File tree

‎crates/engine/src/media/source.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{Arc, Deserialize, DevelopSettings, MediaKind, Photo, Rgb32f, Rgba8, Serialize, SourceInfo};
22

33
/// Bump when the pipeline's output changes, to invalidate cached thumbnails.
4-
pub const RENDER_CACHE_VERSION: u64 = 73;
4+
pub const RENDER_CACHE_VERSION: u64 = 74;
55

66
/// Thumbnails render at one of these long edges (so window/cell size changes reuse the cache).
77
pub const THUMB_SIZES: [usize; 4] = [128, 256, 384, 512];

‎crates/raw/src/vendor/arw_lens.rs‎

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Sony's in-file lens-correction records (shading, lateral chromatic aberration, distortion): bounded decoding of
22
//! the raw image IFD's fields and their encrypted `SR2SubIFD` copies into [`SonyLensCorrections`], and validated
3-
//! ILCE-7RM4A and ILCE-7CR distortion tables into DNG warps for the shared optics pipeline.
3+
//! ILCE-7RM4A, ILCE-7M3 and ILCE-7CR distortion tables into DNG warps for the shared optics pipeline.
44
//!
55
//! Tag identity/layout: https://exiftool.org/TagNames/EXIF.html (`0x7031` to `0x7037`, signed shorts) and
66
//! https://exiftool.org/TagNames/Sony.html#SR2SubIFD (`0x797d`, `0x7980`, `0x7982`). The `SR2SubIFD` setting tags
@@ -34,9 +34,9 @@ const DISTORTION: Tags = Tags { setting: (0x7036, 0x7981), table: (0x7037, 0x798
3434
/// TIFF field types.
3535
const SHORT: u16 = 3;
3636
const SSHORT: u16 = 8;
37-
/// Models using the validated A7R IVA conversion. The A7CR uses a separate conversion.
37+
/// Models using the validated A7R IVA conversion (ILCE-7RM4A, ILCE-7M3). The A7CR uses a separate conversion.
3838
/// ILCE-7RM4 and ILCE-7RM4A are distinct models, not interchangeable aliases.
39-
const DISTORTION_MODELS: &[&str] = &["ILCE-7RM4A"];
39+
const DISTORTION_MODELS: &[&str] = &["ILCE-7RM4A", "ILCE-7M3"];
4040
/// Most directory entries scanned: a classic TIFF directory's largest count, also bounding a BigTIFF one.
4141
const MAX_ENTRIES: usize = 1 << 16;
4242
const SAMPLES: usize = 1024;
@@ -1397,6 +1397,47 @@ mod tests {
13971397
}
13981398
}
13991399

1400+
// ILCE-7M3 raw-IFD tables (FE 16-35mm F4 ZA OSS at 16 and 35 mm, FE 28-70mm F3.5-5.6 OSS at 70 mm) and the
1401+
// geometry of the camera's own JPEG of the same exposure (Lens Comp. Distortion: Auto): checkerboard corners of
1402+
// that JPEG matched with the uncorrected raw and fitted with the warp's polynomial over the 6000×4000 frame (rms
1403+
// 0.11–0.25 px). See docs/sony-lens-corrections.md.
1404+
const A7M3: [([i16; 16], [f64; 4]); 3] = [
1405+
(
1406+
[32, 2, -38, -83, -138, -199, -270, -336, -402, -462, -519, -568, -611, -643, -670, -690],
1407+
[1.0247000859, -0.1092847508, 0.1061422243, -0.0397989678],
1408+
),
1409+
([2, 2, 4, 9, 18, 29, 45, 65, 92, 124, 164, 210, 264, 329, 403, 489], [0.9708150714, 0.0157256288, 0.0175613359, -0.004107544]),
1410+
([4, 7, 18, 40, 68, 108, 155, 212, 280, 359, 453, 557, 679, 819, 978, 1161], [0.9342002611, 0.0560486347, 0.0076184603, 0.0021497933]),
1411+
];
1412+
1413+
#[test]
1414+
fn ilce_7m3_matches_the_cameras_own_jpeg_geometry() {
1415+
let frame = Rect::new(0, 0, 6000, 4000);
1416+
let evaluate = |k: &[f64], r: f64| r * (k[0] + r * r * (k[1] + r * r * (k[2] + r * r * k[3])));
1417+
for (values, reference) in A7M3 {
1418+
let Opcode::WarpRectilinear { planes, center } = distortion("ILCE-7M3", &values, frame, frame).unwrap() else { panic!("warp") };
1419+
assert_eq!(center, [0.5, 0.5]);
1420+
// The camera fills its frame with its own zoom; compare the shape over the measured radii (to 0.97).
1421+
let radii: Vec<f64> = (1..=97).map(|i| i as f64 / 100.0).collect();
1422+
let (ours, camera): (Vec<f64>, Vec<f64>) = radii.iter().map(|&r| (evaluate(&planes[0], r), evaluate(&reference, r))).unzip();
1423+
let worst = |ours: &[f64]| {
1424+
let zoom = ours.iter().zip(&camera).map(|(a, b)| a * b).sum::<f64>() / ours.iter().map(|a| a * a).sum::<f64>();
1425+
ours.iter().zip(&camera).map(|(a, b)| (a * zoom - b).abs()).fold(0.0, f64::max)
1426+
};
1427+
// 0.0008 of the half diagonal is 2.9 px on the 6000 px frame (measured: 0.4–2.4 px); uncorrected is 10×+ off.
1428+
let (corrected, uncorrected) = (worst(&ours), worst(&radii));
1429+
assert!(corrected < 0.0008 && uncorrected > 10.0 * corrected, "{values:?}: {corrected} vs {uncorrected}");
1430+
}
1431+
// Sony's crop and the default crop agree on this body (12, 12, 6000×4000 of 6048×4024), so the warp sits on
1432+
// the image centre.
1433+
let Opcode::WarpRectilinear { center, .. } =
1434+
distortion("ILCE-7M3", &A7M3[0].0, Rect::new(0, 0, 6048, 4024), Rect::new(12, 12, 6000, 4000)).unwrap()
1435+
else {
1436+
panic!("warp")
1437+
};
1438+
assert!((center[0] * 6047.0 - 3011.5).abs() < 1e-9 && (center[1] * 4023.0 - 2011.5).abs() < 1e-9, "{center:?}");
1439+
}
1440+
14001441
#[test]
14011442
fn barrel_framing_and_offset_crop_keep_the_same_geometry() {
14021443
let crop = Rect::new(32, 20, 9504, 6336);
@@ -1427,14 +1468,16 @@ mod tests {
14271468
#[test]
14281469
fn refuses_unvalidated_models_even_with_a_valid_table() {
14291470
assert!(distortion("ILCE-7RM4A", &TELE, AREA, AREA).is_some());
1430-
for model in ["", "ILCE-7M3", "ILCE-7M4", "ILCE-7RM4", "ILCE-7RM5", "ILCE-9M2", "DSC-RX100M3", "ILCE-7RM4A unknown", "ILCE-7CR"] {
1471+
assert!(distortion("ILCE-7M3", &TELE, AREA, AREA).is_some());
1472+
for model in ["", "ILCE-7M4", "ILCE-7RM4", "ILCE-7RM5", "ILCE-9M2", "DSC-RX100M3", "ILCE-7RM4A unknown", "ILCE-7CR", "ILCE-7M3 ", "ILCE-7SM3"]
1473+
{
14311474
assert!(distortion(model, &TELE, AREA, AREA).is_none(), "{model}");
14321475
}
14331476
}
14341477

14351478
#[test]
14361479
fn header_and_full_decode_preserve_correction_through_dng() {
1437-
for (model, expected) in [("ILCE-7RM4A", 1), ("ILCE-7RM4", 0), ("ILCE-7M3", 0), ("", 0)] {
1480+
for (model, expected) in [("ILCE-7RM4A", 1), ("ILCE-7RM4", 0), ("ILCE-7M3", 1), ("ILCE-7M4", 0), ("", 0)] {
14381481
for (height, expected) in [(20, expected), (16, 0)] {
14391482
for order in [ByteOrder::Little, ByteOrder::Big] {
14401483
let mut raw = IfdBuilder::new();

‎crates/raw/tests/it/corpus.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,8 @@ fn sony_embedded_distortion_is_limited_to_validated_models() {
10701070
for (name, model, expected) in [
10711071
("arw-sony-a7rm4a-compressed.arw", "ILCE-7RM4A", 1),
10721072
("arw-sony-a9m2-compressed.arw", "ILCE-9M2", 0),
1073-
("arw-sony-a7m3-compressed.arw", "ILCE-7M3", 0),
1074-
("arw-sony-a7m3-uncompressed.arw", "ILCE-7M3", 0),
1073+
("arw-sony-a7m3-compressed.arw", "ILCE-7M3", 1),
1074+
("arw-sony-a7m3-uncompressed.arw", "ILCE-7M3", 1),
10751075
("arw-sony-a7m4-14bit.arw", "ILCE-7M4", 0),
10761076
("arw-sony-a7m4-lossless-l.arw", "ILCE-7M4", 0),
10771077
("arw-sony-a7m4-lossless-m.arw", "ILCE-7M4", 0),
@@ -1228,7 +1228,7 @@ fn a_sony_fixture_that_differs_from_its_pin_fails() {
12281228

12291229
/// Sony's lens-correction records (`lightcraft_raw::lens_metadata`, `crates/raw/src/vendor/arw_lens.rs`) on the public
12301230
/// samples: shading, CA and distortion decoded from the raw IFD with their settings, equal to their `SR2SubIFD` copies,
1231-
/// the same from header and full decode, and nothing applied beyond the validated ILCE-7RM4A distortion. Expected
1231+
/// the same from header and full decode, and nothing applied beyond the validated ILCE-7RM4A and ILCE-7M3 distortion. Expected
12321232
/// tables and settings: what ExifTool, run as a black-box tool, prints for these files. Every file is checked against
12331233
/// its pinned SHA-256 before it is decoded; absent files are skipped.
12341234
#[test]
@@ -1352,13 +1352,13 @@ fn sony_lens_records_of_the_public_samples() {
13521352
eprintln!("{name}: shading, CA and distortion decoded; distortion {status:?}");
13531353
checked += 1;
13541354
}
1355-
// every Sony corpus file: only the ILCE-7RM4A's distortion is ever applied, and an applied status is an opcode
1355+
// every Sony corpus file: only the ILCE-7RM4A's and ILCE-7M3's distortion is ever applied, and an applied status is an opcode
13561356
for (name, _) in SONY_SAMPLES {
13571357
let Some(bytes) = pinned_sony(&root, name) else { continue };
13581358
let info = probe_info(&bytes).unwrap_or_else(|e| panic!("{name}: {e}"));
13591359
let Some(s) = &info.lens_metadata.sony else { continue };
13601360
let applied = s.distortion.status == SonyLensStatus::Applied;
1361-
assert_eq!(applied, info.metadata.model.as_deref() == Some("ILCE-7RM4A"), "{name}");
1361+
assert_eq!(applied, matches!(info.metadata.model.as_deref(), Some("ILCE-7RM4A" | "ILCE-7M3")), "{name}");
13621362
assert_eq!(info.opcodes.list3.len(), usize::from(applied), "{name}");
13631363
assert!(![s.shading.status, s.chromatic_aberration.status].contains(&SonyLensStatus::Applied), "{name}");
13641364
checked += 1;

‎docs/gaps.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Hours are Opus 5.5 agent wall-clock hours (see [target-app-parity.md](target-app
2222
| 5 B | **AI masks: Subject, Sky, People, Background, Landscape** are heuristics; Object / Describe run SAM 3 but its download has no mirror configured | `crates/segment`; ai-masks.md; MASK rows 67% | masking is how most Lightroom users edit today | 40–70 + model decision | [target-app-parity](target-app-parity.md#ai) |
2323
| 6 B | **Compressed ORF** (every Olympus / OM body since ~2008) | measured: 66 of 78 Olympus / OM models preview-only; `orf.rs` refuses; OM bucket 3% of photographers, 3% of them fully work | +2.6 points; best gain per hour of any raw gap (~0.2) | 8–15 | [raw-parity](raw-parity.md#compressed-orf-a-clean-room-starting-point) (the two Olympus patents that describe the method) |
2424
| 7 | **Nikon High Efficiency NEF** (HE / HE★ on Z 8, Z 9, Z 6III, Z f, Z50II, Z5II when set to HE) | named and preview only (#193); needs a pure-Rust JPEG XS decoder | +1.1 points (only shots taken in HE; lossless works on the same bodies); low gain per hour (~0.04), so not a beta blocker | 20–40 | [raw-parity](raw-parity.md) |
25-
| 8 B | **No lens profile database** (LR-EDIT-OPTICS-PROFILE): only DNG opcodes, RW2 in-file distortion, Sony ILCE-7RM4A, full-frame ILCE-7CR distortion (Auto only) and ILCE-7RM6 and ILCE-6700 distortion (`docs/sony-ilce7rm6-lens-corrections.md`) and Nikon Z 6II / Z 8 / Z f distortion (`docs/nikon-lens-corrections.md`); tracked in #329 | Adobe ships 3,635 lens profiles; we never use them | distortion / vignetting correction is a default step for many | 40–80 + calibration shots | [raw-parity](raw-parity.md#lens-profiles) |
25+
| 8 B | **No lens profile database** (LR-EDIT-OPTICS-PROFILE): only DNG opcodes, RW2 in-file distortion, Sony ILCE-7RM4A, ILCE-7M3, full-frame ILCE-7CR distortion (Auto only) and ILCE-7RM6 and ILCE-6700 distortion (`docs/sony-ilce7rm6-lens-corrections.md`) and Nikon Z 6II / Z 8 / Z f distortion (`docs/nikon-lens-corrections.md`); tracked in #329 | Adobe ships 3,635 lens profiles; we never use them | distortion / vignetting correction is a default step for many | 40–80 + calibration shots | [raw-parity](raw-parity.md#lens-profiles) |
2626
| 9 B | **Tests don't run in CI on macOS or Windows, and no CI job runs the GPU equivalence tests**: the CI gate (`ci.yml`, #2667) runs `cargo xtask ci`, which includes `cargo test`, on Linux x64 for every push to `main` and every pull request; FreeBSD runs `cargo test` nightly, on pushes to `release` and on PRs that change its workflow or `packaging/freebsd/`; the macOS and Windows jobs build packages | `.github/workflows/` (ci, freebsd, packaging-lint, release, sonarcloud, windows-arm64); the gate's runner has Mesa software Vulkan drivers installed, but `Gpu::new` refuses software adapters (`crates/gpu/src/ctx.rs`), so the CPU ↔ GPU equivalence tests skip; the linux-riscv64 release job added in 0.6.0 (#844) runs only `lightcraft-cli --version` under QEMU; #1148 (open, not merged; #2667 names it superseded) has the macOS and Windows test legs and a `LIGHTCRAFT_GPU_ALLOW_SOFTWARE` opt-in that runs the GPU tests on lavapipe, Metal and WARP | a regression that only shows on macOS or Windows, or only on a GPU, reaches users; `cargo xtask ci` runs only on Linux in CI | 6–12 | [target-app-parity](target-app-parity.md#by-dimension) |
2727
| 10 B | **Per-model verification thin, plus cheap per-body decode fixes**: 557 of 1,446 Adobe models verified (39%), ~86% of photographers on a verified body; Nikon 5 bodies verified, Canon 34, Leica 14 (the Q3 by a recorded check of 38 private DNGs). Cheap fixes: Z 6II packed 14-bit NEF (#769, PR #671), Sony A100 regression (#702); F828 SRF now discovered and imported as preview-only, sensor decoding still missing, DSLR-A200…A390 / A850 12-bit ARW (#535) | measured: [raw/coverage.tsv](raw/coverage.tsv) | per-body bugs (levels, crops, WB) surface only from users | 25–45 | [raw-parity](raw-parity.md#by-maker-measured) |
2828
| 11 | **Enhance: Raw Details, Super Resolution; AI denoise without shippable weights or X-Trans** | ENH rows 0%; denoise Bayer only, RawNIND weights GPL and opt-in | Fujifilm users get no AI denoise; nobody gets it out of the box | 30–60 + model decision | [raw-parity](raw-parity.md#demosaic-levels-crops-and-lens-metadata) |

0 commit comments

Comments
 (0)