diff --git a/README.md b/README.md
index 42b164d6c64..6f872a67823 100644
--- a/README.md
+++ b/README.md
@@ -97,9 +97,9 @@ OkLCh, a modern perceptual colour space.
### β¨ Effects
-**Texture** for fine detail, **Clarity** for mid-tone punch, **Dehaze** (dark-channel prior with guided refinement;
-push it negative to add atmosphere), post-crop **Vignette** with highlight priority, roundness and feather, and
-resolution-independent film **Grain** with size and roughness.
+**Texture** for fine detail, **Clarity** for mid-tone punch, **Dehaze** (a guided dark-channel haze estimate of the
+whole frame that clears haze without darkening the photo or crushing its shadows, #1237; push it negative for a soft veil), post-crop **Vignette** with
+highlight priority, roundness and feather, and resolution-independent film **Grain** with size and roughness.
### π Tone Curve
Parametric region curve with movable splits **plus** point curves for RGB, Red, Green and Blue. Curves are monotone by
diff --git a/crates/develop/src/settings.rs b/crates/develop/src/settings.rs
index a40f094c25f..4af2d9a06f1 100644
--- a/crates/develop/src/settings.rs
+++ b/crates/develop/src/settings.rs
@@ -84,17 +84,26 @@ pub enum Process {
/// Highlights and Shadows keep the local contrast of the tones they move: their edge-aware base
/// is taken of a fine median of log luminance (issue #632).
V2,
+ /// Dehaze estimates haze from a patch-minimum dark channel, eases in, and never pushes a
+ /// pixel below a tenth of its darkest channel (issue #1237).
+ V3,
+ /// Dehaze estimates haze with a dark-channel prior on a fixed proxy of the whole frame (patch
+ /// minimum, guided refinement, colour airlight) and recovers it gently, so +25..+50 no longer
+ /// darkens the photo and crushes shadows (issue #1237). Without Dehaze it renders like V3.
+ V4,
}
impl Process {
/// Every process, oldest first.
- pub const ALL: [Process; 2] = [Process::V1, Process::V2];
- pub const LATEST: Process = Process::V2;
+ pub const ALL: [Process; 4] = [Process::V1, Process::V2, Process::V3, Process::V4];
+ pub const LATEST: Process = Process::V4;
pub const fn version(self) -> ProcessVersion {
match self {
Process::V1 => ProcessVersion(1),
Process::V2 => ProcessVersion(2),
+ Process::V3 => ProcessVersion(3),
+ Process::V4 => ProcessVersion(4),
}
}
}
diff --git a/crates/develop/src/tests_process.rs b/crates/develop/src/tests_process.rs
index f89ebfa1154..0d83942dd73 100644
--- a/crates/develop/src/tests_process.rs
+++ b/crates/develop/src/tests_process.rs
@@ -160,3 +160,25 @@ fn the_process_is_not_an_edit_nor_part_of_copied_settings() {
/// A process other than the latest: a newer LightCraft's number (no older one than V1 exists).
const LATEST_PLUS_ONE: u32 = ProcessVersion::LATEST.0 + 1;
+
+/// Issue #1237: V4 is the latest; settings saved on V2 stay V2 (outdated, not upgraded on load) and
+/// round-trip as 2, V3 settings as 3, V4 settings as 4.
+#[test]
+fn v4_is_the_latest_and_v2_settings_stay_v2() {
+ assert_eq!(Process::LATEST, Process::V4);
+ assert_eq!(Process::ALL, [Process::V1, Process::V2, Process::V3, Process::V4]);
+ assert_eq!(Process::V3.version(), ProcessVersion(3));
+ assert_eq!(Process::V4.version(), ProcessVersion(4));
+ let v2 = DevelopSettings::from_json(&json!({"process": 2, "effects": {"dehaze": 30.0}})).unwrap();
+ assert_eq!((v2.process, v2.process.process()), (ProcessVersion(2), Process::V2));
+ assert!(v2.process.is_known() && v2.process.is_outdated());
+ assert_eq!(v2.to_json()["process"], json!(2));
+ let v3 = DevelopSettings { process: Process::V3.version(), ..v2.clone() };
+ assert!(v3.process.is_known() && v3.process.is_outdated());
+ assert_eq!(DevelopSettings::from_json(&v3.to_json()).unwrap().process.process(), Process::V3);
+ let v4 = DevelopSettings { process: Process::V4.version(), ..v2.clone() };
+ assert!(v4.process.is_known() && !v4.process.is_outdated());
+ assert_eq!(DevelopSettings::from_json(&v4.to_json()).unwrap().process.process(), Process::V4);
+ assert_ne!(v4.hash64(), v2.hash64(), "another process is another preview");
+ assert_ne!(v4.hash64(), v3.hash64(), "another process is another preview");
+}
diff --git a/crates/engine/src/tests_process.rs b/crates/engine/src/tests_process.rs
index d101073ecfd..7ccf062b2ed 100644
--- a/crates/engine/src/tests_process.rs
+++ b/crates/engine/src/tests_process.rs
@@ -6,7 +6,7 @@
use std::sync::Arc;
use lightcraft_catalog::{Photo, PhotoId, Source};
-use lightcraft_develop::{DevelopSettings, ProcessVersion};
+use lightcraft_develop::{DevelopSettings, Process, ProcessVersion};
use serde_json::json;
use crate::{EngineError, Session};
@@ -262,3 +262,22 @@ fn update_to_current_process_checks_named_photos_not_the_selection() {
// `ids: null` names nothing: the selection decides (and there is none)
assert!(matches!(s.execute("develop.updateProcess", &json!({"ids": null})), Err(EngineError::Disabled(..))));
}
+
+/// Issue #1237: V4 (the new Dehaze) is the latest; photos edited on V1 and V2 move to it only with
+/// Update to Current Process, keep their sliders, and undo puts each back on its own process.
+#[test]
+fn v1_and_v2_photos_update_to_v4() {
+ assert_eq!(ProcessVersion::LATEST, Process::V4.version());
+ let mut s = Session::with_demo();
+ let ids: Vec = s.visible_cloned().into_iter().take(3).collect();
+ let (v1, v2) = (Process::V1.version(), Process::V2.version());
+ put(&mut s, ids[0], v1, 0.5);
+ put(&mut s, ids[1], v2, -0.5);
+ select(&mut s, &ids);
+ let r = s.execute("develop.updateProcess", &json!({})).unwrap();
+ assert_eq!(r, json!({"changed": 2, "process": 4}));
+ assert_eq!(ids.iter().map(|id| process(&s, *id)).collect::>(), [Process::V4.version(); 3]);
+ assert_eq!([s.develop_of(ids[0]).unwrap().light.exposure, s.develop_of(ids[1]).unwrap().light.exposure], [0.5, -0.5]);
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert_eq!([process(&s, ids[0]), process(&s, ids[1]), process(&s, ids[2])], [v1, v2, Process::V4.version()]);
+}
diff --git a/crates/gpu/src/ctx.rs b/crates/gpu/src/ctx.rs
index fb000c031e9..badab5f4626 100644
--- a/crates/gpu/src/ctx.rs
+++ b/crates/gpu/src/ctx.rs
@@ -22,6 +22,7 @@ const MODULES: &[Module] = &[
("base_p", false, "f32"),
("clar", false, "f32"),
("tex", false, "f32"),
+ // V1 / V2: the dehaze dark plane; V4: the haze map's a / b coefficients (`HAS_HAZE`)
("dark", false, "f32"),
("masks", false, "f32"),
("aux", false, "f32"),
@@ -32,7 +33,7 @@ const MODULES: &[Module] = &[
Module {
src: include_str!("wgsl/blur.wgsl"),
bindings: &[("src", false, "f32"), ("dst", true, "f32")],
- entries: &["box_h", "box_v", "median_h", "median_v"],
+ entries: &["box_h", "box_v", "median_h", "median_v", "min_h", "min_v"],
},
Module {
src: include_str!("wgsl/resize.wgsl"),
@@ -259,6 +260,24 @@ fn constants() -> String {
use lightcraft_pipeline::masks::{AUTO_TOL_CHROMA, AUTO_TOL_EV};
s += &format!("const AUTO_TOL_EV: f32 = {AUTO_TOL_EV:?};\nconst AUTO_TOL_CHROMA: f32 = {AUTO_TOL_CHROMA:?};\n");
s += &format!("const SHADOW_TINT_K: f32 = {:?};\n", lightcraft_pipeline::colorops::SHADOW_TINT);
+ {
+ use lightcraft_pipeline::haze as hz;
+ for (name, v) in [
+ ("HZ_AIR_FLOOR", hz::AIR_FLOOR),
+ ("HZ_G_MAX", hz::G_MAX),
+ ("HZ_OMEGA", hz::OMEGA),
+ ("HZ_OMEGA_POWER", hz::OMEGA_POWER),
+ ("HZ_T_FLOOR", hz::T_FLOOR),
+ ("HZ_SKY_K", hz::SKY_K),
+ ("HZ_CHROMA_KEEP", hz::CHROMA_KEEP),
+ ("HZ_VEIL", hz::VEIL),
+ ("HZ_VEIL_BASE", hz::VEIL_BASE),
+ ("HZ_VEIL_TOP", hz::VEIL_TOP),
+ ] {
+ s += &format!("const {name}: f32 = {v:?};\n");
+ }
+ s += &format!("const HZ_COMP_N: u32 = {}u;\n", hz::COMP_N);
+ }
for (i, h) in GRAIN_HASH.iter().enumerate() {
s += &format!("const GRAIN_H{i}: u32 = {h}u;\n");
}
diff --git a/crates/gpu/src/lib.rs b/crates/gpu/src/lib.rs
index 7efae6a5763..37384761ac9 100644
--- a/crates/gpu/src/lib.rs
+++ b/crates/gpu/src/lib.rs
@@ -443,6 +443,20 @@ pub fn stage_bytes(stages: &StageCache) -> usize {
}
}
+/// Process V4 haze maps a view's GPU stages (kept with its [`StageCache`]) uploaded so far: one
+/// per map, not one per render (a diagnostic); 0 when it has none.
+pub fn haze_uploads(stages: &StageCache) -> u64 {
+ #[cfg(not(target_arch = "wasm32"))]
+ {
+ stages.peek_extension::().map(|g| g.haze_uploads()).unwrap_or(0)
+ }
+ #[cfg(target_arch = "wasm32")]
+ {
+ let _ = stages;
+ 0
+ }
+}
+
/// Render `src` with `s` on the GPU, reusing the device-resident stages kept with `stages` (the
/// view's CPU stage cache). `None`: render on the CPU instead. [`try_render`] also says why.
pub fn render(src: &Arc, info: &SourceInfo, s: &DevelopSettings, req: &RenderRequest, stages: Option<&StageCache>) -> Option {
diff --git a/crates/gpu/src/params.rs b/crates/gpu/src/params.rs
index 7f9405492c4..266f284aea5 100644
--- a/crates/gpu/src/params.rs
+++ b/crates/gpu/src/params.rs
@@ -4,6 +4,7 @@
use lightcraft_develop::VignetteStyle;
use lightcraft_pipeline::colorops::POINT_WORDS;
use lightcraft_pipeline::finish::{FinishParams, MASK_TERMS, srgb_lut};
+use lightcraft_pipeline::haze::{COMP_N, HazeMap};
/// Entries per tone-curve table (`lightcraft_pipeline::finish` builds them at this size).
pub const CURVE_N: u32 = 1024;
@@ -26,12 +27,20 @@ const FIELDS: &[(&str, usize)] = &[
("CLAR", 1),
("TEX", 1),
("DEHAZE", 1),
+ ("DEHAZE_V3", 1),
("SHARPEN", 1),
("SHARPEN_MASK", 1),
("HAS_CLAR", 1),
("HAS_TEX", 1),
("HAS_DARK", 1),
("HAS_CHROMA", 1),
+ // process V4's haze map (`lightcraft_pipeline::haze`): its a / b proxy (interleaved) is bound
+ // in place of the V1 / V2 dark plane, which V4 doesn't compute
+ ("HAS_HAZE", 1),
+ ("HAZE_W", 1),
+ ("HAZE_H", 1),
+ ("HAZE_AIR", 3),
+ ("HAZE_COMP", COMP_N),
("OPS_IDENTITY", 1),
("VIBRANCE", 1),
("SATURATION", 1),
@@ -57,7 +66,8 @@ const FIELDS: &[(&str, usize)] = &[
("VIG_POWER", 1),
("VIG_HL", 1),
("VIG_STYLE", 1),
- // the window's offset in the whole output and the whole output's size (pixels)
+ // the window's offset in the whole output and the whole output's size (pixels; the vignette
+ // and V4's haze map read it)
("VIG_VIEW", 4),
("GRAIN", 1),
("GRAIN_AMT", 1),
@@ -139,8 +149,9 @@ pub struct Present {
}
/// The `finish` kernel's parameter block and auxiliary table (tone LUT | chroma curve | sRGB LUT | curve LUTs |
-/// mask terms) for `fp` with `masks` (their local adjustments' terms).
-pub fn finish_block(fp: &FinishParams, masks: &[[f32; MASK_TERMS]], present: &Present) -> (Vec, Vec) {
+/// mask terms) for `fp` with `masks` (their local adjustments' terms) and, for process V4's Dehaze,
+/// `haze`, the map whose coefficients ([`haze_coeffs`]) are bound in the `dark` slot.
+pub fn finish_block(fp: &FinishParams, masks: &[[f32; MASK_TERMS]], present: &Present, haze: Option<&HazeMap>) -> (Vec, Vec) {
let mut aux: Vec = fp.tone.lut().to_vec();
aux.extend_from_slice(fp.tone.chroma_lut());
let srgb_off = aux.len();
@@ -175,12 +186,22 @@ pub fn finish_block(fp: &FinishParams, masks: &[[f32; MASK_TERMS]], present: &Pr
p.f("CLAR", fp.clar);
p.f("TEX", fp.tex);
p.f("DEHAZE", fp.dehaze);
+ p.b("DEHAZE_V3", fp.dehaze_v3);
p.f("SHARPEN", fp.sharpen);
p.f("SHARPEN_MASK", fp.sharpen_mask);
p.b("HAS_CLAR", present.clarity);
p.b("HAS_TEX", present.texture);
p.b("HAS_DARK", present.dark);
p.b("HAS_CHROMA", present.chroma);
+ p.fs("VIG_VIEW", &fp.view);
+ if let Some(m) = haze {
+ let (w, h) = m.size();
+ p.b("HAS_HAZE", true);
+ p.u("HAZE_W", w as u32);
+ p.u("HAZE_H", h as u32);
+ p.fs("HAZE_AIR", &m.air);
+ p.fs("HAZE_COMP", &m.comp);
+ }
let ops = &fp.ops;
p.b("OPS_IDENTITY", ops.is_identity());
@@ -213,7 +234,6 @@ pub fn finish_block(fp: &FinishParams, masks: &[[f32; MASK_TERMS]], present: &Pr
p.f("VIG_ASPECT_MIX", v.aspect_mix);
p.f("VIG_POWER", v.power);
p.f("VIG_HL", v.highlights);
- p.fs("VIG_VIEW", &fp.view);
p.u(
"VIG_STYLE",
match v.style {
@@ -246,3 +266,9 @@ pub fn finish_block(fp: &FinishParams, masks: &[[f32; MASK_TERMS]], present: &Pr
}
(p.0, aux)
}
+
+/// The haze map's guided-filter coefficients, interleaved `a, b` per proxy pixel (row-major), as
+/// the `finish` kernel samples them.
+pub fn haze_coeffs(m: &HazeMap) -> Vec {
+ m.a.data.iter().zip(&m.b.data).flat_map(|(a, b)| [*a, *b]).collect()
+}
diff --git a/crates/gpu/src/render.rs b/crates/gpu/src/render.rs
index b747e0d327f..6a2bb691ea4 100644
--- a/crates/gpu/src/render.rs
+++ b/crates/gpu/src/render.rs
@@ -8,6 +8,7 @@ use lightcraft_develop::DevelopSettings;
use lightcraft_geom::Orientation;
use lightcraft_pipeline::finish::{FinishParams, MASK_TERMS, mask_terms};
use lightcraft_pipeline::geometry::SampleMode;
+use lightcraft_pipeline::haze::HazeMap;
use lightcraft_pipeline::local::plane_at;
use lightcraft_pipeline::{Plan, RenderRequest, Rendered, SourceInfo, local};
use lightcraft_raster::resample::Filter;
@@ -23,10 +24,31 @@ pub struct GpuStages {
entries: Mutex>,
/// The uploaded source (a view renders one photo at several sizes).
source: Mutex |