Crate quantette

source ·
Expand description

A library for fast and high quality image quantization and palette generation.

quantette can perform quantization in perceptually uniform color spaces like CIELAB and Oklab for more accurate results.

§Features

To reduce dependencies and compile times, quantette has several cargo features that can be turned off or on:

  • pipelines: exposes builder structs that serve as the high-level API (more details below).
  • colorspaces: allows performing quantization in the CIELAB or Oklab color spaces via the high-level API.
  • kmeans: adds an additional high quality quantization method that takes longer to run.
  • threads: exposes parallel versions of most functions via rayon.
  • image: enables integration with the image crate.

By default, all features are enabled.

§High-Level API

To get started with the high-level API, see ImagePipeline. If you want a color palette instead of a quantized image, see PalettePipeline instead. Both of these have examples in their documentation, but here is an additional example:

let img = image::open("some image")?.into_rgb8();

let quantized = ImagePipeline::try_from(&img)?
    .palette_size(128) // set the max number of colors in the palette
    .dither(false) // turn dithering off
    .colorspace(ColorSpace::Oklab) // use a more accurate color space
    .quantize_method(QuantizeMethod::kmeans()) // use a more accurate quantization algorithm
    .quantized_rgbimage_par(); // run the pipeline in parallel to get a [`RgbImage`]

Note that some of the options and functions above require certain features to be enabled.

All of the color types present in the public API for this crate (like Srgb or Oklab) are from the palette crate. You can check it out for more information. For example, its documentation should provide you everything you need to know to cast a Vec<Srgb<u8>> into a Vec<[u8; 3]>.

Re-exports§

Modules§

  • Color quantization by k-means clustering.
  • Wu’s color quantizer (Greedy Orthogonal Bipartitioning).

Structs§

  • An error type for when the length of an input (e.g., Vec or slice) is above the maximum supported value.
  • A simple new type wrapper around &'a [Color] with the invariant that the length of the inner slice must not be greater than MAX_PIXELS.
  • Floyd–Steinberg dithering.
  • A builder struct to specify options to create a quantized image or an indexed palette from an image.
  • Deduplicated colors and their frequency counts.
  • A builder struct to specify the parameters for k-means.
  • A builder struct to specify options to create a color palette for an image or slice of colors.
  • This type is used to specify the (maximum) number of colors to include in a palette.
  • The output struct returned by quantization functions.
  • Deduplicated colors and their frequency counts.
  • A builder struct to specify the parameters for Wu’s quantization method.

Enums§

  • The set of supported color spaces that can be used when performing color quantization.
  • The set of supported color quantization methods.

Constants§

  • The maximum supported number of palette colors is 256.
  • The maximum supported image size in number of pixels is u32::MAX.

Traits§

  • Types that may be cast to and from a fixed sized array.
  • A generalization trait over regular ColorSlices and deduplicated pixels like UniqueColorCounts.
  • Types that allow reconstructing the original image/color slice in parallel from a Vec of indices into a color palette.
  • Types that allow reconstructing the original image/color slice from a Vec of indices into a color palette.
  • A numerical trait used to prevent overflow when summing any Count number of Selfs.
  • A marker trait signifying that the “zero value” for the type can be represented by the all zeros bit pattern.