LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #1545: LR-RAW-DNG: preserve lens corrections in the existing DNG tone-fit proxy
aionggbb930900af94
diff --cc crates/engine/src/camera_preview.rsindex 7cd336de1,c08cb96a9..3850c2ea3--- a/crates/engine/src/camera_preview.rs+++ b/crates/engine/src/camera_preview.rs@@@ -34,10 -34,8 +34,11 @@@ use lightcraft_raw::/// 7: the sensor proxy follows the file's lens warp when the camera JPEG is lens-corrected./// 8: the bundled NIKON Z 6_2 profile./// 9: the bundled NIKON Z 8 and NIKON D5300 profiles.+/// 10: DNG tone fit for profiles with a look table and for 1024 px (Lightroom) previews.+/// 12: tone curves of low-contrast scenes (range limit 1.2, with the bright-area check for curves under 1.5, #699).+/// 10: tone-only fallback for near-black scenes with too few colour pairs (#1587).+ /// 10: DNG tone fitting uses a lens-corrected proxy when the file carries lens opcodes.-pub const LOOK_VERSION: u32 = 10;+pub const LOOK_VERSION: u32 = 12;#[derive(Clone, Debug)]pub(crate) struct CameraLook {@@@ -4304,8 -3962,29 +4308,29 @@@ mod testsassert!(plain.data.iter().all(|p| *p == [0.2; 3]));}+ /// Lens opcodes prevent mosaic binning. The DNG fit still gets a proxy, with the file's+ /// full-resolution corrections applied once rather than silently losing the tone fit.+ #[test]+ fn dng_sensor_proxy_applies_lens_opcodes_before_downsampling() {+ use lightcraft_raw::Opcode;+ let bytes = crate::tests_xmp::synthetic_dng_with(None, Default::default());+ let mut raw = lightcraft_raw::decode(&bytes).unwrap();+ raw.data = lightcraft_raw::RawData::U16(vec![4000; raw.width * raw.height]);+ raw.opcodes.list3 = vec![Opcode::FixVignetteRadial { k: [1.0, 0.0, 0.0, 0.0, 0.0], center: [0.5, 0.5] }];+ assert!(raw.develop_binned(2, SENSOR_CLIP).unwrap().is_none());+ let proxy = sensor_proxy(&raw, 2, 32).expect("a corrected CFA proxy even when binning is unavailable");+ assert_eq!((proxy.width, proxy.height), (32, 24));+ let center = proxy.data[12 * 32 + 16][1];+ let corner = proxy.data[0][1];+ assert!((1.8..2.1).contains(&(corner / center)), "one vignetting gain, not zero or two: {corner} / {center}");+ let full = raw.develop(lightcraft_raw::Method::Bilinear).unwrap();+ assert_eq!(proxy.data, full.data, "the same opcode interpretation as raw development");+ let small = sensor_proxy(&raw, 2, 16).unwrap();+ assert_eq!(small.data, fit(&full, 16, 16, Filter::Box).data, "correct first, then reduce");+ }+/// Which DNGs get a tone fitted to their camera JPEG: a colour matrix, a tone curve that is absent or the- /// identity, no look table; and no other raw format.+ /// identity, with or without a look table; and no other raw format.#[test]fn dng_tone_gates_follow_the_files_own_tags() {use lightcraft_raw::profile::{HsvTable, ToneCurve};