PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge PR #7948: PSB save: 8-byte-length global blocks use the 8B64 signature, so Photoshop opens the file (#7937)
David Mannbc5e4d4c8d84
diff --cc crates/io/src/multichannel_map.rsindex 18b3f47ab,db31e743e..c145b8b46--- a/crates/io/src/multichannel_map.rs+++ b/crates/io/src/multichannel_map.rs@@@ -168,9 -152,10 +168,9 @@@ pub(crate) fn layerless_filelet global_blocks: Vec<TaggedBlock> = crate::annotations_map::export_blocks(doc, crate::pattern_map::export_global_blocks(doc)).into_iter().filter(|(_, key, _)| !matches!(key, b"Layr" | b"Lr16" | b"Lr32"))- .map(|(sig, key, data)| crate::psd_export::global_block(crate::psd_export::block_signature(sig, header.version), key, &data))- .map(|(sig, key, data)| crate::psd_export::global_block(sig, key, &data))++ .map(|(sig, key, data)| crate::psd_export::global_block(crate::psd_export::block_signature(sig, key, header.version), key, &data)).collect();- let color_mode_data = photocraft_psd::hdr::color_mode_data_for_depth(header.depth);- let file = PsdFile {+ PsdFile {header,color_mode_data,resources,diff --cc crates/io/src/psd_export.rsindex c2b561688,28ea88499..9a88d5a09--- a/crates/io/src/psd_export.rs+++ b/crates/io/src/psd_export.rs@@@ -1516,9 -1516,16 +1516,16 @@@ pub(crate) fn estimate_psd_size(doc: &D/// The signature a kept tagged block is written with. `8B64` exists only in PSB files: a PSD/// with an `8B64` block (kept from a PSB source, e.g. its global `FMsk` or `cinf`) is refused by- /// Photoshop as "not compatible with this version" (measured in Photoshop 27.11).- pub(crate) fn block_signature(sig: [u8; 4], version: Version) -> [u8; 4] {- if version == Version::Psd && sig == *b"8B64" { *b"8BIM" } else { sig }+ /// Photoshop as "not compatible with this version" (measured in Photoshop 27.11). The other way+ /// round, a PSB block with an 8-byte length is `8B64`, as Photoshop writes it: an `8BIM` `lnk2`,+ /// `pths` or `cinf` (kept from a PSD source, whose lengths the PSB widens) makes Photoshop read+ /// the length as 4 bytes and refuse the whole file (#7937).-fn block_signature(sig: [u8; 4], key: [u8; 4], version: Version) -> [u8; 4] {++pub(crate) fn block_signature(sig: [u8; 4], key: [u8; 4], version: Version) -> [u8; 4] {+ match version {+ Version::Psd if sig == *b"8B64" => *b"8BIM",+ Version::Psb if sig == *b"8BIM" && photocraft_psd::tagged::uses_long_length(version, &key) => *b"8B64",+ _ => sig,+ }}pub(crate) fn psd_version(doc: &Document, force_psb: bool, size_exceeds_limit: bool) -> Version {