… | |
… | |
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> |
|
|
8 | |
|
|
9 | #include <magic.h> |
7 | |
10 | |
8 | #include <jpeglib.h> |
11 | #include <jpeglib.h> |
9 | #include <glib.h> |
12 | #include <glib.h> |
10 | #include <gtk/gtk.h> |
13 | #include <gtk/gtk.h> |
11 | #include <gdk-pixbuf/gdk-pixbuf.h> |
14 | #include <gdk-pixbuf/gdk-pixbuf.h> |
12 | |
15 | |
13 | #include <gperl.h> |
16 | #include <gperl.h> |
14 | #include <gtk2perl.h> |
17 | #include <gtk2perl.h> |
15 | |
18 | |
16 | #define IW 80 /* MUST match Schnauer.pm! */ |
19 | #define IW 80 /* MUST match Schnauzer.pm! */ |
17 | #define IH 60 /* MUST match Schnauer.pm! */ |
20 | #define IH 60 /* MUST match Schnauzer.pm! */ |
18 | |
21 | |
19 | #define RAND (seed = (seed + 7141) * 54773 % 134456) |
22 | #define RAND (seed = (seed + 7141) * 54773 % 134456) |
20 | |
23 | |
21 | #define LINELENGTH 240 |
24 | #define LINELENGTH 240 |
22 | |
25 | |
… | |
… | |
126 | |
129 | |
127 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV |
130 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV |
128 | |
131 | |
129 | PROTOTYPES: ENABLE |
132 | PROTOTYPES: ENABLE |
130 | |
133 | |
|
|
134 | # missing function in perl. really :) |
|
|
135 | int |
|
|
136 | common_prefix_length (a, b) |
|
|
137 | unsigned char *a = (unsigned char *)SvPVutf8_nolen ($arg); |
|
|
138 | unsigned char *b = (unsigned char *)SvPVutf8_nolen ($arg); |
|
|
139 | CODE: |
|
|
140 | RETVAL = 0; |
|
|
141 | |
|
|
142 | while (*a == *b && *a) |
|
|
143 | { |
|
|
144 | RETVAL += (*a & 0xc0) != 0x80; |
|
|
145 | a++, b++; |
|
|
146 | } |
|
|
147 | |
|
|
148 | OUTPUT: |
|
|
149 | RETVAL |
|
|
150 | |
|
|
151 | const char * |
|
|
152 | magic (const char *path) |
|
|
153 | CODE: |
|
|
154 | { |
|
|
155 | static magic_t cookie; |
|
|
156 | |
|
|
157 | if (!cookie) |
|
|
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 | { |
|
|
180 | cookie = magic_open (MAGIC_MIME); |
|
|
181 | |
|
|
182 | if (cookie) |
|
|
183 | magic_load (cookie, 0); |
|
|
184 | else |
|
|
185 | XSRETURN_UNDEF; |
|
|
186 | } |
|
|
187 | |
|
|
188 | RETVAL = magic_file (cookie, path); |
|
|
189 | } |
|
|
190 | OUTPUT: |
|
|
191 | RETVAL |
|
|
192 | |
131 | # missing in Gtk2 perl module |
193 | # missing in Gtk2 perl module |
132 | |
194 | |
133 | gboolean |
195 | gboolean |
134 | gdk_net_wm_supports (GdkAtom property) |
196 | gdk_net_wm_supports (GdkAtom property) |
135 | CODE: |
197 | CODE: |
… | |
… | |
184 | struct jpg_err_mgr jerr; |
246 | struct jpg_err_mgr jerr; |
185 | guchar *data; |
247 | guchar *data; |
186 | int rs; |
248 | int rs; |
187 | FILE *fp; |
249 | FILE *fp; |
188 | volatile GdkPixbuf *pb = 0; |
250 | volatile GdkPixbuf *pb = 0; |
189 | gchar *filename; |
|
|
190 | |
251 | |
191 | RETVAL = 0; |
252 | RETVAL = 0; |
192 | |
253 | |
193 | filename = g_filename_from_utf8 (SvPVutf8_nolen (path), -1, 0, 0, 0); |
|
|
194 | fp = fopen (filename, "rb"); |
254 | fp = fopen (SvPVbyte_nolen (path), "rb"); |
195 | g_free (filename); |
|
|
196 | |
255 | |
197 | if (!fp) |
256 | if (!fp) |
198 | XSRETURN_UNDEF; |
257 | XSRETURN_UNDEF; |
199 | |
258 | |
200 | cinfo.err = jpeg_std_error (&jerr.err); |
259 | cinfo.err = jpeg_std_error (&jerr.err); |
… | |
… | |
272 | fclose (fp); |
331 | fclose (fp); |
273 | jpeg_destroy_decompress (&cinfo); |
332 | jpeg_destroy_decompress (&cinfo); |
274 | } |
333 | } |
275 | OUTPUT: |
334 | OUTPUT: |
276 | 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 | 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 | } |
277 | |
379 | |
278 | ############################################################################# |
380 | ############################################################################# |
279 | |
381 | |
280 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer |
382 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer |
281 | |
383 | |