[][src]Function imagequant_sys::liq_write_remapped_image

pub unsafe extern "C" fn liq_write_remapped_image(
    result: &mut liq_result,
    input_image: &mut liq_image,
    buffer: *mut u8,
    buffer_size: usize
) -> liq_error

Remaps the image to palette and writes its pixels to the given buffer, 1 pixel per byte.

The buffer must be large enough to fit the entire image, i.e. width×height bytes large. For safety, pass the size of the buffer as buffer_size.

For best performance call liq_get_palette() after this function, as palette is improved during remapping (except when liq_histogram_quantize() is used).

Returns LIQ_BUFFER_TOO_SMALL if given size of the buffer is not enough to fit the entire image.

int buffer_size = width*height;
char *buffer = malloc(buffer_size);
if (LIQ_OK == liq_write_remapped_image(result, input_image, buffer, buffer_size)) {
    liq_palette *pal = liq_get_palette(result);
    // save image
}

See liq_get_palette().

The buffer is assumed to be contiguous, with rows ordered from top to bottom, and no gaps between rows. If you need to write rows with padding or upside-down order, then use liq_write_remapped_image_rows().

Please note that it only writes raw uncompressed pixels to memory. It does not perform any PNG compression. If you'd like to create a PNG file then you need to pass the raw pixel data to another library, e.g. libpng or lodepng. See rwpng.c in pngquant project for an example how to do that.