libimagequant.h 6.8 KB

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