vips.c 17 KB

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