mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 01:18:43 +00:00
Replace Color: subtract-only samples start from the From colour (CodeRabbit follow-up on adjust_cmds.rs:418-425)
Test: replace_color_subtract_only_starts_from_the_from_colour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9b9deca07d
commit
ebcc2b5e91
2 files changed
+21
No files matched your search
@@ -444,6 +444,13 @@ fn replace_color(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
};
|
||||
if subtracted || points.len() > 1 {
|
||||
let mut q = json!({"points": p.get("points").cloned().unwrap_or(Value::Array(Vec::new())), "fuzziness": fuzz});
|
||||
// With no Add samples, the subtraction starts from the dialog's From colour, not the
|
||||
// foreground; with them, the samples alone span the range, as in Color Range.
|
||||
if points.is_empty()
|
||||
&& let Some(color) = p.get("color")
|
||||
{
|
||||
q["color"] = color.clone();
|
||||
}
|
||||
for key in ["subtractPoints", "order", "localized", "range"] {
|
||||
if let Some(v) = p.get(key) {
|
||||
q[key] = v.clone();
|
||||
|
||||
@@ -803,6 +803,20 @@ fn replace_color_adds_and_subtracts_samples_as_color_range_does() {
|
||||
|
||||
/// A malformed `subtractPoints` is refused even with one sample, where the single-colour path
|
||||
/// would otherwise ignore it (CodeRabbit review on #10443).
|
||||
/// #10443 review: with only Subtract from Sample clicks, the dialog's From colour is what the
|
||||
/// subtraction starts from, not the foreground (black here), so the red is still replaced.
|
||||
#[test]
|
||||
fn replace_color_subtract_only_starts_from_the_from_colour() {
|
||||
let (red, blue) = ([0.85, 0.1, 0.1, 1.0], [0.1, 0.15, 0.85, 1.0]);
|
||||
let mut s = session(8, "rgb");
|
||||
paint(&mut s, |x, _| if x < 16 { red } else { blue });
|
||||
let (r0, b0) = (rgba(&s, 4, 16), rgba(&s, 24, 16));
|
||||
let p = json!({"color": "#d91a1a", "hue": 120, "fuzziness": 40, "points": [], "subtractPoints": [[24, 16]]});
|
||||
s.execute("image.adjustments.replaceColor", p).unwrap();
|
||||
assert_ne!(rgba(&s, 4, 16), r0, "the From colour (red) is replaced");
|
||||
assert_eq!(rgba(&s, 24, 16), b0, "the subtracted blue is left alone");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replace_color_refuses_malformed_subtract_points() {
|
||||
let mut s = session(8, "rgb");
|
||||
|
||||
Reference in new issue
Block a user