1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-11-24 08:12:38 +02:00
imgproxy/vips.h

295 lines
7.5 KiB
C
Raw Normal View History

2017-09-27 10:42:49 +02:00
#include <stdlib.h>
#include <vips/vips.h>
#include <vips/vips7compat.h>
2018-09-09 16:11:34 +02:00
#include "image_types.h"
2017-09-27 10:42:49 +02:00
#define VIPS_SUPPORT_SMARTCROP \
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 5))
2017-10-19 18:38:09 +02:00
#define VIPS_SUPPORT_HASALPHA \
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 5))
2017-09-27 22:12:38 +02:00
#define VIPS_SUPPORT_GIF \
2018-11-08 12:34:21 +02:00
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 3))
#define VIPS_SUPPORT_MAGICK \
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 7))
2017-09-27 22:12:38 +02:00
#define EXIF_ORIENTATION "exif-ifd0-Orientation"
2017-09-27 10:42:49 +02:00
int
2017-10-05 01:59:23 +02:00
vips_initialize() {
2017-09-27 10:42:49 +02:00
return vips_init("imgproxy");
}
2017-09-28 15:43:21 +02:00
void
clear_image(VipsImage **in) {
2017-10-05 18:50:41 +02:00
if (G_IS_OBJECT(*in)) g_clear_object(in);
2017-09-28 15:43:21 +02:00
}
2017-10-05 01:56:42 +02:00
void
g_free_go(void **buf) {
g_free(*buf);
}
2017-09-27 21:17:17 +02:00
void
swap_and_clear(VipsImage **in, VipsImage *out) {
2017-09-28 15:43:21 +02:00
clear_image(in);
2017-09-27 21:17:17 +02:00
*in = out;
}
2017-09-27 10:42:49 +02:00
int
vips_type_find_load_go(int imgtype) {
if (imgtype == JPEG) {
2018-11-08 12:34:21 +02:00
return vips_type_find("VipsOperation", "jpegload_buffer");
2017-09-27 10:42:49 +02:00
}
if (imgtype == PNG) {
2018-11-08 12:34:21 +02:00
return vips_type_find("VipsOperation", "pngload_buffer");
2017-09-27 10:42:49 +02:00
}
if (imgtype == WEBP) {
2018-11-08 12:34:21 +02:00
return vips_type_find("VipsOperation", "webpload_buffer");
2017-09-27 10:42:49 +02:00
}
2017-10-05 01:59:23 +02:00
if (imgtype == GIF) {
2018-11-08 12:34:21 +02:00
return vips_type_find("VipsOperation", "gifload_buffer");
2017-10-05 01:59:23 +02:00
}
return 0;
2017-09-27 10:42:49 +02:00
}
int
vips_type_find_save_go(int imgtype) {
if (imgtype == JPEG) {
return vips_type_find("VipsOperation", "jpegsave_buffer");
}
if (imgtype == PNG) {
return vips_type_find("VipsOperation", "pngsave_buffer");
}
2017-10-05 01:59:23 +02:00
if (imgtype == WEBP) {
return vips_type_find("VipsOperation", "webpsave_buffer");
}
2018-11-08 12:34:21 +02:00
if (imgtype == GIF) {
return vips_type_find("VipsOperation", "magicksave_buffer");
}
2017-10-05 01:59:23 +02:00
return 0;
2017-09-27 10:42:49 +02:00
}
int
2018-11-08 12:34:21 +02:00
vips_jpegload_go(void *buf, size_t len, int shrink, VipsImage **out) {
if (shrink > 1) {
return vips_jpegload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, "shrink", shrink, NULL);
}
2018-11-08 12:34:21 +02:00
return vips_jpegload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, NULL);
}
int
vips_pngload_go(void *buf, size_t len, VipsImage **out) {
return vips_pngload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, NULL);
}
int
vips_webpload_go(void *buf, size_t len, int shrink, VipsImage **out) {
if (shrink > 1) {
return vips_webpload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, "shrink", shrink, NULL);
}
return vips_webpload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, NULL);
}
int
vips_gifload_go(void *buf, size_t len, int pages, VipsImage **out) {
#if VIPS_SUPPORT_GIF
return vips_gifload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, "n", pages, NULL);
#else
vips_error("vips_gifload_go", "Loading GIF is not supported");
2018-11-08 12:34:21 +02:00
return 1;
#endif
2017-09-27 21:17:17 +02:00
}
2017-09-27 10:42:49 +02:00
int
vips_get_exif_orientation(VipsImage *image) {
const char *orientation;
if (
vips_image_get_typeof(image, EXIF_ORIENTATION) != 0 &&
2018-11-29 11:24:18 +02:00
vips_image_get_string(image, EXIF_ORIENTATION, &orientation) == 0
) return atoi(&orientation[0]);
return 1;
}
2017-09-27 10:42:49 +02:00
int
vips_support_smartcrop() {
#if VIPS_SUPPORT_SMARTCROP
2017-10-05 01:59:23 +02:00
return 1;
2017-09-27 10:42:49 +02:00
#else
2017-10-05 01:59:23 +02:00
return 0;
2017-09-27 10:42:49 +02:00
#endif
}
2017-10-19 17:51:44 +02:00
VipsBandFormat
vips_band_format(VipsImage *in) {
return in->BandFmt;
}
2017-10-19 18:38:09 +02:00
gboolean
vips_image_hasalpha_go(VipsImage * in) {
#if VIPS_SUPPORT_HASALPHA
return vips_image_hasalpha(in);
#else
2017-10-19 18:55:19 +02:00
return( in->Bands == 2 ||
(in->Bands == 4 && in->Type != VIPS_INTERPRETATION_CMYK) ||
in->Bands > 4 );
2017-10-19 18:38:09 +02:00
#endif
}
2017-10-19 17:51:44 +02:00
int
vips_premultiply_go(VipsImage *in, VipsImage **out) {
return vips_premultiply(in, out, NULL);
}
int
vips_unpremultiply_go(VipsImage *in, VipsImage **out) {
return vips_unpremultiply(in, out, NULL);
}
int
vips_cast_go(VipsImage *in, VipsImage **out, VipsBandFormat format) {
return vips_cast(in, out, format, NULL);
}
2017-09-27 10:42:49 +02:00
int
2017-10-18 00:23:17 +02:00
vips_resize_go(VipsImage *in, VipsImage **out, double scale) {
return vips_resize(in, out, scale, NULL);
}
int
vips_need_icc_import(VipsImage *in) {
return in->Type == VIPS_INTERPRETATION_CMYK;
}
int
vips_icc_import_go(VipsImage *in, VipsImage **out, char *profile) {
2018-01-11 11:32:44 +02:00
return vips_icc_import(in, out, "input_profile", profile, "embedded", TRUE, "pcs", VIPS_PCS_XYZ, NULL);
}
2017-10-18 00:23:17 +02:00
int
vips_colourspace_go(VipsImage *in, VipsImage **out, VipsInterpretation cs) {
return vips_colourspace(in, out, cs, NULL);
}
2017-10-18 00:23:17 +02:00
int
vips_rot_go(VipsImage *in, VipsImage **out, VipsAngle angle) {
return vips_rot(in, out, angle, NULL);
}
2017-10-18 00:23:17 +02:00
int
vips_flip_horizontal_go(VipsImage *in, VipsImage **out) {
return vips_flip(in, out, VIPS_DIRECTION_HORIZONTAL, NULL);
}
2017-09-27 21:17:17 +02:00
2017-10-18 00:23:17 +02:00
int
vips_smartcrop_go(VipsImage *in, VipsImage **out, int width, int height) {
#if VIPS_SUPPORT_SMARTCROP
return vips_smartcrop(in, out, width, height, NULL);
#else
vips_error("vips_smartcrop_go", "Smart crop is not supported");
2017-10-18 00:35:13 +02:00
return 1;
2017-10-18 00:23:17 +02:00
#endif
}
2017-09-27 21:17:17 +02:00
2018-09-07 16:46:16 +02:00
int
vips_gaussblur_go(VipsImage *in, VipsImage **out, double sigma) {
return vips_gaussblur(in, out, sigma, NULL);
}
int
vips_sharpen_go(VipsImage *in, VipsImage **out, double sigma) {
return vips_sharpen(in, out, "sigma", sigma, NULL);
}
2018-10-02 14:20:23 +02:00
int
vips_flatten_go(VipsImage *in, VipsImage **out, double r, double g, double b) {
VipsArrayDouble *bg = vips_array_double_newv(3, r, g, b);
int res = vips_flatten(in, out, "background", bg, NULL);
vips_area_unref((VipsArea *)bg);
return res;
}
2017-10-18 00:23:17 +02:00
int
vips_extract_area_go(VipsImage *in, VipsImage **out, int left, int top, int width, int height) {
return vips_extract_area(in, out, left, top, width, height, NULL);
2017-09-27 21:17:17 +02:00
}
2018-10-19 11:47:11 +02:00
int
vips_replicate_go(VipsImage *in, VipsImage **out, int across, int down) {
return vips_replicate(in, out, across, down, NULL);
}
int
vips_embed_go(VipsImage *in, VipsImage **out, int x, int y, int width, int height) {
return vips_embed(in, out, x, y, width, height, NULL);
}
int
vips_extract_band_go(VipsImage *in, VipsImage **out, int band, int band_num) {
return vips_extract_band(in, out, band, "n", band_num, NULL);
}
int
vips_bandjoin_go (VipsImage *in1, VipsImage *in2, VipsImage **out) {
return vips_bandjoin2(in1, in2, out, NULL);
}
int
vips_bandjoin_const_go (VipsImage *in, VipsImage **out, double c) {
return vips_bandjoin_const1(in, out, c, NULL);
}
int
vips_linear_go (VipsImage *in, VipsImage **out, double a, double b) {
return vips_linear1(in, out, a, b, NULL);
}
int
vips_ifthenelse_go(VipsImage *cond, VipsImage *in1, VipsImage *in2, VipsImage **out) {
return vips_ifthenelse(cond, in1, in2, out, "blend", TRUE, NULL);
}
2018-11-08 12:34:21 +02:00
int
vips_arrayjoin_go(VipsImage **in, VipsImage **out, int n) {
return vips_arrayjoin(in, out, n, "across", 1, NULL);
}
2017-09-27 10:42:49 +02:00
int
2017-10-05 01:59:23 +02:00
vips_jpegsave_go(VipsImage *in, void **buf, size_t *len, int strip, int quality, int interlace) {
2017-09-27 10:42:49 +02:00
return vips_jpegsave_buffer(in, buf, len, "strip", strip, "Q", quality, "optimize_coding", TRUE, "interlace", interlace, NULL);
}
int
vips_pngsave_go(VipsImage *in, void **buf, size_t *len, int interlace, int embed_profile) {
if (embed_profile) {
return vips_pngsave_buffer(in, buf, len, "filter", VIPS_FOREIGN_PNG_FILTER_NONE, "interlace", interlace, NULL);
}
return vips_pngsave_buffer(in, buf, len, "profile", "none", "filter", VIPS_FOREIGN_PNG_FILTER_NONE, "interlace", interlace, NULL);
2017-09-27 10:42:49 +02:00
}
int
2017-10-05 01:59:23 +02:00
vips_webpsave_go(VipsImage *in, void **buf, size_t *len, int strip, int quality) {
return vips_webpsave_buffer(in, buf, len, "strip", strip, "Q", quality, NULL);
2017-09-27 10:42:49 +02:00
}
2017-09-27 21:17:17 +02:00
2018-11-08 12:34:21 +02:00
int
vips_gifsave_go(VipsImage *in, void **buf, size_t *len) {
#if VIPS_SUPPORT_MAGICK
return vips_magicksave_buffer(in, buf, len, "format", "gif", NULL);
#else
vips_error("vips_gifsave_go", "Saving GIF is not supported");
2018-11-08 12:34:21 +02:00
return 1;
#endif
}
2017-09-27 21:17:17 +02:00
void
2017-10-05 01:59:23 +02:00
vips_cleanup() {
2017-09-27 21:17:17 +02:00
vips_thread_shutdown();
vips_error_clear();
}