… | |
… | |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
4 | |
4 | |
5 | #include <string.h> |
5 | #include <string.h> |
6 | #include <setjmp.h> |
6 | #include <setjmp.h> |
|
|
7 | #include <math.h> |
7 | |
8 | |
8 | #include <magic.h> |
9 | #include <magic.h> |
9 | |
10 | |
10 | #include <jpeglib.h> |
11 | #include <jpeglib.h> |
11 | #include <glib.h> |
12 | #include <glib.h> |
… | |
… | |
13 | #include <gdk-pixbuf/gdk-pixbuf.h> |
14 | #include <gdk-pixbuf/gdk-pixbuf.h> |
14 | |
15 | |
15 | #include <gperl.h> |
16 | #include <gperl.h> |
16 | #include <gtk2perl.h> |
17 | #include <gtk2perl.h> |
17 | |
18 | |
18 | #define IW 80 /* MUST match Schnauer.pm! */ |
19 | #define IW 80 /* MUST match Schnauzer.pm! */ |
19 | #define IH 60 /* MUST match Schnauer.pm! */ |
20 | #define IH 60 /* MUST match Schnauzer.pm! */ |
20 | |
21 | |
21 | #define RAND (seed = (seed + 7141) * 54773 % 134456) |
22 | #define RAND (seed = (seed + 7141) * 54773 % 134456) |
22 | |
23 | |
23 | #define LINELENGTH 240 |
24 | #define LINELENGTH 240 |
24 | |
25 | |
… | |
… | |
331 | jpeg_destroy_decompress (&cinfo); |
332 | jpeg_destroy_decompress (&cinfo); |
332 | } |
333 | } |
333 | OUTPUT: |
334 | OUTPUT: |
334 | RETVAL |
335 | RETVAL |
335 | |
336 | |
|
|
337 | void |
|
|
338 | compare (GdkPixbuf *a, GdkPixbuf *b) |
|
|
339 | PPCODE: |
|
|
340 | { |
|
|
341 | int w = gdk_pixbuf_get_width (a); |
|
|
342 | int h = gdk_pixbuf_get_height (a); |
|
|
343 | int sa = gdk_pixbuf_get_rowstride (a); |
|
|
344 | int sb = gdk_pixbuf_get_rowstride (b); |
|
|
345 | |
|
|
346 | guchar *pa = gdk_pixbuf_get_pixels (a); |
|
|
347 | guchar *pb = gdk_pixbuf_get_pixels (b); |
|
|
348 | |
|
|
349 | int x, y; |
|
|
350 | |
|
|
351 | assert (w == gdk_pixbuf_get_width (b)); |
|
|
352 | assert (h == gdk_pixbuf_get_height (b)); |
|
|
353 | |
|
|
354 | assert (gdk_pixbuf_get_n_channels (a) == 3); |
|
|
355 | assert (gdk_pixbuf_get_n_channels (b) == 3); |
|
|
356 | |
|
|
357 | double diff = 0.; |
|
|
358 | int peak = 0; |
|
|
359 | |
|
|
360 | for (y = 0; y < h; y++) |
|
|
361 | { |
|
|
362 | guchar *pa_ = pa + y * sa; |
|
|
363 | guchar *pb_ = pb + y * sb; |
|
|
364 | |
|
|
365 | for (x = 0; x < w; x ++) |
|
|
366 | { |
|
|
367 | int d; |
|
|
368 | |
|
|
369 | d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d)); |
|
|
370 | d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d)); |
|
|
371 | d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d)); |
|
|
372 | } |
|
|
373 | } |
|
|
374 | |
|
|
375 | EXTEND (SP, 2); |
|
|
376 | PUSHs (sv_2mortal (newSVnv (sqrt (diff / (w * h * 3. * 255. * 255.))))); |
|
|
377 | PUSHs (sv_2mortal (newSVnv (peak / 255.))); |
|
|
378 | } |
|
|
379 | |
336 | ############################################################################# |
380 | ############################################################################# |
337 | |
381 | |
338 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer |
382 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer |
339 | |
383 | |
340 | SV * |
384 | SV * |