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