pub fn quantize_colors(
path: &Path,
depth: u8,
size: u32,
) -> Result<Vec<Color>, String>Expand description
The main colors of the image file at path, most common first.
The file is decoded as Image decodes it, under
the same caps, then halved until its longer side is at most size
pixels; 0 keeps its size. Its pixels are split by median cut into up to
2^depth boxes, with depth clamped to 0..=8: each time, the box with
the widest range on one channel is split at its median on that channel.
Each box gives the mean of its pixels, opaque. Pixels with alpha under
128 are skipped. Boxes with as many pixels as each other go by their
color’s bytes, so a result is the same on every run. An image with
fewer distinct colors than boxes gives each of them once.
Decoding a wallpaper takes tens of milliseconds, so call it off the loop’s thread.
§Errors
If the file is missing or isn’t a regular file, isn’t a PNG, JPEG, GIF, WebP or SVG, is past the caps, or doesn’t decode.