vips.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. #include "vips.h"
  2. #include <string.h>
  3. #define VIPS_SUPPORT_SMARTCROP \
  4. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 5))
  5. #define VIPS_SUPPORT_HASALPHA \
  6. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 5))
  7. #define VIPS_SUPPORT_GIF \
  8. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 3))
  9. #define VIPS_SUPPORT_SVG \
  10. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 3))
  11. #define VIPS_SUPPORT_TIFF \
  12. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 6))
  13. #define VIPS_SUPPORT_MAGICK \
  14. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 7))
  15. #define VIPS_SUPPORT_PNG_QUANTIZATION \
  16. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 7))
  17. #define VIPS_SUPPORT_WEBP_SCALE_ON_LOAD \
  18. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 8))
  19. #define VIPS_SUPPORT_WEBP_ANIMATION \
  20. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 8))
  21. #define VIPS_SUPPORT_HEIF \
  22. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 8))
  23. #define VIPS_SUPPORT_AVIF \
  24. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 9))
  25. #define VIPS_SUPPORT_COMPOSITE \
  26. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 6))
  27. #define VIPS_SUPPORT_FIND_TRIM \
  28. (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 6))
  29. #define EXIF_ORIENTATION "exif-ifd0-Orientation"
  30. #if (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 8))
  31. #define VIPS_BLOB_DATA_TYPE const void *
  32. #else
  33. #define VIPS_BLOB_DATA_TYPE void *
  34. #endif
  35. int
  36. vips_initialize() {
  37. return vips_init("imgproxy");
  38. }
  39. void
  40. clear_image(VipsImage **in) {
  41. if (G_IS_OBJECT(*in)) g_clear_object(in);
  42. }
  43. void
  44. g_free_go(void **buf) {
  45. g_free(*buf);
  46. }
  47. void
  48. swap_and_clear(VipsImage **in, VipsImage *out) {
  49. clear_image(in);
  50. *in = out;
  51. }
  52. int
  53. vips_type_find_load_go(int imgtype) {
  54. switch (imgtype)
  55. {
  56. case (JPEG):
  57. return vips_type_find("VipsOperation", "jpegload_buffer");
  58. case (PNG):
  59. return vips_type_find("VipsOperation", "pngload_buffer");
  60. case (WEBP):
  61. return vips_type_find("VipsOperation", "webpload_buffer");
  62. case (GIF):
  63. return vips_type_find("VipsOperation", "gifload_buffer");
  64. case (SVG):
  65. return vips_type_find("VipsOperation", "svgload_buffer");
  66. case (HEIC):
  67. return vips_type_find("VipsOperation", "heifload_buffer");
  68. case (AVIF):
  69. return vips_type_find("VipsOperation", "heifload_buffer");
  70. case (BMP):
  71. return vips_type_find("VipsOperation", "magickload_buffer");
  72. case (TIFF):
  73. return vips_type_find("VipsOperation", "tiffload_buffer");
  74. }
  75. return 0;
  76. }
  77. int
  78. vips_type_find_save_go(int imgtype) {
  79. switch (imgtype)
  80. {
  81. case (JPEG):
  82. return vips_type_find("VipsOperation", "jpegsave_buffer");
  83. case (PNG):
  84. return vips_type_find("VipsOperation", "pngsave_buffer");
  85. case (WEBP):
  86. return vips_type_find("VipsOperation", "webpsave_buffer");
  87. case (GIF):
  88. return vips_type_find("VipsOperation", "magicksave_buffer");
  89. #if VIPS_SUPPORT_AVIF
  90. case (AVIF):
  91. return vips_type_find("VipsOperation", "heifsave_buffer");
  92. #endif
  93. case (ICO):
  94. return vips_type_find("VipsOperation", "pngsave_buffer");
  95. case (BMP):
  96. return vips_type_find("VipsOperation", "magicksave_buffer");
  97. case (TIFF):
  98. return vips_type_find("VipsOperation", "tiffsave_buffer");
  99. }
  100. return 0;
  101. }
  102. int
  103. vips_jpegload_go(void *buf, size_t len, int shrink, VipsImage **out) {
  104. if (shrink > 1)
  105. return vips_jpegload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, "shrink", shrink, NULL);
  106. return vips_jpegload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, NULL);
  107. }
  108. int
  109. vips_pngload_go(void *buf, size_t len, VipsImage **out) {
  110. return vips_pngload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, NULL);
  111. }
  112. int
  113. vips_webpload_go(void *buf, size_t len, double scale, int pages, VipsImage **out) {
  114. return vips_webpload_buffer(
  115. buf, len, out,
  116. "access", VIPS_ACCESS_SEQUENTIAL,
  117. #if VIPS_SUPPORT_WEBP_SCALE_ON_LOAD
  118. "scale", scale,
  119. #else
  120. "shrink", (int)(1.0 / scale),
  121. #endif
  122. #if VIPS_SUPPORT_WEBP_ANIMATION
  123. "n", pages,
  124. #endif
  125. NULL
  126. );
  127. }
  128. int
  129. vips_gifload_go(void *buf, size_t len, int pages, VipsImage **out) {
  130. #if VIPS_SUPPORT_GIF
  131. return vips_gifload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, "n", pages, NULL);
  132. #else
  133. vips_error("vips_gifload_go", "Loading GIF is not supported (libvips 8.3+ reuired)");
  134. return 1;
  135. #endif
  136. }
  137. int
  138. vips_svgload_go(void *buf, size_t len, double scale, VipsImage **out) {
  139. #if VIPS_SUPPORT_SVG
  140. return vips_svgload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, "scale", scale, NULL);
  141. #else
  142. vips_error("vips_svgload_go", "Loading SVG is not supported (libvips 8.5+ reuired)");
  143. return 1;
  144. #endif
  145. }
  146. int
  147. vips_heifload_go(void *buf, size_t len, VipsImage **out) {
  148. #if VIPS_SUPPORT_HEIF
  149. return vips_heifload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, NULL);
  150. #else
  151. vips_error("vips_heifload_go", "Loading HEIF is not supported (libvips 8.8+ reuired)");
  152. return 1;
  153. #endif
  154. }
  155. int
  156. vips_bmpload_go(void *buf, size_t len, VipsImage **out) {
  157. #if VIPS_SUPPORT_MAGICK
  158. return vips_magickload_buffer(buf, len, out, NULL);
  159. #else
  160. vips_error("vips_bmpload_go", "Loading BMP is not supported");
  161. return 1;
  162. #endif
  163. }
  164. int
  165. vips_tiffload_go(void *buf, size_t len, VipsImage **out) {
  166. #if VIPS_SUPPORT_TIFF
  167. return vips_tiffload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, NULL);
  168. #else
  169. vips_error("vips_tiffload_go", "Loading TIFF is not supported (libvips 8.6+ reuired)");
  170. return 1;
  171. #endif
  172. }
  173. int
  174. vips_get_orientation(VipsImage *image) {
  175. #ifdef VIPS_META_ORIENTATION
  176. int orientation;
  177. if (
  178. vips_image_get_typeof(image, VIPS_META_ORIENTATION) == G_TYPE_INT &&
  179. vips_image_get_int(image, VIPS_META_ORIENTATION, &orientation) == 0
  180. ) return orientation;
  181. #else
  182. const char *orientation;
  183. if (
  184. vips_image_get_typeof(image, EXIF_ORIENTATION) == VIPS_TYPE_REF_STRING &&
  185. vips_image_get_string(image, EXIF_ORIENTATION, &orientation) == 0
  186. ) return atoi(orientation);
  187. #endif
  188. return 1;
  189. }
  190. int
  191. vips_support_smartcrop() {
  192. return VIPS_SUPPORT_SMARTCROP;
  193. }
  194. VipsBandFormat
  195. vips_band_format(VipsImage *in) {
  196. return in->BandFmt;
  197. }
  198. gboolean
  199. vips_support_webp_animation() {
  200. return VIPS_SUPPORT_WEBP_ANIMATION;
  201. }
  202. gboolean
  203. vips_is_animated(VipsImage * in) {
  204. return( vips_image_get_typeof(in, "page-height") != G_TYPE_INVALID &&
  205. vips_image_get_typeof(in, "gif-delay") != G_TYPE_INVALID &&
  206. vips_image_get_typeof(in, "gif-loop") != G_TYPE_INVALID );
  207. }
  208. gboolean
  209. vips_image_hasalpha_go(VipsImage * in) {
  210. #if VIPS_SUPPORT_HASALPHA
  211. return vips_image_hasalpha(in);
  212. #else
  213. return( in->Bands == 2 ||
  214. (in->Bands == 4 && in->Type != VIPS_INTERPRETATION_CMYK) ||
  215. in->Bands > 4 );
  216. #endif
  217. }
  218. int
  219. vips_addalpha_go(VipsImage *in, VipsImage **out) {
  220. return vips_addalpha(in, out, NULL);
  221. }
  222. int
  223. vips_copy_go(VipsImage *in, VipsImage **out) {
  224. return vips_copy(in, out, NULL);
  225. }
  226. int
  227. vips_cast_go(VipsImage *in, VipsImage **out, VipsBandFormat format) {
  228. return vips_cast(in, out, format, NULL);
  229. }
  230. int
  231. vips_rad2float_go(VipsImage *in, VipsImage **out) {
  232. return vips_rad2float(in, out, NULL);
  233. }
  234. int
  235. vips_resize_go(VipsImage *in, VipsImage **out, double scale) {
  236. return vips_resize(in, out, scale, NULL);
  237. }
  238. int
  239. vips_resize_with_premultiply(VipsImage *in, VipsImage **out, double scale) {
  240. VipsBandFormat format;
  241. VipsImage *tmp1, *tmp2;
  242. format = vips_band_format(in);
  243. if (vips_premultiply(in, &tmp1, NULL))
  244. return 1;
  245. if (vips_resize(tmp1, &tmp2, scale, NULL)) {
  246. clear_image(&tmp1);
  247. return 1;
  248. }
  249. swap_and_clear(&tmp1, tmp2);
  250. if (vips_unpremultiply(tmp1, &tmp2, NULL)) {
  251. clear_image(&tmp1);
  252. return 1;
  253. }
  254. swap_and_clear(&tmp1, tmp2);
  255. if (vips_cast(tmp1, out, format, NULL)) {
  256. clear_image(&tmp1);
  257. return 1;
  258. }
  259. clear_image(&tmp1);
  260. return 0;
  261. }
  262. int
  263. vips_icc_is_srgb_iec61966(VipsImage *in) {
  264. VIPS_BLOB_DATA_TYPE data;
  265. size_t data_len;
  266. // 1998-12-01
  267. static char date[] = { 7, 206, 0, 2, 0, 9 };
  268. // 2.1
  269. static char version[] = { 2, 16, 0, 0 };
  270. if (vips_image_get_blob(in, VIPS_META_ICC_NAME, &data, &data_len))
  271. return FALSE;
  272. // Less than header size
  273. if (data_len < 128)
  274. return FALSE;
  275. // Predict it is sRGB IEC61966 2.1 by checking some header fields
  276. return ((memcmp(data + 48, "IEC ", 4) == 0) && // Device manufacturer
  277. (memcmp(data + 52, "sRGB", 4) == 0) && // Device model
  278. (memcmp(data + 80, "HP ", 4) == 0) && // Profile creator
  279. (memcmp(data + 24, date, 6) == 0) && // Date of creation
  280. (memcmp(data + 8, version, 4) == 0)); // Version
  281. }
  282. int
  283. vips_has_embedded_icc(VipsImage *in) {
  284. return vips_image_get_typeof(in, VIPS_META_ICC_NAME) != 0;
  285. }
  286. int
  287. vips_icc_import_go(VipsImage *in, VipsImage **out) {
  288. return vips_icc_import(in, out, "embedded", TRUE, "pcs", VIPS_PCS_XYZ, NULL);
  289. }
  290. int
  291. vips_icc_export_go(VipsImage *in, VipsImage **out) {
  292. return vips_icc_export(in, out, NULL);
  293. }
  294. int
  295. vips_icc_export_srgb(VipsImage *in, VipsImage **out) {
  296. return vips_icc_export(in, out, "output_profile", "sRGB", NULL);
  297. }
  298. int
  299. vips_icc_transform_go(VipsImage *in, VipsImage **out) {
  300. return vips_icc_transform(in, out, "sRGB", "embedded", TRUE, "pcs", VIPS_PCS_XYZ, NULL);
  301. }
  302. int
  303. vips_icc_remove(VipsImage *in, VipsImage **out) {
  304. if (vips_copy(in, out, NULL)) return 1;
  305. vips_image_remove(*out, VIPS_META_ICC_NAME);
  306. return 0;
  307. }
  308. int
  309. vips_colourspace_go(VipsImage *in, VipsImage **out, VipsInterpretation cs) {
  310. return vips_colourspace(in, out, cs, NULL);
  311. }
  312. int
  313. vips_rot_go(VipsImage *in, VipsImage **out, VipsAngle angle) {
  314. return vips_rot(in, out, angle, NULL);
  315. }
  316. int
  317. vips_flip_horizontal_go(VipsImage *in, VipsImage **out) {
  318. return vips_flip(in, out, VIPS_DIRECTION_HORIZONTAL, NULL);
  319. }
  320. int
  321. vips_smartcrop_go(VipsImage *in, VipsImage **out, int width, int height) {
  322. #if VIPS_SUPPORT_SMARTCROP
  323. return vips_smartcrop(in, out, width, height, NULL);
  324. #else
  325. vips_error("vips_smartcrop_go", "Smart crop is not supported (libvips 8.5+ reuired)");
  326. return 1;
  327. #endif
  328. }
  329. int
  330. vips_gaussblur_go(VipsImage *in, VipsImage **out, double sigma) {
  331. return vips_gaussblur(in, out, sigma, NULL);
  332. }
  333. int
  334. vips_sharpen_go(VipsImage *in, VipsImage **out, double sigma) {
  335. return vips_sharpen(in, out, "sigma", sigma, NULL);
  336. }
  337. int
  338. vips_flatten_go(VipsImage *in, VipsImage **out, double r, double g, double b) {
  339. VipsArrayDouble *bg = vips_array_double_newv(3, r, g, b);
  340. int res = vips_flatten(in, out, "background", bg, NULL);
  341. vips_area_unref((VipsArea *)bg);
  342. return res;
  343. }
  344. int
  345. vips_extract_area_go(VipsImage *in, VipsImage **out, int left, int top, int width, int height) {
  346. return vips_extract_area(in, out, left, top, width, height, NULL);
  347. }
  348. int
  349. vips_trim(VipsImage *in, VipsImage **out, double threshold,
  350. gboolean smart, double r, double g, double b,
  351. gboolean equal_hor, gboolean equal_ver) {
  352. #if VIPS_SUPPORT_FIND_TRIM
  353. VipsImage *tmp;
  354. if (vips_image_hasalpha(in)) {
  355. if (vips_flatten(in, &tmp, NULL))
  356. return 1;
  357. } else {
  358. if (vips_copy(in, &tmp, NULL))
  359. return 1;
  360. }
  361. double *bg;
  362. int bgn;
  363. VipsArrayDouble *bga;
  364. if (smart) {
  365. if (vips_getpoint(tmp, &bg, &bgn, 0, 0, NULL)) {
  366. clear_image(&tmp);
  367. return 1;
  368. }
  369. bga = vips_array_double_new(bg, bgn);
  370. } else {
  371. bga = vips_array_double_newv(3, r, g, b);
  372. bg = 0;
  373. }
  374. int left, right, top, bot, width, height, diff;
  375. if (vips_find_trim(tmp, &left, &top, &width, &height, "background", bga, "threshold", threshold, NULL)) {
  376. clear_image(&tmp);
  377. vips_area_unref((VipsArea *)bga);
  378. g_free(bg);
  379. return 1;
  380. }
  381. if (equal_hor) {
  382. right = in->Xsize - left - width;
  383. diff = right - left;
  384. if (diff > 0) {
  385. width += diff;
  386. } else if (diff < 0) {
  387. left = right;
  388. width -= diff;
  389. }
  390. }
  391. if (equal_ver) {
  392. bot = in->Ysize - top - height;
  393. diff = bot - top;
  394. if (diff > 0) {
  395. height += diff;
  396. } else if (diff < 0) {
  397. top = bot;
  398. height -= diff;
  399. }
  400. }
  401. clear_image(&tmp);
  402. vips_area_unref((VipsArea *)bga);
  403. g_free(bg);
  404. if (width == 0 || height == 0) {
  405. return vips_copy(in, out, NULL);
  406. }
  407. return vips_extract_area(in, out, left, top, width, height, NULL);
  408. #else
  409. vips_error("vips_trim", "Trim is not supported (libvips 8.6+ reuired)");
  410. return 1;
  411. #endif
  412. }
  413. int
  414. vips_replicate_go(VipsImage *in, VipsImage **out, int width, int height) {
  415. VipsImage *tmp;
  416. if (vips_replicate(in, &tmp, 1 + width / in->Xsize, 1 + height / in->Ysize, NULL))
  417. return 1;
  418. if (vips_extract_area(tmp, out, 0, 0, width, height, NULL)) {
  419. clear_image(&tmp);
  420. return 1;
  421. }
  422. clear_image(&tmp);
  423. return 0;
  424. }
  425. int
  426. vips_embed_go(VipsImage *in, VipsImage **out, int x, int y, int width, int height, double *bg, int bgn) {
  427. VipsArrayDouble *bga = vips_array_double_new(bg, bgn);
  428. int ret = vips_embed(
  429. in, out, x, y, width, height,
  430. "extend", VIPS_EXTEND_BACKGROUND,
  431. "background", bga,
  432. NULL
  433. );
  434. vips_area_unref((VipsArea *)bga);
  435. return ret;
  436. }
  437. int
  438. vips_ensure_alpha(VipsImage *in, VipsImage **out) {
  439. if (vips_image_hasalpha_go(in)) {
  440. return vips_copy(in, out, NULL);
  441. }
  442. return vips_bandjoin_const1(in, out, 255, NULL);
  443. }
  444. int
  445. vips_apply_watermark(VipsImage *in, VipsImage *watermark, VipsImage **out, double opacity) {
  446. #if VIPS_SUPPORT_COMPOSITE
  447. VipsImage *base = vips_image_new();
  448. VipsImage **t = (VipsImage **) vips_object_local_array(VIPS_OBJECT(base), 5);
  449. if (opacity < 1) {
  450. if (
  451. vips_extract_band(watermark, &t[0], 0, "n", watermark->Bands - 1, NULL) ||
  452. vips_extract_band(watermark, &t[1], watermark->Bands - 1, "n", 1, NULL) ||
  453. vips_linear1(t[1], &t[2], opacity, 0, NULL) ||
  454. vips_bandjoin2(t[0], t[2], &t[3], NULL)
  455. ) {
  456. clear_image(&base);
  457. return 1;
  458. }
  459. } else {
  460. if (vips_copy(watermark, &t[3], NULL)) {
  461. clear_image(&base);
  462. return 1;
  463. }
  464. }
  465. int res =
  466. vips_composite2(in, t[3], &t[4], VIPS_BLEND_MODE_OVER, "compositing_space", in->Type, NULL) ||
  467. vips_cast(t[4], out, vips_image_get_format(in), NULL);
  468. clear_image(&base);
  469. return res;
  470. #else
  471. vips_error("vips_apply_watermark", "Watermarking is not supported (libvips 8.6+ reuired)");
  472. return 1;
  473. #endif
  474. }
  475. int
  476. vips_arrayjoin_go(VipsImage **in, VipsImage **out, int n) {
  477. return vips_arrayjoin(in, out, n, "across", 1, NULL);
  478. }
  479. int
  480. vips_strip(VipsImage *in, VipsImage **out) {
  481. if (vips_copy(in, out, NULL)) return 1;
  482. gchar **fields = vips_image_get_fields(in);
  483. for (int i = 0; fields[i] != NULL; i++) {
  484. gchar *name = fields[i];
  485. if (strcmp(name, VIPS_META_ICC_NAME) == 0) continue;
  486. vips_image_remove(*out, name);
  487. }
  488. g_strfreev(fields);
  489. return 0;
  490. }
  491. int
  492. vips_jpegsave_go(VipsImage *in, void **buf, size_t *len, int quality, int interlace) {
  493. return vips_jpegsave_buffer(
  494. in, buf, len,
  495. "Q", quality,
  496. "optimize_coding", TRUE,
  497. "interlace", interlace,
  498. NULL
  499. );
  500. }
  501. int
  502. vips_pngsave_go(VipsImage *in, void **buf, size_t *len, int interlace, int quantize, int colors) {
  503. return vips_pngsave_buffer(
  504. in, buf, len,
  505. "filter", VIPS_FOREIGN_PNG_FILTER_NONE,
  506. "interlace", interlace,
  507. #if VIPS_SUPPORT_PNG_QUANTIZATION
  508. "palette", quantize,
  509. "colours", colors,
  510. #endif // VIPS_SUPPORT_PNG_QUANTIZATION
  511. NULL);
  512. }
  513. int
  514. vips_webpsave_go(VipsImage *in, void **buf, size_t *len, int quality) {
  515. return vips_webpsave_buffer(
  516. in, buf, len,
  517. "Q", quality,
  518. NULL
  519. );
  520. }
  521. int
  522. vips_gifsave_go(VipsImage *in, void **buf, size_t *len) {
  523. #if VIPS_SUPPORT_MAGICK
  524. return vips_magicksave_buffer(in, buf, len, "format", "gif", NULL);
  525. #else
  526. vips_error("vips_gifsave_go", "Saving GIF is not supported (libvips 8.7+ reuired)");
  527. return 1;
  528. #endif
  529. }
  530. int
  531. vips_tiffsave_go(VipsImage *in, void **buf, size_t *len, int quality) {
  532. #if VIPS_SUPPORT_TIFF
  533. return vips_tiffsave_buffer(in, buf, len, "Q", quality, NULL);
  534. #else
  535. vips_error("vips_tiffsave_go", "Saving TIFF is not supported (libvips 8.6+ reuired)");
  536. return 1;
  537. #endif
  538. }
  539. int
  540. vips_avifsave_go(VipsImage *in, void **buf, size_t *len, int quality) {
  541. #if VIPS_SUPPORT_AVIF
  542. return vips_heifsave_buffer(in, buf, len, "Q", quality, "compression", VIPS_FOREIGN_HEIF_COMPRESSION_AV1, NULL);
  543. #else
  544. vips_error("vips_avifsave_go", "Saving AVIF is not supported (libvips 8.9+ reuired)");
  545. return 1;
  546. #endif
  547. }
  548. int
  549. vips_bmpsave_go(VipsImage *in, void **buf, size_t *len) {
  550. #if VIPS_SUPPORT_MAGICK
  551. return vips_magicksave_buffer(in, buf, len, "format", "bmp", NULL);
  552. #else
  553. vips_error("vips_bmpsave_go", "Saving BMP is not supported");
  554. return 1;
  555. #endif
  556. }
  557. void
  558. vips_cleanup() {
  559. vips_error_clear();
  560. vips_thread_shutdown();
  561. }