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

Comparing CV/CV.xs (file contents):
Revision 1.49 by root, Wed May 24 19:22:32 2017 UTC vs.
Revision 1.51 by root, Sat Dec 23 04:11:49 2017 UTC

9#include <magic.h> 9#include <magic.h>
10 10
11#include <jpeglib.h> 11#include <jpeglib.h>
12#include <glib.h> 12#include <glib.h>
13#include <gtk/gtk.h> 13#include <gtk/gtk.h>
14#include <gdk/gdkx.h>
14#include <gdk-pixbuf/gdk-pixbuf.h> 15#include <gdk-pixbuf/gdk-pixbuf.h>
15 16
16#include <gperl.h> 17#include <gperl.h>
17#include <gtk2perl.h> 18#include <gtk2perl.h>
18 19
19#include <assert.h> 20#include <assert.h>
20 21
22#if WEBP
23#include <webp/decode.h>
24#endif
25
21#include "perlmulticore.h" 26#include "perlmulticore.h"
22 27
23#define IW 80 /* MUST match Schnauzer.pm! */ 28#define IW 80 /* MUST match Schnauzer.pm! */
24#define IH 60 /* MUST match Schnauzer.pm! */ 29#define IH 60 /* MUST match Schnauzer.pm! */
25 30
28#define LINELENGTH 240 33#define LINELENGTH 240
29 34
30#define ELLIPSIS "\xe2\x80\xa6" 35#define ELLIPSIS "\xe2\x80\xa6"
31 36
32typedef char *octet_string; 37typedef char *octet_string;
38
39static magic_t magic_cookie[2]; /* !mime, mime */
33 40
34struct jpg_err_mgr 41struct jpg_err_mgr
35{ 42{
36 struct jpeg_error_mgr err; 43 struct jpeg_error_mgr err;
37 jmp_buf setjmp_buffer; 44 jmp_buf setjmp_buffer;
214 221
215 OUTPUT: 222 OUTPUT:
216 RETVAL 223 RETVAL
217 224
218const char * 225const char *
219magic (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
220 CODE: 232 CODE:
221{ 233{
222 static magic_t cookie; 234 STRLEN len;
223 235 char *data = SvPVbyte (path_or_data, len);
224 if (!cookie)
225 {
226 cookie = magic_open (MAGIC_SYMLINK);
227
228 if (cookie)
229 magic_load (cookie, 0);
230 else
231 XSRETURN_UNDEF;
232 }
233
234 RETVAL = magic_file (cookie, path);
235}
236 OUTPUT:
237 RETVAL
238
239const char *
240magic_mime (octet_string path)
241 CODE:
242{
243 static magic_t cookie;
244
245 if (!cookie)
246 {
247 cookie = magic_open (MAGIC_MIME | MAGIC_SYMLINK);
248
249 if (cookie)
250 magic_load (cookie, 0);
251 else
252 XSRETURN_UNDEF;
253 }
254 236
255 perlinterp_release (); 237 perlinterp_release ();
256 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
257 perlinterp_acquire (); 249 perlinterp_acquire ();
258} 250}
259 OUTPUT: 251 OUTPUT:
260 RETVAL 252 RETVAL
261 253
313 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE 305 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
314 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN 306 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN
315 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE 307 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE
316 : angle); 308 : angle);
317 perlinterp_acquire (); 309 perlinterp_acquire ();
310 OUTPUT:
311 RETVAL
312
313GdkPixbuf_noinc *
314decode_webp (SV *image_data, int thumbnail = 0, int iw = 0, int ih = 0)
315 CODE:
316{
317#if WEBP
318 guchar *data;
319 STRLEN data_size;
320 int alpha;
321 WebPDecoderConfig config;
322 int inw, inh;
323
324 data = SvPVbyte (image_data, data_size);
325
326 perlinterp_release ();
327
328 RETVAL = 0;
329
330 if (!WebPInitDecoderConfig (&config))
331 goto err;
332
333 config.options.use_threads = 1;
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
341 if (thumbnail)
342 {
343 if (inw * ih > inh * iw)
344 ih = (iw * inh + inw - 1) / inw;
345 else
346 iw = (ih * inw + inh - 1) / inh;
347
348 config.options.bypass_filtering = 1;
349 config.options.no_fancy_upsampling = 1;
350
351 config.options.use_scaling = 1;
352 config.options.scaled_width = iw;
353 config.options.scaled_height = ih;
354 }
355 else
356 {
357 iw = inw;
358 ih = inh;
359 }
360
361 alpha = config.input.has_alpha;
362
363 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, !!alpha, 8, iw, ih);
364 if (!RETVAL)
365 goto err;
366
367 config.output.colorspace = alpha ? MODE_RGBA : MODE_RGB;
368 config.output.u.RGBA.rgba = gdk_pixbuf_get_pixels (RETVAL);
369 config.output.u.RGBA.stride = gdk_pixbuf_get_rowstride (RETVAL);
370 config.output.u.RGBA.size = gdk_pixbuf_get_byte_length (RETVAL);
371 config.output.is_external_memory = 1;
372
373 if (WebPDecode (data, data_size, &config) != VP8_STATUS_OK)
374 {
375 g_object_unref (RETVAL);
376 RETVAL = 0;
377 goto err;
378 }
379
380 err:
381 perlinterp_acquire ();
382#else
383 croak ("load_webp: webp not enabled at compile time");
384#endif
385}
318 OUTPUT: 386 OUTPUT:
319 RETVAL 387 RETVAL
320 388
321GdkPixbuf_noinc * 389GdkPixbuf_noinc *
322load_jpeg (SV *path, int thumbnail = 0, int iw = 0, int ih = 0) 390load_jpeg (SV *path, int thumbnail = 0, int iw = 0, int ih = 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines