Carry the learned denoise's switch and grain as edit settings
Whether to use the learned denoise, and how much grain to keep, are what a photographer sets, so they travel the one road every setting does: published as a capability, captured by Preset, stored in the sidecar, replayed by the undo stack (FR-DEV-3c). Published only on a photograph that can take it, for the lens switch's reason; the availability is derived from the file and is not in the state. Off by default, grain 0; a reset returns both.
This commit is contained in:
@@ -170,6 +170,18 @@ pub struct EditGraph {
|
||||
/// correction the photograph asked for — see
|
||||
/// [`crate::descriptor::ParamDescriptor::switch_on`].
|
||||
lens_profile_applied: bool,
|
||||
/// TRACES: FR-DEV-3g
|
||||
/// Whether this photograph can take the learned denoise — a Bayer
|
||||
/// mosaic — set by whoever opened it. Derived from the file like the
|
||||
/// lens profile, so not in the state; it only decides whether the
|
||||
/// switch below is offered.
|
||||
denoise_available: bool,
|
||||
/// Whether the learned denoise replaces the demosaic. An edit: published
|
||||
/// 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,
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3f
|
||||
@@ -226,6 +238,9 @@ impl EditGraph {
|
||||
],
|
||||
lens_profile: None,
|
||||
lens_profile_applied: true,
|
||||
denoise_available: false,
|
||||
denoise_applied: false,
|
||||
denoise_grain: 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,6 +414,26 @@ impl EditGraph {
|
||||
self.lens_profile.as_ref()
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3g
|
||||
/// Offer the learned denoise, or not: true for a Bayer mosaic.
|
||||
pub fn set_denoise_available(&mut self, available: bool) {
|
||||
self.denoise_available = available;
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3g
|
||||
/// Whether the learned denoise is asked for. A setting kept on a
|
||||
/// photograph that cannot take it is harmless and does nothing, as a
|
||||
/// lens switch with no profile does.
|
||||
pub fn denoise_applied(&self) -> bool {
|
||||
self.denoise_applied
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3g
|
||||
/// The grain to keep, 0–1.
|
||||
pub fn denoise_grain(&self) -> f32 {
|
||||
self.denoise_grain / 100.0
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3
|
||||
/// Whether the matched profile is being applied.
|
||||
pub fn lens_profile_applied(&self) -> bool {
|
||||
@@ -581,9 +616,37 @@ impl EditGraph {
|
||||
}
|
||||
});
|
||||
|
||||
// TRACES: FR-DEV-3g
|
||||
// Offered only where the photograph can take it, for the lens
|
||||
// switch's reason: a control that can do nothing must not look as if
|
||||
// it could.
|
||||
let denoise = self.denoise_available.then(|| {
|
||||
let desc = crate::learned_denoise::descriptor();
|
||||
OpCapability {
|
||||
id: desc.id,
|
||||
label: desc.label,
|
||||
active: self.denoise_applied,
|
||||
params: desc
|
||||
.params
|
||||
.iter()
|
||||
.map(|p| ParamCapability {
|
||||
id: p.id,
|
||||
label: p.label,
|
||||
kind: p.kind.clone(),
|
||||
default: p.default,
|
||||
value: self.param(desc.id, p.id).unwrap_or(p.default),
|
||||
facet: p.facet,
|
||||
})
|
||||
.collect(),
|
||||
presentation: None,
|
||||
attributes: desc.attributes.clone(),
|
||||
}
|
||||
});
|
||||
|
||||
switch
|
||||
.into_iter()
|
||||
.chain(warps)
|
||||
.chain(denoise)
|
||||
.chain(ops)
|
||||
.chain(std::iter::once(framing))
|
||||
.collect()
|
||||
@@ -675,6 +738,11 @@ impl EditGraph {
|
||||
// `capabilities`, with the operations and the warps and for the
|
||||
// same reason (FR-DEV-3c).
|
||||
lens_profile_applied: _,
|
||||
// Derived from the file, like the profile above.
|
||||
denoise_available: _,
|
||||
// Edits, in the state through `capabilities` like the lens switch.
|
||||
denoise_applied: _,
|
||||
denoise_grain: _,
|
||||
masks,
|
||||
film,
|
||||
spots,
|
||||
@@ -746,6 +814,16 @@ impl EditGraph {
|
||||
}
|
||||
|
||||
pub fn set_param(&mut self, op: OpId, param: ParamId, value: f32) {
|
||||
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::GRAIN => {
|
||||
self.denoise_grain = value.clamp(0.0, 100.0)
|
||||
}
|
||||
_ => log::warn!("unknown parameter {param} on {op}; ignoring"),
|
||||
}
|
||||
return;
|
||||
}
|
||||
if op == crate::lens::profile_switch::ID {
|
||||
if param != crate::lens::profile_switch::APPLY {
|
||||
log::warn!("unknown parameter {param} on {op}; ignoring");
|
||||
@@ -803,6 +881,15 @@ impl EditGraph {
|
||||
|
||||
/// Read a parameter back.
|
||||
pub fn param(&self, op: OpId, param: ParamId) -> Option<f32> {
|
||||
if op == crate::learned_denoise::ID {
|
||||
return match param {
|
||||
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),
|
||||
_ => None,
|
||||
};
|
||||
}
|
||||
if op == crate::lens::profile_switch::ID {
|
||||
return (param == crate::lens::profile_switch::APPLY)
|
||||
.then_some(if self.lens_profile_applied { 1.0 } else { 0.0 });
|
||||
@@ -849,6 +936,10 @@ impl EditGraph {
|
||||
// a reset does not change which lens took the photograph. What returns
|
||||
// to default is the answer to whether to use it, which is on.
|
||||
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;
|
||||
}
|
||||
|
||||
/// Set the crop rectangle. Clamped to keep it inside the frame.
|
||||
@@ -1995,4 +2086,40 @@ mod tests {
|
||||
let after = cropped.render_scale(source, (1500, 1000));
|
||||
assert!(after.ratio() > fit.ratio());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_learned_denoise_is_offered_only_where_it_can_run() {
|
||||
use crate::learned_denoise;
|
||||
let mut g = EditGraph::default_chain();
|
||||
assert!(!g.capabilities().iter().any(|c| c.id == learned_denoise::ID));
|
||||
g.set_denoise_available(true);
|
||||
let cap = g
|
||||
.capabilities()
|
||||
.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!((g.denoise_grain() - 0.3).abs() < 1e-6);
|
||||
g.reset();
|
||||
assert!(!g.denoise_applied());
|
||||
assert_eq!(g.denoise_grain(), 0.0);
|
||||
}
|
||||
|
||||
#[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);
|
||||
let state = g.state();
|
||||
let mut h = EditGraph::default_chain();
|
||||
h.set_denoise_available(true);
|
||||
let _ = h.set_state(&state);
|
||||
assert!(h.denoise_applied());
|
||||
assert!((h.denoise_grain() - 0.4).abs() < 1e-6);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user