Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

PSD: parameterless smart filters (Blur, Sharpen, Find Edges, Solarize…) open and save like Photoshop (#6296)

David Mann7d36b417e575
diff --git a/crates/io/src/smart_map.rs b/crates/io/src/smart_map.rs
index 3de336e16..be0a376c7 100644
--- a/crates/io/src/smart_map.rs
+++ b/crates/io/src/smart_map.rs
@@ -144,7 +144,7 @@ const fn code(c: &[u8; 4]) -> i32 {
i32::from_be_bytes(*c)
}
-const KNOWN: [Known; 14] = [
+const KNOWN: [Known; 25] = [
Known { class: "GsnB", filter_id: code(b"GsnB"), name: "Gaussian Blur...", command: "filter.blur.gaussianBlur" },
Known { class: "boxblur", filter_id: 840, name: "Box Blur...", command: "filter.blur.boxBlur" },
Known { class: "MtnB", filter_id: code(b"MtnB"), name: "Motion Blur...", command: "filter.blur.motionBlur" },
@@ -160,8 +160,24 @@ const KNOWN: [Known; 14] = [
Known { class: "Crvs", filter_id: code(b"Crvs"), name: "Curves...", command: "image.adjustments.curves" },
// Shadows/Highlights at its defaults stores no `Fltr` (`hasoptions` false).
Known { class: "adaptCorrect", filter_id: 781, name: "Shado&ws/Highlights...", command: "image.adjustments.shadowsHighlights" },
+ // Filters without options (measured in Photoshop): `hasoptions` false, no `Fltr`, only the
+ // four-char `filterID`. The class is that code; see `NO_OPTIONS`.
+ Known { class: "Blr ", filter_id: code(b"Blr "), name: "Blur", command: "filter.blur.blur" },
+ Known { class: "BlrM", filter_id: code(b"BlrM"), name: "Blur More", command: "filter.blur.blurMore" },
+ Known { class: "Avrg", filter_id: code(b"Avrg"), name: "Average", command: "filter.blur.average" },
+ Known { class: "Dspc", filter_id: code(b"Dspc"), name: "Despeckle", command: "filter.noise.despeckle" },
+ Known { class: "FndE", filter_id: code(b"FndE"), name: "Find Edges", command: "filter.stylize.findEdges" },
+ Known { class: "Fct ", filter_id: code(b"Fct "), name: "Facet", command: "filter.pixelate.facet" },
+ Known { class: "Frgm", filter_id: code(b"Frgm"), name: "Fragment", command: "filter.pixelate.fragment" },
+ Known { class: "Shrp", filter_id: code(b"Shrp"), name: "Sharpen", command: "filter.sharpen.sharpen" },
+ Known { class: "ShrM", filter_id: code(b"ShrM"), name: "Sharpen More", command: "filter.sharpen.sharpenMore" },
+ Known { class: "ShrE", filter_id: code(b"ShrE"), name: "Sharpen Edges", command: "filter.sharpen.sharpenEdges" },
+ Known { class: "Slrz", filter_id: code(b"Slrz"), name: "Solarize", command: "filter.stylize.solarize" },
];
+/// Classes of the filters that have no options: Photoshop stores them without a `Fltr`.
+const NO_OPTIONS: [&str; 11] = ["Blr ", "BlrM", "Avrg", "Dspc", "FndE", "Fct ", "Frgm", "Shrp", "ShrM", "ShrE", "Slrz"];
+
fn known_by_command(command: &str) -> Option<&'static Known> {
KNOWN.iter().find(|k| k.command == command)
}
@@ -264,6 +280,7 @@ fn known_params(class: &str, f: Option<&Descriptor>) -> Option<(&'static str, J)
let k = KNOWN.iter().find(|k| k.class == class)?;
let params = match (class, f) {
("adaptCorrect", None) => json!({}),
+ (c, None) if NO_OPTIONS.contains(&c) => json!({}),
(_, None) => return None,
("GsnB" | "boxblur" | "Mdn " | "HghP" | "Mxm " | "Mnm ", Some(f)) => json!({"radius": px(f, "Rds ")?}),
("MtnB", Some(f)) => json!({"angle": int(f, "Angl")?, "distance": px(f, "Dstn")?}),
@@ -603,6 +620,9 @@ fn fltr_for(k: &Known, p: &J) -> Result<Option<Descriptor>, String> {
}
return Ok(None);
}
+ // No settings to write; any parameter keys an old record carries have no effect on the
+ // filter either, so nothing is lost.
+ c if NO_OPTIONS.contains(&c) => return Ok(None),
_ => return Err("not a recognized filter".into()),
}))
}
@@ -1080,6 +1100,96 @@ mod tests {
}
}
+ /// The filters without options, their measured `filterID`s (as Photoshop wrote them).
+ const MEASURED_NO_OPTIONS: [(&str, i32); 11] = [
+ ("filter.blur.blur", 1114403360),
+ ("filter.blur.blurMore", 1114403405),
+ ("filter.blur.average", 1098281575),
+ ("filter.noise.despeckle", 1148416099),
+ ("filter.stylize.findEdges", 1181639749),
+ ("filter.pixelate.facet", 1180922912),
+ ("filter.pixelate.fragment", 1181902701),
+ ("filter.sharpen.sharpen", 1399353968),
+ ("filter.sharpen.sharpenMore", 1399353933),
+ ("filter.sharpen.sharpenEdges", 1399353925),
+ ("filter.stylize.solarize", 1399616122),
+ ];
+
+ /// A filter without options as Photoshop saves it: `hasoptions` false, no `Fltr`, a localized
+ /// name and the current colours.
+ fn photoshop_no_options_item(name: &str, filter_id: Value) -> Descriptor {
+ let rgb = |r: f64, g: f64, b: f64| {
+ Value::Descriptor(Descriptor::new("RGBC").with("Rd ", Value::Double(r)).with("Grn ", Value::Double(g)).with("Bl ", Value::Double(b)))
+ };
+ Descriptor::new("filterFX")
+ .with("Nm ", Value::Text(UnicodeString::new_nul(name)))
+ .with("blendOptions", Value::Descriptor(Descriptor::new("blendOptions").with("Opct", unit(b"#Prc", 60.0)).with("Md ", enumv("BlnM", "Mltp"))))
+ .with("enab", Value::Boolean(false))
+ .with("hasoptions", Value::Boolean(false))
+ .with("FrgC", rgb(167.0, 157.0, 147.0))
+ .with("BckC", rgb(255.0, 255.0, 255.0))
+ .with("filterID", filter_id)
+ }
+
+ #[test]
+ fn filters_without_options_round_trip_in_the_measured_shape() {
+ let keys = ["Nm ", "blendOptions", "enab", "hasoptions", "FrgC", "BckC", "filterID"];
+ for (command, id) in MEASURED_NO_OPTIONS {
+ let mut f = sf(command, json!({}));
+ f.blend = BlendMode::Overlay;
+ f.opacity = 0.75;
+ f.visible = false;
+ let d = item_for_filter(&f).unwrap();
+ let got: Vec<String> = d.items.iter().map(|(k, _)| String::from_utf8_lossy(k.as_bytes()).into_owned()).collect();
+ assert_eq!(got, keys, "{command}");
+ assert_eq!(d.get("hasoptions"), Some(&Value::Boolean(false)), "{command}");
+ assert_eq!(d.get("filterID"), Some(&Value::Integer(id)), "{command}");
+ let back = filter_from_item(&Descriptor::from_bytes(&d.to_bytes()).unwrap());
+ assert_eq!(back, f, "{command}");
+ // Keys an old record may carry have no effect on these filters: still written.
+ let extra = item_for_filter(&sf(command, json!({"radius": 3.0, "layer": "L"}))).unwrap();
+ assert_eq!(extra.get("filterID"), Some(&Value::Integer(id)), "{command}");
+ for p in [json!(null), json!("x"), json!([1, 2])] {
+ assert!(item_for_filter(&sf(command, p)).is_ok(), "{command}");
+ }
+ }
+ }
+
+ #[test]
+ fn photoshop_filters_without_options_open_editable() {
+ for (command, id) in MEASURED_NO_OPTIONS {
+ let item = photoshop_no_options_item("Weichzeichnen", Value::Integer(id));
+ let f = filter_from_item(&Descriptor::from_bytes(&item.to_bytes()).unwrap());
+ assert_eq!(f.command, command);
+ assert_eq!(f.params, json!({}));
+ assert_eq!((f.visible, f.blend), (false, BlendMode::Multiply));
+ assert!((f.opacity - 0.6).abs() < 1e-6);
+ }
+ }
+
+ #[test]
+ fn malformed_filters_without_options_are_kept_verbatim() {
+ let blur = code(b"Blr ");
+ let cases = [
+ // An id no filter has, a missing id, ids of the wrong type.
+ photoshop_no_options_item("X", Value::Integer(code(b"Zzzz"))),
+ Descriptor::new("filterFX").with("hasoptions", Value::Boolean(false)),
+ photoshop_no_options_item("X", Value::Double(f64::from(blur))),
+ photoshop_no_options_item("X", Value::Double(f64::NAN)),
+ photoshop_no_options_item("X", Value::Text(UnicodeString::new_nul("Blr "))),
+ photoshop_no_options_item("X", Value::Integer(-1)),
+ // Settings we don't know of on a filter that has none.
+ photoshop_no_options_item("X", Value::Integer(blur)).with("Fltr", Value::Descriptor(Descriptor::new("Blr ").with("Amnt", Value::Integer(5)))),
+ ];
+ for item in cases {
+ let f = filter_from_item(&item);
+ assert_eq!(f.command, UNSUPPORTED_FILTER, "{item:?}");
+ // Written back (a bare item gains blending and visibility) and still not editable.
+ let back = filter_from_item(&item_for_filter(&f).unwrap());
+ assert_eq!((back.command.as_str(), &back.params["filterID"]), (UNSUPPORTED_FILTER, &f.params["filterID"]));
+ }
+ }
+
#[test]
fn unknown_filters_keep_their_descriptor() {
let item = Descriptor::new("filterFX")
diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md
index ba7462370..6bfbac17e 100644
--- a/docs/file-format-parity.md
+++ b/docs/file-format-parity.md
@@ -1,6 +1,6 @@
# File-format parity
-> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-13 · **Change:** minor (earlier: PDF write one flattened page via Save As / Save a Copy / CLI, #3401; CMYK Invert, Posterize and Threshold on the inks; smart filter masks on PSD open and save; Photoshop-oracle floor 188/258; lossy DNG, compression 34892, decodes with its levels and LinearizationTable applied to the stored 8-bit samples, FILE-215-11; CMYK Hue/Saturation and Color Balance keep the black ink; CMYK Posterize on the stored values, psd-tools oracle floor 242/309; CMYK adjustment layers composite on the document's inks; Photoshop-oracle floor 165/258; CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; modern Brightness/Contrast's brightness curve; Photoshop-oracle floor 151/258; Lab documents composite on their stored L, a, b; Photoshop-oracle floor 152/258; Levels on whole levels at every step with Photoshop's shadow toe; Photoshop-oracle floor 146/258, psd-tools 238/309; 32-bit adjustments unclipped; Photoshop-oracle floor 149/258; mask feathers blur with their exact variance; Threshold splits on Photoshop's luminosity; a pass-through clipping base with an adjustment renders isolated; psd-tools oracle floor 240/309; 16-bit Posterize as Photoshop bins it; psd-tools oracle floor 241/309; Gradient Map luminosity; Photoshop-oracle floor 147/258; PSD: `Mt16`/`Mt32` merged transparency read; palette PNGs open in Indexed Color mode, #4804; earlier: CMYK Invert, Posterize and Threshold on the inks; 16-bit Lab Invert; Photoshop-oracle floor 145/258; `.atn` import maps 112 events; DDS textures open, #1327; DPX read and write, #1049; #2465 fixed: CS2 placed layers with only a `PlLd` block open their contents; Photoshop Actions `.atn` read and write; `.shc` contour files read and write; earlier the same day: indexed BMP palette mode; Save keeps a JPEG's quality and a WebP's encoding) · **Target:** Adobe Photoshop 2026
+> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-15 · **Change:** minor (PSD smart filters without options, Blur to Solarize, open and save editable, FILE-215-2; earlier: PDF write one flattened page via Save As / Save a Copy / CLI, #3401; CMYK Invert, Posterize and Threshold on the inks; smart filter masks on PSD open and save; Photoshop-oracle floor 188/258; lossy DNG, compression 34892, decodes with its levels and LinearizationTable applied to the stored 8-bit samples, FILE-215-11; CMYK Hue/Saturation and Color Balance keep the black ink; CMYK Posterize on the stored values, psd-tools oracle floor 242/309; CMYK adjustment layers composite on the document's inks; Photoshop-oracle floor 165/258; CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; modern Brightness/Contrast's brightness curve; Photoshop-oracle floor 151/258; Lab documents composite on their stored L, a, b; Photoshop-oracle floor 152/258; Levels on whole levels at every step with Photoshop's shadow toe; Photoshop-oracle floor 146/258, psd-tools 238/309; 32-bit adjustments unclipped; Photoshop-oracle floor 149/258; mask feathers blur with their exact variance; Threshold splits on Photoshop's luminosity; a pass-through clipping base with an adjustment renders isolated; psd-tools oracle floor 240/309; 16-bit Posterize as Photoshop bins it; psd-tools oracle floor 241/309; Gradient Map luminosity; Photoshop-oracle floor 147/258; PSD: `Mt16`/`Mt32` merged transparency read; palette PNGs open in Indexed Color mode, #4804; earlier: CMYK Invert, Posterize and Threshold on the inks; 16-bit Lab Invert; Photoshop-oracle floor 145/258; `.atn` import maps 112 events; DDS textures open, #1327; DPX read and write, #1049; #2465 fixed: CS2 placed layers with only a `PlLd` block open their contents; Photoshop Actions `.atn` read and write; `.shc` contour files read and write; earlier the same day: indexed BMP palette mode; Save keeps a JPEG's quality and a WebP's encoding) · **Target:** Adobe Photoshop 2026
Every format Photoshop 2026 (27.11.0) reads or writes, with PhotoCraft's support, fidelity and
tests. Photoshop's list comes from its `Info.plist` `CFBundleDocumentTypes`, the PiPL read/write
@@ -21,7 +21,7 @@ XL are missing (gap G10). Remaining: 300–500 h including PSD fidelity.
| Format | Photoshop | PhotoCraft read | PhotoCraft write | Fidelity and tests |
|---|---|---|---|---|
-| PSD | R/W | yes | yes | 1/8/16/32-bit; Bitmap, Gray, Indexed, RGB, CMYK, Multichannel, Lab, Duotone; layers, groups, masks, vector masks, adjustment and fill layers, effects, text, shapes, smart objects (SoLd/lnk2; CS2 PlLd/lnkD read with their warp, kept as is or re-saved as SoLd once edited), smart filters (14 mapped plus Filter Gallery with Chrome, rest verbatim), slices, comps, Advanced Blending. Oracle floors: Photoshop-authored 188/258, io 148/170, psd-tools 249/309; round trip ≥ 169/170, 308/309, 258/256. Known failures: #1281, #2469 (#2374, text layers, closed 2026-10-10; #2465, CS2 `PlLd`-only smart objects, fixed 2026-10-12) |
+| PSD | R/W | yes | yes | 1/8/16/32-bit; Bitmap, Gray, Indexed, RGB, CMYK, Multichannel, Lab, Duotone; layers, groups, masks, vector masks, adjustment and fill layers, effects, text, shapes, smart objects (SoLd/lnk2; CS2 PlLd/lnkD read with their warp, kept as is or re-saved as SoLd once edited), smart filters (25 mapped plus Filter Gallery with Chrome, rest verbatim), slices, comps, Advanced Blending. Oracle floors: Photoshop-authored 188/258, io 148/170, psd-tools 249/309; round trip ≥ 169/170, 308/309, 258/256. Known failures: #1281, #2469 (#2374, text layers, closed 2026-10-10; #2465, CS2 `PlLd`-only smart objects, fixed 2026-10-12) |
| PSB | R/W | yes | yes | Auto-switches above 2 GB (REL-212-2); 4–5 GB fixtures generated (FILE-216-2); > 4 GB fails on Windows (#375) |
| Cloud PSD (.psdc) | R/W | no | no | Out of scope (Adobe cloud) |
| TIFF | R/W | yes | yes | 8/16/32f, Gray/RGB/CMYK, BigTIFF, every IFD, banded parallel decode; layered TIFF both byte orders (FILE-215-7: extra alpha channels not written) |
@@ -142,6 +142,7 @@ remaining gaps in #1606 stay tracked with per-sample corpus ceilings.
| Date | Change | Summary |
|---|---|---|
+| 2026-10-15 | minor | PSD smart filters without options (Blur, Blur More, Average, Despeckle, Find Edges, Facet, Fragment, Sharpen, Sharpen More, Sharpen Edges, Solarize) map both ways as Photoshop stores them: `hasoptions` false, no `Fltr`, the four-char `filterID` (FILE-215-2) |
| 2026-10-14 | minor | PSD smart filter masks: Photoshop stores a smart object's filtered pixels without its filter mask and mixes the unfiltered ones (`FEid`) back in; import now mixes them and export writes them that way, so sf-filter-mask-hard, -gradient and sf-stack-blend-and-mask pass; Photoshop-oracle floor 185 → 188 of 258 |
| 2026-10-13 | minor | Lossy DNG (compression 34892) decodes: 8-bit baseline JPEG tiles and strips, CFA and LinearRaw, partial edge tiles; the stored values take the normal levels and LinearizationTable (FILE-215-11, lossy DNG part) |
| 2026-10-14 | minor | Corpus floors raised to the measured results of the CMYK, Lab, 32-bit, Levels, Threshold, Posterize, feather and pass-through fixes landed together: Photoshop-authored 165 → 185 of 258, io 146 → 148 of 170, psd-tools 242 → 249 of 309 |
diff --git a/docs/scorecard.md b/docs/scorecard.md
index 1e0576ba0..6dd813f4d 100644
--- a/docs/scorecard.md
+++ b/docs/scorecard.md
@@ -99,7 +99,7 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t
| Id | Target | Status | Issue | Note |
|---|---|---|---|---|
| FILE-215-1 | Smart Objects export as embedded Smart Objects (SoLd + lnk2), not flat pixels | done | [#215](https://github.com/storytold/photocraft/issues/215) | psd_export.rs smart_blocks: PlLd + SoLd, source in lnk2 (.pcraft -> PSB); engine tests/smart_psd.rs; Photoshop 2026 opens 8/16-bit exports as live smart objects. Linked files are embedded |
-| FILE-215-2 | Smart Filters survive PSD save and re-open (filterFX descriptor read and written) | partial | [#215](https://github.com/storytold/photocraft/issues/215) | smart_map.rs: 14 filters plus a verified Camera Raw subset mapped both ways, others kept verbatim, mask in FEid; io tests/smart_corpus.rs. PhotoCraft-only filters (Twirl, Liquify…) and unmapped Camera Raw settings are left out of filterFX with a warning |
+| FILE-215-2 | Smart Filters survive PSD save and re-open (filterFX descriptor read and written) | partial | [#215](https://github.com/storytold/photocraft/issues/215) | smart_map.rs: 25 filters (incl. Blur, Blur More, Average, Despeckle, Find Edges, Facet, Fragment, Sharpen, Sharpen More, Sharpen Edges and Solarize, which have no options) plus a verified Camera Raw subset mapped both ways, others kept verbatim, mask in FEid; io tests/smart_corpus.rs. PhotoCraft-only filters (Twirl, Liquify…) and unmapped Camera Raw settings are left out of filterFX with a warning |
| FILE-215-3 | Filter mask can be painted directly, with undo | missing | [#215](https://github.com/storytold/photocraft/issues/215) | smart_cmds.rs:382 mask only from the selection |
| FILE-215-4 | Adjustments (Hue/Sat + Colorize, Curves, Levels, Shadows/Highlights) apply as Smart Filters | done | [#215](https://github.com/storytold/photocraft/issues/215) | Image › Adjustments on a smart object records image.adjustments.<kind> as a smart filter (adjust_cmds.rs adjust_as_smart_filter; the selection becomes the filter mask), re-rendered from the source by adjust_as_filter and re-editable with layer.smartFilter.setParams; PSD maps Levels/Curves/Shadows-Highlights both ways (smart_map.rs). Opening the editor from the smart-filter row is FILE-215-5's row work |
| FILE-215-5 | Smart Filter rows: collapse, mask thumb, blend icon, drag reorder, context menu, live preview | partial | [#215](https://github.com/storytold/photocraft/issues/215) | smart_ui.rs:31 rows + visibility + editor; no collapse, drag or context menu |
diff --git a/scorecard/file_compat.toml b/scorecard/file_compat.toml
index d7e82c9ae..11088ab5c 100644
--- a/scorecard/file_compat.toml
+++ b/scorecard/file_compat.toml
@@ -17,7 +17,7 @@ id = "FILE-215-2"
target = "Smart Filters survive PSD save and re-open (filterFX descriptor read and written)"
status = "partial"
issue = 215
-note = "smart_map.rs: 14 filters plus a verified Camera Raw subset mapped both ways, others kept verbatim, mask in FEid; io tests/smart_corpus.rs. PhotoCraft-only filters (Twirl, Liquify…) and unmapped Camera Raw settings are left out of filterFX with a warning"
+note = "smart_map.rs: 25 filters (incl. Blur, Blur More, Average, Despeckle, Find Edges, Facet, Fragment, Sharpen, Sharpen More, Sharpen Edges and Solarize, which have no options) plus a verified Camera Raw subset mapped both ways, others kept verbatim, mask in FEid; io tests/smart_corpus.rs. PhotoCraft-only filters (Twirl, Liquify…) and unmapped Camera Raw settings are left out of filterFX with a warning"
[[item]]
id = "FILE-215-3"