mirror of
https://github.com/storytold/photocraft.git
synced 2026-10-14 19:26:51 -04:00
uses_colours() derived from the params notation, but Colored Pencil (paper tint from the background) and Neon Glow (foreground mixed over background) read the colours in their pixel code without listing them. The single-filter commands therefore skipped colour injection and both filters always ran with the default white/black regardless of the session colours, while filter.filterGallery honoured them. Add the two filters to uses_colours() at the source, so the command injection, the gallery dialog note, and smart-filter re-renders all agree. Adds regression tests: filter.gallery.coloredPencil and filter.gallery.neonGlow output must change with the session background (both identical on main). Co-authored-by: Brandon Fenty <[email protected]>
This commit is contained in:
1 parent
f15fb4ee6e
commit
080f2c4c8d
2 files changed
+38
-2
No files matched your search
@@ -147,9 +147,12 @@ impl GalleryFilter {
|
||||
out
|
||||
}
|
||||
|
||||
/// Whether the filter reads the foreground / background colours.
|
||||
/// Whether the filter reads the foreground / background colours. Derived
|
||||
/// from the params notation, plus the filters whose pixel code reads the
|
||||
/// colours without listing them (issue #709): Colored Pencil uses the
|
||||
/// background as paper tint, Neon Glow mixes foreground over background.
|
||||
pub fn uses_colours(self) -> bool {
|
||||
self.params_doc().contains("\"foreground\"") || self.params_doc().contains("\"background\"")
|
||||
matches!(self, Self::ColoredPencil | Self::NeonGlow) || self.params_doc().contains("\"foreground\"") || self.params_doc().contains("\"background\"")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
//! Regression tests for issue #709: the single-filter gallery commands must
|
||||
//! record the session foreground/background colours for every filter that
|
||||
//! reads them. Colored Pencil (background) and Neon Glow (both) read the
|
||||
//! colours in their pixel code but omit them from their params notation, so
|
||||
//! the injection was skipped and they always ran with the defaults.
|
||||
use photocraft_engine::Session;
|
||||
use serde_json::json;
|
||||
|
||||
fn px(s: &mut Session, x: i32, y: i32) -> Vec<f32> {
|
||||
serde_json::from_value(s.execute("document.pixel", json!({"x": x, "y": y})).unwrap()).unwrap()
|
||||
}
|
||||
|
||||
fn image(s: &mut Session) -> Vec<f32> {
|
||||
(0..16).flat_map(|y| (0..16).map(move |x| (x, y))).flat_map(|(x, y)| px(s, x, y)).collect()
|
||||
}
|
||||
|
||||
fn one(filter: &str, bg: &str) -> Vec<f32> {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width": 16, "height": 16, "background": "#808080"})).unwrap();
|
||||
s.execute("tools.setColors", json!({"background": bg})).unwrap();
|
||||
s.execute(&format!("filter.gallery.{filter}"), json!({})).unwrap();
|
||||
image(&mut s)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn colored_pencil_honours_session_background() {
|
||||
assert_ne!(one("coloredPencil", "#ffffff"), one("coloredPencil", "#0000ff"), "filter.gallery.coloredPencil must honour the session background");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn neon_glow_honours_session_background() {
|
||||
assert_ne!(one("neonGlow", "#ffffff"), one("neonGlow", "#0000ff"), "filter.gallery.neonGlow must honour the session background");
|
||||
}
|
||||
Reference in new issue
Block a user