use crate::region::DiffResult;
use anyhow::Result;
use std::io::Write;
pub fn write_summary(result: &DiffResult, writer: &mut impl Write) -> Result<()> {
if result.is_match {
writeln!(writer, "Images are identical.")?;
return Ok(());
}
writeln!(writer, "Images differ.")?;
writeln!(
writer,
" Dimensions: {}x{}",
result.dimensions.width, result.dimensions.height
)?;
writeln!(
writer,
" Changed pixels: {} ({:.2}%)",
result.stats.changed_pixels, result.stats.diff_percentage
)?;
if result.stats.antialiased_pixels > 0 {
writeln!(
writer,
" Anti-aliased pixels (excluded): {}",
result.stats.antialiased_pixels
)?;
}
writeln!(writer, " Regions: {}", result.stats.region_count)?;
if let Some(mismatch) = &result.dimension_mismatch {
writeln!(
writer,
" Dimension mismatch: baseline={}x{}, candidate={}x{}",
mismatch.baseline.width,
mismatch.baseline.height,
mismatch.candidate.width,
mismatch.candidate.height
)?;
}
writeln!(writer)?;
for region in &result.regions {
writeln!(
writer,
" Region #{} [{}]: {}x{} at ({},{}) — {} pixels, avg delta {:.3}, max delta {:.3}",
region.id,
region.label,
region.bounding_box.width,
region.bounding_box.height,
region.bounding_box.x,
region.bounding_box.y,
region.pixel_count,
region.avg_delta,
region.max_delta
)?;
}
Ok(())
}