mirror of
https://github.com/arabianq/colorgram-rust.git
synced 2026-04-28 06:31:22 +00:00
Merge pull request #1 from tujdfhxyvweyka5/main
fix: added clamping when input number of colors to extract is greater than the actual colors in image
This commit is contained in:
+2
-1
@@ -121,7 +121,8 @@ pub fn extract<P: AsRef<std::path::Path>>(
|
|||||||
|
|
||||||
used.sort_unstable_by(|a, b| b.0.cmp(&a.0));
|
used.sort_unstable_by(|a, b| b.0.cmp(&a.0));
|
||||||
|
|
||||||
let top_used = &used[..number_of_color];
|
let nmin = number_of_color.min(used.len());
|
||||||
|
let top_used = &used[..nmin];
|
||||||
let sum_counts: u32 = top_used.iter().map(|&(count, _)| count).sum();
|
let sum_counts: u32 = top_used.iter().map(|&(count, _)| count).sum();
|
||||||
|
|
||||||
let mut colors = Vec::with_capacity(number_of_color);
|
let mut colors = Vec::with_capacity(number_of_color);
|
||||||
|
|||||||
Reference in New Issue
Block a user