PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge PR #8229: Integration batch: 8 PRs on main
aiongg77557d75f17e
diff --cc crates/engine/src/layer_style.rsindex 3d7ac40c9,9020e5503..602cf0694--- a/crates/engine/src/layer_style.rs+++ b/crates/engine/src/layer_style.rs@@@ -91,7 -91,7 +91,7 @@@ pub fn effect_defaults(kind: &str) -> V"innerGlow" => {json!({"blend": "Screen", "opacity": 75, "color": "#ffffbe", "source": "edge", "choke": 0, "size": 5, "contour": "Linear", "antiAlias": false, "noise": 0})}- "stroke" => json!({"size": 1, "position": "inside", "blend": "Normal", "opacity": 100, "color": "#000000"}),- "stroke" => json!({"size": 3, "position": "outside", "blend": "Normal", "opacity": 100, "overprint": false, "color": "#000000"}),++ "stroke" => json!({"size": 1, "position": "inside", "blend": "Normal", "opacity": 100, "overprint": false, "color": "#000000"}),"colorOverlay" => json!({"blend": "Normal", "color": "#ff0000", "opacity": 100}),"gradientOverlay" => {json!({"blend": "Normal", "opacity": 100, "from": "#000000", "to": "#ffffff", "reverse": false, "style": "linear", "angle": 90, "scale": 100})@@@ -507,9 -507,10 +507,10 @@@ fn fresh_effect(kind: &str) -> Option<E"innerGlow" => Effect::InnerGlow(glow()),"stroke" => Effect::Stroke(StrokeFx {common: FxCommon::new(BlendMode::Normal, 1.0),- size: 3.0,- position: StrokePosition::Outside,- paint: FxPaint::Color(Color::rgb(1.0, 0.0, 0.0)),+ size: 1.0,+ position: StrokePosition::Inside,+ paint: FxPaint::Color(Color::BLACK),+ overprint: false,}),"colorOverlay" => Effect::ColorOverlay { common: FxCommon::new(BlendMode::Normal, 1.0), color: Color::rgb(1.0, 0.0, 0.0) },"gradientOverlay" => Effect::GradientOverlay { common: FxCommon::new(BlendMode::Normal, 1.0), gradient: Gradient::default(), dither: false },@@@ -1012,7 -1016,7 +1016,7 @@@ pub fn specs() -> Vec<CommandSpec>style_cmd!("stroke","Stroke…",- r##"{"size":px=1,"position":"inside|outside|center","color":"#rrggbb","from":"#rrggbb","to":"#rrggbb","method":"classic|perceptual|linear|smooth"?,"smoothness":0..100=100,"style":str,"angle":deg,"opacity":0..100,"blend":str,"add":bool}"##- r##"{"size":px=3,"position":"outside|inside|center","color":"#rrggbb","from":"#rrggbb","to":"#rrggbb","method":"classic|perceptual|linear|smooth"?,"smoothness":0..100=100,"style":str,"angle":deg,"opacity":0..100,"blend":str,"overprint":bool,"add":bool}"##++ r##"{"size":px=1,"position":"inside|outside|center","color":"#rrggbb","from":"#rrggbb","to":"#rrggbb","method":"classic|perceptual|linear|smooth"?,"smoothness":0..100=100,"style":str,"angle":deg,"opacity":0..100,"blend":str,"overprint":bool,"add":bool}"##),style_cmd!("colorOverlay", "Color Overlay…", r##"{"color":"#rrggbb","opacity":0..100=100,"blend":str,"add":bool}"##),style_cmd!(diff --cc crates/io/src/psd_export.rsindex 4c3ec0047,67d70d0a8..b89bfc3e6--- a/crates/io/src/psd_export.rs+++ b/crates/io/src/psd_export.rs@@@ -618,17 -617,11 +621,19 @@@ impl Ex// updated in place.let keep = keep|| (matches!(a, photocraft_doc::Adjustment::GradientMap { .. })- && raw.iter_mut().any(|(k, d)| k == b"grdm" && adjust_map::retarget_gradient_map(d, a, channels)));+ && raw.iter_mut().any(|(k, d)| {+ k == b"grdm" && !adjust_map::is_unpadded_photocraft_gradient_map(d) && adjust_map::retarget_gradient_map(d, a, channels)+ }));+ // An adjustment type no mapper knows (#6575) is its block: kept verbatim, and+ // never written a second time beside a stale copy.+ let own = match a {+ photocraft_doc::Adjustment::Unsupported { psd_key, .. } => Some(psd_key.as_bytes()),+ _ => None,+ };+ let keep =+ keep || matches!(a, photocraft_doc::Adjustment::Unsupported { raw: r, .. } if raw.iter().any(|(k, d)| own == Some(&k[..]) && d == r));if !keep {- raw.retain(|(k, _)| !adjust_map::ADJUSTMENT_KEYS.contains(&k) && k != b"CgEd");+ raw.retain(|(k, _)| !adjust_map::ADJUSTMENT_KEYS.contains(&k) && k != b"CgEd" && own != Some(&k[..]));let w = adjust_map::write(a);if w.is_empty() {self.warnings.push(format!("layer \"{}\": {} adjustment is not yet written to PSD", l.name, a.label()));diff --cc crates/io/src/smart_map.rsindex 5ec4db118,21590064f..57dd0440f--- a/crates/io/src/smart_map.rs+++ b/crates/io/src/smart_map.rs@@@ -150,7 -144,7 +150,7 @@@ const fn code(c: &[u8; 4]) -> i32i32::from_be_bytes(*c)}- const KNOWN: [Known; 41] = [-const KNOWN: [Known; 18] = [++const KNOWN: [Known; 45] = [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" },@@@ -182,77 -160,17 +182,86 @@@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" },+ // Smart Sharpen has a numeric filterID and a stringID class, like Box Blur.+ Known { class: SMART_SHARPEN, filter_id: 1131, name: "Smart Sharpen...", command: "filter.sharpen.smartSharpen" },+ Known { class: "DstS", filter_id: code(b"DstS"), name: "Dust & Scratches...", command: "filter.noise.dustAndScratches" },+ Known { class: "LnsF", filter_id: code(b"LnsF"), name: "Lens Flare...", command: "filter.render.lensFlare" },+ // These three also read the item's foreground and background colours (`coloured_params`).+ Known { class: "Fbrs", filter_id: code(b"Fbrs"), name: "Fibers...", command: "filter.render.fibers" },+ Known { class: "Clds", filter_id: code(b"Clds"), name: "Clouds", command: "filter.render.clouds" },+ Known { class: "DfrC", filter_id: code(b"DfrC"), name: "Difference Clouds", command: "filter.render.differenceClouds" },];+ /// Lens Flare's `Lns ` enum and our `lens` values. Photoshop's codes keep the old lens names:+ /// Nikon 35 mm and 105 mm primes, a Panavision movie prime.+ const LENSES: [(&[u8; 4], &str); 4] = [(b"Zm ", "zoom"), (b"Nkn ", "prime35"), (b"Nkn1", "prime105"), (b"PnVs", "moviePrime")];++/// 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"];++// ---------- Smart Sharpen and Dust & Scratches ----------+//+// Measured in Photoshop (applied through Action Manager to a smart object, saved, `filterFX` read+// back):+//+// ```text+// Smart Sharpen (filterID 1131): smartSharpen { presetKind = presetKindType enum (only on the+// default entry), useLegacy bool, Amnt UntF #Prc, Rds UntF #Pxl, noiseReduction UntF #Prc,+// blur = blurType enum (GsnB | lensBlur | MtnB), Angl long (Motion Blur only) }+// Dust & Scratches (filterID DstS): DstS { Rds long, Thsh long }+// ```+//+// PhotoCraft's Smart Sharpen removes a Gaussian blur, non-legacy: Lens Blur, Motion Blur, legacy+// mode, Shadow/Highlight settings or any other key keep the whole entry verbatim. `presetKind`+// only names the dialog's preset: it is accepted on open but not kept (the engine takes no such+// parameter) and not written (Photoshop leaves it out of entries with explicit values).++const SMART_SHARPEN: &str = "smartSharpen";+const SMART_SHARPEN_KEYS: [&str; 6] = ["presetKind", "useLegacy", "Amnt", "Rds ", "noiseReduction", "blur"];++/// A `UntF` value in `unit`, finite and within `lo..=hi`.+fn unit_in(d: &Descriptor, key: &str, u: &[u8; 4], lo: f64, hi: f64) -> Option<f64> {+ match d.get(key)? {+ Value::UnitFloat { unit, value } if unit == u && value.is_finite() && (lo..=hi).contains(value) => Some(*value),+ _ => None,+ }+}++/// `filter.sharpen.smartSharpen` params; `None` for a setting PhotoCraft doesn't render.+fn smart_sharpen_params(f: &Descriptor) -> Option<J> {+ if f.items.iter().any(|(k, _)| !SMART_SHARPEN_KEYS.iter().any(|x| k.is(x))) {+ return None;+ }+ let Some(Value::Boolean(false)) = f.get("useLegacy") else { return None };+ let Some(Value::Enumerated { type_id, value }) = f.get("blur") else { return None };+ if !type_id.is("blurType") || !value.is("GsnB") {+ return None;+ }+ let mut out = Map::new();+ out.insert("amount".into(), json!(unit_in(f, "Amnt", b"#Prc", 1.0, 500.0)?));+ out.insert("radius".into(), json!(unit_in(f, "Rds ", b"#Pxl", 0.1, 64.0)?));+ out.insert("reduceNoise".into(), json!(unit_in(f, "noiseReduction", b"#Prc", 0.0, 100.0)?));+ match f.get("presetKind") {+ None => {}+ Some(Value::Enumerated { type_id, .. }) if type_id.is("presetKindType") => {}+ Some(_) => return None,+ }+ Some(J::Object(out))+}+fn known_by_command(command: &str) -> Option<&'static Known> {KNOWN.iter().find(|k| k.command == command)}@@@ -519,64 -289,14 +528,70 @@@ fn known_params(class: &str, f: Option<};json!({"amount": px(f, "Nose")?, "distribution": dist, "monochromatic": mono, "seed": int(f, "FlRs").unwrap_or(0)})}+ ("surfaceBlur", Some(f)) if only_keys(f, &["Rds ", "Thsh"]) => json!({+ "radius": in_range(px(f, "Rds ")?, 1.0, 100.0)?,+ "threshold": int_in(f, "Thsh", 2, 255)?,+ }),+ ("SmrB", Some(f)) if only_keys(f, &["Rds ", "Thsh", "SmBQ", "SmBM"]) => json!({+ "radius": in_range(px(f, "Rds ")?, 0.1, 100.0)?,+ "threshold": in_range(px(f, "Thsh")?, 0.1, 100.0)?,+ "quality": enum_name(f, "SmBQ", &SMART_BLUR_QUALITY)?,+ "mode": enum_name(f, "SmBM", &SMART_BLUR_MODE)?,+ }),+ ("RdlB", Some(f)) if only_keys(f, &["Amnt", "BlrM", "BlrQ"]) => json!({+ "amount": int_in(f, "Amnt", 1, 100)?,+ "method": enum_name(f, "BlrM", &RADIAL_METHOD)?,+ "quality": enum_name(f, "BlrQ", &RADIAL_QUALITY)?,+ }),("Msc ", Some(f)) => json!({"cellSize": px(f, "ClSz")?}),+ ("Mztn", Some(f)) => {+ let t = enum_of(f, "MztT")?;+ json!({"type": MEZZOTINT_TYPES.iter().find(|(c, _)| t == &c[..])?.1})+ }+ ("ClrH", Some(f)) => color_halftone_params(f)?,("Embs", Some(f)) => json!({"angle": int(f, "Angl")?, "height": int(f, "Hght")?, "amount": int(f, "Amnt")?}),+ (SMART_SHARPEN, Some(f)) => smart_sharpen_params(f)?,+ ("DstS", Some(f)) => {+ if f.items.iter().any(|(k, _)| !k.is("Rds ") && !k.is("Thsh")) {+ return None;+ }+ json!({"radius": int_in(f, "Rds ", 1, 500)?, "threshold": int_in(f, "Thsh", 0, 255)?})+ }+ ("Dfs ", Some(f)) => json!({"mode": enum_from(f, "Md ", "DfsM", &DIFFUSE_MODES)?}),+ ("TrcC", Some(f)) => json!({"level": int_in(f, "Lvl ", 0, 255)?, "edge": enum_from(f, "Edg ", "CntE", &TRACE_EDGES)?}),+ ("Crst", Some(f)) => json!({"cellSize": int_in(f, "ClSz", CELL_SIZE.0, CELL_SIZE.1)?}),+ ("Pntl", Some(f)) => {+ let mut p = json!({"cellSize": int_in(f, "ClSz", CELL_SIZE.0, CELL_SIZE.1)?});+ // Pointillize paints the gaps in the background colour the entry carries.+ if item.get("BckC").is_some() {+ p["background"] = get_desc(item, "BckC").and_then(rgbc_colour)?;+ }+ p+ }+ ("Wnd ", Some(f)) => json!({+ "method": enum_from(f, "WndM", "WndM", &WIND_METHODS)?,+ "direction": enum_from(f, "Drct", "Drct", &WIND_DIRECTIONS)?,+ }),+ ("Extr", Some(f)) => json!({+ "type": enum_from(f, "ExtT", "ExtT", &EXTRUDE_TYPES)?,+ "size": int_in(f, "ExtS", EXTRUDE_SIZE.0, EXTRUDE_SIZE.1)?,+ "depth": int_in(f, "ExtD", EXTRUDE_DEPTH.0, EXTRUDE_DEPTH.1)?,+ "depthMode": enum_from(f, "ExtR", "ExtR", &EXTRUDE_DEPTHS)?,+ "solidFrontFaces": bool_at(f, "ExtF")?,+ "maskIncompleteBlocks": bool_at(f, "ExtM")?,+ }),+ ("Tls ", Some(f)) => tiles_params(f, item)?,+ ("Ofst", Some(f)) => {+ let fill = OFFSET_FILL.iter().find(|(psd, _)| enum_of(f, "Fl ") == Some(psd.as_bytes()))?.1;+ json!({"horizontal": int(f, "Hrzn")?, "vertical": int(f, "Vrtc")?, "undefinedAreas": fill})+ }+ ("Cstm", Some(f)) => custom_params(f)?,+ ("LnsF", Some(f)) => {+ let centre = get_desc(f, "FlrC")?;+ let lens = enum_of(f, "Lns ")?;+ let lens = LENSES.iter().find(|(c, _)| lens == &c[..])?.1;+ json!({"brightness": int(f, "Brgh")?, "centerX": px(centre, "Hrzn")?, "centerY": px(centre, "Vrtc")?, "lens": lens})+ }("Lvls", Some(f)) => levels_params(f)?,("Crvs", Some(f)) => curves_params(f)?,_ => return None,@@@ -764,10 -504,9 +799,11 @@@ pub fn filter_from_item(item: &Descriptlet known = match class.as_deref() {Some(camera_raw::CLASS) => camera_raw::import_params(item).map(|p| (camera_raw::COMMAND, p)),Some(displace::CLASS) => displace::import_params(item).map(|p| (displace::COMMAND, p)),+ Some(hue_sat::CLASS) => fltr.and_then(hue_sat::import_params).map(|p| (hue_sat::COMMAND, p)),+ Some(perspective_warp::CLASS) => perspective_warp::import_params(item).map(|p| (perspective_warp::COMMAND, p)),Some(GALLERY_CLASS) => fltr.and_then(|f| gallery_params(item, f)).map(|p| (GALLERY_COMMAND, p)),+ Some(c @ ("Fbrs" | "Clds" | "DfrC")) => fltr.and_then(|f| coloured_params(c, item, f)),- c => c.and_then(|c| known_params(c, fltr)),+ c => c.and_then(|c| known_params(c, fltr, item)),};let (command, params) = match known {Some((c, p)) => (c.to_string(), p),@@@ -922,89 -629,19 +958,100 @@@ fn fltr_for(k: &Known, p: &J) -> Result.with("Mnch", Value::Boolean(p.get("monochromatic").and_then(J::as_bool).unwrap_or(false))).with("FlRs", pi(p, "seed", 0.0))}+ "surfaceBlur" => d.with("Rds ", unit(b"#Pxl", pf(p, "radius", 5.0))).with("Thsh", pi(p, "threshold", 15.0)),+ "SmrB" => d+ .with("Rds ", Value::Double(pf(p, "radius", 3.0)))+ .with("Thsh", Value::Double(pf(p, "threshold", 25.0)))+ .with("SmBQ", enum_param(p, "quality", "high", "SmBQ", &SMART_BLUR_QUALITY)?)+ .with("SmBM", enum_param(p, "mode", "normal", "SmBM", &SMART_BLUR_MODE)?),+ "RdlB" => {+ // Photoshop wrote no centre key for a centred blur; an off-centre one is unmeasured.+ if ["centerX", "centerY"].iter().any(|k| (pf(p, k, 0.5) - 0.5).abs() > 1e-9) {+ return Err("an off-centre Radial Blur centre is not written to PSD".into());+ }+ d.with("Amnt", pi(p, "amount", 10.0))+ .with("BlrM", enum_param(p, "method", "spin", "BlrM", &RADIAL_METHOD)?)+ .with("BlrQ", enum_param(p, "quality", "good", "BlrQ", &RADIAL_QUALITY)?)+ }"Msc " => d.with("ClSz", unit(b"#Pxl", pf(p, "cellSize", 10.0))),+ // Photoshop's Mezzotint has no seed (it is random on every render), so `seed` is not saved.+ "Mztn" => {+ let t = p.get("type").and_then(J::as_str).unwrap_or("fineDots");+ let code = MEZZOTINT_TYPES.iter().find(|(_, k)| *k == t).map_or(b"FnDt", |(c, _)| *c);+ d.with("MztT", Value::Enumerated { type_id: Id::new("MztT"), value: Id::Code(*code) })+ }+ "ClrH" => {+ // Longs within the dialog's ranges (what the engine accepts: radius 4..127, angles ±360).+ let long = |key: &str, default: f64, lo: f64, hi: f64| Value::Integer(pf(p, key, default).round().clamp(lo, hi) as i32);+ d.with("Rds ", long("maxRadius", 8.0, 4.0, 127.0))+ .with("Ang1", long("channel1", 108.0, -360.0, 360.0))+ .with("Ang2", long("channel2", 162.0, -360.0, 360.0))+ .with("Ang3", long("channel3", 90.0, -360.0, 360.0))+ .with("Ang4", long("channel4", 45.0, -360.0, 360.0))+ }"Embs" => d.with("Angl", pi(p, "angle", 135.0)).with("Hght", pi(p, "height", 3.0)).with("Amnt", pi(p, "amount", 100.0)),+ SMART_SHARPEN => {+ // The engine's defaults and ranges (it clamps the same way when rendering).+ d.with("useLegacy", Value::Boolean(false))+ .with("Amnt", unit(b"#Prc", pf(p, "amount", 100.0).clamp(1.0, 500.0)))+ .with("Rds ", unit(b"#Pxl", pf(p, "radius", 1.0).clamp(0.1, 64.0)))+ .with("noiseReduction", unit(b"#Prc", pf(p, "reduceNoise", 10.0).clamp(0.0, 100.0)))+ .with("blur", enumv("blurType", "GsnB"))+ }+ // Photoshop stores whole pixels and levels.+ "DstS" => {+ let whole = |key: &str, default: f64, lo: f64, hi: f64| Value::Integer(pf(p, key, default).round().clamp(lo, hi) as i32);+ d.with("Rds ", whole("radius", 1.0, 1.0, 500.0)).with("Thsh", whole("threshold", 0.0, 0.0, 255.0))+ }+ // Photoshop stores no random seed for these: `seed` is ours only and is not written.+ "Dfs " => d.with("Md ", enum_out(p, "mode", "normal", "DfsM", &DIFFUSE_MODES)?),+ "TrcC" => d.with("Lvl ", pi_in(p, "level", 128.0, 0, 255)).with("Edg ", enum_out(p, "edge", "lower", "CntE", &TRACE_EDGES)?),+ "Crst" => d.with("ClSz", pi_in(p, "cellSize", 10.0, CELL_SIZE.0, CELL_SIZE.1)),+ "Pntl" => d.with("ClSz", pi_in(p, "cellSize", 5.0, CELL_SIZE.0, CELL_SIZE.1)),+ // Photoshop stores no random seed for these: our `seed` is not written.+ "Wnd " => {+ d.with("WndM", enum_out(p, "method", "wind", "WndM", &WIND_METHODS)?).with("Drct", enum_out(p, "direction", "fromRight", "Drct", &WIND_DIRECTIONS)?)+ }+ "Extr" => d+ .with("ExtT", enum_out(p, "type", "blocks", "ExtT", &EXTRUDE_TYPES)?)+ .with("ExtS", pi_in(p, "size", 30.0, EXTRUDE_SIZE.0, EXTRUDE_SIZE.1))+ .with("ExtD", pi_in(p, "depth", 30.0, EXTRUDE_DEPTH.0, EXTRUDE_DEPTH.1))+ .with("ExtR", enum_out(p, "depthMode", "random", "ExtR", &EXTRUDE_DEPTHS)?)+ .with("ExtF", bool_param(p, "solidFrontFaces"))+ .with("ExtM", bool_param(p, "maskIncompleteBlocks")),+ "Tls " => d+ .with("TlNm", pi_in(p, "count", 10.0, TILE_COUNT.0, TILE_COUNT.1))+ .with("TlOf", pi_in(p, "maxOffset", 10.0, TILE_OFFSET.0, TILE_OFFSET.1))+ .with("FlCl", enum_out(p, "fill", "background", "FlCl", &TILE_FILLS)?),+ "Ofst" => {+ // As the engine reads it: anything but repeat / transparent wraps.+ let ours = p.get("undefinedAreas").and_then(J::as_str).unwrap_or("wrap");+ let fill = OFFSET_FILL.iter().find(|(_, o)| *o == ours).map_or("Wrp ", |(psd, _)| *psd);+ d.with("Hrzn", pi(p, "horizontal", 0.0)).with("Vrtc", pi(p, "vertical", 0.0)).with("Fl ", enumv("FlMd", fill))+ }+ "Cstm" => {+ // The engine's identity kernel when none is given; missing cells are 0.+ let kernel = p.get("kernel").and_then(J::as_array);+ let cell = |i: usize| match kernel {+ Some(a) => a.get(i).and_then(J::as_f64).filter(|v| v.is_finite()).unwrap_or(0.0),+ None => f64::from(u8::from(i == 12)),+ };+ let m = (0..25).map(|i| whole(cell(i), CUSTOM_CELL, "a kernel value")).collect::<Result<Vec<_>, _>>()?;+ d.with("Scl ", whole(pf(p, "scale", 1.0), CUSTOM_SCALE, "Scale")?)+ .with("Ofst", whole(pf(p, "offset", 0.0), CUSTOM_OFFSET, "Offset")?)+ .with("Mtrx", Value::List(m))+ }+ "LnsF" => {+ let lens = p.get("lens").and_then(J::as_str).unwrap_or("zoom");+ let code = LENSES.iter().find(|(_, l)| *l == lens).ok_or_else(|| format!("lens `{lens}` has no PSD equivalent"))?.0;+ let mut centre = Descriptor::new("Pnt ").with("Hrzn", Value::Double(pf(p, "centerX", 0.5))).with("Vrtc", Value::Double(pf(p, "centerY", 0.5)));+ centre.name = UnicodeString::new_nul("");+ d.with("Brgh", pi(p, "brightness", 100.0))+ .with("FlrC", Value::Descriptor(centre))+ .with("Lns ", Value::Enumerated { type_id: Id::new("Lns "), value: Id::Code(*code) })+ }+ "Fbrs" => d.with("Vrnc", pi(p, "variance", 16.0)).with("Strg", pi(p, "strength", 4.0)).with("RndS", seed_param(p)),+ "Clds" | "DfrC" => d.with("FlRs", seed_param(p)),"Lvls" => d.with("Adjs", adjustments(p, false)?),"Crvs" => d.with("Adjs", adjustments(p, true)?),"adaptCorrect" => {@@@ -1052,12 -680,15 +1099,17 @@@ pub fn item_for_filter(f: &SmartFilter}let k = known_by_command(&f.command).ok_or("this filter has no PSD equivalent")?;let fltr = fltr_for(k, &f.params)?;- // Pointillize's background and Tiles' fill colours are the entry's; the others write the defaults.- let (foreground, background) = match k.class {- // Fibers and the clouds draw with the colours stored on the item; the others store- // Photoshop's defaults.- let coloured = matches!(k.class, "Fbrs" | "Clds" | "DfrC");- let (fg, bg) =- if coloured { (colour_rgbc(f.params.get("foreground"), 0.0)?, colour_rgbc(f.params.get("background"), 255.0)?) } else { (rgbc(0.0), rgbc(255.0)) };++ // Pointillize's background, Tiles' colours and the render filters' colours are the entry's;++ // the others store Photoshop's defaults.++ let (fg, bg) = match k.class {+ "Pntl" => (rgbc(0.0), colour_rgbc(f.params.get("background"), 255.0)?),- "Tls " => (colour_rgbc(f.params.get("foreground"), 0.0)?, colour_rgbc(f.params.get("background"), 255.0)?),++ "Tls " | "Fbrs" | "Clds" | "DfrC" => (colour_rgbc(f.params.get("foreground"), 0.0)?, colour_rgbc(f.params.get("background"), 255.0)?),+ _ => (rgbc(0.0), rgbc(255.0)),+ };+ // The render filters are written with the descriptor names Photoshop gives them: the filter's+ // own name on `Fltr` and empty ones on the colours.- let render = coloured || k.class == "LnsF";++ let render = matches!(k.class, "Fbrs" | "Clds" | "DfrC" | "LnsF");+ let (fltr, fg, bg) = if render { (fltr.map(|f| named(f, k.name.trim_end_matches("..."))), named_value(fg), named_value(bg)) } else { (fltr, fg, bg) };let mut d = Descriptor::new("filterFX").with("Nm ", Value::Text(UnicodeString::new_nul(k.name))).with("blendOptions", blend_options(f))diff --cc docs/file-format-parity.mdindex 0a80894db,67a7b024b..034c8240e--- a/docs/file-format-parity.md+++ b/docs/file-format-parity.md@@@ -1,6 -1,6 +1,6 @@@# File-format parity- > **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-15 · **Change:** minor (DDS textures save: uncompressed or BC1–BC3, optional mip chain, DDS Options in Save As (#1327); PSD smart filters: 41 filters (27 more: Blur, Surface Blur, Smart Sharpen, Diffuse, Wind, Offset, Mezzotint and others) plus Hue/Saturation and Perspective Warp mapped both ways, #6296, #6298, #6300, #6302, #6304, #6314, #6316, #6267, #6268, FILE-215-2; large-file fixtures: a 20 MP layered PSD, a 150-layer layout, a 2 GB PSD and a 4.4 GB PSB generated at test time and round-tripped, FILE-216-2 done, #5107; earlier: PNG `sTER` stereo pairing kept on save, #6063; 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 (Photoshop mixed-order TIFF type geometry, #4758; PSD smart filters: Clouds, Difference Clouds, Fibers and Lens Flare open as editable filters; DDS textures save: uncompressed or BC1–BC3, optional mip chain, DDS Options in Save As (#1327); earlier: PNG `sTER` stereo pairing kept on save, #6063; 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 (Photoshop mixed-order TIFF type geometry, #4758; DDS textures save: uncompressed or BC1–BC3, optional mip chain, DDS Options in Save As (#1327); PSD smart filters: 45 filters (31 more: Blur, Surface Blur, Smart Sharpen, Diffuse, Wind, Offset, Mezzotint, Clouds, Difference Clouds, Fibers, Lens Flare and others) plus Hue/Saturation and Perspective Warp mapped both ways, #6296, #6298, #6300, #6302, #6304, #6314, #6316, #6267, #6268, FILE-215-2; large-file fixtures: a 20 MP layered PSD, a 150-layer layout, a 2 GB PSD and a 4.4 GB PSB generated at test time and round-tripped, FILE-216-2 done, #5107; earlier: PNG `sTER` stereo pairing kept on save, #6063; 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 2026Every format Photoshop 2026 (27.11.0) reads or writes, with PhotoCraft's support, fidelity andtests. Photoshop's list comes from its `Info.plist` `CFBundleDocumentTypes`, the PiPL read/write@@@ -21,10 -21,10 +21,10 @@@ XL are missing (gap G10). Remaining: 30| 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 (41 mapped plus Hue/Saturation, Perspective Warp, Filter Gallery with Chrome and a Camera Raw subset, 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 (18 mapped, among them Clouds, Difference Clouds, Fibers and Lens Flare, 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) |++| 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 (45 mapped, among them Clouds, Difference Clouds, Fibers and Lens Flare, plus Hue/Saturation, Perspective Warp, Filter Gallery with Chrome and a Camera Raw subset, 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); generated 20 MP, 150-layer, 2 GB PSD and 4.4 GB PSB fixtures opened, saved and re-opened by io tests/large_files.rs (FILE-216-2, 2026-10-13; the 4.4 GB PSB opens on Windows); > 4 GB from the app's File › Open 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) |+ | TIFF | R/W | yes | yes | 8/16/32f, Gray/RGB/CMYK, BigTIFF, every IFD, banded parallel decode; layered TIFF both byte orders, including Photoshop mixed-order type blocks (#4758); undecodable type keeps saved pixels (FILE-215-7: extra alpha channels not written) || JPEG | R/W | yes | yes | 8-bit Gray/RGB/CMYK, ICC/EXIF/XMP; Save keeps the opened file's quality (estimated from its quantisation tables, #2399); no JPEG Options dialog (quality 0–12, baseline/progressive) (FILE-215-19) || PNG | R/W | yes | yes | 8/16-bit, ICC/text; APNG first frame only; alpha channels on open (#2225); palette PNGs open in Indexed Color mode with their transparent entry (#4804); Save keeps a stereo PNG's `sTER` pairing (#6063) || GIF | R/W | yes | yes | File › Open keeps the first frame; New Video Layer from File and Video Frames to Layers take every frame, with the timeline rate from the delays (#572). Per-frame delays and keeping the frames in `.pcraft` are not done |@@@ -142,18 -142,12 +142,21 @@@ remaining gaps in #1606 stay tracked wi| Date | Change | Summary ||---|---|---|+ | 2026-10-15 | minor | PSD smart filters: Clouds, Difference Clouds, Fibers and Lens Flare open as editable filters with their seeds, colours and lens, and save like Photoshop (checked against a Photoshop 27 file); render filters on a smart object work within the object, so a flare sits where Photoshop puts it || 2026-10-15 | minor | DDS textures save (#1327): uncompressed or BC1/BC2/BC3 (DXT1/3/5) from a clean-room block encoder, optional box-filtered mip chain, legacy header; DDS Options in Save As and Save a Copy, `ddsCompression`/`ddsMipmaps` for scripts, the CLI and MCP |+| 2026-10-16 | minor | PSD smart filters: Perspective Warp (`perspectiveWarpTransform`: `vertices`, `warpedVertices`, `quads` of vertex indices, document pixels) opens as `layer.smartObjects.perspectiveWarp`, one plane per quad, and re-renders warped; save writes the original item with only the geometry rewritten, or a new one in Photoshop's layout; inconsistent descriptors stay verbatim (FILE-215-2, #6268) |+| 2026-10-16 | minor | PSD smart filters: Hue/Saturation (`HStr`: `Clrz`, `Adjs` = master `Hst2` plus one per edited range with `LclR` and its four range sliders, all longs, measured on a Photoshop-saved file) opens as `image.adjustments.hueSaturation`, re-renders with the smart object and saves in Photoshop's layout; layouts outside it stay verbatim (FILE-215-2, #6267) |+| 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-15 | minor | PSD smart filters: Surface Blur (filterID 1135, `surfaceBlur`), Smart Blur (`SmrB`) and Radial Blur (`RdlB`) open as editable filters and save with the keys, types and enums measured in Photoshop; out-of-range, unknown-enum or extra-key entries (an off-centre Radial Blur) stay verbatim (#6298, FILE-215-2) |+| 2026-10-15 | minor | PSD smart filters: Smart Sharpen (filterID 1131, Gaussian removal; Lens/Motion Blur and legacy entries stay verbatim) and Dust & Scratches (`DstS`) open as editable filters and save in Photoshop's measured shape (#6300) |+| 2026-10-15 | minor | PSD smart filters: Diffuse (`Dfs `, `DfsM` mode), Trace Contour (`TrcC`, level and `CntE` edge), Crystallize (`Crst`) and Pointillize (`Pntl`, background from `BckC`) open as editable smart filters and save in the shape measured in Photoshop (#6302, FILE-215-2) |+| 2026-10-15 | minor | PSD smart filters: Wind (`Wnd `, `WndM` method, `Drct` direction), Extrude (`Extr`, `ExtT` type, size, depth, `ExtR` depth mode, solid front faces, mask incomplete blocks) and Tiles (`Tls `, count, offset, `FlCl` fill with the entry's `FrgC`/`BckC`) open as editable smart filters and save in the shape measured in Photoshop (#6314, FILE-215-2) |+| 2026-10-15 | minor | PSD smart filters: Offset (`Ofst`: `Hrzn`/`Vrtc` long, `Fl ` `FlMd` Wrap/Background/Repeat) and Custom (`Cstm`: `Scl `, `Ofst` long, 25-long `Mtrx`) map both ways in `filterFX`, matching descriptors measured in Photoshop (FILE-215-2, #6304) |+| 2026-10-15 | minor | PSD smart filters: Mezzotint (`Mztn`, `MztT` enum, all 10 types) and Color Halftone (`ClrH`, `Rds `/`Ang1`–`Ang4` longs) open as editable filters and save in Photoshop's shape, measured in Photoshop (FILE-215-2); Mezzotint's PhotoCraft-only seed is not saved || 2026-10-15 | minor | PNG: a stereo PNG's `sTER` pairing (PNG Extensions 1.4.0 §3.6) is read on open and written back on save, so the file still says it is a stereo pair (#6063) || 2026-10-15 | minor | PSD guides: image resource 1092 (guides v2) gives guides their own colours on import; 1092 and 1097 (guide GUIDs) are written back only while they still describe the document's guides, so an edit no longer leaves Photoshop a stale second guide list (#5966) |+ | 2026-10-15 | minor | Bevel & Emboss Gloss Contour › Anti-aliased (`antialiasGloss`) is read and written, set by `glossAntiAlias` and shown in the Layer Style dialog; a PSD whose bevel is edited no longer loses it. Rendering still ignores contour anti-aliasing, as for the other effects' contours |+ | 2026-10-15 | minor | Stroke › Overprint (`overprint`) is read and written, set by the stroke command's `overprint` and shown in the Layer Style dialog; an edited stroke no longer drops it. Rendering ignores it for now || 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 |