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_paletteandbuild_palette_rgbabuild a single palette from multiple frames, thenQuantizeResult::remapmaps each frame against it. no_std+alloc: alwaysno_std; works in WASM and embedded contexts.
Re-exports§
pub use error::QuantizeError;
Modules§
Structs§
- Img
- Basic struct used for both owned (alias
ImgVec) and borrowed (aliasImgRef) image fragments. - Quantize
Config - Configuration for palette quantization.
- Quantize
Result - Result of palette quantization.
- RGB
- A
Red + Green + Bluepixel. - RGBA
- A
Red + Green + Blue + Alphapixel.
Enums§
- Output
Format - 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.