… | |
… | |
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 | |
… | |
… | |
153 | { |
154 | { |
154 | static magic_t cookie; |
155 | static magic_t cookie; |
155 | |
156 | |
156 | if (!cookie) |
157 | if (!cookie) |
157 | { |
158 | { |
|
|
159 | cookie = magic_open (MAGIC_NONE); |
|
|
160 | |
|
|
161 | if (cookie) |
|
|
162 | magic_load (cookie, 0); |
|
|
163 | else |
|
|
164 | XSRETURN_UNDEF; |
|
|
165 | } |
|
|
166 | |
|
|
167 | RETVAL = magic_file (cookie, path); |
|
|
168 | } |
|
|
169 | OUTPUT: |
|
|
170 | RETVAL |
|
|
171 | |
|
|
172 | const char * |
|
|
173 | magic_mime (const char *path) |
|
|
174 | CODE: |
|
|
175 | { |
|
|
176 | static magic_t cookie; |
|
|
177 | |
|
|
178 | if (!cookie) |
|
|
179 | { |
158 | cookie = magic_open (MAGIC_MIME); |
180 | cookie = magic_open (MAGIC_MIME); |
159 | |
181 | |
160 | if (cookie) |
182 | if (cookie) |
161 | magic_load (cookie, 0); |
183 | magic_load (cookie, 0); |
162 | else |
184 | else |
… | |
… | |
309 | fclose (fp); |
331 | fclose (fp); |
310 | jpeg_destroy_decompress (&cinfo); |
332 | jpeg_destroy_decompress (&cinfo); |
311 | } |
333 | } |
312 | OUTPUT: |
334 | OUTPUT: |
313 | RETVAL |
335 | RETVAL |
|
|
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 | if (w && h) |
|
|
361 | for (y = 0; y < h; y++) |
|
|
362 | { |
|
|
363 | guchar *pa_ = pa + y * sa; |
|
|
364 | guchar *pb_ = pb + y * sb; |
|
|
365 | |
|
|
366 | for (x = 0; x < w; x++) |
|
|
367 | { |
|
|
368 | int d; |
|
|
369 | |
|
|
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 | d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d)); |
|
|
373 | } |
|
|
374 | } |
|
|
375 | |
|
|
376 | EXTEND (SP, 2); |
|
|
377 | PUSHs (sv_2mortal (newSVnv (sqrt (diff / (w * h * 3. * 255. * 255.))))); |
|
|
378 | PUSHs (sv_2mortal (newSVnv (peak / 255.))); |
|
|
379 | } |
314 | |
380 | |
315 | ############################################################################# |
381 | ############################################################################# |
316 | |
382 | |
317 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer |
383 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer |
318 | |
384 | |