vips.c 17 KB

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