67 lines
3.3 KiB
Rust
67 lines
3.3 KiB
Rust
fn main() {
|
|
let tests = [
|
|
("drop shadow", "/home/hc/Pictures/_psd_stil_test/test_2/drop shadow.psd", "/home/hc/Pictures/_psd_stil_test/test_2/drop shadow.png"),
|
|
("inner shadow", "/home/hc/Pictures/_psd_stil_test/test_2/inner shadow.psd", "/home/hc/Pictures/_psd_stil_test/test_2/inner shadow.png"),
|
|
("inner bevel", "/home/hc/Pictures/_psd_stil_test/test_2/inner bevel.psd", "/home/hc/Pictures/_psd_stil_test/test_2/inner bevel.png"),
|
|
("Emboss", "/home/hc/Pictures/_psd_stil_test/test_2/Emboss.psd", "/home/hc/Pictures/_psd_stil_test/test_2/Emboss.png"),
|
|
("inner glow", "/home/hc/Pictures/_psd_stil_test/test_2/inner glow.psd", "/home/hc/Pictures/_psd_stil_test/test_2/inner glow.png"),
|
|
("stroke", "/home/hc/Pictures/_psd_stil_test/test_2/stroke.psd", "/home/hc/Pictures/_psd_stil_test/test_2/stroke.png"),
|
|
];
|
|
|
|
for (label, psd_path, ref_path) in &tests {
|
|
if !std::path::Path::new(psd_path).exists() {
|
|
println!("{}: PSD not found", label);
|
|
continue;
|
|
}
|
|
if !std::path::Path::new(ref_path).exists() {
|
|
println!("{}: ref not found", label);
|
|
continue;
|
|
}
|
|
|
|
let layers = match hcie_psd::import_psd(std::path::Path::new(psd_path)) {
|
|
Ok(l) => l,
|
|
Err(e) => { println!("{}: import failed: {}", label, e); continue; }
|
|
};
|
|
|
|
let comp_layers: Vec<hcie_composite::Layer> = layers.iter().map(|l| hcie_composite::Layer {
|
|
name: l.name.clone(),
|
|
layer_type: l.layer_type.clone(),
|
|
data: l.data.clone(),
|
|
pixels: l.pixels.clone(),
|
|
width: l.width, height: l.height, visible: l.visible,
|
|
opacity: l.opacity, blend_mode: l.blend_mode.clone(),
|
|
locked: l.locked, dirty: l.dirty, id: l.id, parent_id: l.parent_id,
|
|
styles: l.styles.clone(), clipping_mask: l.clipping_mask,
|
|
collapsed: l.collapsed, adjustment: l.adjustment.clone(),
|
|
mask_pixels: l.mask_pixels.clone(), mask_bounds: l.mask_bounds,
|
|
mask_default_color: l.mask_default_color,
|
|
curve_points: l.curve_points.clone(),
|
|
fill_opacity: l.fill_opacity,
|
|
effects: l.effects.clone(),
|
|
effects_dirty: std::sync::atomic::AtomicBool::new(false),
|
|
effects_cache: std::sync::Mutex::new(None),
|
|
adjustment_raw: None,
|
|
is_section_divider: false,
|
|
image_resources_raw: None,
|
|
}).collect();
|
|
|
|
let canvas_w = comp_layers[0].width;
|
|
let canvas_h = comp_layers[0].height;
|
|
let output = hcie_composite::composite_layers(&comp_layers, canvas_w, canvas_h);
|
|
|
|
let ref_img = image::open(ref_path).unwrap().to_rgba8();
|
|
if ref_img.width() != canvas_w || ref_img.height() != canvas_h {
|
|
println!("{}: dim mismatch {}x{} vs {}x{}", label, canvas_w, canvas_h, ref_img.width(), ref_img.height());
|
|
continue;
|
|
}
|
|
|
|
let ref_pixels: Vec<u8> = ref_img.pixels().flat_map(|p| p.0.iter().copied()).collect();
|
|
let mut diff_sum = 0.0f64;
|
|
let px_cnt = (canvas_w * canvas_h) as f64;
|
|
for i in 0..output.len() {
|
|
diff_sum += (output[i] as f64 - ref_pixels[i] as f64).abs();
|
|
}
|
|
println!("{}: MAE={:.2}", label, diff_sum / px_cnt);
|
|
}
|
|
}
|