--- CV/CV.xs 2005/07/20 06:20:36 1.17 +++ CV/CV.xs 2005/08/16 23:50:39 1.23 @@ -2,9 +2,12 @@ #include "perl.h" #include "XSUB.h" +#include #include #include +#include +#include #include #include @@ -125,6 +128,19 @@ PROTOTYPES: ENABLE +# missing in Gtk2 perl module + +gboolean +gdk_net_wm_supports (GdkAtom property) + CODE: +#if defined(GDK_WINDOWING_X11) && !defined(GDK_MULTIHEAD_SAFE) + RETVAL = gdk_net_wm_supports (property); +#else + RETVAL = 0; +#endif + OUTPUT: + RETVAL + GdkPixbuf_noinc * transpose (GdkPixbuf *pb) CODE: @@ -174,7 +190,7 @@ RETVAL GdkPixbuf_noinc * -load_jpeg (char *path, int thumbnail=0) +load_jpeg (SV *path, int thumbnail=0) CODE: { struct jpeg_decompress_struct cinfo; @@ -183,9 +199,15 @@ int rs; FILE *fp; volatile GdkPixbuf *pb = 0; + gchar *filename; + RETVAL = 0; - if (!(fp = fopen (path, "rb"))) + filename = g_filename_from_utf8 (SvPVutf8_nolen (path), -1, 0, 0, 0); + fp = fopen (filename, "rb"); + g_free (filename); + + if (!fp) XSRETURN_UNDEF; cinfo.err = jpeg_std_error (&jerr.err); @@ -226,8 +248,8 @@ cinfo.do_fancy_upsampling = FALSE; while (cinfo.scale_denom < 8 - && (cinfo.output_width >> 1) >= IW - && (cinfo.output_height >> 1) >= IH) + && cinfo.output_width >= IW*4 + && cinfo.output_height >= IH*4) { cinfo.scale_denom <<= 1; jpeg_calc_output_dimensions (&cinfo); @@ -270,8 +292,51 @@ MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer +SV * +foldcase (SV *pathsv) + PROTOTYPE: $ + CODE: +{ + STRLEN plen; + U8 *path = SvPVutf8 (pathsv, plen); + U8 *pend = path + plen; + U8 dst [plen * 6 * 3], *dstp = dst; + + while (path < pend) + { + U8 ch = *path; + + if (ch >= 'a' && ch <= 'z') + *dstp++ = *path++; + else if (ch >= '0' && ch <= '9') + { + STRLEN el, nl = 0; + while (*path >= '0' && *path <= '9' && path < pend) + path++, nl++; + + for (el = nl; el < 6; el++) + *dstp++ = '0'; + + memcpy (dstp, path - nl, nl); + dstp += nl; + } + else + { + STRLEN cl; + to_utf8_fold (path, dstp, &cl); + dstp += cl; + path += is_utf8_char (path); + } + } + + RETVAL = newSVpvn (dst, dstp - dst); +} + OUTPUT: + RETVAL + GdkPixbuf_noinc * p7_to_pb (int w, int h, guchar *src) + PROTOTYPE: @ CODE: { int x, y; @@ -353,60 +418,6 @@ OUTPUT: RETVAL -SV * -make_histogram (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 - ############################################################################# MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript @@ -539,5 +550,62 @@ OUTPUT: RETVAL +############################################################################# + +MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Plugin::RCluster + +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