PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Address CodeRabbit review: keep a filter whose Fltr is not a descriptor verbatim
David Mann19f9f500420c
diff --git a/crates/io/src/smart_map.rs b/crates/io/src/smart_map.rsindex 6a4d405cc..8af46c6a6 100644--- a/crates/io/src/smart_map.rs+++ b/crates/io/src/smart_map.rs@@ -487,6 +487,9 @@ pub fn filter_from_item(item: &Descriptor) -> SmartFilter {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(GALLERY_CLASS) => fltr.and_then(|f| gallery_params(item, f)).map(|p| (GALLERY_COMMAND, p)),+ // A `Fltr` that is there but not a descriptor is settings we can't read: kept verbatim+ // rather than taken for a filter stored without options (which would drop it on save).+ _ if fltr.is_none() && item.get("Fltr").is_some() => None,c => c.and_then(|c| known_params(c, fltr)),};let (command, params) = match known {@@ -1273,12 +1276,18 @@ mod tests {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)))),+ // Settings that aren't a descriptor, on a filter that has none.+ photoshop_no_options_item("X", Value::Integer(blur)).with("Fltr", Value::Integer(5)),+ photoshop_no_options_item("X", Value::Integer(blur)).with("Fltr", Value::Text(UnicodeString::new_nul("Blr "))),+ photoshop_no_options_item("X", Value::Integer(781)).with("Fltr", 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());+ let written = item_for_filter(&f).unwrap();+ assert_eq!(written.get("Fltr"), item.get("Fltr"), "{item:?}");+ let back = filter_from_item(&written);assert_eq!((back.command.as_str(), &back.params["filterID"]), (UNSUPPORTED_FILTER, &f.params["filterID"]));}}