60 lines
3.0 KiB
Rust
60 lines
3.0 KiB
Rust
use std::path::Path;
|
|
|
|
fn main() {
|
|
let args: Vec<String> = std::env::args().collect();
|
|
let input = args.get(1).map(|s| s.as_str()).unwrap_or("_images/_test_images/example3/Example3-mini.psd");
|
|
let output = args.get(2).map(|s| s.as_str()).unwrap_or("/tmp/self_roundtrip_1.psd");
|
|
let output2 = args.get(3).map(|s| s.as_str()).unwrap_or("/tmp/self_roundtrip_2.psd");
|
|
|
|
println!("=== Self Round-Trip Test: import -> save -> import -> save ===");
|
|
println!("Input: {}", input);
|
|
println!("Pass 1: {}", output);
|
|
println!("Pass 2: {}", output2);
|
|
|
|
// Pass 1: import original and save
|
|
let psd = hcie_psd::Psd::from_bytes(&std::fs::read(input).expect("read")).expect("parse");
|
|
let layers1 = hcie_psd::import_psd(Path::new(input)).expect("import1");
|
|
hcie_psd::save_psd(&layers1, psd.width(), psd.height(), &psd.rgba(), Path::new(output)).expect("save1");
|
|
println!("Pass 1 OK: {} layers", layers1.len());
|
|
|
|
// Pass 2: re-open the file we just saved
|
|
let psd2_bytes = std::fs::read(output).expect("read2");
|
|
println!("Pass 1 file size: {} bytes", psd2_bytes.len());
|
|
let psd2 = hcie_psd::Psd::from_bytes(&psd2_bytes).expect("parse2");
|
|
let layers2 = hcie_psd::import_psd(Path::new(output)).expect("import2");
|
|
hcie_psd::save_psd(&layers2, psd2.width(), psd2.height(), &psd2.rgba(), Path::new(output2)).expect("save2");
|
|
println!("Pass 2 OK: {} layers", layers2.len());
|
|
|
|
// Compare pass1 and pass2 layer lists
|
|
println!("\n=== Layer Comparison ===");
|
|
compare_layer_lists(&layers1, &layers2);
|
|
}
|
|
|
|
fn compare_layer_lists(a: &[hcie_protocol::Layer], b: &[hcie_protocol::Layer]) {
|
|
println!("A: {} layers, B: {} layers", a.len(), b.len());
|
|
for i in 0..a.len().max(b.len()) {
|
|
let la = a.get(i);
|
|
let lb = b.get(i);
|
|
if let (Some(a), Some(b)) = (la, lb) {
|
|
let _name_match = a.name == b.name;
|
|
let type_match = std::mem::discriminant(&a.layer_type) == std::mem::discriminant(&b.layer_type);
|
|
let blend_match = std::mem::discriminant(&a.blend_mode) == std::mem::discriminant(&b.blend_mode);
|
|
let fx_match = a.effects.len() == b.effects.len();
|
|
let adj_match = a.adjustment_raw.is_some() == b.adjustment_raw.is_some();
|
|
let div_match = a.is_section_divider == b.is_section_divider;
|
|
println!(
|
|
" [{}] '{}' type_match={} blend_match={} fx_match={}({}/{}) adj_match={} div_match={}",
|
|
i, a.name, type_match, blend_match, fx_match, a.effects.len(), b.effects.len(), adj_match, div_match
|
|
);
|
|
if !blend_match {
|
|
println!(" BLEND MISMATCH: A={:?} B={:?}", a.blend_mode, b.blend_mode);
|
|
}
|
|
if !fx_match {
|
|
println!(" FX MISMATCH: A effects={:?} B effects={:?}", a.effects, b.effects);
|
|
}
|
|
} else {
|
|
println!(" [{}] A={} B={}", i, la.map(|l| l.name.as_str()).unwrap_or("<missing>"), lb.map(|l| l.name.as_str()).unwrap_or("<missing>"));
|
|
}
|
|
}
|
|
}
|