mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
test(psd): account for required odd TySh padding and pin merged parser
This commit is contained in:
1 parent
9ac3a66c4d
commit
e2f218749d
3 files changed
+29
-22
No files matched your search
Generated
+2
-2
@@ -1632,7 +1632,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-psd"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=10632da31bd7c0c976c97b3b524a14a0880ec474#10632da31bd7c0c976c97b3b524a14a0880ec474"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=20220807a4c33a35a72c7b4dfad90edd29205e34#20220807a4c33a35a72c7b4dfad90edd29205e34"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"flate2",
|
||||
@@ -5798,7 +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=10632da31bd7c0c976c97b3b524a14a0880ec474)",
|
||||
"craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=20220807a4c33a35a72c7b4dfad90edd29205e34)",
|
||||
"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)",
|
||||
|
||||
@@ -29,7 +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 = "10632da31bd7c0c976c97b3b524a14a0880ec474" }
|
||||
craft-psd-tysh = { package = "craft-psd", version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "20220807a4c33a35a72c7b4dfad90edd29205e34" }
|
||||
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" }
|
||||
|
||||
@@ -643,24 +643,31 @@ fn unicode_names_preserve_empty_lossy_and_terminator_policy() {
|
||||
|
||||
#[test]
|
||||
fn oversized_tysh_fallback_remains_type_and_roundtrips_raw_block() {
|
||||
let mut file = testgen::small(Version::Psd, Compression::Raw);
|
||||
let mut raw = vec![0u8; craft_psd_tysh::text::envelope::MAX_BYTES + 1];
|
||||
for (i, value) in [1.0f64, 0.0, 0.0, 1.0, 25.0, 30.0].iter().enumerate() {
|
||||
raw[2 + i * 8..10 + i * 8].copy_from_slice(&value.to_be_bytes());
|
||||
for extra in [1, 2] {
|
||||
let mut file = testgen::small(Version::Psd, Compression::Raw);
|
||||
let mut raw = vec![0u8; craft_psd_tysh::text::envelope::MAX_BYTES + extra];
|
||||
for (i, value) in [1.0f64, 0.0, 0.0, 1.0, 25.0, 30.0].iter().enumerate() {
|
||||
raw[2 + i * 8..10 + i * 8].copy_from_slice(&value.to_be_bytes());
|
||||
}
|
||||
file.layers_mut()[0].blocks.push(craft_psd::TaggedBlock::new(*b"TySh", raw.clone()));
|
||||
let (doc, _, _) = psd_to_document_decoded_integrity(&file, &photocraft_raster::Interrupt::NONE, None).unwrap();
|
||||
let text = doc
|
||||
.layers
|
||||
.iter()
|
||||
.find_map(|layer| match &layer.content {
|
||||
LayerContent::Text(text) => Some(text),
|
||||
_ => None,
|
||||
})
|
||||
.expect("oversized descriptor must retain a type layer rather than rasterizing");
|
||||
assert!(text.text.is_empty());
|
||||
assert_eq!(text.psd_raw.as_deref().unwrap().as_slice(), raw);
|
||||
let saved = crate::psd_export::document_to_psd(&doc).unwrap();
|
||||
let block = saved.layers().iter().find_map(|layer| layer.block(b"TySh")).unwrap();
|
||||
// Layer blocks include a zero pad inside odd lengths for PSD reader compatibility (#200).
|
||||
// No original byte may change; only that required pad may be appended.
|
||||
if raw.len() % 2 == 1 {
|
||||
raw.push(0);
|
||||
}
|
||||
assert_eq!(block.data, raw);
|
||||
}
|
||||
file.layers_mut()[0].blocks.push(craft_psd::TaggedBlock::new(*b"TySh", raw.clone()));
|
||||
let (doc, _, _) = psd_to_document_decoded_integrity(&file, &photocraft_raster::Interrupt::NONE, None).unwrap();
|
||||
let text = doc
|
||||
.layers
|
||||
.iter()
|
||||
.find_map(|layer| match &layer.content {
|
||||
LayerContent::Text(text) => Some(text),
|
||||
_ => None,
|
||||
})
|
||||
.expect("oversized descriptor must retain a type layer rather than rasterizing");
|
||||
assert!(text.text.is_empty());
|
||||
assert_eq!(text.psd_raw.as_deref().unwrap().as_slice(), raw);
|
||||
let saved = crate::psd_export::document_to_psd(&doc).unwrap();
|
||||
let block = saved.layers().iter().find_map(|layer| layer.block(b"TySh")).unwrap();
|
||||
assert_eq!(block.data, raw);
|
||||
}
|
||||
Reference in new issue
Block a user