Exoquant 0.1.0
Exoquant is a very high quality image quantization library written in Rust featuring code for basic color quantization, K-Means palette optimization and remapping and dithering with Floyd-Steinberg and ordered ditherers.
This version of the library is a much improved rewrite of a C library of the same name written back in 2004.
Usage
Add exoquant as a dependency to your Cargo.toml:
[]
= "0.2.0"
Basic API:
For simple use cases, there is a convenience function that simply takes true color image data + a few options as input and returns the palette and indexed image data as output:
use *;
let image = test_image;
let = convert_to_indexed;
Low-Level API:
The low-level API gives you full control over the quantization workflow. It allows for use-cases like:
- only create a palette and do the remapping in your own custom code
- remap images to an existing palette or one created with a different library
- generating a single palette for multiple input images (or, say, frames of a GIF)
- implement your own custom ditherer (also usable with the basic API)
Using the low-level API to quantize an image looks like this:
use *;
use Optimizer;
let image = test_image;
let histogram = image.pixels.iter.cloned.collect;
let colorspace = default;
let optimizer = KMeans;
let mut quantizer = new;
while quantizer.num_colors < 256
let palette = quantizer.colors;
// this optimization is more useful than the above and a lot less slow
let palette = optimizer.optimize_palette;
let ditherer = new;
let remapper = new;
let indexed_data = remapper.remap;