LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #1258: Ignore hidden and empty masks when choosing develop planes.
aionggb1c4cb7df94c
diff --cc crates/pipeline/src/local.rsindex 679acabfe,c0eb7f1fd..451b694d8--- a/crates/pipeline/src/local.rs+++ b/crates/pipeline/src/local.rs@@@ -659,53 -604,46 +663,76 @@@ mod testsassert!((luminance_2020(c) - 0.3).abs() < 0.01);}+ // A windowed render's airlight proxy is kept per (source, frame, size): the airlight is the one sampling anew gives,+ // and another source or frame of the same size gets its own, never the proxy kept for the last one+ #[test]+ fn the_kept_airlight_proxy_matches_a_fresh_one_and_misses_on_another_source_or_frame() {+ let (info, s) = (SourceInfo::default(), DevelopSettings::default());+ let hazy = Rgb32f::from_fn(300, 200, |x, y| {+ let v = 0.05 + 0.6 * x as f32 / 300.0;+ [v, v * 0.95, v * (0.8 + 0.2 * y as f32 / 200.0)]+ });+ let other = Rgb32f::from_fn(300, 200, |x, y| [0.02 + 0.1 * ((x + y) % 7) as f32 / 7.0; 3]);+ let fresh = |src: &Rgb32f, frame: &Frame| {+ let mut img = frame.sample(src, 48, 32);+ white_balance(&mut img, &info, &s);+ airlight(&gaussian(&img.map(dark_of), (0.02 * frame.px_per_long(48)).max(1.0) as f32))+ };+ let frame = crate::frame_for(&hazy, &info, &s, true);+ let kept = frame_proxy(&hazy, &frame, 48, 32);+ assert!(Arc::ptr_eq(&kept, &frame_proxy(&hazy, &frame, 48, 32)), "the second ask is served from the cache");+ assert_eq!(frame_airlight(&hazy, &info, &s, &frame, 48, 32).to_bits(), fresh(&hazy, &frame).to_bits());+ assert_eq!(frame_airlight(&hazy, &info, &s, &frame, 48, 32).to_bits(), fresh(&hazy, &frame).to_bits());+ // another source of the same size+ assert_ne!(fresh(&other, &frame), fresh(&hazy, &frame));+ assert_eq!(frame_airlight(&other, &info, &s, &frame, 48, 32).to_bits(), fresh(&other, &frame).to_bits());+ // the same source, cropped to its darker half+ let mut cropped = frame.clone();+ cropped.crop.rect.x1 = 0.5;+ assert_ne!(fresh(&hazy, &cropped), fresh(&hazy, &frame));+ assert_eq!(frame_airlight(&hazy, &info, &s, &cropped, 48, 32).to_bits(), fresh(&hazy, &cropped).to_bits());+ }+#[test]- fn exposure_doubles() {+ fn a_hidden_or_empty_mask_does_not_request_the_tone_base() {+ use lightcraft_develop::{Mask, MaskComponent, MaskOp, MaskShape};+ use lightcraft_geom::Point;+ let shape = MaskShape::Linear { start: Point::new(0.0, 0.0), end: Point::new(1.0, 0.0) };+ let component = MaskComponent { name: None, op: MaskOp::Add, invert: false, shape };let mut s = DevelopSettings::default();- s.light.exposure = 1.0;- let mut img = Rgb32f::filled(2, 2, [0.1, 0.2, 0.3]);- scene_linear_pre(&mut img, &SourceInfo::default(), &s);- assert!((img.get(1, 1)[2] - 0.6).abs() < 1e-5);+ s.masks.push(Mask {+ visible: false,+ components: vec![component],+ adjust: lightcraft_develop::LocalAdjustments { highlights: 40.0, ..Default::default() },+ ..Default::default()+ });+ assert!(plane_sigmas(&s, 2000.0, Quality::Full).base.is_none());+ s.masks[0].visible = true;+ s.masks[0].components.clear();+ assert!(plane_sigmas(&s, 2000.0, Quality::Full).base.is_none());+ s.masks[0].components.push(MaskComponent {+ name: None,+ op: MaskOp::Add,+ invert: false,+ shape: MaskShape::Linear { start: Point::new(0.0, 0.0), end: Point::new(1.0, 0.0) },+ });+ assert!(plane_sigmas(&s, 2000.0, Quality::Full).base.is_some());}- }-- #[cfg(test)]- mod fast_tests {- use super::*;#[test]- fn fast_guided_close_to_reference() {- let p = Plane::from_fn(160, 120, |x, y| ((x as f32 * 0.13).sin() + (y as f32 * 0.07).cos()) * 2.0 + if x > 80 { 1.5 } else { 0.0 });+ fn nr_contrast_keeps_fine_texture() {+ let src = Rgb32f::from_fn(48, 16, |x, y| {+ let n = if (x + y) % 2 == 0 { 0.12 } else { -0.12 };+ [0.3 + n; 3]+ });+ let mut flat = DevelopSettings::default();+ flat.detail.nr_luminance = 100.0;+ let mut held = flat.clone();+ held.detail.nr_contrast = 100.0;+ let mut a = src.clone();+ let mut b = src.clone();+ denoise(&mut a, &flat, 48, 48);+ denoise(&mut b, &held, 48, + if x > 80 { 1.5 } else { 0.0 });let a = guided(&p, 12.0, 0.3);let b = guided_fast(&p, 12.0, 0.3);let err: f32 = a.data.iter().zip(&b.data).map(|(u, v)| (u - v).abs()).sum::<f32>() / a.len() as f32;