mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Gradient: Behind on a mask or channel is an error (#12011)
Masks, alpha channels and the Quick Mask have no transparency to paint behind, so paint.gradient in Behind changed nothing there and still reported success. It now refuses before the edit, as the issue asks where Behind has no meaning. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
9318c81283
commit
af709cbe24
2 files changed
+18
No files matched your search
@@ -66,3 +66,17 @@ fn an_unknown_mode_is_an_error_naming_it_and_paints_nothing() {
|
||||
assert_eq!(rgba_at(&s, 550)[3], 0.0, "{mode}: nothing is painted");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn behind_on_a_mask_or_channel_is_an_error_and_records_nothing() {
|
||||
let mut s = red_half();
|
||||
s.execute("layer.layerMask.revealAll", json!({})).unwrap();
|
||||
s.execute("channel.new", json!({})).unwrap();
|
||||
s.execute("select.editInQuickMaskMode", json!({"on": true})).unwrap();
|
||||
let steps = s.active().unwrap().history.entries().len();
|
||||
for target in [json!("mask"), json!("quickMask"), json!({"channel": 0})] {
|
||||
let err = drag(&mut s, json!({"mode": "behind", "target": target})).expect_err("behind on a mask or channel");
|
||||
assert!(err.to_string().contains("behind"), "{target}: {err}");
|
||||
assert_eq!(s.active().unwrap().history.entries().len(), steps, "{target}: no History step");
|
||||
}
|
||||
}
|
||||
@@ -200,6 +200,10 @@ fn gradient(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let reverse = b(p, "reverse", false);
|
||||
let opacity = opacity(p, "paint.gradient")?;
|
||||
let mode = fill_mode(p, "paint.gradient", false)?;
|
||||
// Masks and channels have no transparency to paint behind: Behind would change nothing there.
|
||||
if mode == FillMode::Behind && crate::channel_cmds::target_of(p) != crate::channel_cmds::Target::Pixels {
|
||||
return Err(EngineError::BadParams { cmd: "paint.gradient".into(), msg: "mode `behind` paints only a layer's pixels, not a mask or channel".into() });
|
||||
}
|
||||
let dither = b(p, "dither", true); // Photoshop dithers gradients by default (reduces banding).
|
||||
let layer = if p.get("layer").is_some() { Some(crate::commands::layer_param(s, p)?) } else { s.active().and_then(|st| st.active_layer) };
|
||||
s.edit(step_name(p), |doc, _| {
|
||||
|
||||
Reference in new issue
Block a user