Skip to content
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ad7b302
LR-EDIT-EFFECTS-DEHAZE: make cargo xtask ci pass on macOS before the …
mattsivak Oct 12, 2026
e272ce6
LR-EDIT-EFFECTS-DEHAZE: honest docs, Dehaze is too strong (#1237)
mattsivak Oct 12, 2026
ca2b637
LR-EDIT-EFFECTS-DEHAZE: dehaze_report measurement example and a hazy …
mattsivak Oct 12, 2026
81ef61c
LR-EDIT-EFFECTS-DEHAZE: process V3 scaffold, the latest process
mattsivak Oct 12, 2026
34bfc39
LR-EDIT-EFFECTS-DEHAZE: V3 haze map on a fixed whole-frame proxy (CPU)
mattsivak Oct 12, 2026
0f6c30c
LR-EDIT-EFFECTS-DEHAZE: V3 per-pixel dehaze on the CPU
mattsivak Oct 12, 2026
a8bc671
LR-EDIT-EFFECTS-DEHAZE: V3 dehaze on the GPU
mattsivak Oct 12, 2026
c29eb5b
LR-EDIT-EFFECTS-DEHAZE: haze map cache, draft reuse, GPU upload once,…
mattsivak Oct 12, 2026
6b7b686
LR-EDIT-EFFECTS-DEHAZE: process V3 dehaze (patch dark channel, eased …
emmertex Oct 12, 2026
0afac1b
LR-EDIT-EFFECTS-DEHAZE: tune V3 Dehaze, gentler veil, no horizon band…
mattsivak Oct 12, 2026
8c14ff8
LR-EDIT-EFFECTS-DEHAZE: the airlight skips the sun and takes the haze…
mattsivak Oct 12, 2026
103b7ca
LR-EDIT-EFFECTS-DEHAZE: one shared transpose, per-thread min-filter s…
mattsivak Oct 12, 2026
387cb5c
LR-EDIT-EFFECTS-DEHAZE: leaner haze API, separable map sampling, per-…
mattsivak Oct 12, 2026
401453e
LR-EDIT-EFFECTS-DEHAZE: the linear-image keys don't carry the process
mattsivak Oct 12, 2026
58c463a
LR-EDIT-EFFECTS-DEHAZE: skip the non-UTF-8 folder test only when the …
mattsivak Oct 12, 2026
c4cda96
LR-EDIT-EFFECTS-DEHAZE: one set of Dehaze measurement helpers for the…
mattsivak Oct 12, 2026
62acd27
Merge upstream/main into fix/1237-dehaze-v3
emmertex Oct 13, 2026
c77afaf
LR-EDIT-EFFECTS-DEHAZE: raise the V3 transmission floor to 0.3 so +10…
emmertex Oct 13, 2026
7dff190
Merge #1283 (emmertex/fix/1237-dehaze-v3 @ c77afafd) into dehaze-v3
mattsivak Oct 19, 2026
d12b1ce
Merge main into dehaze-v3
mattsivak Oct 19, 2026
ae403b4
LR-EDIT-EFFECTS-DEHAZE: adapt to main: the kept-airlight-proxy test s…
mattsivak Oct 19, 2026
8a3005e
LR-EDIT-EFFECTS-DEHAZE: keep haze maps when trimming stage caches, ro…
mattsivak Oct 19, 2026
a5e378d
Merge main into dehaze-v3 (conflicts resolved)
mattsivak Oct 21, 2026
7988b8b
LR-EDIT-EFFECTS-DEHAZE: V4 Dehaze a row at a time, about twice as fast
mattsivak Oct 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ OkLCh, a modern perceptual colour space.
<td width="50%" valign="top">

### ✨ 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
Expand Down
13 changes: 11 additions & 2 deletions crates/develop/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions crates/develop/src/tests_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
21 changes: 20 additions & 1 deletion crates/engine/src/tests_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<PhotoId> = 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::<Vec<_>>(), [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()]);
}
21 changes: 20 additions & 1 deletion crates/gpu/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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");
}
Expand Down
14 changes: 14 additions & 0 deletions crates/gpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,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::<GpuStages>().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<Rgb32f>, info: &SourceInfo, s: &DevelopSettings, req: &RenderRequest, stages: Option<&StageCache>) -> Option<Rendered> {
Expand Down
34 changes: 30 additions & 4 deletions crates/gpu/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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<u32>, Vec<f32>) {
/// 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<u32>, Vec<f32>) {
let mut aux: Vec<f32> = fp.tone.lut().to_vec();
aux.extend_from_slice(fp.tone.chroma_lut());
let srgb_off = aux.len();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<f32> {
m.a.data.iter().zip(&m.b.data).flat_map(|(a, b)| [*a, *b]).collect()
}
Loading
Loading