Skip to main content

Crate zenquant

Crate zenquant 

Source
Expand description

AQ-informed color quantization for indexed image formats.

zenquant reduces truecolor images to 256-color palettes using perceptual masking (butteraugli-inspired AQ weights), OKLab color space, and optional Viterbi DP for run-length–friendly index ordering.

§Quick start

use zenquant::{QuantizeConfig, OutputFormat};

let config = QuantizeConfig::new(OutputFormat::Png);
let result = zenquant::quantize(&pixels, 8, 8, &config).unwrap();

let palette = result.palette();   // &[[u8; 3]]
let indices = result.indices();   // &[u8]

§Features

  • Perceptual masking: concentrates palette entries where human vision is most sensitive (smooth gradients, skin tones) rather than wasting entries on noisy textures.
  • OKLab color space: all clustering happens in a perceptually uniform space, so “nearest color” actually looks nearest.
  • Format-aware tuning: palette sorting and dither strength are optimized per output format (GIF, PNG, WebP lossless).
  • Shared palettes: build_palette and build_palette_rgba build a single palette from multiple frames, then QuantizeResult::remap maps each frame against it.
  • no_std + alloc: always no_std; works in WASM and embedded contexts.

Re-exports§

pub use error::QuantizeError;

Modules§

error

Structs§

Img
Basic struct used for both owned (alias ImgVec) and borrowed (alias ImgRef) image fragments.
QuantizeConfig
Configuration for palette quantization.
QuantizeResult
Result of palette quantization.
RGB
A Red + Green + Blue pixel.
RGBA
A Red + Green + Blue + Alpha pixel.

Enums§

OutputFormat
Target output format — controls palette sorting, dither strength, and compression tuning.
Quality
Quality preset — controls k-means iterations, AQ masking, and Viterbi optimization.

Functions§

build_palette
Build a shared palette from multiple RGB frames.
build_palette_rgba
Build a shared palette from multiple RGBA frames.
quantize
Quantize an RGB image to an indexed palette.
quantize_rgba
Quantize an RGBA image to an indexed palette.

Type Aliases§

ImgRef
Reference to pixels inside another image. Pass this structure by value (i.e. ImgRef, not &ImgRef).
ImgVec
Image owning its pixels.