Small, portable C library for high-quality conversion of RGBA images to 8-bit indexed-color (palette) images. It's powering pngquant2.
This is a low-level crate exposing a C API. If you're looking for a Rust library, see imagequant.
Libimagequant is dual-licensed:
For Free/Libre Open Source Software it's available under GPL v3 or later with additional copyright notices for older parts of the code.
For use in non-GPL software (e.g. closed-source or App Store distribution) please ask email@example.com for a commercial license.
The basic flow is:
- Create attributes object and configure the library.
- Create image object from RGBA pixels or data source.
- Perform quantization (generate palette).
- Store remapped image and final palette.
- Free memory.
Please note that libimagequant only handles raw uncompressed arrays of pixels in memory and is completely independent of any file format.
There are 3 ways to create image object for quantization:
liq_image_create_rgba()for simple, contiguous RGBA pixel arrays (width×height×4 bytes large bitmap).
liq_image_create_rgba_rows()for non-contiguous RGBA pixel arrays (that have padding between rows or reverse order, e.g. BMP).
liq_image_create_custom()for RGB, ABGR, YUV and all other formats that can be converted on-the-fly to RGBA (you have to supply the conversion function).
Note that "image" here means raw uncompressed pixels. If you have a compressed image file, such as PNG, you must use another library (e.g. lodepng) to decode it first.