-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify.c
More file actions
282 lines (239 loc) · 7.06 KB
/
Copy pathverify.c
File metadata and controls
282 lines (239 loc) · 7.06 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
#include <vips/vips.h>
#include <lcms2.h>
/* Confirms a format's loader/saver class actually linked into the static
* binary, not just that its containing library compiled somewhere upstream.
*/
typedef struct {
const char *nickname;
int expect_present;
} check_t;
static check_t checks[] = {
{ "jpegload", 1 }, { "jpegsave", 1 },
{ "pngload", 1 }, { "pngsave", 1 },
{ "webpload", 1 }, { "webpsave", 1 },
{ "tiffload", 1 }, { "tiffsave", 1 },
{ "gifload", 1 }, /* built-in nsgif */
{ "gifsave", 0 }, /* needs imagequant/quantizr (Rust), deferred - expected absent */
{ "heifload", 1 }, { "heifsave", 1 }, /* HEIC + AVIF */
{ "jxlload", 1 }, { "jxlsave", 1 },
{ "jp2kload", 1 }, { "jp2ksave", 1 }, /* JPEG2000 via openjpeg */
{ "openexrload", 1 }, /* EXR is load-only in libvips */
{ "radload", 1 }, { "radsave", 1 }, /* built-in */
{ "csvload", 1 }, { "csvsave", 1 }, /* built-in */
{ "rsvgload", 0 }, /* Rust, deferred */
{ "pdfload", 0 }, /* poppler/pdfium, deferred */
{ "magicksave", 0 }, /* ImageMagick, deferred */
{ "openslideload", 0 }, /* deferred */
{ "icc_transform", 1 }, /* lcms2 */
};
/* actual encode -> decode round trips, not just class registration.
* .heic/.avif are deliberately excluded: libheif was built decode-only
* (libde265 + dav1d, no x265/aom encoder), so heifsave has no codec to
* encode with even though the operation class is linked in. */
static const char *roundtrip_suffixes[] = {
".jpg", ".png", ".webp", ".tif", ".jxl", ".jp2",
};
static int
check_classes( void )
{
int i;
int failures = 0;
for( i = 0; i < (int) VIPS_NUMBER( checks ); i++ ) {
GType type = vips_type_find( "VipsOperation", checks[i].nickname );
int present = type != 0;
int ok = present == checks[i].expect_present;
printf( "%-16s present=%-3s expected=%-3s %s\n",
checks[i].nickname,
present ? "yes" : "no",
checks[i].expect_present ? "yes" : "no",
ok ? "OK" : "MISMATCH" );
if( !ok )
failures++;
}
return failures;
}
static int
check_roundtrips( void )
{
int i;
int failures = 0;
for( i = 0; i < (int) VIPS_NUMBER( roundtrip_suffixes ); i++ ) {
const char *suffix = roundtrip_suffixes[i];
VipsImage *im;
VipsImage *im2;
void *buf;
size_t len;
int ok;
if( vips_black( &im, 32, 32, NULL ) ) {
printf( "%-6s roundtrip: FAIL (vips_black: %s)\n",
suffix, vips_error_buffer() );
vips_error_clear();
failures++;
continue;
}
if( vips_image_write_to_buffer( im, suffix, &buf, &len, NULL ) ) {
printf( "%-6s roundtrip: FAIL (save: %s)\n",
suffix, vips_error_buffer() );
vips_error_clear();
g_object_unref( im );
failures++;
continue;
}
g_object_unref( im );
im2 = vips_image_new_from_buffer( buf, len, "", NULL );
g_free( buf );
if( !im2 ) {
printf( "%-6s roundtrip: FAIL (load: %s)\n",
suffix, vips_error_buffer() );
vips_error_clear();
failures++;
continue;
}
ok = vips_image_get_width( im2 ) == 32 &&
vips_image_get_height( im2 ) == 32;
g_object_unref( im2 );
printf( "%-6s roundtrip: %s\n", suffix, ok ? "OK" : "FAIL (size mismatch)" );
if( !ok )
failures++;
}
return failures;
}
/* proves libexif actually round-trips metadata through jpegsave/jpegload,
* not just that the operation classes are linked in */
static int
check_exif( void )
{
VipsImage *im;
VipsImage *im2;
void *buf;
size_t len;
int orientation = 0;
int has_field;
int ok;
if( vips_black( &im, 32, 32, NULL ) ) {
printf( "exif: FAIL (vips_black: %s)\n", vips_error_buffer() );
vips_error_clear();
return 1;
}
vips_image_set_int( im, VIPS_META_ORIENTATION, 6 );
if( vips_image_write_to_buffer( im, ".jpg", &buf, &len, NULL ) ) {
printf( "exif: FAIL (save: %s)\n", vips_error_buffer() );
vips_error_clear();
g_object_unref( im );
return 1;
}
g_object_unref( im );
im2 = vips_image_new_from_buffer( buf, len, "", NULL );
g_free( buf );
if( !im2 ) {
printf( "exif: FAIL (load: %s)\n", vips_error_buffer() );
vips_error_clear();
return 1;
}
has_field = vips_image_get_typeof( im2, VIPS_META_ORIENTATION ) != 0;
if( has_field )
vips_image_get_int( im2, VIPS_META_ORIENTATION, &orientation );
g_object_unref( im2 );
ok = has_field && orientation == 6;
printf( "exif: %s (orientation set to 6, read back as %d)\n",
ok ? "OK" : "FAIL", orientation );
return ok ? 0 : 1;
}
/* proves lcms2 actually performs a real ICC transform, not just that the
* icc_transform class links - generates a real sRGB profile with lcms2's
* own API rather than guessing whether vips's "srgb" keyword resolves
* without a profile file on disk */
static int
check_icc( void )
{
const char *path = "/tmp/verify-srgb.icc";
cmsHPROFILE profile;
VipsImage *im;
VipsImage *out;
int rc;
profile = cmsCreate_sRGBProfile();
if( !profile || !cmsSaveProfileToFile( profile, path ) ) {
printf( "icc: FAIL (couldn't generate sRGB profile with lcms2)\n" );
if( profile )
cmsCloseProfile( profile );
return 1;
}
cmsCloseProfile( profile );
if( vips_black( &im, 32, 32, "bands", 3, NULL ) ) {
printf( "icc: FAIL (vips_black: %s)\n", vips_error_buffer() );
vips_error_clear();
unlink( path );
return 1;
}
rc = vips_icc_transform( im, &out, path, "input_profile", path, NULL );
g_object_unref( im );
unlink( path );
if( rc ) {
printf( "icc: FAIL (vips_icc_transform: %s)\n", vips_error_buffer() );
vips_error_clear();
return 1;
}
g_object_unref( out );
printf( "icc: OK (transformed through a real lcms2-generated sRGB profile)\n" );
return 0;
}
/* proves the fftw-linked vips_fwfft/vips_invfft path actually runs and
* round-trips a real image, not just that fftw3 is present in the link line */
static int
check_fftw( void )
{
VipsImage *im;
VipsImage *freq;
VipsImage *back;
double avg_before, avg_after;
int ok;
if( vips_black( &im, 64, 64, NULL ) ) {
printf( "fftw: FAIL (vips_black: %s)\n", vips_error_buffer() );
vips_error_clear();
return 1;
}
if( vips_fwfft( im, &freq, NULL ) ) {
printf( "fftw: FAIL (vips_fwfft: %s)\n", vips_error_buffer() );
vips_error_clear();
g_object_unref( im );
return 1;
}
if( vips_invfft( freq, &back, "real", TRUE, NULL ) ) {
printf( "fftw: FAIL (vips_invfft: %s)\n", vips_error_buffer() );
vips_error_clear();
g_object_unref( im );
g_object_unref( freq );
return 1;
}
g_object_unref( freq );
vips_avg( im, &avg_before, NULL );
vips_avg( back, &avg_after, NULL );
g_object_unref( im );
g_object_unref( back );
ok = fabs( avg_before - avg_after ) < 1.0;
printf( "fftw: %s (avg before=%.3f after=%.3f)\n",
ok ? "OK" : "FAIL", avg_before, avg_after );
return ok ? 0 : 1;
}
int
main( int argc, char **argv )
{
int failures = 0;
if( VIPS_INIT( argv[0] ) )
vips_error_exit( "unable to init vips" );
printf( "libvips %s\n\n", vips_version_string() );
failures += check_classes();
printf( "\n" );
failures += check_roundtrips();
printf( "\n" );
failures += check_exif();
failures += check_icc();
failures += check_fftw();
printf( "\n%s\n", failures ? "FAILURES" : "ALL OK" );
vips_shutdown();
return failures ? 1 : 0;
}