Adds most of the mt and cleanup

This commit is contained in:
Dandaedre 2024-09-06 17:29:37 +02:00
parent f58997b479
commit c632641b39
3 changed files with 20 additions and 19 deletions

View File

@ -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()

View File

@ -35,7 +35,7 @@ struct Cli {
/// Number of passes to process
#[arg(short, long, value_name = "NB_RUNS")]
runs: Option<usize>,
runs: Option<u64>,
/// 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)));

View File

@ -84,6 +84,10 @@ pub(crate) fn export_html(export_path: PathBuf, color_vec: Vec<ColorIndex>) {
write!(out, "</div>").unwrap();
}
write!(out, "</body></html>").unwrap();
println!(
"Exported pallete to file: {}",
export_path.to_string_lossy()
);
}
// Save the kcluster picture