|
1 | 1 | //! Sony's in-file lens-correction records (shading, lateral chromatic aberration, distortion): bounded decoding of |
2 | 2 | //! 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. |
4 | 4 | //! |
5 | 5 | //! Tag identity/layout: https://exiftool.org/TagNames/EXIF.html (`0x7031` to `0x7037`, signed shorts) and |
6 | 6 | //! 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 |
34 | 34 | /// TIFF field types. |
35 | 35 | const SHORT: u16 = 3; |
36 | 36 | 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. |
38 | 38 | /// 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"]; |
40 | 40 | /// Most directory entries scanned: a classic TIFF directory's largest count, also bounding a BigTIFF one. |
41 | 41 | const MAX_ENTRIES: usize = 1 << 16; |
42 | 42 | const SAMPLES: usize = 1024; |
@@ -1397,6 +1397,47 @@ mod tests { |
1397 | 1397 | } |
1398 | 1398 | } |
1399 | 1399 |
|
| 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 | + |
1400 | 1441 | #[test] |
1401 | 1442 | fn barrel_framing_and_offset_crop_keep_the_same_geometry() { |
1402 | 1443 | let crop = Rect::new(32, 20, 9504, 6336); |
@@ -1427,14 +1468,16 @@ mod tests { |
1427 | 1468 | #[test] |
1428 | 1469 | fn refuses_unvalidated_models_even_with_a_valid_table() { |
1429 | 1470 | 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 | + { |
1431 | 1474 | assert!(distortion(model, &TELE, AREA, AREA).is_none(), "{model}"); |
1432 | 1475 | } |
1433 | 1476 | } |
1434 | 1477 |
|
1435 | 1478 | #[test] |
1436 | 1479 | 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)] { |
1438 | 1481 | for (height, expected) in [(20, expected), (16, 0)] { |
1439 | 1482 | for order in [ByteOrder::Little, ByteOrder::Big] { |
1440 | 1483 | let mut raw = IfdBuilder::new(); |
|
0 commit comments