use colorthief::{Algorithm, RgbFrame, extract, extract_with};
fn main() {
let mut buf = Vec::with_capacity(32 * 32 * 3);
for row in 0..32 {
for _ in 0..32 {
let rgb = if row < 24 {
[220, 30, 30]
} else {
[30, 30, 220]
};
buf.extend_from_slice(&rgb);
}
}
let frame = RgbFrame::try_new(&buf, 32, 32, 96).expect("frame");
println!("== default (CIEDE2000Exact) ==");
for d in extract(frame, 5) {
println!(
" rgb={:?} name={:?} family={:?} pop={} ({:.1}%)",
d.rgb(),
d.color().name(),
d.color().family().as_str(),
d.population(),
d.percentage(),
);
}
println!("\n== Algorithm::DeltaE76 (fastest) ==");
for d in extract_with(frame, 5, Algorithm::DeltaE76) {
println!(
" rgb={:?} name={:?} pop={} ({:.1}%)",
d.rgb(),
d.color().name(),
d.population(),
d.percentage(),
);
}
}