1 /* 2 * http://pngquant.org 3 */ 4 5 #ifndef LIBIMAGEQUANT_H 6 #define LIBIMAGEQUANT_H 7 8 #ifndef LIQ_EXPORT 9 #define LIQ_EXPORT extern 10 #endif 11 12 #define LIQ_VERSION 20401 13 #define LIQ_VERSION_STRING "2.4.1" 14 15 #ifndef LIQ_PRIVATE 16 #if defined(__GNUC__) || defined (__llvm__) 17 #define LIQ_PRIVATE __attribute__((visibility("hidden"))) 18 #else 19 #define LIQ_PRIVATE 20 #endif 21 #endif 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #include <stddef.h> 28 #include <glib.h> 29 30 typedef struct liq_attr liq_attr; 31 typedef struct liq_image liq_image; 32 typedef struct liq_result liq_result; 33 34 typedef struct liq_color { 35 unsigned char r, g, b, a; 36 } liq_color; 37 38 typedef struct liq_palette { 39 unsigned int count; 40 liq_color entries[256]; 41 } liq_palette; 42 43 typedef enum liq_error { 44 LIQ_OK = 0, 45 LIQ_QUALITY_TOO_LOW = 99, 46 LIQ_VALUE_OUT_OF_RANGE = 100, 47 LIQ_OUT_OF_MEMORY, 48 LIQ_NOT_READY, 49 LIQ_BITMAP_NOT_AVAILABLE, 50 LIQ_BUFFER_TOO_SMALL, 51 LIQ_INVALID_POINTER, 52 } liq_error; 53 54 enum liq_ownership {LIQ_OWN_ROWS=4, LIQ_OWN_PIXELS=8}; 55 56 LIQ_EXPORT liq_attr* liq_attr_create(void); 57 LIQ_EXPORT liq_attr* liq_attr_create_with_allocator(void* (*malloc)(size_t), void (*free)(void*)); 58 LIQ_EXPORT liq_attr* liq_attr_copy(liq_attr *orig); 59 LIQ_EXPORT void liq_attr_destroy(liq_attr *attr); 60 61 LIQ_EXPORT liq_error liq_set_max_colors(liq_attr* attr, int colors); 62 LIQ_EXPORT int liq_get_max_colors(const liq_attr* attr); 63 LIQ_EXPORT liq_error liq_set_speed(liq_attr* attr, int speed); 64 LIQ_EXPORT int liq_get_speed(const liq_attr* attr); 65 LIQ_EXPORT liq_error liq_set_min_opacity(liq_attr* attr, int min); 66 LIQ_EXPORT int liq_get_min_opacity(const liq_attr* attr); 67 LIQ_EXPORT liq_error liq_set_min_posterization(liq_attr* attr, int bits); 68 LIQ_EXPORT int liq_get_min_posterization(const liq_attr* attr); 69 LIQ_EXPORT liq_error liq_set_quality(liq_attr* attr, int minimum, int maximum); 70 LIQ_EXPORT int liq_get_min_quality(const liq_attr* attr); 71 LIQ_EXPORT int liq_get_max_quality(const liq_attr* attr); 72 LIQ_EXPORT void liq_set_last_index_transparent(liq_attr* attr, int is_last); 73 74 typedef void liq_log_callback_function(const liq_attr*, const char *message, void* user_info); 75 typedef void liq_log_flush_callback_function(const liq_attr*, void* user_info); 76 LIQ_EXPORT void liq_set_log_callback(liq_attr*, liq_log_callback_function*, void* user_info); 77 LIQ_EXPORT void liq_set_log_flush_callback(liq_attr*, liq_log_flush_callback_function*, void* user_info); 78 79 LIQ_EXPORT liq_image *liq_image_create_rgba_rows(liq_attr *attr, void* rows[], int width, int height, double gamma); 80 LIQ_EXPORT liq_image *liq_image_create_rgba(liq_attr *attr, void* bitmap, int width, int height, double gamma); 81 82 typedef void liq_image_get_rgba_row_callback(liq_color row_out[], int row, int width, void* user_info); 83 LIQ_EXPORT liq_image *liq_image_create_custom(liq_attr *attr, liq_image_get_rgba_row_callback *row_callback, void* user_info, int width, int height, double gamma); 84 85 LIQ_EXPORT liq_error liq_image_set_memory_ownership(liq_image *image, int ownership_flags); 86 LIQ_EXPORT liq_error liq_image_add_fixed_color(liq_image *img, liq_color color); 87 LIQ_EXPORT int liq_image_get_width(const liq_image *img); 88 LIQ_EXPORT int liq_image_get_height(const liq_image *img); 89 LIQ_EXPORT void liq_image_destroy(liq_image *img); 90 91 LIQ_EXPORT liq_result *liq_quantize_image(liq_attr *options, liq_image *input_image); 92 93 LIQ_EXPORT liq_error liq_set_dithering_level(liq_result *res, float dither_level); 94 LIQ_EXPORT liq_error liq_set_output_gamma(liq_result* res, double gamma); 95 LIQ_EXPORT double liq_get_output_gamma(const liq_result *result); 96 97 LIQ_EXPORT const liq_palette *liq_get_palette(liq_result *result); 98 99 LIQ_EXPORT liq_error liq_write_remapped_image(liq_result *result, liq_image *input_image, void *buffer, size_t buffer_size); 100 LIQ_EXPORT liq_error liq_write_remapped_image_rows(liq_result *result, liq_image *input_image, unsigned char **row_pointers); 101 102 LIQ_EXPORT double liq_get_quantization_error(liq_result *result); 103 LIQ_EXPORT int liq_get_quantization_quality(liq_result *result); 104 105 LIQ_EXPORT void liq_result_destroy(liq_result *); 106 LIQ_EXPORT int liq_version(void); 107 108 109 #ifdef __cplusplus 110 } 111 #endif 112 113 #endif 114