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:
arabian
2026-01-06 04:59:23 +03:00
committed by GitHub
+2 -1
View File
@@ -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);