--- CV/CV.xs 2005/07/20 09:06:37 1.18 +++ CV/CV.xs 2005/08/19 00:34:54 1.25 @@ -6,6 +6,8 @@ #include #include +#include +#include #include #include @@ -126,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: @@ -175,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; @@ -184,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); @@ -227,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); @@ -277,16 +298,20 @@ CODE: { STRLEN plen; - U8 *path = SvPVutf8 (pathsv, plen); + U8 *path = (U8 *)SvPVutf8 (pathsv, plen); U8 *pend = path + plen; U8 dst [plen * 6 * 3], *dstp = dst; while (path < pend) { - if (*path >= '0' && *path <= '9') + 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') + while (*path >= '0' && *path <= '9' && path < pend) path++, nl++; for (el = nl; el < 6; el++) @@ -304,18 +329,20 @@ } } - RETVAL = newSVpvn (dst, dstp - dst); + RETVAL = newSVpvn ((const char *)dst, dstp - dst); } OUTPUT: RETVAL GdkPixbuf_noinc * -p7_to_pb (int w, int h, guchar *src) +p7_to_pb (int w, int h, SV *src_sv) + PROTOTYPE: @ CODE: { int x, y; guchar *dst, *d; int dstr; + guchar *src = (guchar *)SvPVbyte_nolen (src_sv); RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); dst = gdk_pixbuf_get_pixels (RETVAL); @@ -352,7 +379,7 @@ SvPOK_only (RETVAL); SvCUR_set (RETVAL, w * h); - dst = SvPVX (RETVAL); + dst = (guchar *)SvPVX (RETVAL); memset (Er, 0, sizeof (int) * IW); memset (Eg, 0, sizeof (int) * IW); @@ -392,60 +419,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 @@ -510,7 +483,7 @@ SvPOK_only (RETVAL); SvCUR_set (RETVAL, 6 * 8 * 12 / 8); - dst = SvPVX (RETVAL); + dst = (guchar *)SvPVX (RETVAL); /* some primitive error distribution + random dithering */ @@ -578,5 +551,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