PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Save As: offer ICO, GIF and BMP in the file type list (#4357) (#4405)
F4LCON851916e0d7df
diff --git a/apps/photocraft/src/services.rs b/apps/photocraft/src/services.rsindex 7ec91954b..f892de31c 100644--- a/apps/photocraft/src/services.rs+++ b/apps/photocraft/src/services.rs@@ -60,6 +60,10 @@ const SAVE_FILTERS: &[(&str, &[&str])] = &[("WebP", &["webp"]),("TIFF", &["tif"]),("Targa", &["tga"]),+ // Also in Photoshop's Save As list; ICO is PhotoCraft's own (#4357): up to 256×256, with alpha.+ ("BMP", &["bmp"]),+ ("GIF", &["gif"]),+ ("ICO", &["ico"]),("OpenEXR", &["exr"]),("FITS", &["fits", "fit"]),("DPX", &["dpx"]),@@ -670,6 +674,33 @@ mod tests {assert_eq!(save_filters("Untitled")[0].0, "PSD Document", "no extension keeps the default");}+ /// Every flat format Save As offers is one PhotoCraft writes, and ICO is among them (#4357).+ #[test]+ fn save_as_offers_only_writable_formats_including_ico() {+ let layered = ["psd", "psb", "pcraft", "ora"];+ for (name, exts) in SAVE_FILTERS {+ for ext in exts.iter().filter(|e| !layered.contains(e)) {+ let format = photocraft_codecs::from_extension(ext).unwrap_or_else(|| panic!("{name}: .{ext} is no known format"));+ assert!(format.caps().write, "{name}: .{ext} can't be written");+ }+ }+ for ext in ["ico", "gif", "bmp"] {+ assert!(save_filters("Untitled-1.psd").iter().any(|(_, exts)| exts.iter().any(|e| e == ext)), ".{ext} is offered");+ }+ assert_eq!(save_filters("icon.ico")[0].0, "ICO", "an .ico name leads with its own type");+ // What Save As writes there: an icon up to 256×256, and a clear error past that.+ let doc = |side: u32| {+ let mut s = Session::new();+ s.execute("file.new", json!({"width": side, "height": side})).unwrap();+ s.active().unwrap().doc.clone()+ };+ let opts = export_options(&photocraft_ui_egui::ExportSettings::default());+ let icon = photocraft_io::export(&doc(256), "icon.ico", &opts).unwrap();+ assert_eq!(icon.bytes[..4], [0, 0, 1, 0], "an ICO header");+ let err = photocraft_io::export(&doc(300), "icon.ico", &opts).map(|_| ()).unwrap_err().to_string();+ assert!(err.contains("256"), "{err}");+ }+#[test]fn block_on_waits_for_a_wake_from_another_thread() {let (tx, rx) = std::sync::mpsc::channel::<std::task::Waker>();