mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 01:18:43 +00:00
Start Stylize and Pixelate ATN adapters with parameterless events
This commit is contained in:
1 parent
47287016d3
commit
7906cd8bc2
5 files changed
+69
No files matched your search
@@ -36,6 +36,7 @@ mod steps_doc;
|
||||
mod steps_image;
|
||||
mod steps_layer;
|
||||
mod steps_make;
|
||||
mod steps_stylize;
|
||||
mod tables;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -145,3 +146,6 @@ mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod layer_props_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod stylize_tests;
|
||||
@@ -52,6 +52,19 @@ macro_rules! ev {
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! stylize_event {
|
||||
($code:literal, $name:literal, $label:literal, $id:literal) => {
|
||||
Event {
|
||||
code: $code,
|
||||
name: $name,
|
||||
label: $label,
|
||||
ids: &[$id],
|
||||
from: |d| super::steps_stylize::from($id, d),
|
||||
to: |_, p| if pixel_target(p) { super::steps_stylize::to($id, p) } else { None },
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Minimum / Maximum with Preserve: Roundness. The descriptor here maps the radius only, and
|
||||
/// Photoshop's encoding of the shape isn't verified, so such a step is not exported: it would
|
||||
/// replay as the default Squareness (#7233).
|
||||
@@ -185,6 +198,10 @@ macro_rules! clipping_event {
|
||||
/// Every Photoshop event PhotoCraft maps. The order matters only for the panel label.
|
||||
pub(super) const EVENTS: &[Event] = &[
|
||||
// Filters.
|
||||
stylize_event!("FndE", "findEdges", "Find Edges", "filter.stylize.findEdges"),
|
||||
stylize_event!("Slrz", "solarize", "Solarize", "filter.stylize.solarize"),
|
||||
stylize_event!("Fct ", "facet", "Facet", "filter.pixelate.facet"),
|
||||
stylize_event!("Frgm", "fragment", "Fragment", "filter.pixelate.fragment"),
|
||||
ev!("GsnB", "gaussianBlur", "Gaussian Blur", "filter.blur.gaussianBlur", &[F("Rds ", "radius", Kind::Px)]),
|
||||
ev!(
|
||||
"UnsM",
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//! Descriptor adapters for the measured Stylize and Pixelate action events.
|
||||
|
||||
use super::descriptors::desc;
|
||||
use super::fields::{Mapped, step};
|
||||
use super::{Descriptor, Value, json};
|
||||
|
||||
pub(super) fn from(id: &str, d: &Descriptor) -> Mapped {
|
||||
if d.items.is_empty() { step(id, json!({})) } else { Mapped::Unsupported { harmless: false } }
|
||||
}
|
||||
|
||||
pub(super) fn to(_id: &str, p: &Value) -> Option<Descriptor> {
|
||||
let params = p.as_object()?;
|
||||
// These events have no fields for a layer reference or any native filter settings.
|
||||
params.keys().all(|key| key == "target").then(|| desc("null"))
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parameterless_stylize_and_pixelate_events_use_both_event_id_forms() {
|
||||
for (code, name, id) in [
|
||||
(*b"FndE", "findEdges", "filter.stylize.findEdges"),
|
||||
(*b"Slrz", "solarize", "filter.stylize.solarize"),
|
||||
(*b"Fct ", "facet", "filter.pixelate.facet"),
|
||||
(*b"Frgm", "fragment", "filter.pixelate.fragment"),
|
||||
] {
|
||||
for event in [AtnEvent::Code(code), AtnEvent::name(name)] {
|
||||
let file = AtnFile {
|
||||
name: UnicodeString::new_nul("Group D"),
|
||||
actions: vec![AtnAction {
|
||||
name: UnicodeString::new_nul("A"),
|
||||
items: vec![AtnItem { event, descriptor: Some(desc("null")), ..Default::default() }],
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
};
|
||||
let imported = import(&atn::write(&file).unwrap()).unwrap();
|
||||
assert!(imported.unsupported.is_empty());
|
||||
assert_eq!(imported.actions[0].steps, vec![(id.into(), json!({}))]);
|
||||
assert_eq!(export_item(id, &json!({}), "Group D").unwrap().descriptor, Some(desc("null")));
|
||||
assert!(export_item(id, &json!({"layer": 17}), "Group D").is_none());
|
||||
assert!(export_item(id, &json!({"target": "mask"}), "Group D").is_none());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -476,6 +476,10 @@ fn settings_at_the_value_the_event_plays_still_export() {
|
||||
#[test]
|
||||
fn every_mapped_command_exports_and_imports_back() {
|
||||
let cases: Vec<(&str, Value)> = vec![
|
||||
("filter.stylize.findEdges", json!({})),
|
||||
("filter.stylize.solarize", json!({})),
|
||||
("filter.pixelate.facet", json!({})),
|
||||
("filter.pixelate.fragment", json!({})),
|
||||
("filter.blur.gaussianBlur", json!({"radius": 3.5})),
|
||||
("filter.sharpen.unsharpMask", json!({"amount": 120, "radius": 1.5, "threshold": 3})),
|
||||
("filter.noise.addNoise", json!({"amount": 12.5, "distribution": "gaussian", "monochromatic": true, "seed": 7})),
|
||||
|
||||
Reference in new issue
Block a user