diff --git a/Cargo.toml b/Cargo.toml index 2d49aa8..e380111 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "material-colors" -version = "0.1.1" +version = "0.1.2" edition = "2021" description = "Up-to-date material-color-utilities port" documentation = "https://docs.rs/material-colors" diff --git a/src/quantize/quantizer_wu.rs b/src/quantize/quantizer_wu.rs index c03d535..eba3ce9 100644 --- a/src/quantize/quantizer_wu.rs +++ b/src/quantize/quantizer_wu.rs @@ -107,7 +107,7 @@ impl QuantizerWu { self.moments_b[index] += blue as u32 * count; self.moments[index] += - count as f64 * ((red * red) + (green * green) + (blue * blue)) as f64; + count as f64 * ((red as f64).powi(2) + (green as f64).powi(2) + (blue as f64).powi(2)); } } diff --git a/src/score.rs b/src/score.rs index 7c19d9f..9eb3dae 100644 --- a/src/score.rs +++ b/src/score.rs @@ -75,7 +75,7 @@ impl Score { for hue in hue_population.into_iter().take(360) { let proportion = hue as f64 / population_sum; - for i in (hue - 14)..(hue + 16) { + for i in ((hue as i32) - 14)..((hue as i32) + 16) { let neighbor_hue = sanitize_degrees_int(i as i32); hue_excited_proportions[neighbor_hue as usize] += proportion; diff --git a/src/utils/image.rs b/src/utils/image.rs index 6839a5b..fd9d0da 100644 --- a/src/utils/image.rs +++ b/src/utils/image.rs @@ -1,7 +1,6 @@ use crate::quantize::quantizer::Quantizer; use crate::quantize::quantizer_celebi::QuantizerCelebi; use crate::score::Score; -use crate::utils::color::argb_from_rgb; use super::color::Argb; @@ -10,22 +9,8 @@ use super::color::Argb; /// @param image The image element /// /// @return Source color - the color most suitable for creating a UI theme -pub fn source_color_from_image(image: &[u8]) -> Argb { - // Convert Image data to Pixel Array - let mut pixels = vec![]; - - for i in (0..=image.len()).step_by(4) { - let [r, g, b, a] = [image[i], image[i + 1], image[i + 2], image[i + 3]]; - - if a < 255 { - continue; - } - - pixels.push(argb_from_rgb([r, g, b])); - } - - // Convert Pixels to Material Colors - let result = QuantizerCelebi.quantize(&pixels, 128, None); +pub fn source_color_from_image(image: &[Argb]) -> Argb { + let result = QuantizerCelebi.quantize(image, 128, None); let ranked = Score::score(&result.color_to_count, None, None, None); ranked[0] diff --git a/src/utils/math.rs b/src/utils/math.rs index 0d0d176..4d78897 100644 --- a/src/utils/math.rs +++ b/src/utils/math.rs @@ -4,7 +4,7 @@ pub fn lerp(start: f64, stop: f64, amount: f64) -> f64 { pub fn sanitize_degrees_int(degrees: i32) -> u32 { match degrees { - value if value < 0 => value as u32 + 360, + value if value < 0 => (value + 36) as u32, value => value as u32 % 360, } }