psd: delegate lenient TySh prefix preservation to craft-psd

This commit is contained in:
Dylan M. Taylor committed 2026-11-16 14:34:48 -05:00
1 parent 02e9907f68
commit b512fde2f7
4 files changed
+27 -12

No files matched your search

Generated
+12
View File
@@ -1629,6 +1629,17 @@ dependencies = [
"thiserror 2.0.21",
]
[[package]]
name = "craft-psd"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=1035b2b29914520c17c218d42bda02495ef85668#1035b2b29914520c17c218d42bda02495ef85668"
dependencies = [
"encoding_rs",
"flate2",
"rayon",
"thiserror 2.0.21",
]
[[package]]
name = "craft-psd"
version = "0.1.0"
@@ -5787,6 +5798,7 @@ dependencies = [
"craft-pdf",
"craft-pdn",
"craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=040b5202f9ca2ecaedcaea9351fc095c0d3dc5e8)",
"craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=1035b2b29914520c17c218d42bda02495ef85668)",
"craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2823525586851bf81ccfe9daf838c7a4cafb8ab9)",
"craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=589842f0da5c5a11e71f39b70092dcb918b92f39)",
"craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5e2bc54a48c9f03e7ce4eca42775ce5cc051f5d6)",
+1
View File
@@ -29,6 +29,7 @@ photocraft-doc = { workspace = true }
photocraft-compose = { workspace = true }
photocraft-algo = { workspace = true }
craft-psd = { workspace = true }
craft-psd-tysh = { package = "craft-psd", version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "1035b2b29914520c17c218d42bda02495ef85668" }
craft-psd-displace = { package = "craft-psd", version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2823525586851bf81ccfe9daf838c7a4cafb8ab9" }
craft-psd-names = { package = "craft-psd", git = "https://github.com/storytold/craft-libs", rev = "040b5202f9ca2ecaedcaea9351fc095c0d3dc5e8", version = "0.1.0" }
craft-psd-channels = { package = "craft-psd", git = "https://github.com/storytold/craft-libs", rev = "5e2bc54a48c9f03e7ce4eca42775ce5cc051f5d6", version = "0.1.0" }
+1 -12
View File
@@ -713,18 +713,7 @@ pub(crate) fn quilt_knots(env: &Descriptor, key: &str, patches: usize) -> Option
/// Text content and transform from a `TySh` block (best effort).
pub fn parse_tysh(data: &[u8]) -> Option<(String, Affine)> {
let f = |at: usize| data.get(at..at + 8).map(|b| f64::from_be_bytes(b.try_into().unwrap_or([0; 8])));
let mut m = [0.0; 6];
for (i, v) in m.iter_mut().enumerate() {
*v = f(2 + i * 8)?;
}
// text version (2) at 50, descriptor version (4) at 52, descriptor at 56.
let rest = data.get(52..)?;
let text = parse_prefix_versioned(rest).and_then(|d| match d.get("Txt ") {
Some(Value::Text(t)) => Some(t.to_string_lossy()),
_ => None,
});
Some((text.unwrap_or_default(), Affine { m }))
craft_psd_tysh::text::envelope::parse_tysh_text_prefix(data).map(|(text, m)| (text, Affine { m }))
}
/// Parses a version-16 descriptor at the start of `data` (trailing bytes allowed).
+13
View File
@@ -333,3 +333,16 @@ fn fills_roundtrip() {
}
}
}
#[test]
fn tysh_preservation_fallback_survives_missing_descriptor() {
let mut bytes = vec![0u8; 52];
let expected = [1.0f64, 0.0, 0.0, 1.0, 25.0, 30.0];
for (i, v) in expected.iter().enumerate() {
bytes[2 + i * 8..10 + i * 8].copy_from_slice(&v.to_be_bytes());
}
let (text, transform) = super::parse_tysh(&bytes).unwrap();
assert!(text.is_empty());
assert_eq!(transform.m, expected);
assert!(super::parse_tysh(&bytes[..51]).is_none());
}