mod hat;
use anyhow::Result;
use hat::tiles::{collect_hats, DrawContext, MetaTile, Tile};
use hat::{AMosaic, ImageDrawContext};
use image::{open, ImageBuffer, Rgb};
#[cfg(test)]
mod tests {
use image::RgbImage;
use std::fs;
use super::*;
#[test]
fn test_generate_mosaic_from_input() -> Result<()> {
let input_img = image::open("input.png")?.into_rgb8();
let (width, height) = input_img.dimensions();
let buffer = input_img.clone().into_raw();
let amosaic = AMosaic::new(width, height, buffer);
let mut mosaic_img = RgbImage::from_pixel(width, height, Rgb([255, 255, 255]));
amosaic.draw( 30.0, &mut mosaic_img)?;
mosaic_img.save("output.png")?;
let pixel_sum: u64 = mosaic_img
.pixels()
.map(|p| (p[0] as u64 + p[1] as u64 + p[2] as u64))
.sum();
assert!(
pixel_sum > 0,
"Output image is entirely dark (all pixels black)"
);
Ok(())
}
#[test]
fn test_generate_mosaic_as_svg() -> Result<(), Box<dyn std::error::Error>> {
let input_img = image::open("input.png")?.into_rgb8();
let (width, height) = input_img.dimensions();
let buffer = input_img.clone().into_raw();
let amosaic = AMosaic::new(width, height, buffer);
let svg_output = amosaic.to_svg( 100.0);
fs::write("output.svg", &svg_output)?;
let contents = fs::read_to_string("output.svg")?;
assert!(
contents.starts_with("<?xml") || contents.contains("<svg"),
"SVG output missing expected header or <svg> element"
);
Ok(())
}
}