Develop every raw through the AI denoise by default, with a strength, cached

The learned demosaic was an option under Detail, off by default. It is
now how a Bayer raw is developed: on by default at full strength on
every device — which hardware runs it is the inference engine's choice
— and first in the Adjust panel, since it decides what every control
below is applied to.

Strength (0-100, default 100) replaces Keep grain: grain = 100 -
strength, the same luminance-only blend, so moving it is one GPU pass
and never a re-run. 0.21.0's sidecars stored grain; it is still read,
as the inverse, and never written.

With it on for every photograph, the result is now kept on disk
(denoise.md §7.1, §12): the network's output as half floats, keyed on
a SHA-256 of the file's bytes and the model, oldest first past a 5 GB
budget, beside the inference engine's cache. A reopened photograph and
an export of one already developed read it back instead of running the
network again; a damaged entry is a miss.
This commit is contained in:
2026-10-03 22:16:36 -04:00
parent ff0effbfe1
commit 2e7f14dafe
10 changed files with 397 additions and 51 deletions
+42 -20
View File
@@ -180,8 +180,8 @@ pub struct EditGraph {
/// as [`crate::learned_denoise`], captured, stored and undone with the
/// rest (FR-DEV-3c).
denoise_applied: bool,
/// How much of the removed noise's brightness to put back, 0–100.
denoise_grain: f32,
/// How strongly to denoise, 0–100; what is not taken goes back as grain.
denoise_strength: f32,
}
/// TRACES: FR-DEV-3f
@@ -239,8 +239,8 @@ impl EditGraph {
lens_profile: None,
lens_profile_applied: true,
denoise_available: false,
denoise_applied: false,
denoise_grain: 0.0,
denoise_applied: true,
denoise_strength: 100.0,
}
}
@@ -429,9 +429,9 @@ impl EditGraph {
}
/// TRACES: FR-DEV-3g
/// The grain to keep, 0–1.
/// The grain to keep, 0–1: what the strength does not take.
pub fn denoise_grain(&self) -> f32 {
self.denoise_grain / 100.0
(100.0 - self.denoise_strength) / 100.0
}
/// TRACES: FR-DEV-3
@@ -643,10 +643,12 @@ impl EditGraph {
}
});
switch
// The learned denoise first: it decides what every control below
// is applied to, so it heads the panel (docs/dev/denoise.md §7).
denoise
.into_iter()
.chain(switch)
.chain(warps)
.chain(denoise)
.chain(ops)
.chain(std::iter::once(framing))
.collect()
@@ -742,7 +744,7 @@ impl EditGraph {
denoise_available: _,
// Edits, in the state through `capabilities` like the lens switch.
denoise_applied: _,
denoise_grain: _,
denoise_strength: _,
masks,
film,
spots,
@@ -817,8 +819,12 @@ impl EditGraph {
if op == crate::learned_denoise::ID {
match param {
p if p == crate::learned_denoise::APPLY => self.denoise_applied = value != 0.0,
p if p == crate::learned_denoise::STRENGTH => {
self.denoise_strength = value.clamp(0.0, 100.0)
}
// 0.21.0's grain, the strength's inverse (see `GRAIN`).
p if p == crate::learned_denoise::GRAIN => {
self.denoise_grain = value.clamp(0.0, 100.0)
self.denoise_strength = 100.0 - value.clamp(0.0, 100.0)
}
_ => log::warn!("unknown parameter {param} on {op}; ignoring"),
}
@@ -886,7 +892,8 @@ impl EditGraph {
p if p == crate::learned_denoise::APPLY => {
Some(if self.denoise_applied { 1.0 } else { 0.0 })
}
p if p == crate::learned_denoise::GRAIN => Some(self.denoise_grain),
p if p == crate::learned_denoise::STRENGTH => Some(self.denoise_strength),
p if p == crate::learned_denoise::GRAIN => Some(100.0 - self.denoise_strength),
_ => None,
};
}
@@ -938,8 +945,8 @@ impl EditGraph {
self.set_lens_profile_applied(true);
// The learned denoise returns to off; whether it is available is the
// file's and stays.
self.denoise_applied = false;
self.denoise_grain = 0.0;
self.denoise_applied = true;
self.denoise_strength = 100.0;
}
/// Set the crop rectangle. Clamped to keep it inside the frame.
@@ -2098,23 +2105,38 @@ mod tests {
.into_iter()
.find(|c| c.id == learned_denoise::ID)
.expect("offered");
assert!(!cap.active, "off until asked for");
g.set_param(learned_denoise::ID, learned_denoise::APPLY, 1.0);
g.set_param(learned_denoise::ID, learned_denoise::GRAIN, 30.0);
assert!(g.denoise_applied());
assert!(cap.active, "on by default");
assert_eq!(g.denoise_grain(), 0.0, "at full strength");
assert_eq!(cap.id, g.capabilities()[0].id, "and first in the panel");
g.set_param(learned_denoise::ID, learned_denoise::APPLY, 0.0);
g.set_param(learned_denoise::ID, learned_denoise::STRENGTH, 70.0);
assert!(!g.denoise_applied());
assert!((g.denoise_grain() - 0.3).abs() < 1e-6);
g.reset();
assert!(!g.denoise_applied());
assert!(g.denoise_applied(), "reset is back to on");
assert_eq!(g.denoise_grain(), 0.0);
}
#[test]
fn an_edit_saved_with_grain_keeps_its_look() {
// TRACES: FR-DEV-3g
// 0.21.0 stored the grain kept rather than the strength.
use crate::learned_denoise;
let mut g = EditGraph::default_chain();
g.set_param(learned_denoise::ID, learned_denoise::GRAIN, 25.0);
assert_eq!(
g.param(learned_denoise::ID, learned_denoise::STRENGTH),
Some(75.0)
);
assert!((g.denoise_grain() - 0.25).abs() < 1e-6);
}
#[test]
fn the_learned_denoise_travels_in_the_state() {
use crate::learned_denoise;
let mut g = EditGraph::default_chain();
g.set_denoise_available(true);
g.set_param(learned_denoise::ID, learned_denoise::APPLY, 1.0);
g.set_param(learned_denoise::ID, learned_denoise::GRAIN, 40.0);
g.set_param(learned_denoise::ID, learned_denoise::STRENGTH, 60.0);
let state = g.state();
let mut h = EditGraph::default_chain();
h.set_denoise_available(true);
+16 -7
View File
@@ -18,23 +18,32 @@ use crate::{OpId, ParamId};
pub const ID: OpId = OpId("learned_denoise");
pub const APPLY: ParamId = ParamId("apply");
/// TRACES: FR-DEV-3g
/// How strongly to denoise, 0–100: 100 is the network's result as it is, and
/// lower puts the removed noise's brightness back as grain.
pub const STRENGTH: ParamId = ParamId("strength");
/// What 0.21.0 stored instead of [`STRENGTH`]: the grain kept, its inverse.
/// Still read, so an edit saved by that release keeps its look; never
/// written, and not offered as a control.
pub const GRAIN: ParamId = ParamId("grain");
/// Off by default: it costs seconds per photograph and replaces the
/// demosaic, which is the photographer's call. Grain 0 is the network's
/// result as it is.
/// On by default, at full strength: every Bayer raw is developed from the
/// learned demosaic, and the switch and the slider are there to take it back
/// or ease it off. It costs seconds per photograph the first time, while
/// the classical demosaic shows; the result is cached, so a photograph
/// reopened or exported does not pay again (docs/dev/denoise.md §7).
pub(crate) static DESCRIPTOR: LazyLock<Arc<OpDescriptor>> = LazyLock::new(|| {
Arc::new(OpDescriptor {
id: ID,
label: LocalizedKey("op.learned_denoise"),
params: vec![
ParamDescriptor::switch("apply", "param.learned_denoise.apply"),
ParamDescriptor::switch_on("apply", "param.learned_denoise.apply"),
ParamDescriptor::scalar(
"grain",
"param.learned_denoise.grain",
"strength",
"param.learned_denoise.strength",
0.0,
100.0,
0.0,
100.0,
Unit::Percent,
Scale::Linear,
0,