diff --git a/Cargo.lock b/Cargo.lock index 39fce1ec6..ed67e2422 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1449,7 +1449,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=30cad49e958caa58ebd04eb1d459ab616a07c63f#30cad49e958caa58ebd04eb1d459ab616a07c63f" +source = "git+https://github.com/storytold/craft-libs?rev=f8d869c1e70d1df8109a951c3a30eb2e0aecd54c#f8d869c1e70d1df8109a951c3a30eb2e0aecd54c" dependencies = [ "encoding_rs", "flate2", diff --git a/Cargo.toml b/Cargo.toml index 029ad4992..097fb8389 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs" craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "808730f49b9637b7909fe2ae56f9d63fdb100cae", default-features = false, features = ["read"] } craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } -craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "30cad49e958caa58ebd04eb1d459ab616a07c63f" } +craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "f8d869c1e70d1df8109a951c3a30eb2e0aecd54c" } craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "77686f24fe8665c21369f1b593f4d65a973e2a45" } craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } diff --git a/crates/psd/src/tests/opt.rs b/crates/psd/src/tests/opt.rs index f48b6123b..3f351a7ab 100644 --- a/crates/psd/src/tests/opt.rs +++ b/crates/psd/src/tests/opt.rs @@ -716,3 +716,38 @@ fn identifier_and_index_references_preserve_non_null_classes_exactly() { assert_eq!(out, bytes); } } +#[test] +fn shared_descriptor_nesting_preserves_the_application_boundary() { + use craft_psd::descriptor::{Descriptor as Shared, Value}; + for count in [33, 64, 65] { + let mut value = Value::Integer(1); + for _ in 0..count { + value = Value::Descriptor(Shared::new("null").with("next", value)); + } + let bytes = Shared::new("null").with("root", value).to_bytes(); + let result = crate::descriptor::read_descriptor(&mut Reader::new(&bytes)); + assert_eq!(result.is_ok(), count <= 64, "nested descriptor count {count}: {result:?}"); + } +} + +#[test] +fn shared_placed_layer_adapter_normalizes_before_warp_classification() { + use craft_psd::descriptor::{Descriptor as Shared, Id, Value}; + let warp = Shared::new("warp") + .with("warpStyle", Value::Enumerated { type_id: Id::new("warpStyle"), value: Id::new("warpArc") }) + .with("warpValue", Value::Double(f64::NAN)) + .with("warpPerspective", Value::Double(f64::INFINITY)) + .with("warpPerspectiveOther", Value::Double(f64::NEG_INFINITY)); + let quad = [f64::NAN, 0.0, 20.0, 0.0, 20.0, 10.0, 0.0, 10.0]; + let descriptor = Shared::new("null").with("Trnf", Value::List(quad.into_iter().map(Value::Double).collect())).with("warp", Value::Descriptor(warp)); + let mut bytes = b"soLD".to_vec(); + bytes.extend_from_slice(&4u32.to_be_bytes()); + bytes.extend_from_slice(&16u32.to_be_bytes()); + bytes.extend_from_slice(&descriptor.to_bytes()); + let shared = craft_psd::smart::SmartObject::from_placed_layer_data_with_limits(&bytes, crate::descriptor::PARSE_LIMITS).unwrap(); + let object = crate::placed::from_craft_smart(shared); + assert_eq!(object.quad, [[0.0, 0.0], [20.0, 0.0], [20.0, 10.0], [0.0, 10.0]]); + assert!(object.warp.is_none(), "normalization must precede identity classification"); + assert!(!object.needs_bake()); + assert_eq!(object.map([10.0, 5.0], 20.0, 10.0), [10.0, 5.0]); +}