libimagequant.h 4.1 KB

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