vips.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include <stdlib.h>
  2. #include <vips/vips.h>
  3. #include <vips/vips7compat.h>
  4. #define VIPS_SUPPORT_SMARTCROP \
  5. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 5))
  6. #define VIPS_SUPPORT_RESIZE_KERNEL \
  7. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION > 3) || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 3 && VIPS_MICRO_VERSION >= 1))
  8. enum types {
  9. JPEG = 0,
  10. PNG,
  11. WEBP,
  12. GIF
  13. };
  14. int
  15. vips_initialize()
  16. {
  17. return vips_init("imgproxy");
  18. }
  19. int
  20. vips_type_find_load_go(int imgtype) {
  21. if (imgtype == JPEG) {
  22. return vips_type_find("VipsOperation", "jpegload");
  23. }
  24. if (imgtype == PNG) {
  25. return vips_type_find("VipsOperation", "pngload");
  26. }
  27. if (imgtype == WEBP) {
  28. return vips_type_find("VipsOperation", "webpload");
  29. }
  30. if (imgtype == GIF) {
  31. return vips_type_find("VipsOperation", "gifload");
  32. }
  33. return 0;
  34. }
  35. int
  36. vips_type_find_save_go(int imgtype) {
  37. if (imgtype == JPEG) {
  38. return vips_type_find("VipsOperation", "jpegsave_buffer");
  39. }
  40. if (imgtype == PNG) {
  41. return vips_type_find("VipsOperation", "pngsave_buffer");
  42. }
  43. if (imgtype == WEBP) {
  44. return vips_type_find("VipsOperation", "webpsave_buffer");
  45. }
  46. return 0;
  47. }
  48. int
  49. vips_jpegload_buffer_go(void *buf, size_t len, VipsImage **out)
  50. {
  51. return vips_jpegload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
  52. };
  53. int
  54. vips_pngload_buffer_go(void *buf, size_t len, VipsImage **out)
  55. {
  56. return vips_pngload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
  57. };
  58. int
  59. vips_gifload_buffer_go(void *buf, size_t len, VipsImage **out)
  60. {
  61. return vips_gifload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
  62. };
  63. int
  64. vips_webpload_buffer_go(void *buf, size_t len, VipsImage **out)
  65. {
  66. return vips_webpload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, NULL);
  67. };
  68. int
  69. vips_resize_go(VipsImage *in, VipsImage **out, double scale)
  70. {
  71. #if VIPS_SUPPORT_RESIZE_KERNEL
  72. return vips_resize(in, out, scale, "kernel", VIPS_KERNEL_LANCZOS3, NULL);
  73. #else
  74. return vips_resize(in, out, scale, NULL);
  75. #endif
  76. };
  77. int
  78. vips_support_smartcrop() {
  79. #if VIPS_SUPPORT_SMARTCROP
  80. return 1;
  81. #else
  82. return 0;
  83. #endif
  84. }
  85. int
  86. vips_smartcrop_go(VipsImage *in, VipsImage **out, int width, int height) {
  87. #if VIPS_SUPPORT_SMARTCROP
  88. return vips_smartcrop(in, out, width, height, NULL);
  89. #else
  90. return 0;
  91. #endif
  92. }
  93. int
  94. vips_colourspace_go(VipsImage *in, VipsImage **out, VipsInterpretation space)
  95. {
  96. return vips_colourspace(in, out, space, NULL);
  97. };
  98. int
  99. vips_extract_area_go(VipsImage *in, VipsImage **out, int left, int top, int width, int height)
  100. {
  101. return vips_extract_area(in, out, left, top, width, height, NULL);
  102. }
  103. int
  104. vips_jpegsave_go(VipsImage *in, void **buf, size_t *len, int strip, int quality, int interlace)
  105. {
  106. return vips_jpegsave_buffer(in, buf, len, "strip", strip, "Q", quality, "optimize_coding", TRUE, "interlace", interlace, NULL);
  107. }
  108. int
  109. vips_pngsave_go(VipsImage *in, void **buf, size_t *len)
  110. {
  111. return vips_pngsave_buffer(in, buf, len, "filter", VIPS_FOREIGN_PNG_FILTER_NONE, NULL);
  112. }
  113. int
  114. vips_webpsave_go(VipsImage *in, void **buf, size_t *len, int strip, int quality) {
  115. return vips_webpsave_buffer(in, buf, len, "strip", strip, "Q", quality, NULL);
  116. }