vips.c 16 KB

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