diff --git a/src/image_functions.rs b/src/image_functions.rs index f60b83e..27088e6 100644 --- a/src/image_functions.rs +++ b/src/image_functions.rs @@ -51,7 +51,7 @@ pub(crate) fn extract_kcluster(image: &PathBuf, cli: &Cli, pb: &ProgressBar) -> converge, verbose, &rgb_pixels, - seed + i as u64, + seed + i, ); if run_result.score < result.score { result = run_result; @@ -83,16 +83,7 @@ pub(crate) fn extract_kcluster(image: &PathBuf, cli: &Cli, pb: &ProgressBar) -> /// Extract the first nb unique colors pub(crate) fn extract_colors(image_path: &PathBuf, cli: &Cli, pb: &ProgressBar) -> ColorIndex { let _ = cli; - let name = image_path - .file_name() - .unwrap() - .to_str() - .unwrap() - .split(".") - .next() - .unwrap() - .to_string(); - // Open the image + let name = extract_name(image_path); let img = image::open(Path::new(&image_path)).expect("Failed to open image"); // Create a HashSet to store unique colors @@ -121,7 +112,10 @@ pub(crate) fn extract_colors(image_path: &PathBuf, cli: &Cli, pb: &ProgressBar) let mut vec = Vec::with_capacity(colors.len() + 1); // Print the unique colors for color in &colors { - println!("[{}] {:?}", name, color); + // TODO: Use Message + // if cli.verbosity { + // println!("[{}] {:?}", name, color); + // } vec.push(( color.3, // format!("#{:02X}{:02X}{:02X}", color.0, color.1, color.2), @@ -131,8 +125,10 @@ pub(crate) fn extract_colors(image_path: &PathBuf, cli: &Cli, pb: &ProgressBar) } vec.sort_by_key(|&(k, _, _)| k); - pb.inc(8); // TODO: Have a real pb - println!("[{}] Found {} unique colors", name, colors.len()); + pb.inc(8); // TODO: be more granular + // if cli.verbosity{ + // println!("[{}] Found {} unique colors", name, colors.len()); + // } ColorIndex::new( name, vec.iter() diff --git a/src/main.rs b/src/main.rs index 978cf5f..bf74269 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,7 +35,7 @@ struct Cli { /// Number of passes to process #[arg(short, long, value_name = "NB_RUNS")] - runs: Option, + runs: Option, /// Extra Verbosity #[arg(short, default_value_t = false)] @@ -54,10 +54,11 @@ fn main() { let export_path = match cli.export.clone() { Some(e) => e, None => cli.image[0] - .parent() + // .parent() // Check output here, not later - .expect("Couldn't find a place to save the output") - .to_path_buf(), + // .expect("Couldn't find a place to save the output") + .with_file_name("Palettes.html"), + // .to_path_buf(), }; let mode = match cli.mode { Some(f) => f, @@ -87,7 +88,7 @@ fn main() { .par_iter() // .progress_with(pb_general.clone()) .map(|image| { - let pb = m.add(ProgressBar::new(8)); // TODO: Not use 8 for passes and have it as parameter + let pb = m.add(ProgressBar::new(cli.runs.unwrap_or(8))); pb.enable_steady_tick(Duration::from_millis(100)); pb.set_style(spinner_style.clone()); pb.set_prefix(format!("[{:?}]", small_name(image))); diff --git a/src/utilities.rs b/src/utilities.rs index 488e741..3295eda 100644 --- a/src/utilities.rs +++ b/src/utilities.rs @@ -84,6 +84,10 @@ pub(crate) fn export_html(export_path: PathBuf, color_vec: Vec) { write!(out, "").unwrap(); } write!(out, "").unwrap(); + println!( + "Exported pallete to file: {}", + export_path.to_string_lossy() + ); } // Save the kcluster picture