ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CV/CV.xs
(Generate patch)

Comparing CV/CV.xs (file contents):
Revision 1.17 by root, Wed Jul 20 06:20:36 2005 UTC vs.
Revision 1.23 by root, Tue Aug 16 23:50:39 2005 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5#include <string.h>
5#include <setjmp.h> 6#include <setjmp.h>
6 7
7#include <jpeglib.h> 8#include <jpeglib.h>
9#include <glib.h>
10#include <gtk/gtk.h>
8#include <gdk-pixbuf/gdk-pixbuf.h> 11#include <gdk-pixbuf/gdk-pixbuf.h>
9 12
10#include <gperl.h> 13#include <gperl.h>
11#include <gtk2perl.h> 14#include <gtk2perl.h>
12 15
123 126
124MODULE = Gtk2::CV PACKAGE = Gtk2::CV 127MODULE = Gtk2::CV PACKAGE = Gtk2::CV
125 128
126PROTOTYPES: ENABLE 129PROTOTYPES: ENABLE
127 130
131# missing in Gtk2 perl module
132
133gboolean
134gdk_net_wm_supports (GdkAtom property)
135 CODE:
136#if defined(GDK_WINDOWING_X11) && !defined(GDK_MULTIHEAD_SAFE)
137 RETVAL = gdk_net_wm_supports (property);
138#else
139 RETVAL = 0;
140#endif
141 OUTPUT:
142 RETVAL
143
128GdkPixbuf_noinc * 144GdkPixbuf_noinc *
129transpose (GdkPixbuf *pb) 145transpose (GdkPixbuf *pb)
130 CODE: 146 CODE:
131{ 147{
132 int w = gdk_pixbuf_get_width (pb); 148 int w = gdk_pixbuf_get_width (pb);
172} 188}
173 OUTPUT: 189 OUTPUT:
174 RETVAL 190 RETVAL
175 191
176GdkPixbuf_noinc * 192GdkPixbuf_noinc *
177load_jpeg (char *path, int thumbnail=0) 193load_jpeg (SV *path, int thumbnail=0)
178 CODE: 194 CODE:
179{ 195{
180 struct jpeg_decompress_struct cinfo; 196 struct jpeg_decompress_struct cinfo;
181 struct jpg_err_mgr jerr; 197 struct jpg_err_mgr jerr;
182 guchar *data; 198 guchar *data;
183 int rs; 199 int rs;
184 FILE *fp; 200 FILE *fp;
185 volatile GdkPixbuf *pb = 0; 201 volatile GdkPixbuf *pb = 0;
202 gchar *filename;
203
186 RETVAL = 0; 204 RETVAL = 0;
187 205
188 if (!(fp = fopen (path, "rb"))) 206 filename = g_filename_from_utf8 (SvPVutf8_nolen (path), -1, 0, 0, 0);
207 fp = fopen (filename, "rb");
208 g_free (filename);
209
210 if (!fp)
189 XSRETURN_UNDEF; 211 XSRETURN_UNDEF;
190 212
191 cinfo.err = jpeg_std_error (&jerr.err); 213 cinfo.err = jpeg_std_error (&jerr.err);
192 214
193 jerr.err.error_exit = cv_error_exit; 215 jerr.err.error_exit = cv_error_exit;
224 { 246 {
225 cinfo.dct_method = JDCT_FASTEST; 247 cinfo.dct_method = JDCT_FASTEST;
226 cinfo.do_fancy_upsampling = FALSE; 248 cinfo.do_fancy_upsampling = FALSE;
227 249
228 while (cinfo.scale_denom < 8 250 while (cinfo.scale_denom < 8
229 && (cinfo.output_width >> 1) >= IW 251 && cinfo.output_width >= IW*4
230 && (cinfo.output_height >> 1) >= IH) 252 && cinfo.output_height >= IH*4)
231 { 253 {
232 cinfo.scale_denom <<= 1; 254 cinfo.scale_denom <<= 1;
233 jpeg_calc_output_dimensions (&cinfo); 255 jpeg_calc_output_dimensions (&cinfo);
234 } 256 }
235 } 257 }
268 290
269############################################################################# 291#############################################################################
270 292
271MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer 293MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer
272 294
295SV *
296foldcase (SV *pathsv)
297 PROTOTYPE: $
298 CODE:
299{
300 STRLEN plen;
301 U8 *path = SvPVutf8 (pathsv, plen);
302 U8 *pend = path + plen;
303 U8 dst [plen * 6 * 3], *dstp = dst;
304
305 while (path < pend)
306 {
307 U8 ch = *path;
308
309 if (ch >= 'a' && ch <= 'z')
310 *dstp++ = *path++;
311 else if (ch >= '0' && ch <= '9')
312 {
313 STRLEN el, nl = 0;
314 while (*path >= '0' && *path <= '9' && path < pend)
315 path++, nl++;
316
317 for (el = nl; el < 6; el++)
318 *dstp++ = '0';
319
320 memcpy (dstp, path - nl, nl);
321 dstp += nl;
322 }
323 else
324 {
325 STRLEN cl;
326 to_utf8_fold (path, dstp, &cl);
327 dstp += cl;
328 path += is_utf8_char (path);
329 }
330 }
331
332 RETVAL = newSVpvn (dst, dstp - dst);
333}
334 OUTPUT:
335 RETVAL
336
273GdkPixbuf_noinc * 337GdkPixbuf_noinc *
274p7_to_pb (int w, int h, guchar *src) 338p7_to_pb (int w, int h, guchar *src)
339 PROTOTYPE: @
275 CODE: 340 CODE:
276{ 341{
277 int x, y; 342 int x, y;
278 guchar *dst, *d; 343 guchar *dst, *d;
279 int dstr; 344 int dstr;
351 } 416 }
352} 417}
353 OUTPUT: 418 OUTPUT:
354 RETVAL 419 RETVAL
355 420
356SV *
357make_histogram (SV *ar)
358 CODE:
359{
360 int i;
361 AV *av, *result;
362
363 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV)
364 croak ("Not an array ref as first argument to make_histogram");
365
366 av = (AV *) SvRV (ar);
367 result = newAV ();
368
369 for (i = 0; i <= av_len (av); ++i)
370 {
371 const int HISTSIZE = 64;
372
373 int j;
374 SV *sv = *av_fetch (av, i, 1);
375 STRLEN len;
376 char *buf = SvPVbyte (sv, len);
377
378 int tmphist[HISTSIZE];
379 float *hist;
380
381 SV *histsv = newSV (HISTSIZE * sizeof (float) + 1);
382 SvPOK_on (histsv);
383 SvCUR_set (histsv, HISTSIZE * sizeof (float));
384 hist = (float *)SvPVX (histsv);
385
386 Zero (tmphist, sizeof (tmphist), char);
387
388 for (j = len; j--; )
389 {
390 unsigned int idx
391 = ((*buf & 0xc0) >> 2)
392 | ((*buf & 0x18) >> 1)
393 | (*buf & 0x03);
394
395 ++tmphist[idx];
396 ++buf;
397 }
398
399 for (j = 0; j < HISTSIZE; ++j)
400 hist[j] = (float)tmphist[j] / (len + 1e-30);
401
402 av_push (result, histsv);
403 }
404
405 RETVAL = newRV_noinc ((SV *)result);
406}
407 OUTPUT:
408 RETVAL
409
410############################################################################# 421#############################################################################
411 422
412MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript 423MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
413 424
414void 425void
537 } 548 }
538} 549}
539 OUTPUT: 550 OUTPUT:
540 RETVAL 551 RETVAL
541 552
553#############################################################################
542 554
555MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Plugin::RCluster
543 556
557SV *
558make_histograms (SV *ar)
559 CODE:
560{
561 int i;
562 AV *av, *result;
563
564 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV)
565 croak ("Not an array ref as first argument to make_histogram");
566
567 av = (AV *) SvRV (ar);
568 result = newAV ();
569
570 for (i = 0; i <= av_len (av); ++i)
571 {
572 const int HISTSIZE = 64;
573
574 int j;
575 SV *sv = *av_fetch (av, i, 1);
576 STRLEN len;
577 char *buf = SvPVbyte (sv, len);
578
579 int tmphist[HISTSIZE];
580 float *hist;
581
582 SV *histsv = newSV (HISTSIZE * sizeof (float) + 1);
583 SvPOK_on (histsv);
584 SvCUR_set (histsv, HISTSIZE * sizeof (float));
585 hist = (float *)SvPVX (histsv);
586
587 Zero (tmphist, sizeof (tmphist), char);
588
589 for (j = len; j--; )
590 {
591 unsigned int idx
592 = ((*buf & 0xc0) >> 2)
593 | ((*buf & 0x18) >> 1)
594 | (*buf & 0x03);
595
596 ++tmphist[idx];
597 ++buf;
598 }
599
600 for (j = 0; j < HISTSIZE; ++j)
601 hist[j] = (float)tmphist[j] / (len + 1e-30);
602
603 av_push (result, histsv);
604 }
605
606 RETVAL = newRV_noinc ((SV *)result);
607}
608 OUTPUT:
609 RETVAL
610
611

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines