1 /* 2 * https://pngquant.org 3 */ 4 5 #ifndef LIBIMAGEQUANT_H 6 #define LIBIMAGEQUANT_H 7 8 #ifdef IMAGEQUANT_EXPORTS 9 #define LIQ_EXPORT __declspec(dllexport) 10 #endif 11 12 #ifndef LIQ_EXPORT 13 #define LIQ_EXPORT extern 14 #endif 15 16 #define LIQ_VERSION 21600 17 #define LIQ_VERSION_STRING "2.17.0" 18 19 #ifndef LIQ_PRIVATE 20 #if defined(__GNUC__) || defined (__llvm__) 21 #define LIQ_PRIVATE __attribute__((visibility("hidden"))) 22 #define LIQ_NONNULL __attribute__((nonnull)) 23 #define LIQ_USERESULT __attribute__((warn_unused_result)) 24 #else 25 #define LIQ_PRIVATE 26 #define LIQ_NONNULL 27 #define LIQ_USERESULT 28 #endif 29 #endif 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 #include <stddef.h> 36 37 typedef struct liq_attr liq_attr; 38 typedef struct liq_image liq_image; 39 typedef struct liq_result liq_result; 40 typedef struct liq_histogram liq_histogram; 41 42 typedef struct liq_color { 43 unsigned char r, g, b, a; 44 } liq_color; 45 46 typedef struct liq_palette { 47 unsigned int count; 48 liq_color entries[256]; 49 } liq_palette; 50 51 typedef enum liq_error { 52 LIQ_OK = 0, 53 LIQ_QUALITY_TOO_LOW = 99, 54 LIQ_VALUE_OUT_OF_RANGE = 100, 55 LIQ_OUT_OF_MEMORY, 56 LIQ_ABORTED, 57 LIQ_BITMAP_NOT_AVAILABLE, 58 LIQ_BUFFER_TOO_SMALL, 59 LIQ_INVALID_POINTER, 60 LIQ_UNSUPPORTED, 61 } liq_error; 62 63 enum liq_ownership { 64 LIQ_OWN_ROWS=4, 65 LIQ_OWN_PIXELS=8, 66 LIQ_COPY_PIXELS=16, 67 }; 68 69 typedef struct liq_histogram_entry { 70 liq_color color; 71 unsigned int count; 72 } liq_histogram_entry; 73 74 LIQ_EXPORT LIQ_USERESULT liq_attr* liq_attr_create(void); 75 LIQ_EXPORT LIQ_USERESULT liq_attr* liq_attr_create_with_allocator(void* (*malloc)(size_t), void (*free)(void*)); 76 LIQ_EXPORT LIQ_USERESULT liq_attr* liq_attr_copy(const liq_attr *orig) LIQ_NONNULL; 77 LIQ_EXPORT void liq_attr_destroy(liq_attr *attr) LIQ_NONNULL; 78 79 LIQ_EXPORT LIQ_USERESULT liq_histogram* liq_histogram_create(const liq_attr* attr); 80 LIQ_EXPORT liq_error liq_histogram_add_image(liq_histogram *hist, const liq_attr *attr, liq_image* image) LIQ_NONNULL; 81 LIQ_EXPORT liq_error liq_histogram_add_colors(liq_histogram *hist, const liq_attr *attr, const liq_histogram_entry entries[], int num_entries, double gamma) LIQ_NONNULL; 82 LIQ_EXPORT liq_error liq_histogram_add_fixed_color(liq_histogram *hist, liq_color color, double gamma) LIQ_NONNULL; 83 LIQ_EXPORT void liq_histogram_destroy(liq_histogram *hist) LIQ_NONNULL; 84 85 LIQ_EXPORT liq_error liq_set_max_colors(liq_attr* attr, int colors) LIQ_NONNULL; 86 LIQ_EXPORT LIQ_USERESULT int liq_get_max_colors(const liq_attr* attr) LIQ_NONNULL; 87 LIQ_EXPORT liq_error liq_set_speed(liq_attr* attr, int speed) LIQ_NONNULL; 88 LIQ_EXPORT LIQ_USERESULT int liq_get_speed(const liq_attr* attr) LIQ_NONNULL; 89 LIQ_EXPORT liq_error liq_set_min_opacity(liq_attr* attr, int min) LIQ_NONNULL; 90 LIQ_EXPORT LIQ_USERESULT int liq_get_min_opacity(const liq_attr* attr) LIQ_NONNULL; 91 LIQ_EXPORT liq_error liq_set_min_posterization(liq_attr* attr, int bits) LIQ_NONNULL; 92 LIQ_EXPORT LIQ_USERESULT int liq_get_min_posterization(const liq_attr* attr) LIQ_NONNULL; 93 LIQ_EXPORT liq_error liq_set_quality(liq_attr* attr, int minimum, int maximum) LIQ_NONNULL; 94 LIQ_EXPORT LIQ_USERESULT int liq_get_min_quality(const liq_attr* attr) LIQ_NONNULL; 95 LIQ_EXPORT LIQ_USERESULT int liq_get_max_quality(const liq_attr* attr) LIQ_NONNULL; 96 LIQ_EXPORT void liq_set_last_index_transparent(liq_attr* attr, int is_last) LIQ_NONNULL; 97 98 typedef void liq_log_callback_function(const liq_attr*, const char *message, void* user_info); 99 typedef void liq_log_flush_callback_function(const liq_attr*, void* user_info); 100 LIQ_EXPORT void liq_set_log_callback(liq_attr*, liq_log_callback_function*, void* user_info); 101 LIQ_EXPORT void liq_set_log_flush_callback(liq_attr*, liq_log_flush_callback_function*, void* user_info); 102 103 typedef int liq_progress_callback_function(float progress_percent, void* user_info); 104 LIQ_EXPORT void liq_attr_set_progress_callback(liq_attr*, liq_progress_callback_function*, void* user_info); 105 LIQ_EXPORT void liq_result_set_progress_callback(liq_result*, liq_progress_callback_function*, void* user_info); 106 107 // The rows and their data are not modified. The type of `rows` is non-const only due to a bug in C's typesystem design. 108 LIQ_EXPORT LIQ_USERESULT liq_image *liq_image_create_rgba_rows(const liq_attr *attr, void *const rows[], int width, int height, double gamma) LIQ_NONNULL; 109 LIQ_EXPORT LIQ_USERESULT liq_image *liq_image_create_rgba(const liq_attr *attr, const void *bitmap, int width, int height, double gamma) LIQ_NONNULL; 110 111 typedef void liq_image_get_rgba_row_callback(liq_color row_out[], int row, int width, void* user_info); 112 LIQ_EXPORT LIQ_USERESULT liq_image *liq_image_create_custom(const liq_attr *attr, liq_image_get_rgba_row_callback *row_callback, void* user_info, int width, int height, double gamma); 113 114 LIQ_EXPORT liq_error liq_image_set_memory_ownership(liq_image *image, int ownership_flags) LIQ_NONNULL; 115 LIQ_EXPORT liq_error liq_image_set_background(liq_image *img, liq_image *background_image) LIQ_NONNULL; 116 LIQ_EXPORT liq_error liq_image_set_importance_map(liq_image *img, unsigned char buffer[], size_t buffer_size, enum liq_ownership memory_handling) LIQ_NONNULL; 117 LIQ_EXPORT liq_error liq_image_add_fixed_color(liq_image *img, liq_color color) LIQ_NONNULL; 118 LIQ_EXPORT LIQ_USERESULT int liq_image_get_width(const liq_image *img) LIQ_NONNULL; 119 LIQ_EXPORT LIQ_USERESULT int liq_image_get_height(const liq_image *img) LIQ_NONNULL; 120 LIQ_EXPORT void liq_image_destroy(liq_image *img) LIQ_NONNULL; 121 122 LIQ_EXPORT LIQ_USERESULT liq_error liq_histogram_quantize(liq_histogram *const input_hist, liq_attr *const options, liq_result **result_output) LIQ_NONNULL; 123 LIQ_EXPORT LIQ_USERESULT liq_error liq_image_quantize(liq_image *const input_image, liq_attr *const options, liq_result **result_output) LIQ_NONNULL; 124 125 LIQ_EXPORT liq_error liq_set_dithering_level(liq_result *res, float dither_level) LIQ_NONNULL; 126 LIQ_EXPORT liq_error liq_set_output_gamma(liq_result* res, double gamma) LIQ_NONNULL; 127 LIQ_EXPORT LIQ_USERESULT double liq_get_output_gamma(const liq_result *result) LIQ_NONNULL; 128 129 LIQ_EXPORT LIQ_USERESULT const liq_palette *liq_get_palette(liq_result *result) LIQ_NONNULL; 130 131 LIQ_EXPORT liq_error liq_write_remapped_image(liq_result *result, liq_image *input_image, void *buffer, size_t buffer_size) LIQ_NONNULL; 132 LIQ_EXPORT liq_error liq_write_remapped_image_rows(liq_result *result, liq_image *input_image, unsigned char **row_pointers) LIQ_NONNULL; 133 134 LIQ_EXPORT double liq_get_quantization_error(const liq_result *result) LIQ_NONNULL; 135 LIQ_EXPORT int liq_get_quantization_quality(const liq_result *result) LIQ_NONNULL; 136 LIQ_EXPORT double liq_get_remapping_error(const liq_result *result) LIQ_NONNULL; 137 LIQ_EXPORT int liq_get_remapping_quality(const liq_result *result) LIQ_NONNULL; 138 139 LIQ_EXPORT void liq_result_destroy(liq_result *) LIQ_NONNULL; 140 141 LIQ_EXPORT int liq_version(void); 142 143 144 // Deprecated 145 LIQ_EXPORT LIQ_USERESULT liq_result *liq_quantize_image(liq_attr *options, liq_image *input_image) LIQ_NONNULL; 146 147 #ifdef __cplusplus 148 } 149 #endif 150 151 #endif 152