#![deny(warnings)]
use std::{str::FromStr, time::Instant};
use auto_palette::{ImageData, Palette, Theme};
fn main() {
let theme = match std::env::args().nth(1) {
Some(name) => Theme::from_str(&name)
.map_err(|_| format!("Failed to parse the them '{}'", name))
.unwrap(),
None => {
println!("No theme provided, using the default theme");
Theme::Basic
}
};
let image_data = ImageData::load("./gfx/holly-booth-hLZWGXy5akM-unsplash.jpg").unwrap();
let start = Instant::now();
let palette: Palette<f32> = Palette::extract(&image_data).unwrap();
let duration = start.elapsed();
println!(
"Extracted {} swatch(es) in {}.{:03} seconds",
palette.len(),
duration.as_secs(),
duration.subsec_millis()
);
let swatches = palette.find_swatches_with_theme(5, theme);
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()
);
}
}