use colorthief::{Algorithm, Dominant, Mmcq, RgbFrame};
static mut MMCQ: Mmcq = Mmcq::new();
const W: u32 = 16;
const H: u32 = 16;
const STRIDE: u32 = W * 3;
fn main() {
let mut buf = [0u8; (STRIDE * H) as usize];
for row in 0..H as usize {
let rgb = if row < 12 {
[220, 30, 30]
} else {
[30, 30, 220]
};
for col in 0..W as usize {
let off = row * STRIDE as usize + col * 3;
buf[off..off + 3].copy_from_slice(&rgb);
}
}
let frame = RgbFrame::try_new(&buf, W, H, STRIDE).expect("frame");
let mut out: [Option<Dominant>; 5] = [const { None }; 5];
#[allow(static_mut_refs)]
unsafe {
(*core::ptr::addr_of_mut!(MMCQ)).extract(frame.pixels(), 5, Algorithm::default(), &mut out);
}
for slot in out.iter().flatten() {
println!(
"rgb={:?} name={:?} family={:?} pop={} ({:.1}%)",
slot.rgb(),
slot.color().name(),
slot.color().family().as_str(),
slot.population(),
slot.percentage(),
);
}
}