From a57cb34b513876313c755be2bbebb63138b4932b Mon Sep 17 00:00:00 2001 From: gennyble Date: Mon, 10 Jun 2024 17:07:56 -0500 Subject: Add HighestBits selector to cli --- squash/Cargo.toml | 4 +++- squash/src/cli.rs | 6 ++++++ squash/src/main.rs | 3 ++- src/nih_kmeans.rs | 2 +- src/selection.rs | 1 + 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/squash/Cargo.toml b/squash/Cargo.toml index 971afce..3d94c1a 100644 --- a/squash/Cargo.toml +++ b/squash/Cargo.toml @@ -11,7 +11,9 @@ repository = "https://github.com/gennyble/colorsquash/tree/main/squash" [dependencies] # the meat 'o the thing! the meaning behind it all -colorsquash = { path = "..", version = "0.2.0", features = ["gifed"] } +colorsquash = { path = "..", version = "0.2.0", default-features = false, features = [ + "gifed", +] } # just useful tools for writing binaries anyhow = "1.0.75" diff --git a/squash/src/cli.rs b/squash/src/cli.rs index d47d26b..96a0798 100644 --- a/squash/src/cli.rs +++ b/squash/src/cli.rs @@ -107,6 +107,7 @@ pub enum Selector { #[default] SortSelect, Kmeans, + HighestBits, } pub fn build() -> Cli { @@ -180,6 +181,7 @@ pub fn build() -> Cli { Some(("selector", sel)) | Some(("sel", sel)) => match sel { "sort/select" | "sorsel" => building.selector = Selector::SortSelect, "kmeans" => building.selector = Selector::Kmeans, + "highest-bits" => building.selector = Selector::HighestBits, _ => { eprintln!("'{sel}' is not recognized as a selector. See help=selectors"); std::process::exit(1); @@ -264,6 +266,10 @@ fn print_help_selectors() -> ! { println!("kmeans:"); println!(" uses the kmeans clustering algorithm to select colours."); println!(" Ignores tolerance="); + println!("highest-bits:"); + println!(" quantizes the colours by shifting the bits of their components until"); + println!(" they all fit in the palette."); + println!(" Ignores tolerance="); std::process::exit(0) } diff --git a/squash/src/main.rs b/squash/src/main.rs index c0cea51..878ae37 100644 --- a/squash/src/main.rs +++ b/squash/src/main.rs @@ -1,7 +1,7 @@ use std::time::Duration; use colorsquash::{ - selection::{Kmeans, SortSelect}, + selection::{HighestBits, Kmeans, SortSelect}, SquasherBuilder, }; @@ -34,6 +34,7 @@ fn main() -> Result<(), anyhow::Error> { builder = builder.selector(sorsel); } cli::Selector::Kmeans => builder = builder.selector(Kmeans { max_iter: 10 }), + cli::Selector::HighestBits => builder = builder.selector(HighestBits {}), }; let mut start = std::time::Instant::now(); diff --git a/src/nih_kmeans.rs b/src/nih_kmeans.rs index ee752bc..36b17d1 100644 --- a/src/nih_kmeans.rs +++ b/src/nih_kmeans.rs @@ -91,7 +91,7 @@ impl KMeans { .unwrap() } - #[cfg(rand)] + #[cfg(feature = "rand")] fn get_centroid_seeds_random(&self, k: usize) -> Vec> { if k >= self.samples.len() { return self.samples.iter().map(|&v| v.into()).collect(); diff --git a/src/selection.rs b/src/selection.rs index 41e0254..84d5ea3 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -339,6 +339,7 @@ impl Selector for HighestBits { fn select(&mut self, max_colors: usize, image: ImageData) -> Vec { let max_bits = max_colors.next_power_of_two().ilog2() / 3; let shift = 8 - max_bits; + image .0 .iter() -- cgit 1.4.1-3-g733a5