ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CV/CV.xs
(Generate patch)

Comparing CV/CV.xs (file contents):
Revision 1.50 by root, Sat Dec 23 03:30:28 2017 UTC vs.
Revision 1.51 by root, Sat Dec 23 04:11:49 2017 UTC

33#define LINELENGTH 240 33#define LINELENGTH 240
34 34
35#define ELLIPSIS "\xe2\x80\xa6" 35#define ELLIPSIS "\xe2\x80\xa6"
36 36
37typedef char *octet_string; 37typedef char *octet_string;
38
39static magic_t magic_cookie[2]; /* !mime, mime */
38 40
39struct jpg_err_mgr 41struct jpg_err_mgr
40{ 42{
41 struct jpeg_error_mgr err; 43 struct jpeg_error_mgr err;
42 jmp_buf setjmp_buffer; 44 jmp_buf setjmp_buffer;
219 221
220 OUTPUT: 222 OUTPUT:
221 RETVAL 223 RETVAL
222 224
223const char * 225const char *
224magic (octet_string path) 226magic (SV *path_or_data)
227 ALIAS:
228 magic = 0
229 magic_mime = 1
230 magic_buffer = 2
231 magic_buffer_mime = 3
225 CODE: 232 CODE:
226{ 233{
227 static magic_t cookie; 234 STRLEN len;
228 235 char *data = SvPVbyte (path_or_data, len);
229 if (!cookie)
230 {
231 cookie = magic_open (MAGIC_SYMLINK);
232
233 if (cookie)
234 magic_load (cookie, 0);
235 else
236 XSRETURN_UNDEF;
237 }
238
239 RETVAL = magic_file (cookie, path);
240}
241 OUTPUT:
242 RETVAL
243
244const char *
245magic_mime (octet_string path)
246 CODE:
247{
248 static magic_t cookie;
249
250 if (!cookie)
251 {
252 cookie = magic_open (MAGIC_MIME | MAGIC_SYMLINK);
253
254 if (cookie)
255 magic_load (cookie, 0);
256 else
257 XSRETURN_UNDEF;
258 }
259 236
260 perlinterp_release (); 237 perlinterp_release ();
261 RETVAL = magic_file (cookie, path); 238
239 if (!magic_cookie[0])
240 {
241 magic_cookie[0] = magic_open (MAGIC_SYMLINK);
242 magic_cookie[1] = magic_open (MAGIC_SYMLINK | MAGIC_MIME);
243 }
244
245 RETVAL = ix & 2
246 ? magic_buffer (magic_cookie[ix], data, len)
247 : magic_file (magic_cookie[ix], data);
248
262 perlinterp_acquire (); 249 perlinterp_acquire ();
263} 250}
264 OUTPUT: 251 OUTPUT:
265 RETVAL 252 RETVAL
266 253
322 perlinterp_acquire (); 309 perlinterp_acquire ();
323 OUTPUT: 310 OUTPUT:
324 RETVAL 311 RETVAL
325 312
326GdkPixbuf_noinc * 313GdkPixbuf_noinc *
327load_webp (SV *image_data, int thumbnail = 0, int iw = 0, int ih = 0) 314decode_webp (SV *image_data, int thumbnail = 0, int iw = 0, int ih = 0)
328 CODE: 315 CODE:
329{ 316{
330#if WEBP 317#if WEBP
318 guchar *data;
331 STRLEN data_size; 319 STRLEN data_size;
332 guchar *data = SvPVbyte (image_data, data_size);
333 int alpha; 320 int alpha;
334 WebPDecoderConfig config; 321 WebPDecoderConfig config;
322 int inw, inh;
323
324 data = SvPVbyte (image_data, data_size);
335 325
336 perlinterp_release (); 326 perlinterp_release ();
337 327
338 RETVAL = 0; 328 RETVAL = 0;
339 329
340 if (!WebPInitDecoderConfig (&config)) 330 if (!WebPInitDecoderConfig (&config))
341 goto err; 331 goto err;
342 332
343 config.options.use_threads = 1; 333 config.options.use_threads = 1;
344 334
335 if (WebPGetFeatures (data, data_size, &config.input) != VP8_STATUS_OK)
336 goto err;
337
338 inw = config.input.width;
339 inh = config.input.height;
340
345 if (thumbnail) 341 if (thumbnail)
346 { 342 {
343 if (inw * ih > inh * iw)
344 ih = (iw * inh + inw - 1) / inw;
345 else
346 iw = (ih * inw + inh - 1) / inh;
347
347 config.options.bypass_filtering = 1; 348 config.options.bypass_filtering = 1;
348 config.options.no_fancy_upsampling = 1; 349 config.options.no_fancy_upsampling = 1;
349 350
350 config.options.use_scaling = 1; 351 config.options.use_scaling = 1;
351 config.options.scaled_width = iw; 352 config.options.scaled_width = iw;
352 config.options.scaled_height = ih; 353 config.options.scaled_height = ih;
353 } 354 }
354 else 355 else
355 { 356 {
356 iw = config.input.width; 357 iw = inw;
357 ih = config.input.height; 358 ih = inh;
358 } 359 }
359
360 if (WebPGetFeatures (data, data_size, &config.input) != VP8_STATUS_OK)
361 goto err;
362 360
363 alpha = config.input.has_alpha; 361 alpha = config.input.has_alpha;
364 362
365 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, !!alpha, 8, iw, ih); 363 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, !!alpha, 8, iw, ih);
366 if (!RETVAL) 364 if (!RETVAL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines