Crate imagequant_sys

source ·
Expand description

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.

License

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 kornel@pngquant.org for a commercial license.

Overview

The basic flow is:

  1. Create attributes object and configure the library.
  2. Create image object from RGBA pixels or data source.
  3. Perform quantization (generate palette).
  4. Store remapped image and final palette.
  5. 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.

Structs

Enums

Functions

Returns object that will hold initial settings (attributes) for the library.
Returns pointer to palette optimized for image that has been quantized or remapped (final refinements are applied to the palette during remapping).
Creates an object that represents the image pixels to be used for quantization and remapping.
Remap assuming the image will be always presented exactly on top of this background.
unsafe: It will crash if the owned memory wasn’t allocated using libc::malloc() (or whatever allocator C side is using)
Performs quantization (palette generation) based on settings in attr (from liq_attr_create()) and pixels of the image.
Enables/disables dithering in liq_write_remapped_image().
Specifies maximum number of colors to use.
Quality is in range 0 (worst) to 100 (best) and values are analoguous to JPEG quality (i.e. 80 is usually good enough).
Remaps the image to palette and writes its pixels to the given buffer, 1 pixel per byte.

Type Definitions