LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #1459
Brandon Thomas0a68a21e0333
diff --cc crates/raw/tests/dng.rsindex 5879e9fd8,a26a4375c..57c4917f0--- a/crates/raw/tests/dng.rs+++ b/crates/raw/tests/dng.rs@@@ -1048,27 -1048,20 +1048,45 @@@ fn cfa_pattern_is_relative_to_the_activ}}+/// Two samples a pixel are neither one colour nor RGB. A DNG with them decoded, and developing it read a third sample+/// past each pixel, a panic in release builds too (issue #1511). Such data is refused with a reason, and the demosaic+/// itself no longer reads past a pixel; one, three and four samples develop as before.+#[test]+fn two_samples_per_pixel_are_refused_not_a_panic() {+ let (w, h) = (8, 6);+ let file = |cpp: usize| {+ let mut raw = base_ifd(w, h, 16, cpp, false);+ raw.set_image(ImageData::Strips { rows_per_strip: h as u32, strips: vec![u16_bytes(&pattern(w, h, cpp, 16), ByteOrder::Little)] });+ dng(raw, ByteOrder::Little)+ };+ let err = decode(&file(2)).unwrap_err();+ assert!(matches!(err, lightcraft_raw::RawError::Unsupported(ref m) if m.contains("2 samples")), "{err}");+ for cpp in [1, 3, 4] {+ decode(&file(cpp)).unwrap().develop(Method::Bilinear).unwrap();+ }+ // a raw image built with two samples is refused when it develops+ let raw = synthetic(16, 12, None, 2);+ let err = raw.develop(Method::Ahd).unwrap_err();+ assert!(matches!(err, lightcraft_raw::RawError::Unsupported(_)), "{err}");+ // the demosaic of such data repeats the last sample instead of reading past the pixel+ let n = lightcraft_raw::Normalized { width: 2, height: 1, cpp: 2, data: vec![0.1, 0.2, 0.3, 0.4], cfa: None };+ assert_eq!(lightcraft_raw::demosaic(&n, Method::Ahd).data, vec![[0.1, 0.2, 0.2], [0.3, 0.4, 0.4]]);+}+++ /// DNGs LightCraft wrote before the writer anchored the pattern at the ActiveArea carry a bare "LightCraft" Software+ /// tag and a sensor-origin pattern; they keep that reading, while the current writer marks its files differently.+ #[test]+ fn legacy_lightcraft_dng_keeps_the_sensor_anchored_pattern() {+ let (w, h) = (20, 12);+ let build = |software: &str| {+ let mut raw = base_ifd(w, h, 16, 1, true);+ raw.set_image(ImageData::Strips { rows_per_strip: h as u32, strips: vec![u16_bytes(&pattern(w, h, 1, 16), ByteOrder::Little)] });+ raw.set(t::WHITE_LEVEL, Value::Short(vec![65535]));+ raw.set(t::ACTIVE_AREA, Value::Long(vec![1, 0, h as u32 - 1, w as u32 - 1]));+ raw.set(t::SOFTWARE, Value::Ascii(software.into()));+ decode(&dng(raw, ByteOrder::Little)).unwrap()+ };+ assert_eq!(build("LightCraft").cfa.unwrap().name(), "GRBG");+ assert_eq!(build("Adobe Photoshop Lightroom").cfa.unwrap().name(), "BGGR");+ assert_ne!(lightcraft_raw::dngwrite::SOFTWARE, "LightCraft");+ }