diff --git a/crates/engine/src/cmd/actions_cmds.rs b/crates/engine/src/cmd/actions_cmds.rs index ea68d86b50..d0be63bf5e 100644 --- a/crates/engine/src/cmd/actions_cmds.rs +++ b/crates/engine/src/cmd/actions_cmds.rs @@ -137,9 +137,16 @@ pub(crate) fn recorded_params(s: &Session, id: &str, mut p: Value) -> Value { p } -/// Resolve the recorded visibility target identically in engine and shell playback. +/// Resolve the recorded visibility target identically in engine and shell playback, and drop +/// the `.atn` event a Filter Gallery step remembers for Save Actions: the command, its journal +/// entry (Last Filter), a smart filter and the step's dialog never see it. pub fn playback_params(s: &Session, id: &str, p: &Value) -> Result { let mut p = p.clone(); + if id.starts_with("filter.gallery.") + && let Some(object) = p.as_object_mut() + { + object.remove(crate::atn_cmds::RECORDED_EVENT); + } if id == "layer.setProps" && let Some(target) = p.get("_actionLayer") { diff --git a/crates/engine/src/cmd/atn_cmds.rs b/crates/engine/src/cmd/atn_cmds.rs index e52491d3fc..47f4b688fb 100644 --- a/crates/engine/src/cmd/atn_cmds.rs +++ b/crates/engine/src/cmd/atn_cmds.rs @@ -36,6 +36,7 @@ mod files; mod steps_channels; mod steps_distort; mod steps_doc; +mod steps_gallery; mod steps_image; mod steps_layer; mod steps_make; @@ -65,6 +66,7 @@ use fields::Mapped; use files::{load, save}; #[cfg(test)] use steps_doc::crop_from; +pub(crate) use steps_gallery::RECORDED_EVENT; #[cfg(test)] use steps_image::{apply_image_from, transform_to}; #[cfg(test)] diff --git a/crates/engine/src/cmd/atn_cmds/convert.rs b/crates/engine/src/cmd/atn_cmds/convert.rs index ccdbcf7348..817ef43ef1 100644 --- a/crates/engine/src/cmd/atn_cmds/convert.rs +++ b/crates/engine/src/cmd/atn_cmds/convert.rs @@ -75,7 +75,10 @@ fn convert_action(file: &AtnFile, a: &AtnAction, set: &str, unsupported: &mut Ve (None, _) => Mapped::Unsupported { harmless: false }, }; let (new_steps, enabled) = match mapped { - Mapped::Steps(s) => (s, item.enabled), + Mapped::Steps(mut s) => { + super::steps_gallery::remember_event(item, &mut s); + (s, item.enabled) + } Mapped::Unsupported { harmless } => { let label = file.item_label(item); unsupported.push(Unsupported { action: name.clone(), step: i, event: item.event.id(), name: label.clone() }); @@ -155,6 +158,12 @@ pub(super) fn export_item(id: &str, params: &Value, set: &str) -> Option Option<&'static Event> { .or_else(|| LEGACY_CODES.iter().find(|(code, _)| *code == id).and_then(|(_, name)| by_name(name))), AtnEvent::Name(_) => by_name(&id).or_else(|| NAME_ALIASES.iter().find(|(old, _)| *old == id).and_then(|(_, name)| by_name(name))), } + let find = |id: &str| EVENTS.iter().find(|e| (!e.code.is_empty() && e.code.trim_end() == id.trim_end()) || e.name == id); + find(&id).or_else(|| match item { + // An effect run from its own menu item records its id as the event (#10592). + // By 4-char code or, as newer versions record it, by string ID (`cutout`). + _ if super::steps_gallery::is_effect(item) => find("filterGallery"), + AtnEvent::Code(_) => LEGACY_CODES.iter().find(|(code, _)| *code == id).and_then(|(_, name)| find(name)), + AtnEvent::Name(_) => None, + }) } /// The event `id` exports as: the first event listing it whose converter accepts the params diff --git a/crates/engine/src/cmd/atn_cmds/steps_gallery.rs b/crates/engine/src/cmd/atn_cmds/steps_gallery.rs new file mode 100644 index 0000000000..f430ab11c0 --- /dev/null +++ b/crates/engine/src/cmd/atn_cmds/steps_gallery.rs @@ -0,0 +1,763 @@ +//! Photoshop's Filter Gallery steps (#10592): the `GEfc` event with the effect's id in `GEfk` +//! and its settings, for all 47 effects. Each maps to its `filter.gallery.` command with +//! the keys, limits and defaults Photoshop measures (`docs/atn.md`, Group A); a stack of several +//! effects stays a Photoshop step. + +use super::descriptors::{color_desc, color_hex, desc, enm, get_bool, get_enum, get_num, get_obj, jstr, trimmed}; +use super::events::pixel_target; +use super::fields::{Mapped, step}; +use super::tables::{lookup, lookup_back}; +use super::{AtnEvent, AtnItem, D, Descriptor, Map, Value, json}; +use photocraft_algo::{GalleryEffect, GalleryFilter}; + +/// One key of an effect, in recorded order. +enum G { + /// An integer clamped to `min..=max` on import, as Photoshop clamps it, and its default. + Int(&'static str, &'static str, i32, i32, i32), + /// An enumeration (Photoshop ↔ PhotoCraft values) and Photoshop's default value. An unknown + /// value keeps the step. + Enum(&'static str, &'static str, &'static [(&'static str, &'static str)], &'static str), + Bool(&'static str, &'static str, bool), + /// A colour object ↔ `#rrggbb` and Photoshop's default, which a step recorded without the + /// key loads with. A PhotoCraft step without it saves the effect's own default colour, the + /// one it plays with. + Color(&'static str, &'static str, &'static str), +} + +impl G { + fn key(&self) -> &'static str { + match self { + G::Int(k, ..) | G::Enum(k, ..) | G::Bool(k, ..) | G::Color(k, ..) => k, + } + } + + fn param(&self) -> &'static str { + match self { + G::Int(_, p, ..) | G::Enum(_, p, ..) | G::Bool(_, p, _) | G::Color(_, p, _) => p, + } + } +} + +/// The type Photoshop records an enumeration key with. Its terminology gives stroke direction +/// its own type (`strokeDirectionType`); every other gallery enumeration's type is its key (Glass +/// records `TxtT` / `TxtT`). +fn enum_type(key: &'static str) -> &'static str { + match key { + "SDir" => "StrD", + k => k, + } +} + +/// Photoshop's effect id (`GEfk`), the command, and the effect's keys in recorded order. +/// Generated from the event reference's Group A tables; Glass maps only the textures whose +/// codes the reference gives (Frosted, Canvas). +const GALLERY: &[(&str, &str, &[G])] = &[ + // Accented Edges + ( + "AccE", + "filter.gallery.accentedEdges", + &[G::Int("EdgW", "edgeWidth", 1, 14, 2), G::Int("EdgB", "edgeBrightness", 0, 50, 38), G::Int("Smth", "smoothness", 1, 15, 5)], + ), + // Angled Strokes + ( + "AngS", + "filter.gallery.angledStrokes", + &[G::Int("DrcB", "directionBalance", 0, 100, 50), G::Int("StrL", "strokeLength", 3, 50, 15), G::Int("Shrp", "sharpness", 0, 10, 3)], + ), + // Bas Relief + ( + "BsRl", + "filter.gallery.basRelief", + &[ + G::Int("Dtl ", "detail", 1, 15, 13), + G::Int("Smth", "smoothness", 1, 15, 3), + G::Enum( + "LghD", + "light", + &[ + ("LDBL", "bottomLeft"), + ("LDBR", "bottomRight"), + ("LDBt", "bottom"), + ("LDLf", "left"), + ("LDRg", "right"), + ("LDTL", "topLeft"), + ("LDTR", "topRight"), + ("LDTp", "top"), + ], + "LDBt", + ), + ], + ), + // Chalk Charcoal + ( + "ChlC", + "filter.gallery.chalkCharcoal", + &[G::Int("ChrA", "charcoalArea", 0, 20, 6), G::Int("ChlA", "chalkArea", 0, 20, 6), G::Int("StrP", "strokePressure", 0, 5, 1)], + ), + // Charcoal + ( + "Chrc", + "filter.gallery.charcoal", + &[G::Int("ChAm", "charcoalThickness", 1, 7, 1), G::Int("Dtl ", "detail", 0, 5, 5), G::Int("LgDr", "lightDarkBalance", 0, 100, 50)], + ), + // Chrome + ("Chrm", "filter.gallery.chrome", &[G::Int("Dtl ", "detail", 0, 10, 4), G::Int("Smth", "smoothness", 0, 10, 7)]), + // Colored Pencil + ( + "ClrP", + "filter.gallery.coloredPencil", + &[G::Int("Pncl", "pencilWidth", 1, 24, 4), G::Int("StrP", "strokePressure", 0, 15, 8), G::Int("PprB", "paperBrightness", 0, 50, 25)], + ), + // Conte Crayon + ( + "CntC", + "filter.gallery.conteCrayon", + &[ + G::Int("FrgL", "foregroundLevel", 1, 15, 11), + G::Int("BckL", "backgroundLevel", 1, 15, 7), + G::Enum("TxtT", "texture", &[("TxBr", "brick"), ("TxBu", "burlap"), ("TxCa", "canvas"), ("TxSt", "sandstone")], "TxCa"), + G::Int("Scln", "scaling", 50, 200, 100), + G::Int("Rlf ", "relief", 0, 50, 4), + G::Enum( + "LghD", + "light", + &[ + ("LDBL", "bottomLeft"), + ("LDBR", "bottomRight"), + ("LDBt", "bottom"), + ("LDLf", "left"), + ("LDRg", "right"), + ("LDTL", "topLeft"), + ("LDTR", "topRight"), + ("LDTp", "top"), + ], + "LDTp", + ), + G::Bool("InvT", "invert", false), + ], + ), + // Craquelure + ( + "Crql", + "filter.gallery.craquelure", + &[G::Int("CrcS", "crackSpacing", 2, 100, 15), G::Int("CrcD", "crackDepth", 0, 10, 6), G::Int("CrcB", "crackBrightness", 0, 10, 9)], + ), + // Crosshatch + ( + "Crsh", + "filter.gallery.crosshatch", + &[G::Int("StrL", "strokeLength", 3, 50, 9), G::Int("Shrp", "sharpness", 0, 20, 6), G::Int("Strg", "strength", 1, 3, 1)], + ), + // Cutout + ( + "Ct", + "filter.gallery.cutout", + &[G::Int("NmbL", "numberOfLevels", 2, 8, 4), G::Int("EdgS", "edgeSimplicity", 0, 10, 4), G::Int("EdgF", "edgeFidelity", 1, 3, 2)], + ), + // Dark Strokes + ( + "DrkS", + "filter.gallery.darkStrokes", + &[G::Int("Blnc", "balance", 0, 10, 5), G::Int("BlcI", "blackIntensity", 0, 10, 6), G::Int("WhtI", "whiteIntensity", 0, 10, 2)], + ), + // Diffuse Glow + ( + "DfsG", + "filter.gallery.diffuseGlow", + &[G::Int("Grns", "graininess", 0, 10, 6), G::Int("GlwA", "glowAmount", 0, 20, 10), G::Int("ClrA", "clearAmount", 0, 20, 15)], + ), + // Dry Brush + ("DryB", "filter.gallery.dryBrush", &[G::Int("BrsS", "brushSize", 0, 10, 2), G::Int("BrsD", "brushDetail", 0, 10, 8), G::Int("Txtr", "texture", 1, 3, 1)]), + // Film Grain + ( + "FlmG", + "filter.gallery.filmGrain", + &[G::Int("Grn ", "grain", 0, 20, 4), G::Int("HghA", "highlightArea", 0, 20, 0), G::Int("Intn", "intensity", 0, 10, 10)], + ), + // Fresco + ("Frsc", "filter.gallery.fresco", &[G::Int("BrsS", "brushSize", 0, 10, 2), G::Int("BrsD", "brushDetail", 0, 10, 8), G::Int("Txtr", "texture", 1, 3, 1)]), + // Glass + ( + "Gls", + "filter.gallery.glass", + &[ + G::Int("Dstr", "distortion", 0, 20, 5), + G::Int("Smth", "smoothness", 1, 15, 3), + G::Enum("TxtT", "texture", &[("TxFr", "frosted"), ("TxCa", "canvas")], "TxFr"), + G::Int("Scln", "scaling", 50, 200, 100), + G::Bool("InvT", "invert", false), + ], + ), + // Glowing Edges + ( + "GlwE", + "filter.gallery.glowingEdges", + &[G::Int("EdgW", "edgeWidth", 1, 14, 2), G::Int("EdgB", "edgeBrightness", 0, 20, 6), G::Int("Smth", "smoothness", 1, 15, 5)], + ), + // Graphic Pen + ( + "GraP", + "filter.gallery.graphicPen", + &[ + G::Int("StrL", "strokeLength", 1, 15, 15), + G::Int("LgDr", "lightDarkBalance", 0, 100, 50), + G::Enum("SDir", "strokeDirection", &[("SDHz", "horizontal"), ("SDLD", "leftDiagonal"), ("SDRD", "rightDiagonal"), ("SDVt", "vertical")], "SDRD"), + ], + ), + // Halftone Screen + ( + "HlfS", + "filter.gallery.halftonePattern", + &[ + G::Int("HlSz", "size", 1, 12, 1), + G::Int("Cntr", "contrast", 0, 50, 5), + G::Enum("ScrT", "patternType", &[("ScrC", "circle"), ("ScrD", "dot"), ("ScrL", "line")], "ScrD"), + ], + ), + // Ink Outlines + ( + "InkO", + "filter.gallery.inkOutlines", + &[G::Int("StrL", "strokeLength", 1, 50, 4), G::Int("DrkI", "darkIntensity", 0, 50, 20), G::Int("LghI", "lightIntensity", 0, 50, 10)], + ), + // Mosaic Tiles + ( + "MscT", + "filter.gallery.mosaicTiles", + &[G::Int("TlSz", "tileSize", 2, 100, 12), G::Int("GrtW", "groutWidth", 1, 15, 3), G::Int("LghG", "lightenGrout", 0, 10, 9)], + ), + // Neon Glow + ( + "NGlw", + "filter.gallery.neonGlow", + &[G::Int("Sz ", "glowSize", -24, 24, 5), G::Int("Brgh", "glowBrightness", 0, 50, 15), G::Color("Clr ", "glowColor", "#0000ff")], + ), + // Note Paper + ( + "NtPr", + "filter.gallery.notePaper", + &[G::Int("ImgB", "imageBalance", 0, 50, 25), G::Int("Grns", "graininess", 0, 20, 10), G::Int("Rlf ", "relief", 0, 25, 11)], + ), + // Ocean Ripple + ("OcnR", "filter.gallery.oceanRipple", &[G::Int("RplS", "rippleSize", 1, 15, 9), G::Int("RplM", "rippleMagnitude", 0, 20, 9)]), + // Paint Daubs + ( + "PntD", + "filter.gallery.paintDaubs", + &[ + G::Int("Sz ", "brushSize", 1, 50, 8), + G::Int("Shrp", "sharpness", 0, 40, 7), + G::Enum( + "BrsT", + "brushType", + &[("BrDR", "darkRough"), ("BrSm", "simple"), ("BrSp", "sparkle"), ("BrbW", "wideBlurry"), ("BrsL", "lightRough"), ("BrsW", "wideSharp")], + "BrSm", + ), + ], + ), + // Palette Knife + ( + "PltK", + "filter.gallery.paletteKnife", + &[G::Int("StrS", "strokeSize", 1, 50, 25), G::Int("StDt", "strokeDetail", 1, 3, 3), G::Int("Sftn", "softness", 0, 10, 0)], + ), + // Patchwork + ("Ptch", "filter.gallery.patchwork", &[G::Int("SqrS", "squareSize", 0, 10, 4), G::Int("Rlf ", "relief", 0, 25, 8)]), + // Photocopy + ("Phtc", "filter.gallery.photocopy", &[G::Int("Dtl ", "detail", 1, 24, 7), G::Int("Drkn", "darkness", 1, 50, 8)]), + // Plaster + ( + "Plst", + "filter.gallery.plaster", + &[ + G::Int("ImgB", "imageBalance", 0, 50, 20), + G::Int("Smth", "smoothness", 1, 15, 2), + G::Enum( + "LghP", + "light", + &[ + ("LPBL", "bottomLeft"), + ("LPBr", "bottomRight"), + ("LPBt", "bottom"), + ("LPLf", "left"), + ("LPRg", "right"), + ("LPTL", "topLeft"), + ("LPTR", "topRight"), + ("LPTp", "top"), + ], + "LPTp", + ), + ], + ), + // Plastic Wrap + ( + "PlsW", + "filter.gallery.plasticWrap", + &[G::Int("HghS", "highlightStrength", 0, 20, 15), G::Int("Dtl ", "detail", 1, 15, 9), G::Int("Smth", "smoothness", 1, 15, 7)], + ), + // Poster Edges + ( + "PstE", + "filter.gallery.posterEdges", + &[G::Int("EdgT", "edgeThickness", 0, 10, 2), G::Int("EdgI", "edgeIntensity", 0, 10, 1), G::Int("Pstr", "posterization", 0, 6, 2)], + ), + // Reticulation + ( + "Rtcl", + "filter.gallery.reticulation", + &[G::Int("Dnst", "density", 0, 50, 12), G::Int("BlcL", "foregroundLevel", 0, 50, 40), G::Int("WhtL", "backgroundLevel", 0, 50, 5)], + ), + // Rough Pastels + ( + "RghP", + "filter.gallery.roughPastels", + &[ + G::Int("StrL", "strokeLength", 0, 40, 6), + G::Int("StDt", "strokeDetail", 1, 20, 4), + G::Enum("TxtT", "texture", &[("TxBr", "brick"), ("TxBu", "burlap"), ("TxCa", "canvas"), ("TxSt", "sandstone")], "TxCa"), + G::Int("Scln", "scaling", 50, 200, 100), + G::Int("Rlf ", "relief", 0, 50, 20), + G::Enum( + "LghD", + "light", + &[ + ("LDBL", "bottomLeft"), + ("LDBR", "bottomRight"), + ("LDBt", "bottom"), + ("LDLf", "left"), + ("LDRg", "right"), + ("LDTL", "topLeft"), + ("LDTR", "topRight"), + ("LDTp", "top"), + ], + "LDBt", + ), + G::Bool("InvT", "invert", false), + ], + ), + // Smudge Stick + ( + "SmdS", + "filter.gallery.smudgeStick", + &[G::Int("StrL", "strokeLength", 0, 10, 2), G::Int("HghA", "highlightArea", 0, 20, 0), G::Int("Intn", "intensity", 0, 10, 10)], + ), + // Spatter + ("Spt", "filter.gallery.spatter", &[G::Int("SprR", "sprayRadius", 0, 25, 10), G::Int("Smth", "smoothness", 1, 15, 5)]), + // Sponge + ( + "Spng", + "filter.gallery.sponge", + &[G::Int("BrsS", "brushSize", 0, 10, 2), G::Int("Dfnt", "definition", 0, 25, 12), G::Int("Smth", "smoothness", 1, 15, 5)], + ), + // Sprayed Strokes + ( + "SprS", + "filter.gallery.sprayedStrokes", + &[ + G::Int("StrL", "strokeLength", 0, 20, 12), + G::Int("SprR", "sprayRadius", 0, 25, 7), + G::Enum("SDir", "strokeDirection", &[("SDHz", "horizontal"), ("SDLD", "leftDiagonal"), ("SDRD", "rightDiagonal"), ("SDVt", "vertical")], "SDRD"), + ], + ), + // Stained Glass + ( + "StnG", + "filter.gallery.stainedGlass", + &[G::Int("ClSz", "cellSize", 2, 50, 10), G::Int("BrdT", "borderThickness", 1, 20, 4), G::Int("LghI", "lightIntensity", 0, 10, 3)], + ), + // Stamp + ("Stmp", "filter.gallery.stamp", &[G::Int("LgDr", "lightDarkBalance", 0, 50, 25), G::Int("Smth", "smoothness", 1, 50, 5)]), + // Sumie + ( + "Smie", + "filter.gallery.sumiE", + &[G::Int("StrW", "strokeWidth", 3, 15, 10), G::Int("StrP", "strokePressure", 0, 15, 2), G::Int("Cntr", "contrast", 0, 40, 16)], + ), + // Texturizer + ( + "Txtz", + "filter.gallery.texturizer", + &[ + G::Enum("TxtT", "texture", &[("TxBr", "brick"), ("TxBu", "burlap"), ("TxCa", "canvas"), ("TxSt", "sandstone")], "TxCa"), + G::Int("Scln", "scaling", 50, 200, 100), + G::Int("Rlf ", "relief", 0, 50, 4), + G::Enum( + "LghD", + "light", + &[ + ("LDBL", "bottomLeft"), + ("LDBR", "bottomRight"), + ("LDBt", "bottom"), + ("LDLf", "left"), + ("LDRg", "right"), + ("LDTL", "topLeft"), + ("LDTR", "topRight"), + ("LDTp", "top"), + ], + "LDTp", + ), + G::Bool("InvT", "invert", false), + ], + ), + // Torn Edges + ( + "TrnE", + "filter.gallery.tornEdges", + &[G::Int("ImgB", "imageBalance", 0, 50, 25), G::Int("Smth", "smoothness", 1, 15, 11), G::Int("Cntr", "contrast", 1, 25, 17)], + ), + // Underpainting + ( + "Undr", + "filter.gallery.underpainting", + &[ + G::Int("BrsS", "brushSize", 0, 40, 6), + G::Int("TxtC", "textureCoverage", 0, 40, 16), + G::Enum("TxtT", "texture", &[("TxBr", "brick"), ("TxBu", "burlap"), ("TxCa", "canvas"), ("TxSt", "sandstone")], "TxCa"), + G::Int("Scln", "scaling", 50, 200, 100), + G::Int("Rlf ", "relief", 0, 50, 4), + G::Enum( + "LghD", + "light", + &[ + ("LDBL", "bottomLeft"), + ("LDBR", "bottomRight"), + ("LDBt", "bottom"), + ("LDLf", "left"), + ("LDRg", "right"), + ("LDTL", "topLeft"), + ("LDTR", "topRight"), + ("LDTp", "top"), + ], + "LDTp", + ), + G::Bool("InvT", "invert", false), + ], + ), + // Water Paper + ( + "WtrP", + "filter.gallery.waterPaper", + &[G::Int("FbrL", "fiberLength", 3, 50, 15), G::Int("Brgh", "brightness", 0, 100, 60), G::Int("Cntr", "contrast", 0, 100, 80)], + ), + // Watercolor + ( + "Wtrc", + "filter.gallery.watercolor", + &[G::Int("BrsD", "brushDetail", 1, 14, 9), G::Int("ShdI", "shadowIntensity", 0, 10, 1), G::Int("Txtr", "texture", 1, 3, 1)], + ), + // Grain + ( + "Grn", + "filter.gallery.grain", + &[ + G::Int("Intn", "intensity", 0, 100, 40), + G::Int("Cntr", "contrast", 0, 100, 50), + G::Enum( + "Grnt", + "grainType", + &[ + ("GrCn", "contrasty"), + ("GrSf", "soft"), + ("GrSp", "speckle"), + ("GrSr", "sprinkles"), + ("GrSt", "stippled"), + ("GrnC", "clumped"), + ("GrnE", "enlarged"), + ("GrnH", "horizontal"), + ("GrnR", "regular"), + ("GrnV", "vertical"), + ], + "GrnR", + ), + ], + ), +]; + +pub(super) const GALLERY_IDS: &[&str] = &[ + "filter.gallery.accentedEdges", + "filter.gallery.angledStrokes", + "filter.gallery.basRelief", + "filter.gallery.chalkCharcoal", + "filter.gallery.charcoal", + "filter.gallery.chrome", + "filter.gallery.coloredPencil", + "filter.gallery.conteCrayon", + "filter.gallery.craquelure", + "filter.gallery.crosshatch", + "filter.gallery.cutout", + "filter.gallery.darkStrokes", + "filter.gallery.diffuseGlow", + "filter.gallery.dryBrush", + "filter.gallery.filmGrain", + "filter.gallery.fresco", + "filter.gallery.glass", + "filter.gallery.glowingEdges", + "filter.gallery.graphicPen", + "filter.gallery.halftonePattern", + "filter.gallery.inkOutlines", + "filter.gallery.mosaicTiles", + "filter.gallery.neonGlow", + "filter.gallery.notePaper", + "filter.gallery.oceanRipple", + "filter.gallery.paintDaubs", + "filter.gallery.paletteKnife", + "filter.gallery.patchwork", + "filter.gallery.photocopy", + "filter.gallery.plaster", + "filter.gallery.plasticWrap", + "filter.gallery.posterEdges", + "filter.gallery.reticulation", + "filter.gallery.roughPastels", + "filter.gallery.smudgeStick", + "filter.gallery.spatter", + "filter.gallery.sponge", + "filter.gallery.sprayedStrokes", + "filter.gallery.stainedGlass", + "filter.gallery.stamp", + "filter.gallery.sumiE", + "filter.gallery.texturizer", + "filter.gallery.tornEdges", + "filter.gallery.underpainting", + "filter.gallery.waterPaper", + "filter.gallery.watercolor", + "filter.gallery.grain", +]; + +/// Each effect's own event by string ID, the form newer Photoshop versions record it in +/// (`docs/atn.md`, Group A). Mosaic Tiles (`MscT`) has none. +const EVENT_NAMES: &[(&str, &str)] = &[ + ("AccE", "accentedEdges"), + ("AngS", "angledStrokes"), + ("BsRl", "basRelief"), + ("ChlC", "chalkCharcoal"), + ("Chrc", "charcoal"), + ("Chrm", "chrome"), + ("ClrP", "coloredPencil"), + ("CntC", "conteCrayon"), + ("Crql", "craquelure"), + ("Crsh", "crosshatch"), + ("Ct", "cutout"), + ("DrkS", "darkStrokes"), + ("DfsG", "diffuseGlow"), + ("DryB", "dryBrush"), + ("FlmG", "filmGrain"), + ("Frsc", "fresco"), + ("Gls", "glass"), + ("GlwE", "glowingEdges"), + ("GraP", "graphicPen"), + ("HlfS", "halftoneScreen"), + ("InkO", "inkOutlines"), + ("NGlw", "neonGlow"), + ("NtPr", "notePaper"), + ("OcnR", "oceanRipple"), + ("PntD", "paintDaubs"), + ("PltK", "paletteKnife"), + ("Ptch", "patchwork"), + ("Phtc", "photocopy"), + ("Plst", "plaster"), + ("PlsW", "plasticWrap"), + ("PstE", "posterEdges"), + ("Rtcl", "reticulation"), + ("RghP", "roughPastels"), + ("SmdS", "smudgeStick"), + ("Spt", "spatter"), + ("Spng", "sponge"), + ("SprS", "sprayedStrokes"), + ("StnG", "stainedGlass"), + ("Stmp", "stamp"), + ("Smie", "sumie"), + ("Txtz", "texturizer"), + ("TrnE", "tornEdges"), + ("Undr", "underpainting"), + ("WtrP", "waterPaper"), + ("Wtrc", "watercolor"), + ("Grn", "grain"), +]; + +/// Whether `event` is a Filter Gallery effect's own event: its 4-char code, or its string ID. +/// The reference has each effect recorded as its own event too (Filter › Artistic › Cutout…), +/// carrying the same `GEfk` and settings. +pub(super) fn is_effect(event: &AtnEvent) -> bool { + effect_command(event).is_some() +} + +/// The command of the effect whose own event `event` is (`AccE` or `accentedEdges` → +/// `filter.gallery.accentedEdges`). +fn effect_command(event: &AtnEvent) -> Option<&'static str> { + let id = event.id(); + let code = match event { + AtnEvent::Code(_) => GALLERY.iter().map(|(c, _, _)| *c).find(|c| *c == id.trim_end()), + AtnEvent::Name(_) => EVENT_NAMES.iter().find(|(_, n)| *n == id).map(|(c, _)| *c), + }?; + GALLERY.iter().find(|(c, _, _)| *c == code).map(|(_, cmd, _)| *cmd) +} + +/// The hidden param a step loaded from an effect's own event carries, so it saves back as that +/// event (and panel name) rather than as a `GEfc` Filter Gallery step. Playback strips it +/// (`actions_cmds::playback_params`), so the command, the journal and smart filters never see it. +pub(crate) const RECORDED_EVENT: &str = "_atnEvent"; + +/// Remember the event of a step loaded from an effect's own event (`AccE`, `accentedEdges`). +/// A `GEfc` step carries nothing and saves as `GEfc`, as does a step made in PhotoCraft. +pub(super) fn remember_event(item: &AtnItem, steps: &mut [(String, Value)]) { + if !is_effect(&item.event) { + return; + } + let [(id, Value::Object(p))] = steps else { return }; + if effect_command(&item.event) != Some(id.as_str()) { + return; + } + let kind = match item.event { + AtnEvent::Code(_) => "code", + AtnEvent::Name(_) => "name", + }; + p.insert(RECORDED_EVENT.into(), json!({"event": item.event.id(), "eventKind": kind, "name": item.dictionary()})); +} + +/// The event and panel name a step of command `id` remembered by [`remember_event`] saves as; +/// `None` (save as `GEfc`) when it has none or it is not the own event of `id`'s effect. +pub(super) fn recorded_event(id: &str, params: &Value) -> Option<(AtnEvent, String)> { + let r = params.get(RECORDED_EVENT)?; + let event = jstr(r, "event")?; + let event = match jstr(r, "eventKind")? { + "code" => AtnEvent::Code(event.as_bytes().try_into().ok()?), + "name" => AtnEvent::name(event), + _ => return None, + }; + (effect_command(&event) == Some(id)).then(|| (event, jstr(r, "name").unwrap_or("").to_string())) +} + +/// A Filter Gallery step: the effect `GEfk` names, every key clamped or looked up, Photoshop's +/// default for what it leaves out. An unknown effect, value or key keeps the Photoshop step. +pub(super) fn gallery_from(d: &Descriptor) -> Mapped { + effect_step(d).unwrap_or(Mapped::Unsupported { harmless: false }) +} + +fn effect_step(d: &Descriptor) -> Option { + let effect = get_enum(d, "GEfk")?; + let (_, id, keys) = GALLERY.iter().find(|(code, _, _)| *code == effect)?; + let known: Vec<&str> = keys.iter().map(|k| k.key().trim_end()).chain(["GEfk"]).collect(); + if !d.items.iter().all(|(k, _)| known.contains(&trimmed(k).as_str())) { + return None; + } + let mut p = Map::new(); + for k in keys.iter() { + // Only a missing key takes Photoshop's default: a key that is there with the wrong type + // or a non-finite number keeps the step (`docs/atn.md`) rather than playing a default. + let present = d.get(k.key()).is_some(); + let v = match k { + G::Int(key, _, min, max, default) => { + Value::from(if present { get_num(d, key)?.round().clamp(f64::from(*min), f64::from(*max)) as i32 } else { *default }) + } + G::Enum(key, _, table, default) => Value::from(lookup(table, &if present { get_enum(d, key)? } else { (*default).to_string() })?), + G::Bool(key, _, default) => Value::from(if present { get_bool(d, key)? } else { *default }), + G::Color(key, _, default) => { + if present { + Value::from(color_hex(get_obj(d, key)?)?) + } else { + Value::from(*default) + } + } + }; + p.insert(k.param().into(), v); + } + Some(step(id, Value::Object(p))) +} + +/// The colour `id`'s effect plays with when the step names none (Neon Glow's glow colour), as +/// Photoshop's 0–255 components, unrounded, so the step saves the colour it plays with. +fn default_color(id: &str) -> Option { + let filter = id.strip_prefix("filter.gallery.").and_then(GalleryFilter::from_key)?; + let [r, g, b, _] = GalleryEffect::new(filter).color; + let c = |v: f32| D::Double(f64::from(v) * 255.0); + Some(desc("RGBC").with("Rd ", c(r)).with("Grn ", c(g)).with("Bl ", c(b))) +} + +/// Every key in recorded order, Photoshop's default (which is the command's) for what the step +/// leaves out. A setting the event has no key for (the Sketch effects' pinned colours, a mask +/// target), a fraction in an integer key, an integer outside its setting's range or a value +/// without a Photoshop code refuses the step. +pub(super) fn gallery_to(id: &str, p: &Value) -> Option { + let (code, _, keys) = GALLERY.iter().find(|(_, cmd, _)| *cmd == id)?; + let allowed: Vec<&str> = keys.iter().map(G::param).chain(["target", RECORDED_EVENT]).collect(); + if !pixel_target(p) || !p.as_object().is_none_or(|m| m.iter().all(|(k, v)| v.is_null() || allowed.contains(&k.as_str()))) { + return None; + } + let mut d = desc("null").with("GEfk", enm("GEft", code)); + for k in keys.iter() { + let v = p.get(k.param()).filter(|v| !v.is_null()); + let out = match k { + G::Int(_, _, min, max, default) => { + let n = v.map_or(Some(f64::from(*default)), Value::as_f64)?; + // Outside the setting's range, Photoshop would play it clamped and it would load + // back as another value (`edgeWidth` 99 as 14). + if n.fract() != 0.0 || !(f64::from(*min)..=f64::from(*max)).contains(&n) { + return None; + } + D::Integer(n as i32) + } + G::Enum(key, _, table, default) => enm(enum_type(key), v.map_or(Some(*default), |v| v.as_str().and_then(|s| lookup_back(table, s)))?), + G::Bool(_, _, default) => D::Boolean(v.map_or(Some(*default), Value::as_bool)?), + G::Color(..) => D::Descriptor(match v { + Some(v) => color_desc(v.as_str()?)?, + None => default_color(id)?, + }), + }; + d = d.with(k.key(), out); + } + Some(d) +} + +#[cfg(test)] +mod tests { + use super::*; + use photocraft_algo::GalleryParamKind; + + fn params(m: Mapped) -> (String, Value) { + match m { + Mapped::Steps(mut s) if s.len() == 1 => s.remove(0), + _ => panic!("not one step"), + } + } + + /// Every effect recorded with nothing but `GEfk` loads with Photoshop's defaults, saves + /// back, and loads again as the same step (#10592). + #[test] + fn every_gallery_effect_with_its_defaults_round_trips() { + assert_eq!(GALLERY.len(), GALLERY_IDS.len()); + for (code, id, _) in GALLERY { + assert!(GALLERY_IDS.contains(id), "{id} is not in GALLERY_IDS"); + let (got, first) = params(gallery_from(&desc("null").with("GEfk", enm("GEft", code)))); + assert_eq!(got, *id, "{code}"); + let back = gallery_to(id, &first).unwrap_or_else(|| panic!("{id} {first} does not export")); + assert_eq!(params(gallery_from(&back)), (id.to_string(), first.clone()), "{id}"); + } + } + + /// Each effect's integer limits and defaults, enumeration default and Boolean default are + /// the command's own (`GalleryFilter`'s schema), and every setting of the schema has a key. + #[test] + fn every_gallery_effect_matches_the_commands_schema() { + for (code, id, keys) in GALLERY { + let schema = GalleryFilter::from_key(id).unwrap_or_else(|| panic!("{id} has no schema")).params(); + for p in &schema { + assert!(keys.iter().any(|k| k.param() == p.key), "{id}: {} has no key", p.key); + } + for k in keys.iter() { + let kind = schema.iter().find(|p| p.key == k.param()).map(|p| &p.kind); + match (k, kind) { + (G::Int(_, param, min, max, default), Some(GalleryParamKind::Range { min: lo, max: hi, default: d })) => { + assert_eq!((*min as f32, *max as f32, *default as f32), (*lo, *hi, *d), "{id} {param}"); + } + (G::Enum(_, param, table, default), Some(GalleryParamKind::Choice(choices))) => { + assert_eq!(lookup(table, default), choices.first().copied(), "{id} {param}"); + assert!(table.iter().all(|(_, ours)| choices.contains(ours)), "{id} {param}"); + } + (G::Bool(_, param, default), Some(GalleryParamKind::Bool(d))) => assert_eq!(default, d, "{id} {param}"), + (G::Color(..), None) => {} + (k, kind) => panic!("{code} {id} {}: {kind:?}", k.param()), + } + } + } + } +} diff --git a/crates/engine/src/cmd/atn_cmds/steps_image.rs b/crates/engine/src/cmd/atn_cmds/steps_image.rs index a939178efc..149f1939fb 100644 --- a/crates/engine/src/cmd/atn_cmds/steps_image.rs +++ b/crates/engine/src/cmd/atn_cmds/steps_image.rs @@ -501,24 +501,7 @@ const REFINE_OUTPUT: &[(&str, &str)] = &[ ("selectionOutputToSelection", "selection"), ]; -/// Filter Gallery effects (`GEfc` with the effect in `GEfk`): Photoshop's effect code, the -/// command, and its fields. A stack of several effects stays unsupported. -const GALLERY: &[(&str, &str, &[F])] = &[("Spt", "filter.gallery.spatter", &[F("SprR", "sprayRadius", Kind::Long), F("Smth", "smoothness", Kind::Long)])]; - -pub(super) const GALLERY_IDS: &[&str] = &["filter.gallery.spatter"]; - -pub(super) fn gallery_from(d: &Descriptor) -> Mapped { - let Some(effect) = get_enum(d, "GEfk") else { return Mapped::Unsupported { harmless: false } }; - match GALLERY.iter().find(|(code, _, _)| *code == effect).and_then(|(_, id, fields)| Some((*id, fields_from(d, fields)?))) { - Some((id, p)) => step(id, Value::Object(p)), - None => Mapped::Unsupported { harmless: false }, - } -} - -pub(super) fn gallery_to(id: &str, p: &Value) -> Option { - let (code, _, fields) = GALLERY.iter().find(|(_, cmd, _)| *cmd == id)?; - fields_to(p, fields, desc("null").with("GEfk", enm("GEft", code))) -} +pub(super) use super::steps_gallery::{GALLERY_IDS, gallery_from, gallery_to}; /// Select and Mask as Photoshop CC 2015.5 and later record it (`smartBrushWorkspace`); the /// older Refine Edge event is [`REFINE_EDGE`], which is also what Select and Mask exports as. diff --git a/crates/engine/src/cmd/atn_cmds/tests.rs b/crates/engine/src/cmd/atn_cmds/tests.rs index a7bcb25124..cadb1e6c5a 100644 --- a/crates/engine/src/cmd/atn_cmds/tests.rs +++ b/crates/engine/src/cmd/atn_cmds/tests.rs @@ -722,6 +722,61 @@ fn every_mapped_command_exports_and_imports_back() { ("filter.distort.ripple", json!({"amount": 50, "size": "medium"})), ("filter.pixelate.crystallize", json!({"cellSize": 5})), ("filter.gallery.spatter", json!({"sprayRadius": 7, "smoothness": 15})), + ("filter.gallery.accentedEdges", json!({"edgeWidth": 14, "edgeBrightness": 50, "smoothness": 15})), + ("filter.gallery.angledStrokes", json!({"directionBalance": 100, "strokeLength": 50, "sharpness": 10})), + ("filter.gallery.basRelief", json!({"detail": 15, "smoothness": 15, "light": "bottomLeft"})), + ("filter.gallery.chalkCharcoal", json!({"charcoalArea": 20, "chalkArea": 20, "strokePressure": 5})), + ("filter.gallery.charcoal", json!({"charcoalThickness": 7, "detail": 0, "lightDarkBalance": 100})), + ("filter.gallery.chrome", json!({"detail": 10, "smoothness": 10})), + ("filter.gallery.coloredPencil", json!({"pencilWidth": 24, "strokePressure": 15, "paperBrightness": 50})), + ( + "filter.gallery.conteCrayon", + json!({"foregroundLevel": 15, "backgroundLevel": 15, "texture": "brick", "scaling": 200, "relief": 50, "light": "bottomLeft", "invert": true}), + ), + ("filter.gallery.craquelure", json!({"crackSpacing": 100, "crackDepth": 10, "crackBrightness": 10})), + ("filter.gallery.crosshatch", json!({"strokeLength": 50, "sharpness": 20, "strength": 3})), + ("filter.gallery.cutout", json!({"numberOfLevels": 8, "edgeSimplicity": 10, "edgeFidelity": 3})), + ("filter.gallery.darkStrokes", json!({"balance": 10, "blackIntensity": 10, "whiteIntensity": 10})), + ("filter.gallery.diffuseGlow", json!({"graininess": 10, "glowAmount": 20, "clearAmount": 20})), + ("filter.gallery.dryBrush", json!({"brushSize": 10, "brushDetail": 10, "texture": 3})), + ("filter.gallery.filmGrain", json!({"grain": 20, "highlightArea": 20, "intensity": 0})), + ("filter.gallery.fresco", json!({"brushSize": 10, "brushDetail": 10, "texture": 3})), + ("filter.gallery.glass", json!({"distortion": 20, "smoothness": 15, "texture": "canvas", "scaling": 200, "invert": true})), + ("filter.gallery.glowingEdges", json!({"edgeWidth": 14, "edgeBrightness": 20, "smoothness": 15})), + ("filter.gallery.graphicPen", json!({"strokeLength": 1, "lightDarkBalance": 100, "strokeDirection": "horizontal"})), + ("filter.gallery.halftonePattern", json!({"size": 12, "contrast": 50, "patternType": "circle"})), + ("filter.gallery.inkOutlines", json!({"strokeLength": 50, "darkIntensity": 50, "lightIntensity": 50})), + ("filter.gallery.mosaicTiles", json!({"tileSize": 100, "groutWidth": 15, "lightenGrout": 10})), + ("filter.gallery.neonGlow", json!({"glowSize": 24, "glowBrightness": 50, "glowColor": "#336699"})), + ("filter.gallery.notePaper", json!({"imageBalance": 50, "graininess": 20, "relief": 25})), + ("filter.gallery.oceanRipple", json!({"rippleSize": 15, "rippleMagnitude": 20})), + ("filter.gallery.paintDaubs", json!({"brushSize": 50, "sharpness": 40, "brushType": "darkRough"})), + ("filter.gallery.paletteKnife", json!({"strokeSize": 50, "strokeDetail": 1, "softness": 10})), + ("filter.gallery.patchwork", json!({"squareSize": 10, "relief": 25})), + ("filter.gallery.photocopy", json!({"detail": 24, "darkness": 50})), + ("filter.gallery.plaster", json!({"imageBalance": 50, "smoothness": 15, "light": "bottomLeft"})), + ("filter.gallery.plasticWrap", json!({"highlightStrength": 20, "detail": 15, "smoothness": 15})), + ("filter.gallery.posterEdges", json!({"edgeThickness": 10, "edgeIntensity": 10, "posterization": 6})), + ("filter.gallery.reticulation", json!({"density": 50, "foregroundLevel": 50, "backgroundLevel": 50})), + ( + "filter.gallery.roughPastels", + json!({"strokeLength": 40, "strokeDetail": 20, "texture": "brick", "scaling": 200, "relief": 50, "light": "bottomLeft", "invert": true}), + ), + ("filter.gallery.smudgeStick", json!({"strokeLength": 10, "highlightArea": 20, "intensity": 0})), + ("filter.gallery.sponge", json!({"brushSize": 10, "definition": 25, "smoothness": 15})), + ("filter.gallery.sprayedStrokes", json!({"strokeLength": 20, "sprayRadius": 25, "strokeDirection": "horizontal"})), + ("filter.gallery.stainedGlass", json!({"cellSize": 50, "borderThickness": 20, "lightIntensity": 10})), + ("filter.gallery.stamp", json!({"lightDarkBalance": 50, "smoothness": 50})), + ("filter.gallery.sumiE", json!({"strokeWidth": 15, "strokePressure": 15, "contrast": 40})), + ("filter.gallery.texturizer", json!({"texture": "brick", "scaling": 200, "relief": 50, "light": "bottomLeft", "invert": true})), + ("filter.gallery.tornEdges", json!({"imageBalance": 50, "smoothness": 15, "contrast": 25})), + ( + "filter.gallery.underpainting", + json!({"brushSize": 40, "textureCoverage": 40, "texture": "brick", "scaling": 200, "relief": 50, "light": "bottomLeft", "invert": true}), + ), + ("filter.gallery.waterPaper", json!({"fiberLength": 50, "brightness": 100, "contrast": 100})), + ("filter.gallery.watercolor", json!({"brushDetail": 14, "shadowIntensity": 10, "texture": 3})), + ("filter.gallery.grain", json!({"intensity": 100, "contrast": 100, "grainType": "contrasty"})), ( "select.refineEdge", json!({"radius": 0, "smartRadius": false, "smooth": 2, "feather": 0.5, "contrast": 15, "shiftEdge": -100, "decontaminate": false, "output": "layerMask"}), @@ -3641,6 +3696,248 @@ fn long_names_are_clipped_instead_of_copied_into_every_diagnostic() { assert!(imp.unsupported.iter().all(|u| u.action.chars().count() == MAX_NAME_CHARS)); } +/// A Filter Gallery step as Photoshop records it: `GEfc` with the effect in `GEfk`, or the +/// effect's own event carrying the same key. +fn gallery_step(event: &str, effect: &str, d: Descriptor) -> Mapped { + let d = d.with("GEfk", enm("GEft", effect)); + let event = AtnEvent::Code(event.as_bytes().try_into().unwrap()); + (events::event_for(&event).unwrap_or_else(|| panic!("{effect} is unknown")).from)(&d) +} + +fn gallery_params(m: Mapped) -> (String, Value) { + match m { + Mapped::Steps(mut s) if s.len() == 1 => s.remove(0), + _ => panic!("kept"), + } +} + +/// The Filter Gallery effects load with Photoshop's defaults for missing keys and its clamping, +/// from `GEfc` or from the effect's own event, play, and save back as `GEfc` with every key in +/// recorded order (#10592). +#[test] +fn gallery_effect_steps_load_clamp_play_and_save_back() { + let edges = desc("null").with("EdgW", D::Integer(3)).with("EdgB", D::Integer(20)).with("Smth", D::Integer(7)); + assert_eq!( + gallery_params(gallery_step("GEfc", "AccE", edges.clone())), + ("filter.gallery.accentedEdges".into(), json!({"edgeWidth": 3, "edgeBrightness": 20, "smoothness": 7})) + ); + // Run from its own menu item, the effect's id is the event. + assert_eq!(gallery_params(gallery_step("AccE", "AccE", edges.clone())).0, "filter.gallery.accentedEdges"); + // Missing keys take Photoshop's defaults; enumerations, booleans and colours map. + assert_eq!(gallery_params(gallery_step("GEfc", "BsRl", desc("null"))).1, json!({"detail": 13, "smoothness": 3, "light": "bottom"})); + let pastels = desc("null").with("TxtT", enm("TxtT", "TxBr")).with("LghD", enm("LghD", "LDTR")).with("InvT", D::Boolean(true)); + let p = gallery_params(gallery_step("GEfc", "RghP", pastels)).1; + assert_eq!((p["texture"].as_str(), p["light"].as_str(), p["invert"].as_bool()), (Some("brick"), Some("topRight"), Some(true))); + let glow = desc("null").with("Clr ", D::Descriptor(color_desc("#33cc66").unwrap())); + assert_eq!(gallery_params(gallery_step("GEfc", "NGlw", glow)).1["glowColor"], "#33cc66"); + // Out-of-range values are clamped as Photoshop clamps them. + let wide = desc("null").with("EdgW", D::Integer(99)).with("EdgB", D::Integer(-5)); + let p = gallery_params(gallery_step("GEfc", "AccE", wide)).1; + assert_eq!((p["edgeWidth"].as_i64(), p["edgeBrightness"].as_i64()), (Some(14), Some(0))); + + // Saved back as `GEfc`, with `GEfk` first and every key in recorded order. + let item = export_item("filter.gallery.accentedEdges", &json!({"edgeWidth": 3, "edgeBrightness": 20, "smoothness": 7}), "S").unwrap(); + assert_eq!(item.event.id(), "GEfc"); + let mut expected = vec![(Id::new("GEfk"), enm("GEft", "AccE"))]; + expected.extend(edges.items); + assert_eq!(item.descriptor.unwrap().items, expected); + + // They play. + let mut s = Session::new(); + s.execute("file.new", json!({"width": 24, "height": 24})).unwrap(); + s.execute("filter.render.clouds", json!({})).unwrap(); + for (code, effect) in [("AccE", "accentedEdges"), ("Ct ", "cutout"), ("Plst", "plaster")] { + let (id, p) = gallery_params(gallery_step("GEfc", code, desc("null"))); + assert_eq!(id, format!("filter.gallery.{effect}")); + s.actions.list.push(Action::new(code, vec![(id, p)])); + let played = s.execute("actions.play", json!({"action": code})).unwrap(); + assert_eq!(played["ran"], 1, "{code}: {played}"); + } +} + +/// What the effects cannot play keeps the Photoshop step: an unknown effect or value, a Glass +/// texture the reference gives no code for, a key the effect does not have (#10592). +#[test] +fn gallery_effect_steps_the_commands_cannot_play_are_kept() { + let kept = |m: Mapped| matches!(m, Mapped::Unsupported { harmless: false }); + assert!(kept(gallery_step("GEfc", "Zzzz", desc("null")))); + assert!(kept(gallery_step("GEfc", "BsRl", desc("null").with("LghD", enm("LghD", "LDCn"))))); + assert!(kept(gallery_step("GEfc", "Gls ", desc("null").with("TxtT", enm("TxtT", "TxBr"))))); + assert!(kept(gallery_step("GEfc", "AccE", desc("null").with("Rds ", D::Integer(3))))); +} + +/// What the event cannot hold refuses the step: a fraction in an integer key, the colours a +/// Sketch effect pinned, a value with no Photoshop code, a mask target (#10592). +#[test] +fn gallery_effect_steps_that_cannot_be_written_are_refused() { + for (id, params) in [ + ("filter.gallery.accentedEdges", json!({"edgeWidth": 2.5})), + ("filter.gallery.charcoal", json!({"foreground": "#000000"})), + ("filter.gallery.glass", json!({"texture": "blocks"})), + ("filter.gallery.cutout", json!({"target": "mask"})), + ] { + assert!(export_item(id, ¶ms, "S").is_none(), "{id} {params} exported"); + } + assert!(export_item("filter.gallery.glass", &json!({"texture": "frosted"}), "S").is_some()); +} + +/// An integer outside the setting's range refuses the step rather than saving a value Photoshop +/// clamps on playback and that loads back as another (`edgeWidth` 99 as 14); each end of a range +/// still saves (#10592). +#[test] +fn gallery_effect_integers_outside_the_settings_range_are_refused() { + for (id, params) in [ + ("filter.gallery.accentedEdges", json!({"edgeWidth": 99})), + ("filter.gallery.accentedEdges", json!({"edgeWidth": 0})), + ("filter.gallery.neonGlow", json!({"glowSize": -25, "glowColor": "#336699"})), + ("filter.gallery.glass", json!({"scaling": 201})), + ] { + assert!(export_item(id, ¶ms, "S").is_none(), "{id} {params} exported"); + } + for (id, params) in [ + ("filter.gallery.accentedEdges", json!({"edgeWidth": 1})), + ("filter.gallery.accentedEdges", json!({"edgeWidth": 14})), + ("filter.gallery.neonGlow", json!({"glowSize": -24, "glowColor": "#336699"})), + ("filter.gallery.glass", json!({"scaling": 200})), + ] { + assert!(export_item(id, ¶ms, "S").is_some(), "{id} {params} refused"); + } +} + +/// Neon Glow without a colour plays with the effect's default glow colour, so it saves with that +/// colour, component for component (#10592). +#[test] +fn gallery_neon_glow_without_a_colour_saves_the_colour_it_plays_with() { + let item = export_item("filter.gallery.neonGlow", &json!({"glowSize": 5}), "S").expect("refused"); + let d = item.descriptor.unwrap(); + let c = get_obj(&d, "Clr ").expect("no colour"); + assert_eq!(trimmed(&c.class_id), "RGBC"); + let neon = photocraft_algo::GalleryEffect::new(photocraft_algo::GalleryFilter::NeonGlow).color; + for (key, v) in [("Rd ", neon[0]), ("Grn ", neon[1]), ("Bl ", neon[2])] { + assert_eq!(get_num(c, key), Some(f64::from(v) * 255.0), "{key}"); + } +} + +/// Each enumeration saves with the type Photoshop's terminology gives it: stroke direction's is +/// `StrD`, not its key, and texture's is `TxtT`, as Photoshop records Glass (#10592). +#[test] +fn gallery_effect_enumerations_save_with_photoshops_type_ids() { + let enum_type = |id: &str, params: Value, key: &str| match export_item(id, ¶ms, "S").unwrap().descriptor.unwrap().get(key) { + Some(D::Enumerated { type_id, .. }) => trimmed(type_id), + other => panic!("{id} {key}: {other:?}"), + }; + assert_eq!(enum_type("filter.gallery.graphicPen", json!({}), "SDir"), "StrD"); + assert_eq!(enum_type("filter.gallery.sprayedStrokes", json!({}), "SDir"), "StrD"); + for id in ["filter.gallery.conteCrayon", "filter.gallery.glass", "filter.gallery.roughPastels", "filter.gallery.texturizer", "filter.gallery.underpainting"] + { + assert_eq!(enum_type(id, json!({}), "TxtT"), "TxtT", "{id}"); + } + assert_eq!(enum_type("filter.gallery.basRelief", json!({}), "LghD"), "LghD"); + assert_eq!(enum_type("filter.gallery.plaster", json!({}), "LghP"), "LghP"); + assert_eq!(enum_type("filter.gallery.halftonePattern", json!({}), "ScrT"), "ScrT"); + assert_eq!(enum_type("filter.gallery.paintDaubs", json!({}), "BrsT"), "BrsT"); + assert_eq!(enum_type("filter.gallery.grain", json!({}), "Grnt"), "Grnt"); +} + +/// Neon Glow recorded without `Clr ` glows in Photoshop's default colour, blue (0, 0, 255) per +/// the event reference, not PhotoCraft's own default: the step loads with that colour and saves +/// it back, loading again as the same step (#10592). +#[test] +fn gallery_neon_glow_without_a_colour_loads_photoshops_blue() { + let (id, p) = gallery_params(gallery_step("GEfc", "NGlw", desc("null"))); + assert_eq!(id, "filter.gallery.neonGlow"); + assert_eq!(p, json!({"glowSize": 5, "glowBrightness": 15, "glowColor": "#0000ff"})); + let d = export_item(&id, &p, "S").expect("refused").descriptor.unwrap(); + let c = get_obj(&d, "Clr ").expect("no colour"); + assert_eq!(trimmed(&c.class_id), "RGBC"); + assert_eq!([get_num(c, "Rd "), get_num(c, "Grn "), get_num(c, "Bl ")], [Some(0.0), Some(0.0), Some(255.0)]); + let event = AtnEvent::Code(*b"GEfc"); + let back = (events::event_for(&event).unwrap().from)(&d); + assert_eq!(gallery_params(back), (id, p)); +} + +/// An effect recorded under its own event by string ID (`cutout`, as newer versions record it) +/// maps like its 4-char code; only the effect's string IDs count as names (#10592). +#[test] +fn gallery_effects_recorded_by_string_id_map_like_their_codes() { + for (code, name, effect) in [("Ct ", "cutout", "Ct"), ("HlfS", "halftoneScreen", "HlfS"), ("Grn ", "grain", "Grn")] { + let d = desc("null").with("GEfk", enm("GEft", effect)); + let by_name = (events::event_for(&AtnEvent::name(name)).unwrap_or_else(|| panic!("{name} by name")).from)(&d); + let by_code = (events::event_for(&AtnEvent::Code(code.as_bytes().try_into().unwrap())).unwrap().from)(&d); + assert_eq!(gallery_params(by_name), gallery_params(by_code), "{name}"); + } + assert!(events::event_for(&AtnEvent::name("Ct ")).is_none()); + assert!(events::event_for(&AtnEvent::Code(*b"MscT")).is_some()); +} + +/// A step recorded as the effect's own event (by code or string ID) loads, plays and saves back +/// as that event with its panel name and descriptor unchanged; a `GEfc` step stays `GEfc` +/// (#10592). +#[test] +fn gallery_effect_steps_save_back_as_the_event_they_were_recorded_as() { + let edges = desc("null").with("GEfk", enm("GEft", "AccE")).with("EdgW", D::Integer(2)).with("EdgB", D::Integer(38)).with("Smth", D::Integer(5)); + let cutout = desc("null").with("GEfk", enm("GEft", "Ct")).with("NmbL", D::Integer(6)).with("EdgS", D::Integer(4)).with("EdgF", D::Integer(2)); + let gallery = desc("null").with("GEfk", enm("GEft", "AccE")).with("EdgW", D::Integer(3)).with("EdgB", D::Integer(20)).with("Smth", D::Integer(7)); + let source = vec![item("AccE", "Accented Edges", Some(edges)), item("cutout", "Cutout", Some(cutout)), item("GEfc", "Filter Gallery", Some(gallery))]; + let data = set_of("S", vec![("A", source.clone())]); + let mut s = Session::new(); + let loaded = s.execute("actions.load", json!({"data": data})).unwrap(); + assert_eq!(loaded["unsupported"], json!([]), "{loaded}"); + let ids: Vec<&str> = s.actions.list[0].steps.iter().map(|(id, _)| id.as_str()).collect(); + assert_eq!(ids, ["filter.gallery.accentedEdges", "filter.gallery.cutout", "filter.gallery.accentedEdges"]); + + s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); + s.execute("filter.render.clouds", json!({})).unwrap(); + s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + let played = s.execute("actions.play", json!({"action": "A"})).unwrap(); + assert_eq!(played["ran"], 3, "{played}"); + // The remembered event is for Save Actions only: playback strips it, so the journal (Last + // Filter) and the smart filters (`.pcraft` saves) never carry it. + let gallery: Vec<&Value> = s.journal.iter().filter(|(id, _)| id.starts_with("filter.gallery.")).map(|(_, p)| p).collect(); + assert_eq!(gallery.len(), 3, "{:?}", s.journal); + assert!(gallery.iter().all(|p| p.get("_atnEvent").is_none()), "{gallery:?}"); + let d = s.active().unwrap(); + let photocraft_doc::LayerContent::Smart(sm) = &d.doc.layer(d.active_layer.unwrap()).unwrap().content else { panic!("not smart") }; + assert_eq!(sm.smart_filters.len(), 3); + assert!(sm.smart_filters.iter().all(|f| f.params.get("_atnEvent").is_none()), "{:?}", sm.smart_filters); + + let saved = s.execute("actions.save", json!({"set": "S"})).unwrap(); + assert_eq!(saved["skipped"], json!([])); + let file = atn::parse(&photocraft_paint::tile::b64_decode(saved["data"].as_str().unwrap()).unwrap()).unwrap(); + let got: Vec<_> = file.actions[0].items.iter().map(|i| (i.event.clone(), i.dictionary.clone(), i.descriptor.clone())).collect(); + let want: Vec<_> = source.iter().map(|i| (i.event.clone(), i.dictionary.clone(), i.descriptor.clone())).collect(); + assert_eq!(got, want); + + // A step made in PhotoCraft keeps saving as `GEfc`, and so does a forged event param. + assert_eq!(export_item("filter.gallery.cutout", &json!({}), "S").unwrap().event, AtnEvent::Code(*b"GEfc")); + let forged = json!({"_atnEvent": {"event": "GsnB", "eventKind": "code", "name": "Gaussian Blur"}}); + assert_eq!(export_item("filter.gallery.cutout", &forged, "S").unwrap().event, AtnEvent::Code(*b"GEfc")); + // Another effect's event (stale or forged) does not relabel the step either. + for (event, kind) in [("AccE", "code"), ("accentedEdges", "name")] { + let other = json!({"_atnEvent": {"event": event, "eventKind": kind, "name": "Accented Edges"}}); + let item = export_item("filter.gallery.cutout", &other, "S").unwrap(); + assert_eq!((item.event, item.dictionary), (AtnEvent::Code(*b"GEfc"), b"Filter Gallery".to_vec()), "{event}"); + } + let own = json!({"_atnEvent": {"event": "cutout", "eventKind": "name", "name": "Cutout"}}); + assert_eq!(export_item("filter.gallery.cutout", &own, "S").unwrap().event, AtnEvent::name("cutout")); +} + +/// Only a missing key takes Photoshop's default: a key there with the wrong type or a non-finite +/// number keeps the Photoshop step instead of playing a default (#10592). +#[test] +fn gallery_effect_keys_with_the_wrong_type_keep_the_step() { + let kept = |m: Mapped| matches!(m, Mapped::Unsupported { harmless: false }); + assert!(kept(gallery_step("GEfc", "Txtz", desc("null").with("InvT", D::Integer(1))))); + assert!(kept(gallery_step("GEfc", "AccE", desc("null").with("EdgW", D::Double(f64::NAN))))); + assert!(kept(gallery_step("GEfc", "AccE", desc("null").with("EdgW", D::Double(f64::INFINITY))))); + assert!(kept(gallery_step("GEfc", "AccE", desc("null").with("EdgW", text("9"))))); + assert!(kept(gallery_step("GEfc", "BsRl", desc("null").with("LghD", D::Integer(3))))); + assert!(kept(gallery_step("GEfc", "NGlw", desc("null").with("Clr ", D::Integer(3))))); + // Missing keys still take the defaults. + assert_eq!(gallery_params(gallery_step("GEfc", "Txtz", desc("null"))).1["invert"], false); + assert_eq!(gallery_params(gallery_step("GEfc", "AccE", desc("null").with("EdgB", D::Integer(9)))).1["edgeWidth"], 2); +} + /// Photoshop's Split Channels, Merge Spot Channel, Trap and Match Color steps load as their /// commands and save back with the keys Photoshop records (#10609). #[test] diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index cc93d56e71..9155807734 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -166,6 +166,7 @@ The original reference entry retains its source date and historical totals; curr | 2026-10-31 | minor | `.atn` Group F: selection combinations, Paste Into/Outside, Fade, Link, Distribute, Define Pattern and older mask/merge events load, play and save; 127 supported event IDs, 89 unmapped reference entries; AUTO-219-2 remains partial | | 2026-10-31 | minor | `.atn` Group D: twelve Stylize/Pixelate events load, play and save; 128 supported and 89 unmapped. Supported-table columns corrected against the event registry; the original 117/101 reference entry remains historical. | | 2026-10-31 | minor | `.atn`: Split Channels (`SplC`, its recorded `documentIDs` not replayed or written), Merge Spot Channel (`MSpt`), Trap (`Trap`, `Wdth` clamped to 32767 px) and Match Color without a source (`matchColor`, `noReference`) map to `channel.split`, `channel.mergeSpot`, `image.trap` and `image.adjustments.matchColor`; a Match Color step that matches another image stays a Photoshop step (#10609) | +| 2026-10-31 | minor | `.atn`: Filter Gallery (`GEfc` with the effect in `GEfk`, or the effect's own event) maps all 47 effects to `filter.gallery.` with every key in recorded order, out-of-range values clamped and missing keys given Photoshop's defaults (was Spatter only); Glass maps the Frosted and Canvas textures (#10592) | | 2026-10-26 | minor | Embedded AI/PDF/EPS save-back retains native format and a separate source-bound display preview; original sources remain undoable. Native Adobe interoperability and standalone EPS/DCS remain unverified; no corpus floor or percentage changed. | | 2026-10-22 | minor | Embedded PSD vectors gain explicit bounded SVG editor/save-back; standalone EPS/DCS and native-format fidelity remain open. | | 2026-10-22 | minor | TIFF: flat pages up to 300,000 px a side open (was 2^30 px, about 32,768²): `codecs::TiffBands` decodes a group of rows at a time into the layer's tiles. The 117,504 × 22,464 px banner from #8456 opens in 3.3 s at 11.45 GB peak for a 10.56 GB layer; 30,000² 6.8 s / 6.43 GB → 1.1 s / 3.86 GB; 36 MP 220 → 52 ms. Layered TIFFs still decode whole (#8169) |