Give the tone curve a curve for each colour channel
The declaration in ops/tone_curve.yaml has claimed per-channel curves since it was written — it is the justification for the operation carrying both `tone` and `colour`. Only the master curve existed. This is the other three. The master runs first and the channels grade its result. Both orders are real images and they differ visibly, so the choice is made and written down rather than left to the loop: a point placed on the blue curve should act on the tone the photographer can see, which is what the master has already produced. The other order anchors the grade to tones the master is about to move, so adjusting contrast slides a warm shadow up into the midtones. Every id that existed before today is spelled exactly as it was. The master curve keeps `p2_y` and the new curves take `r_`, `g_` and `b_` prefixes, so a sidecar written when there was one curve loads, means what it meant, and renders the same shader — asserted on the generated source, not on the parameter values. Nothing needed a version check because nothing was renamed. Each curve reaches the shader only when it has been moved off the diagonal, so an S-curve and no colour work generates what it generated when this operation held ten parameters instead of forty, down to the uniform names. The monotonicity guarantee is enforced per curve: a coincident pair on blue divides by zero exactly as thoroughly as one on the master. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1004,7 +1004,7 @@ impl std::error::Error for ParseError {}
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::framing;
|
||||
use crate::ops::{exposure, saturation, white_balance};
|
||||
use crate::ops::{curve, exposure, saturation, white_balance};
|
||||
|
||||
fn edited() -> EditGraph {
|
||||
let mut g = EditGraph::default_chain();
|
||||
@@ -1189,6 +1189,90 @@ mod tests {
|
||||
assert_eq!(once, twice);
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3 | FR-CAT-8
|
||||
/// A file written before the tone curve had per-channel curves.
|
||||
///
|
||||
/// Spelled out as literal text rather than produced by `to_text`, because
|
||||
/// the claim is about *those bytes*: a sidecar generated by this build
|
||||
/// would agree with this build by construction, and would go on agreeing
|
||||
/// with it through a rename that broke every file on disk.
|
||||
#[test]
|
||||
fn a_sidecar_from_before_the_channel_curves_still_names_the_master() {
|
||||
let text = "drsc 1\n\n[version u1]\nname = Default\nrevision = 4\nmodified = 9\n\
|
||||
tone_curve.p1_y = 0.15\ntone_curve.p3_y = 0.85\n";
|
||||
let parsed = Sidecar::parse(text).expect("valid");
|
||||
let mut g = EditGraph::default_chain();
|
||||
parsed.default_version().expect("a version").apply(&mut g);
|
||||
|
||||
// The S-curve the file describes, on the master curve and nowhere
|
||||
// else.
|
||||
assert_eq!(g.param(curve::ID, curve::P1_Y), Some(0.15));
|
||||
assert_eq!(g.param(curve::ID, curve::P3_Y), Some(0.85));
|
||||
for channel in [curve::Channel::Red, curve::Channel::Green, curve::Channel::Blue] {
|
||||
for point in 0..curve::POINTS {
|
||||
for axis in [curve::Axis::X, curve::Axis::Y] {
|
||||
let id = curve::coordinate(channel, point, axis);
|
||||
let expected = g
|
||||
.capabilities()
|
||||
.iter()
|
||||
.find(|c| c.id == curve::ID)
|
||||
.and_then(|c| c.params.iter().find(|p| p.id == id))
|
||||
.map(|p| p.default);
|
||||
assert_eq!(
|
||||
g.param(curve::ID, id),
|
||||
expected,
|
||||
"{id} moved, and no line in the file mentions it"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// And writing it back produces the same two lines: the curves the file
|
||||
// never mentioned are still at their defaults, so they are still
|
||||
// absent (`only_non_default_values_are_written`).
|
||||
let written = Sidecar::parse(&Sidecar::parse(text).expect("valid").to_text())
|
||||
.expect("valid")
|
||||
.to_text();
|
||||
assert!(written.contains("tone_curve.p1_y = 0.15"), "{written}");
|
||||
assert!(written.contains("tone_curve.p3_y = 0.85"), "{written}");
|
||||
assert!(
|
||||
!written.contains("tone_curve.r_"),
|
||||
"an untouched channel curve was written out:\n{written}"
|
||||
);
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3
|
||||
/// The other direction: the new curves persist like any other parameter.
|
||||
#[test]
|
||||
fn a_per_channel_curve_survives_the_round_trip() {
|
||||
let mut g = EditGraph::default_chain();
|
||||
// A faded shadow: blue lifted at the black point, red pulled down.
|
||||
let blue = curve::coordinate(curve::Channel::Blue, 0, curve::Axis::Y);
|
||||
let red = curve::coordinate(curve::Channel::Red, 4, curve::Axis::Y);
|
||||
g.set_param(curve::ID, blue, 0.08);
|
||||
g.set_param(curve::ID, red, 0.92);
|
||||
g.set_param(curve::ID, curve::P2_Y, 0.55);
|
||||
|
||||
let mut sidecar = Sidecar::new();
|
||||
sidecar.put(version_of(&g));
|
||||
let text = sidecar.to_text();
|
||||
// Keyed by the channel-prefixed id, which is what makes the master's
|
||||
// unprefixed ones safe to leave alone.
|
||||
assert!(text.contains("tone_curve.b_p0_y = 0.08"), "{text}");
|
||||
|
||||
let parsed = Sidecar::parse(&text).expect("valid");
|
||||
let mut restored = EditGraph::default_chain();
|
||||
parsed
|
||||
.default_version()
|
||||
.expect("a version")
|
||||
.apply(&mut restored);
|
||||
|
||||
assert_eq!(restored.param(curve::ID, blue), Some(0.08));
|
||||
assert_eq!(restored.param(curve::ID, red), Some(0.92));
|
||||
assert_eq!(restored.param(curve::ID, curve::P2_Y), Some(0.55));
|
||||
assert!(!restored.is_neutral());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unknown_operation_survives_a_round_trip() {
|
||||
// The data-loss case that matters: a device running an older build
|
||||
|
||||
Reference in New Issue
Block a user