--- CV/CV.xs 2006/06/22 22:01:26 1.37 +++ 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,12 +246,19 @@ XSRETURN_UNDEF; } + perlinterp_release (); RETVAL = magic_file (cookie, path); + perlinterp_acquire (); } OUTPUT: RETVAL -# missing in Gtk2 perl module +# missing/broken in Gtk2 perl module + +void +gdk_window_clear_hints (GdkWindow *window) + CODE: + gdk_window_set_geometry_hints (window, 0, 0); gboolean gdk_net_wm_supports (GdkAtom property) @@ -261,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); @@ -279,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 @@ -311,6 +330,8 @@ if (!fp) XSRETURN_UNDEF; + perlinterp_release (); + cinfo.err = jpeg_std_error (&jerr.err); jerr.err.error_exit = cv_error_exit; @@ -324,6 +345,7 @@ if (pb) g_object_unref ((gpointer)pb); + perlinterp_acquire (); XSRETURN_UNDEF; } @@ -385,6 +407,7 @@ jpeg_finish_decompress (&cinfo); fclose (fp); jpeg_destroy_decompress (&cinfo); + perlinterp_acquire (); } OUTPUT: RETVAL @@ -392,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); @@ -428,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.))); @@ -437,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; @@ -453,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; @@ -466,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); @@ -650,7 +685,7 @@ AV *av, *result; if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV) - croak ("Not an array ref as first argument to make_histogram"); + croak ("Not an array ref as first argument to extract_features"); av = (AV *) SvRV (ar); result = newAV (); @@ -713,7 +748,7 @@ hist [0] = f_h.v1 * 2.; hist [1] = f_h.v2 * 2.; hist [2] = f_h.v3 * 2.; hist [3] = f_s.v1 ; hist [4] = f_s.v2 ; hist [5] = f_s.v3 ; - hist [6] = f_v.v1 ; hist [7] = f_v.v2 ; hist [8] = f_v.v3 ; + hist [6] = f_v.v1 * .5; hist [7] = f_v.v2 * .5; hist [8] = f_v.v3 * .5; av_push (result, histsv); } @@ -723,58 +758,3 @@ OUTPUT: RETVAL -SV * -make_histograms (SV *ar) - CODE: -{ - int i; - AV *av, *result; - - if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV) - croak ("Not an array ref as first argument to make_histogram"); - - av = (AV *) SvRV (ar); - result = newAV (); - - for (i = 0; i <= av_len (av); ++i) - { - const int HISTSIZE = 64; - - int j; - SV *sv = *av_fetch (av, i, 1); - STRLEN len; - char *buf = SvPVbyte (sv, len); - - int tmphist[HISTSIZE]; - float *hist; - - SV *histsv = newSV (HISTSIZE * sizeof (float) + 1); - SvPOK_on (histsv); - SvCUR_set (histsv, HISTSIZE * sizeof (float)); - hist = (float *)SvPVX (histsv); - - Zero (tmphist, sizeof (tmphist), char); - - for (j = len; j--; ) - { - unsigned int idx - = ((*buf & 0xc0) >> 2) - | ((*buf & 0x18) >> 1) - | (*buf & 0x03); - - ++tmphist[idx]; - ++buf; - } - - for (j = 0; j < HISTSIZE; ++j) - hist[j] = (float)tmphist[j] / (len + 1e-30); - - av_push (result, histsv); - } - - RETVAL = newRV_noinc ((SV *)result); -} - OUTPUT: - RETVAL - -