fix: preserve XML and raster import semantics after codec cutover

This commit is contained in:
Dylan M. Taylor
2026-11-14 23:25:19 +00:00
parent 1e1100a9ed
commit 5122a1f9d9
10 changed files with 249 additions and 57 deletions
+11 -2
View File
@@ -144,9 +144,18 @@ fn unpack(mut src: &[u8], out: &mut Vec<u8>) {
}
}
/// The composite as a reader sees it.
/// The stored composite: RGB stays white-matted, with its original alpha.
fn merged(f: &[u8]) -> Vec<u8> {
craft_psd::PsdFile::from_bytes(f).expect("a PSD a reader takes").composite_rgba8().expect("composite").data
let psd = craft_psd::PsdFile::from_bytes(f).expect("a PSD a reader takes");
if psd.header.color_mode != craft_psd::ColorMode::Rgb {
return psd.composite_rgba8().expect("composite").data;
}
assert_eq!(psd.header.depth, 8);
let samples = psd.decode_merged().expect("stored composite planes");
let count = psd.header.width as usize * psd.header.height as usize;
(0..count)
.flat_map(|i| [samples[i], samples[count + i], samples[2 * count + i], if psd.merged_has_alpha() { samples[3 * count + i] } else { 255 }])
.collect()
}
fn pixel(px: &[u8], width: usize, x: usize, y: usize) -> [u8; 4] {
+5
View File
@@ -172,6 +172,11 @@ fn packbits_and_bilevel_images_decode() {
let dec = craft_image_codecs::decode_as(craft_image_codecs::Format::Tiff, &file).unwrap();
assert_eq!(dec.width(), 10);
assert_eq!(dec.height(), 3);
assert_eq!(
dec.data(),
[0, 255, 0, 255, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
"WhiteIsZero samples are inverted and row padding is ignored"
);
// A buffer that doesn't match the size is refused, not written.
let short = Image { data: &rows[..5], ..image };
assert!(t::write(&short, &Layout { byte_order: ByteOrder::Little, compression: Compression::None, ppi: 72.0, icc: None }).is_err());