--- CV/CV.xs 2006/11/25 15:00:51 1.40 +++ CV/CV.xs 2015/07/04 05:31:17 1.46 @@ -16,6 +16,10 @@ #include #include +#include + +#include "perlmulticore.h" + #define IW 80 /* MUST match Schnauzer.pm! */ #define IH 60 /* MUST match Schnauzer.pm! */ @@ -25,6 +29,8 @@ #define ELLIPSIS "\xe2\x80\xa6" +typedef char *octet_string; + struct jpg_err_mgr { struct jpeg_error_mgr err; @@ -204,14 +210,14 @@ RETVAL const char * -magic (const char *path) +magic (octet_string path) CODE: { static magic_t cookie; if (!cookie) { - cookie = magic_open (MAGIC_NONE); + cookie = magic_open (MAGIC_SYMLINK); if (cookie) magic_load (cookie, 0); @@ -225,14 +231,14 @@ RETVAL const char * -magic_mime (const char *path) +magic_mime (octet_string path) CODE: { static magic_t cookie; if (!cookie) { - cookie = magic_open (MAGIC_MIME); + cookie = magic_open (MAGIC_MIME | MAGIC_SYMLINK); if (cookie) magic_load (cookie, 0); @@ -240,7 +246,9 @@ XSRETURN_UNDEF; } + perlinterp_release (); RETVAL = magic_file (cookie, path); + perlinterp_acquire (); } OUTPUT: RETVAL @@ -266,6 +274,7 @@ GdkPixbuf_noinc * dealpha_expose (GdkPixbuf *pb) CODE: + perlinterp_release (); { int w = gdk_pixbuf_get_width (pb); int h = gdk_pixbuf_get_height (pb); @@ -284,17 +293,22 @@ for (i = 0; i < 3; i++) dst[x * 3 + y * dstr + i] = src[x * bpp + y * sstr + i]; } + perlinterp_acquire (); OUTPUT: RETVAL GdkPixbuf_noinc * rotate (GdkPixbuf *pb, int angle) CODE: + perlinterp_release (); + if (angle < 0) + angle += 360; RETVAL = gdk_pixbuf_rotate_simple (pb, angle == 0 ? GDK_PIXBUF_ROTATE_NONE : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE : angle); + perlinterp_acquire (); OUTPUT: RETVAL @@ -316,6 +330,8 @@ if (!fp) XSRETURN_UNDEF; + perlinterp_release (); + cinfo.err = jpeg_std_error (&jerr.err); jerr.err.error_exit = cv_error_exit; @@ -329,6 +345,7 @@ if (pb) g_object_unref ((gpointer)pb); + perlinterp_acquire (); XSRETURN_UNDEF; } @@ -390,6 +407,7 @@ jpeg_finish_decompress (&cinfo); fclose (fp); jpeg_destroy_decompress (&cinfo); + perlinterp_acquire (); } OUTPUT: RETVAL @@ -397,9 +415,11 @@ void compare (GdkPixbuf *a, GdkPixbuf *b) PPCODE: + perlinterp_release (); { int w = gdk_pixbuf_get_width (a); int h = gdk_pixbuf_get_height (a); + int sa = gdk_pixbuf_get_rowstride (a); int sb = gdk_pixbuf_get_rowstride (b); @@ -433,6 +453,8 @@ } } + perlinterp_acquire (); + EXTEND (SP, 2); PUSHs (sv_2mortal (newSVnv (sqrt (diff / (w * h * 3. * 255. * 255.))))); PUSHs (sv_2mortal (newSVnv (peak / 255.))); @@ -442,13 +464,15 @@ MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer +# currently only works for filenames (octet strings) + SV * foldcase (SV *pathsv) PROTOTYPE: $ CODE: { STRLEN plen; - U8 *path = (U8 *)SvPVutf8 (pathsv, plen); + U8 *path = (U8 *)SvPV (pathsv, plen); U8 *pend = path + plen; U8 dst [plen * 6 * 3], *dstp = dst; @@ -458,6 +482,8 @@ if (ch >= 'a' && ch <= 'z') *dstp++ = *path++; + else if (ch >= 'A' && ch <= 'Z') + *dstp++ = *path++ + ('a' - 'A'); else if (ch >= '0' && ch <= '9') { STRLEN el, nl = 0; @@ -471,12 +497,16 @@ dstp += nl; } else + *dstp++ = *path++; +#if 0 + else { STRLEN cl; to_utf8_fold (path, dstp, &cl); dstp += cl; path += is_utf8_char (path); } +#endif } RETVAL = newSVpvn ((const char *)dst, dstp - dst);