forked from imgproxy/imgproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvips.h
214 lines (181 loc) · 5.06 KB
/
vips.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include <stdlib.h>
#include <vips/vips.h>
#include <vips/vips7compat.h>
#define VIPS_SUPPORT_SMARTCROP \
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 5))
#define VIPS_SUPPORT_HASALPHA \
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 5))
#define VIPS_SUPPORT_GIF \
VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 3)
#define EXIF_ORIENTATION "exif-ifd0-Orientation"
enum types {
UNKNOWN = 0,
JPEG,
PNG,
WEBP,
GIF
};
int
vips_initialize() {
return vips_init("imgproxy");
}
void
clear_image(VipsImage **in) {
if (G_IS_OBJECT(*in)) g_clear_object(in);
}
void
g_free_go(void **buf) {
g_free(*buf);
}
void
swap_and_clear(VipsImage **in, VipsImage *out) {
clear_image(in);
*in = out;
}
int
vips_type_find_load_go(int imgtype) {
if (imgtype == JPEG) {
return vips_type_find("VipsOperation", "jpegload");
}
if (imgtype == PNG) {
return vips_type_find("VipsOperation", "pngload");
}
if (imgtype == WEBP) {
return vips_type_find("VipsOperation", "webpload");
}
if (imgtype == GIF) {
return vips_type_find("VipsOperation", "gifload");
}
return 0;
}
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");
}
if (imgtype == WEBP) {
return vips_type_find("VipsOperation", "webpsave_buffer");
}
return 0;
}
int
vips_load_buffer(void *buf, size_t len, int imgtype, int shrink, VipsImage **out) {
switch (imgtype) {
case JPEG:
if (shrink > 1) {
return vips_jpegload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, "shrink", shrink, NULL);
}
return vips_jpegload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, NULL);
case PNG:
return vips_pngload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, NULL);
case WEBP:
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);
#if VIPS_SUPPORT_GIF
case GIF:
return vips_gifload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, NULL);
#endif
}
return 1;
}
int
vips_get_exif_orientation(VipsImage *image) {
const char *orientation;
if (
vips_image_get_typeof(image, EXIF_ORIENTATION) != 0 &&
!vips_image_get_string(image, EXIF_ORIENTATION, &orientation)
) return atoi(&orientation[0]);
return 1;
}
int
vips_support_smartcrop() {
#if VIPS_SUPPORT_SMARTCROP
return 1;
#else
return 0;
#endif
}
VipsBandFormat
vips_band_format(VipsImage *in) {
return in->BandFmt;
}
gboolean
vips_image_hasalpha_go(VipsImage * in) {
#if VIPS_SUPPORT_HASALPHA
return vips_image_hasalpha(in);
#else
return( in->Bands == 2 ||
(in->Bands == 4 && in->Type != VIPS_INTERPRETATION_CMYK) ||
in->Bands > 4 );
#endif
}
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);
}
int
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) {
return vips_icc_import(in, out, "input_profile", profile, "embedded", TRUE, "pcs", VIPS_PCS_XYZ, NULL);
}
int
vips_colourspace_go(VipsImage *in, VipsImage **out, VipsInterpretation cs) {
return vips_colourspace(in, out, cs, NULL);
}
int
vips_rot_go(VipsImage *in, VipsImage **out, VipsAngle angle) {
return vips_rot(in, out, angle, NULL);
}
int
vips_flip_horizontal_go(VipsImage *in, VipsImage **out) {
return vips_flip(in, out, VIPS_DIRECTION_HORIZONTAL, NULL);
}
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
return 1;
#endif
}
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);
}
int
vips_jpegsave_go(VipsImage *in, void **buf, size_t *len, int strip, int quality, int interlace) {
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) {
return vips_pngsave_buffer(in, buf, len, "filter", VIPS_FOREIGN_PNG_FILTER_NONE, "interlace", interlace, NULL);
}
int
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);
}
void
vips_cleanup() {
vips_thread_shutdown();
vips_error_clear();
}