#![deny(warnings)]
use anyhow::{Context, Error};
use auto_palette::{ImageData, Palette};
fn main() -> Result<(), Error> {
let path = std::env::args().nth(1).unwrap_or_else(|| {
println!("No image path provided, using the default image path");
"./gfx/holly-booth-hLZWGXy5akM-unsplash.jpg".into()
});
let image_data = ImageData::load(&path)
.with_context(|| format!("Failed to load the image data from the file: {}", path))?;
let palette: Palette<f32> = Palette::extract(&image_data)
.with_context(|| "Failed to extract the palette from the image data".to_string())?;
println!("Extracted {} swatch(es)", palette.len());
let swatches = palette
.find_swatches(5)
.with_context(|| "Failed to find swatches in the palette".to_string())?;
println!(
"{:>2} | {:<7} | {:<12} | {:<10} | {:<6}",
"#", "Color", "Position", "Population", "Ratio"
);
for (i, swatch) in swatches.iter().enumerate() {
println!(
"{:>2} | {:<7} | {:>4?} | {:>10} | {:>5.2}",
i + 1,
swatch.color().to_hex_string(),
swatch.position(),
swatch.population(),
swatch.ratio()
);
}
Ok(())
}