PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge PR #6305: PSD: Offset and Custom smart filters open and save like Photoshop (#6304)
aiongg9bf386adc90f
diff --cc crates/io/src/smart_map.rsindex e1b68817a,1a8c29e91..19e75b9d7--- a/crates/io/src/smart_map.rs+++ b/crates/io/src/smart_map.rs@@@ -559,61 -324,11 +560,62 @@@ 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": unit_in(f, "Rds ", b"#Pxl", 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(double(f, "Rds ")?, 0.1, 100.0)?,+ "threshold": in_range(double(f, "Thsh")?, 0.1, 100.0)?,+ "quality": enum_name(f, "SmBQ", "SmBQ", &SMART_BLUR_QUALITY)?,+ "mode": enum_name(f, "SmBM", "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", "BlrM", &RADIAL_METHOD)?,+ "quality": enum_name(f, "BlrQ", "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;+ only_keys(f, &["Hrzn", "Vrtc", "Fl "])?;+ let fill = OFFSET_FILL.iter().find(|(psd, _)| typed_enum(f, "Fl ", "FlMd") == Some(psd.as_bytes()))?.1;json!({"horizontal": int(f, "Hrzn")?, "vertical": int(f, "Vrtc")?, "undefinedAreas": fill})}("Cstm", Some(f)) => custom_params(f)?,@@@ -2343,8 -1327,12 +2345,12 @@@ mod testsoffset_fltr(i(1), unit(b"#Pxl", f64::NAN), enumv("FlMd", "Wrp ")),Descriptor::new("Ofst").with("Hrzn", i(1)).with("Fl ", enumv("FlMd", "Wrp ")),Descriptor::new("Ofst"),+ // A mistyped enum, a setting we don't write back and a repeated one.+ offset_fltr(i(1), i(2), enumv("Xxxx", "Wrp ")),+ offset_fltr(i(1), i(2), enumv("FlMd", "Wrp ")).with("Xtra", i(1)),+ offset_fltr(i(1), i(2), enumv("FlMd", "Wrp ")).with("Hrzn", i(3)),] {- let item = measured_item(b"Ofst", "Offset...", fltr);+ let item = measured_named_item(b"Ofst", "Offset...", fltr);let f = filter_from_item(&item);assert_eq!(f.command, UNSUPPORTED_FILTER, "{item:?}");assert_eq!(item_for_filter(&f).unwrap().to_bytes(), item.to_bytes(), "kept byte for byte");@@@ -2424,8 -1412,10 +2430,10 @@@Descriptor::new("Cstm").with("Scl ", i(1)).with("Ofst", i(0)).with("Mtrx", i(5)),Descriptor::new("Cstm").with("Scl ", i(1)).with("Mtrx", Value::List(longs(&SHARPEN))),Descriptor::new("Cstm"),+ // A setting we don't write back.+ custom_fltr(i(1), i(0), longs(&SHARPEN)).with("Xtra", i(1)),] {- let item = measured_item(b"Cstm", "Custom...", fltr);+ let item = measured_named_item(b"Cstm", "Custom...", fltr);let f = filter_from_item(&item);assert_eq!(f.command, UNSUPPORTED_FILTER, "{item:?}");assert_eq!(item_for_filter(&f).unwrap().to_bytes(), item.to_bytes(), "kept byte for byte");