Files
photocraft/crates/io/tests/it/psd_roundtrip_bytes.rs
Dylan M. Taylor 74330157cb Use craft-psd for PSD/PSB format code (#13414)
* Use craft-psd from craft-libs; remove crates/psd

* Regenerate the scorecard (28 crate roots)

* Take craft-psd at craft-libs 55d120f2

* Regenerate lockfile for current shared format crates

* Pin shared format crates to current craft-libs main

* Match brush import cap to shared decoder budget

* xtask: update layer fixtures after PSD extraction
2026-11-12 02:53:54 -05:00

29 lines
1.4 KiB
Rust

//! The parallel RLE/decode paths must not change output bytes: a document exported by this
//! branch re-exports byte-equal after a decode/encode cycle, and matches main's exporter
//! (verified by the corpus round-trip floors in `corpus.rs`; here the byte-equality of the
//! codec layer itself is pinned).
use craft_psd::compression::{Compression, PlaneLayout, decode_planes, encode_planes};
use craft_psd::header::Version;
#[test]
fn encode_decode_planes_round_trip_exactly() {
let mut data: u64 = 0x0123_4567_89ab_cdef;
let mut next = move || {
data ^= data << 13;
data ^= data >> 7;
data ^= data << 17;
data
};
for (version, planes, w, h, depth) in
[(Version::Psd, 1usize, 640usize, 480usize, 8u16), (Version::Psb, 1, 15000, 10000, 8), (Version::Psd, 4, 513, 65, 8), (Version::Psb, 3, 64, 2049, 16)]
{
let layout = PlaneLayout { planes, width: w, height: h, depth, version };
let n = layout.decoded_len().expect("size");
let pattern: Vec<u8> = if h % 2 == 0 { vec![42u8; n] } else { (0..n).map(|i| ((i as u64 ^ next()) % 251) as u8).collect() };
let encoded = encode_planes(Compression::Rle, &pattern, &layout).expect("encode");
let decoded = decode_planes(Compression::Rle, &encoded, &layout).expect("decode");
assert_eq!(decoded, pattern, "{version:?} {planes}x{w}x{h} d{depth}");
}
}