2 unstable releases

Uses old Rust 2015

0.2.0 Sep 4, 2016
0.1.0 Sep 4, 2016

#1487 in Images

Download history 154/week @ 2026-01-18 104/week @ 2026-01-25 149/week @ 2026-02-01 57/week @ 2026-02-08 130/week @ 2026-02-15 429/week @ 2026-02-22 148/week @ 2026-03-01 129/week @ 2026-03-08 141/week @ 2026-03-15 164/week @ 2026-03-22 154/week @ 2026-03-29 243/week @ 2026-04-05 282/week @ 2026-04-12 415/week @ 2026-04-19 198/week @ 2026-04-26 105/week @ 2026-05-03

1,012 downloads per month
Used in 8 crates

MIT license

50KB
999 lines

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:

[dependencies]
exoquant = "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 exoquant::*;
let image = testdata::test_image();

let (palette, indexed_data) = convert_to_indexed(&image.pixels, image.width, 256,
  &optimizer::KMeans, &ditherer::FloydSteinberg::new());

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 exoquant::*;
use exoquant::optimizer::Optimizer;

let image = testdata::test_image();

let histogram = image.pixels.iter().cloned().collect();

let colorspace = SimpleColorSpace::default();
let optimizer = optimizer::KMeans;
let mut quantizer = Quantizer::new(&histogram, &colorspace);
while quantizer.num_colors() < 256 {
  quantizer.step();
  // very optional optimization, !very slow!
  // you probably only want to do this every N steps, if at all.
  if quantizer.num_colors() % 64 == 0 {
    quantizer = quantizer.optimize(&optimizer, 4);
  }
}

let palette = quantizer.colors(&colorspace);
// this optimization is more useful than the above and a lot less slow
let palette = optimizer.optimize_palette(&colorspace, &palette, &histogram, 16);

let ditherer = ditherer::FloydSteinberg::new();
let remapper = Remapper::new(&palette, &colorspace, &ditherer);
let indexed_data = remapper.remap(&image.pixels, image.width);

API Documentation

Click here for a online version of the API Documenation

Dependencies

~0–275KB