Files
photocraft/crates/psd/tests/layer_block_order.rs
Elvis33LEandClaude Opus 5.5 1452c49258 PSD save: stream Lr16/Lr32 layer blocks into the output (#1158)
Saving a 16- or 32-bit PSD built the Lr16/Lr32 layer payload in a temporary buffer and cloned
every global tagged block before copying them into the file. The payload is now written
straight into the output with its length patched afterwards, and the neighbouring blocks are
borrowed. Output is byte-identical: all 735 corpus PSD/PSBs re-save to the same bytes. A 24 MP
layer saves in 66 ms instead of 75 ms at 16-bit and 132 ms instead of 164 ms at 32-bit, and the
temporary 144-288 MB copy is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 01:13:22 -04:00

27 lines
1.2 KiB
Rust

//! The global layer block retains its insertion position and neighboring opaque blocks.
use photocraft_psd::*;
#[test]
fn global_layer_block_roundtrips_with_opaque_neighbors() {
for version in [Version::Psd, Version::Psb] {
for depth in [16, 32] {
for index in 0..=2 {
for signature in [*b"8BIM", *b"8B64"] {
let mut file = testgen::layered(version, ColorMode::Rgb, depth, Compression::Raw);
file.global_blocks = vec![TaggedBlock::new(*b"zz01", vec![7, 8, 9]), TaggedBlock::new(*b"zz02", vec![10, 11])];
file.layer_info_placement = LayerInfoPlacement::GlobalBlock {
index,
signature,
key: if depth == 16 { *b"Lr16" } else { *b"Lr32" },
padding: Some(vec![31, 32, 33]),
};
let bytes = file.to_bytes().unwrap();
let parsed = PsdFile::from_bytes(&bytes).unwrap();
assert_eq!(parsed, file, "{version:?} {depth} {index} {signature:?}");
assert_eq!(parsed.to_bytes().unwrap(), bytes);
}
}
}
}
}