PhotoCraft: An open-source, photo editor written by scratch in pure Rust
PSD Wave smart filters: keep more than 64 generators verbatim
abc2cb85760b1c36c6
diff --git a/crates/algo/src/distort.rs b/crates/algo/src/distort.rsindex 664169afa..f16145256 100644--- a/crates/algo/src/distort.rs+++ b/crates/algo/src/distort.rs@@ -95,6 +95,10 @@ pub(crate) fn spherize(src: &Image, out: Rect, ctx: &Ctx, amount: f32, mode: Sph})}+/// The most Wave generators the renderer models: it clamps the setting to this, so a file asking+/// for more (the command allows up to 999) would render differently from how it was authored.+pub const MAX_WAVE_GENERATORS: u32 = 64;+/// Wave generator settings.pub(crate) struct WaveSpec {pub generators: u32,@@ -121,7 +125,7 @@ fn shape(t: WaveType, phase: f32) -> f32 {}pub(crate) fn wave(src: &Image, out: Rect, ctx: &Ctx, w: WaveSpec) -> Vec<f32> {- let n = w.generators.clamp(1, 64);+ let n = w.generators.clamp(1, MAX_WAVE_GENERATORS);let lerp = |(a, b): (f32, f32), t: f32| a + (b - a).max(0.0) * t;let gens: Vec<(f32, f32, f32, f32)> = (0..n).map(|i| {diff --git a/crates/algo/src/lib.rs b/crates/algo/src/lib.rsindex 49ab15871..377bb9281 100644--- a/crates/algo/src/lib.rs+++ b/crates/algo/src/lib.rs@@ -85,6 +85,7 @@ pub mod warp;pub mod wideangle;pub use artistic::{GALLERY_CATEGORIES, GalleryEffect, GalleryFilter, GalleryParam, GalleryParamKind};+pub use distort::MAX_WAVE_GENERATORS;pub use image::{Edge, Image};pub use params_ext::*;diff --git a/crates/io/src/smart_map.rs b/crates/io/src/smart_map.rsindex a9bce4727..0d78f2ffc 100644--- a/crates/io/src/smart_map.rs+++ b/crates/io/src/smart_map.rs@@ -304,13 +304,17 @@ fn known_params(class: &str, f: Option<&Descriptor>) -> Option<(&'static str, J)("Plr ", Some(f)) => json!({"mode": enum_param(f, "Cnvr", &POLAR_MODE)?}),("ZgZg", Some(f)) => json!({"amount": int(f, "Amnt")?, "ridges": int(f, "NmbR")?, "style": enum_param(f, "ZZTy", &ZIGZAG_STYLE)?}),("Wave", Some(f)) => {- // PhotoCraft's Wave has no Scale: a scaled wave stays verbatim rather than lose it.- if int(f, "SclH")? != 100 || int(f, "SclV")? != 100 {+ // PhotoCraft's Wave has no Scale: a scaled wave stays verbatim rather than lose it. The+ // same for more generators than the renderer models, which would draw fewer than+ // Photoshop did (and than the file asks for, once its cached pixels are re-rendered).+ let generators = int(f, "NmbG")?;+ let modelled = u32::try_from(generators).is_ok_and(|g| (1..=photocraft_algo::MAX_WAVE_GENERATORS).contains(&g));+ if int(f, "SclH")? != 100 || int(f, "SclV")? != 100 || !modelled {return None;}json!({"type": enum_param(f, "Wvtp", &WAVE_TYPE)?,- "generators": int(f, "NmbG")?,+ "generators": generators,"wavelengthMin": int(f, "WLMn")?,"wavelengthMax": int(f, "WLMx")?,"amplitudeMin": int(f, "AmMn")?,@@ -1233,24 +1237,48 @@ mod tests {let f = filter_from_item(&item);assert_eq!(f.command, UNSUPPORTED_FILTER);assert_eq!(item_for_filter(&f).unwrap().get("Fltr"), item.get("Fltr"));- // Unscaled, it opens as PhotoCraft's Wave (Triangle, the other settings as stored).+ // Unscaled, but with 332 generators (the renderer draws 64 at most), it stays Photoshop's too.let mut unscaled = match item.get("Fltr") {Some(Value::Descriptor(d)) => d.clone(),other => panic!("wave: no Fltr ({other:?})"),};set(&mut unscaled, "SclV", Value::Integer(100));- let f = filter_from_item(&photoshop_item(unscaled.clone()));- assert_eq!(- (f.command.as_str(), &f.params),- (- "filter.distort.wave",- &json!({"type": "triangle", "generators": 332, "wavelengthMin": 213, "wavelengthMax": 214, "amplitudeMin": 240, "amplitudeMax": 241,- "undefinedAreas": "wrap", "seed": 1270346})- )- );- match item_for_filter(&f).unwrap().get("Fltr") {- Some(Value::Descriptor(ours)) => assert_eq!((&ours.class_id, &ours.items), (&unscaled.class_id, &unscaled.items)),- other => panic!("wave: no Fltr ({other:?})"),+ let item = photoshop_item(unscaled);+ let f = filter_from_item(&item);+ assert_eq!(f.command, UNSUPPORTED_FILTER);+ assert_eq!(item_for_filter(&f).unwrap().get("Fltr"), item.get("Fltr"));+ }++ /// An unscaled Wave opens as PhotoCraft's Wave (Triangle, the other settings as stored) up to+ /// the generators the renderer models; one more and it stays Photoshop's, unchanged.+ #[test]+ fn wave_maps_up_to_the_generators_the_renderer_models() {+ let max = i32::try_from(photocraft_algo::MAX_WAVE_GENERATORS).unwrap();+ assert_eq!(max, 64);+ let mut wave = Descriptor::from_bytes(&from_hex(PHOTOSHOP_WAVE).unwrap()).unwrap();+ set(&mut wave, "SclV", Value::Integer(100));+ for (generators, mapped) in [(1, true), (max, true), (max + 1, false), (999, false), (0, false), (-1, false)] {+ set(&mut wave, "NmbG", Value::Integer(generators));+ let item = photoshop_item(wave.clone());+ let f = filter_from_item(&item);+ if mapped {+ assert_eq!(+ (f.command.as_str(), &f.params),+ (+ "filter.distort.wave",+ &json!({"type": "triangle", "generators": generators, "wavelengthMin": 213, "wavelengthMax": 214, "amplitudeMin": 240,+ "amplitudeMax": 241, "undefinedAreas": "wrap", "seed": 1270346})+ ),+ "{generators} generators"+ );+ match item_for_filter(&f).unwrap().get("Fltr") {+ Some(Value::Descriptor(ours)) => assert_eq!((&ours.class_id, &ours.items), (&wave.class_id, &wave.items), "{generators} generators"),+ other => panic!("wave: no Fltr ({other:?})"),+ }+ } else {+ assert_eq!(f.command, UNSUPPORTED_FILTER, "{generators} generators");+ assert_eq!(item_for_filter(&f).unwrap().get("Fltr"), item.get("Fltr"), "{generators} generators");+ }}}diff --git a/docs/file-format-parity.md b/docs/file-format-parity.mdindex 2b6c62be6..2eeac93a7 100644--- a/docs/file-format-parity.md+++ b/docs/file-format-parity.md@@ -145,7 +145,7 @@ remaining gaps in #1606 stay tracked with per-sample corpus ceilings.| 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 |-| 2026-10-13 | minor | PSD smart filters: Pinch, Polar Coordinates, Ripple, Spherize, Twirl, Wave, ZigZag and Invert open as editable filters and are saved instead of dropped (checked against a Photoshop 27 file); a scaled Wave and Shear stay verbatim |+| 2026-10-13 | minor | PSD smart filters: Pinch, Polar Coordinates, Ripple, Spherize, Twirl, Wave, ZigZag and Invert open as editable filters and are saved instead of dropped (checked against a Photoshop 27 file); a scaled Wave, a Wave with more than 64 generators and Shear stay verbatim || 2026-10-13 | minor | CMYK Hue/Saturation (not Colorize) and Color Balance work on C, M and Y as inverted RGB with black kept, on the inks for display, export and destructive edits; cmyk8/16 hue-saturation 100% → 0.4–0.7% bad pixels, color-balance 74% → 25% || 2026-10-13 | minor | CMYK Posterize works on the stored values (1 − ink), as Photoshop does: psd-tools posterize_cmyk passes (13.8 % → 0 of pixels off on the ink path); psd-tools floor → 242 of 309 || 2026-10-13 | minor | CMYK documents whose layers are plain raster layers plus Invert, Posterize, Threshold, Brightness/Contrast, Levels or Curves layers composite on their own inks for display, export and flattening: the cmyk8/16 oracles for those seven adjustments pass; Photoshop-oracle floor 151 → 165 of 258 |