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

Comparing CV/CV.xs (file contents):
Revision 1.42 by root, Sun Sep 14 12:47:59 2008 UTC vs.
Revision 1.46 by root, Sat Jul 4 05:31:17 2015 UTC

13#include <gtk/gtk.h> 13#include <gtk/gtk.h>
14#include <gdk-pixbuf/gdk-pixbuf.h> 14#include <gdk-pixbuf/gdk-pixbuf.h>
15 15
16#include <gperl.h> 16#include <gperl.h>
17#include <gtk2perl.h> 17#include <gtk2perl.h>
18
19#include <assert.h>
20
21#include "perlmulticore.h"
18 22
19#define IW 80 /* MUST match Schnauzer.pm! */ 23#define IW 80 /* MUST match Schnauzer.pm! */
20#define IH 60 /* MUST match Schnauzer.pm! */ 24#define IH 60 /* MUST match Schnauzer.pm! */
21 25
22#define RAND (seed = (seed + 7141) * 54773 % 134456) 26#define RAND (seed = (seed + 7141) * 54773 % 134456)
211{ 215{
212 static magic_t cookie; 216 static magic_t cookie;
213 217
214 if (!cookie) 218 if (!cookie)
215 { 219 {
216 cookie = magic_open (MAGIC_NONE); 220 cookie = magic_open (MAGIC_SYMLINK);
217 221
218 if (cookie) 222 if (cookie)
219 magic_load (cookie, 0); 223 magic_load (cookie, 0);
220 else 224 else
221 XSRETURN_UNDEF; 225 XSRETURN_UNDEF;
232{ 236{
233 static magic_t cookie; 237 static magic_t cookie;
234 238
235 if (!cookie) 239 if (!cookie)
236 { 240 {
237 cookie = magic_open (MAGIC_MIME); 241 cookie = magic_open (MAGIC_MIME | MAGIC_SYMLINK);
238 242
239 if (cookie) 243 if (cookie)
240 magic_load (cookie, 0); 244 magic_load (cookie, 0);
241 else 245 else
242 XSRETURN_UNDEF; 246 XSRETURN_UNDEF;
243 } 247 }
244 248
249 perlinterp_release ();
245 RETVAL = magic_file (cookie, path); 250 RETVAL = magic_file (cookie, path);
251 perlinterp_acquire ();
246} 252}
247 OUTPUT: 253 OUTPUT:
248 RETVAL 254 RETVAL
249 255
250# missing/broken in Gtk2 perl module 256# missing/broken in Gtk2 perl module
266 RETVAL 272 RETVAL
267 273
268GdkPixbuf_noinc * 274GdkPixbuf_noinc *
269dealpha_expose (GdkPixbuf *pb) 275dealpha_expose (GdkPixbuf *pb)
270 CODE: 276 CODE:
277 perlinterp_release ();
271{ 278{
272 int w = gdk_pixbuf_get_width (pb); 279 int w = gdk_pixbuf_get_width (pb);
273 int h = gdk_pixbuf_get_height (pb); 280 int h = gdk_pixbuf_get_height (pb);
274 int bpp = gdk_pixbuf_get_n_channels (pb); 281 int bpp = gdk_pixbuf_get_n_channels (pb);
275 int x, y, i; 282 int x, y, i;
284 for (x = 0; x < w; x++) 291 for (x = 0; x < w; x++)
285 for (y = 0; y < h; y++) 292 for (y = 0; y < h; y++)
286 for (i = 0; i < 3; i++) 293 for (i = 0; i < 3; i++)
287 dst[x * 3 + y * dstr + i] = src[x * bpp + y * sstr + i]; 294 dst[x * 3 + y * dstr + i] = src[x * bpp + y * sstr + i];
288} 295}
296 perlinterp_acquire ();
289 OUTPUT: 297 OUTPUT:
290 RETVAL 298 RETVAL
291 299
292GdkPixbuf_noinc * 300GdkPixbuf_noinc *
293rotate (GdkPixbuf *pb, int angle) 301rotate (GdkPixbuf *pb, int angle)
294 CODE: 302 CODE:
303 perlinterp_release ();
304 if (angle < 0)
305 angle += 360;
295 RETVAL = gdk_pixbuf_rotate_simple (pb, angle == 0 ? GDK_PIXBUF_ROTATE_NONE 306 RETVAL = gdk_pixbuf_rotate_simple (pb, angle == 0 ? GDK_PIXBUF_ROTATE_NONE
296 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE 307 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
297 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN 308 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN
298 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE 309 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE
299 : angle); 310 : angle);
311 perlinterp_acquire ();
300 OUTPUT: 312 OUTPUT:
301 RETVAL 313 RETVAL
302 314
303GdkPixbuf_noinc * 315GdkPixbuf_noinc *
304load_jpeg (SV *path, int thumbnail=0) 316load_jpeg (SV *path, int thumbnail=0)
316 fp = fopen (SvPVbyte_nolen (path), "rb"); 328 fp = fopen (SvPVbyte_nolen (path), "rb");
317 329
318 if (!fp) 330 if (!fp)
319 XSRETURN_UNDEF; 331 XSRETURN_UNDEF;
320 332
333 perlinterp_release ();
334
321 cinfo.err = jpeg_std_error (&jerr.err); 335 cinfo.err = jpeg_std_error (&jerr.err);
322 336
323 jerr.err.error_exit = cv_error_exit; 337 jerr.err.error_exit = cv_error_exit;
324 jerr.err.output_message = cv_error_output; 338 jerr.err.output_message = cv_error_output;
325 339
329 jpeg_destroy_decompress (&cinfo); 343 jpeg_destroy_decompress (&cinfo);
330 344
331 if (pb) 345 if (pb)
332 g_object_unref ((gpointer)pb); 346 g_object_unref ((gpointer)pb);
333 347
348 perlinterp_acquire ();
334 XSRETURN_UNDEF; 349 XSRETURN_UNDEF;
335 } 350 }
336 351
337 jpeg_create_decompress (&cinfo); 352 jpeg_create_decompress (&cinfo);
338 353
390 } 405 }
391 406
392 jpeg_finish_decompress (&cinfo); 407 jpeg_finish_decompress (&cinfo);
393 fclose (fp); 408 fclose (fp);
394 jpeg_destroy_decompress (&cinfo); 409 jpeg_destroy_decompress (&cinfo);
410 perlinterp_acquire ();
395} 411}
396 OUTPUT: 412 OUTPUT:
397 RETVAL 413 RETVAL
398 414
399void 415void
400compare (GdkPixbuf *a, GdkPixbuf *b) 416compare (GdkPixbuf *a, GdkPixbuf *b)
401 PPCODE: 417 PPCODE:
418 perlinterp_release ();
402{ 419{
403 int w = gdk_pixbuf_get_width (a); 420 int w = gdk_pixbuf_get_width (a);
404 int h = gdk_pixbuf_get_height (a); 421 int h = gdk_pixbuf_get_height (a);
422
405 int sa = gdk_pixbuf_get_rowstride (a); 423 int sa = gdk_pixbuf_get_rowstride (a);
406 int sb = gdk_pixbuf_get_rowstride (b); 424 int sb = gdk_pixbuf_get_rowstride (b);
407 425
408 guchar *pa = gdk_pixbuf_get_pixels (a); 426 guchar *pa = gdk_pixbuf_get_pixels (a);
409 guchar *pb = gdk_pixbuf_get_pixels (b); 427 guchar *pb = gdk_pixbuf_get_pixels (b);
432 d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d)); 450 d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d));
433 d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d)); 451 d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d));
434 d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d)); 452 d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d));
435 } 453 }
436 } 454 }
455
456 perlinterp_acquire ();
437 457
438 EXTEND (SP, 2); 458 EXTEND (SP, 2);
439 PUSHs (sv_2mortal (newSVnv (sqrt (diff / (w * h * 3. * 255. * 255.))))); 459 PUSHs (sv_2mortal (newSVnv (sqrt (diff / (w * h * 3. * 255. * 255.)))));
440 PUSHs (sv_2mortal (newSVnv (peak / 255.))); 460 PUSHs (sv_2mortal (newSVnv (peak / 255.)));
441} 461}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines