Files

47 lines
1.9 KiB
Rust

fn main() {
use std::io::Write;
let base = "_images/_psd_stil_test";
let tests = [
("outer_glow", "outer_glow"),
("outer_glow_2", "outer_glow_2"),
("outer_glow_3", "outer_glow_3"),
("sultan Layer 1", "sultan_test/sultan/Layer 1"),
("emboss", "emboss"),
];
for (name, path) in &tests {
let psd_path = format!("{}/{}.psd", base, path);
let png_path = format!("{}/{}.png", base, path);
if !std::path::Path::new(&psd_path).exists() { continue; }
let ref_img = image::open(&png_path).unwrap().to_rgba8();
let ref_pixels = ref_img.into_raw();
let layers = hcie_psd::import_psd(std::path::Path::new(&psd_path)).unwrap();
let layer = &layers[0];
let px = (layer.width * layer.height) as usize;
let fx_effects: Vec<hcie_fx::LayerEffect> = layer.effects.iter()
.map(|e| hcie_fx::types::protocol_to_hcie_fx_effect(e)).collect();
let composite = hcie_fx::apply_layer_effects(&layer.pixels, layer.width, layer.height, &fx_effects, 1.0);
let mut raw_diff = 0.0f64;
let mut comp_diff = 0.0f64;
for i in 0..px {
let rd = (0..4).map(|c| (layer.pixels[i*4+c] as i32 - ref_pixels[i*4+c] as i32).abs() as f64).sum::<f64>();
raw_diff += rd;
let cd = (0..4).map(|c| (composite[i*4+c] as i32 - ref_pixels[i*4+c] as i32).abs() as f64).sum::<f64>();
comp_diff += cd;
}
let raw_mae = raw_diff / px as f64 / 4.0;
let comp_mae = comp_diff / px as f64 / 4.0;
for e in &layer.effects {
println!("{}: {:?}", name, e);
}
println!(" {} {}x{} raw={:.3} composite={:.3} improvement={:.1}%",
name, layer.width, layer.height, raw_mae, comp_mae,
(raw_mae - comp_mae) / raw_mae * 100.0);
}
std::io::stdout().flush().ok();
}