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

Comparing CV/CV.xs (file contents):
Revision 1.18 by root, Wed Jul 20 09:06:37 2005 UTC vs.
Revision 1.24 by root, Wed Aug 17 05:25:28 2005 UTC

4 4
5#include <string.h> 5#include <string.h>
6#include <setjmp.h> 6#include <setjmp.h>
7 7
8#include <jpeglib.h> 8#include <jpeglib.h>
9#include <glib.h>
10#include <gtk/gtk.h>
9#include <gdk-pixbuf/gdk-pixbuf.h> 11#include <gdk-pixbuf/gdk-pixbuf.h>
10 12
11#include <gperl.h> 13#include <gperl.h>
12#include <gtk2perl.h> 14#include <gtk2perl.h>
13 15
124 126
125MODULE = Gtk2::CV PACKAGE = Gtk2::CV 127MODULE = Gtk2::CV PACKAGE = Gtk2::CV
126 128
127PROTOTYPES: ENABLE 129PROTOTYPES: ENABLE
128 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
129GdkPixbuf_noinc * 144GdkPixbuf_noinc *
130transpose (GdkPixbuf *pb) 145transpose (GdkPixbuf *pb)
131 CODE: 146 CODE:
132{ 147{
133 int w = gdk_pixbuf_get_width (pb); 148 int w = gdk_pixbuf_get_width (pb);
173} 188}
174 OUTPUT: 189 OUTPUT:
175 RETVAL 190 RETVAL
176 191
177GdkPixbuf_noinc * 192GdkPixbuf_noinc *
178load_jpeg (char *path, int thumbnail=0) 193load_jpeg (SV *path, int thumbnail=0)
179 CODE: 194 CODE:
180{ 195{
181 struct jpeg_decompress_struct cinfo; 196 struct jpeg_decompress_struct cinfo;
182 struct jpg_err_mgr jerr; 197 struct jpg_err_mgr jerr;
183 guchar *data; 198 guchar *data;
184 int rs; 199 int rs;
185 FILE *fp; 200 FILE *fp;
186 volatile GdkPixbuf *pb = 0; 201 volatile GdkPixbuf *pb = 0;
202 gchar *filename;
203
187 RETVAL = 0; 204 RETVAL = 0;
188 205
189 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)
190 XSRETURN_UNDEF; 211 XSRETURN_UNDEF;
191 212
192 cinfo.err = jpeg_std_error (&jerr.err); 213 cinfo.err = jpeg_std_error (&jerr.err);
193 214
194 jerr.err.error_exit = cv_error_exit; 215 jerr.err.error_exit = cv_error_exit;
225 { 246 {
226 cinfo.dct_method = JDCT_FASTEST; 247 cinfo.dct_method = JDCT_FASTEST;
227 cinfo.do_fancy_upsampling = FALSE; 248 cinfo.do_fancy_upsampling = FALSE;
228 249
229 while (cinfo.scale_denom < 8 250 while (cinfo.scale_denom < 8
230 && (cinfo.output_width >> 1) >= IW 251 && cinfo.output_width >= IW*4
231 && (cinfo.output_height >> 1) >= IH) 252 && cinfo.output_height >= IH*4)
232 { 253 {
233 cinfo.scale_denom <<= 1; 254 cinfo.scale_denom <<= 1;
234 jpeg_calc_output_dimensions (&cinfo); 255 jpeg_calc_output_dimensions (&cinfo);
235 } 256 }
236 } 257 }
281 U8 *pend = path + plen; 302 U8 *pend = path + plen;
282 U8 dst [plen * 6 * 3], *dstp = dst; 303 U8 dst [plen * 6 * 3], *dstp = dst;
283 304
284 while (path < pend) 305 while (path < pend)
285 { 306 {
307 U8 ch = *path;
308
286 if (*path >= '0' && *path <= '9') 309 if (ch >= 'a' && ch <= 'z')
310 *dstp++ = *path++;
311 else if (ch >= '0' && ch <= '9')
287 { 312 {
288 STRLEN el, nl = 0; 313 STRLEN el, nl = 0;
289 while (*path >= '0' && *path <= '9') 314 while (*path >= '0' && *path <= '9' && path < pend)
290 path++, nl++; 315 path++, nl++;
291 316
292 for (el = nl; el < 6; el++) 317 for (el = nl; el < 6; el++)
293 *dstp++ = '0'; 318 *dstp++ = '0';
294 319
308} 333}
309 OUTPUT: 334 OUTPUT:
310 RETVAL 335 RETVAL
311 336
312GdkPixbuf_noinc * 337GdkPixbuf_noinc *
313p7_to_pb (int w, int h, guchar *src) 338p7_to_pb (int w, int h, SV *src_sv)
339 PROTOTYPE: @
314 CODE: 340 CODE:
315{ 341{
316 int x, y; 342 int x, y;
317 guchar *dst, *d; 343 guchar *dst, *d;
318 int dstr; 344 int dstr;
345 guchar *src = SvPVbyte_nolen (src_sv);
319 346
320 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); 347 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
321 dst = gdk_pixbuf_get_pixels (RETVAL); 348 dst = gdk_pixbuf_get_pixels (RETVAL);
322 dstr = gdk_pixbuf_get_rowstride (RETVAL); 349 dstr = gdk_pixbuf_get_rowstride (RETVAL);
323 350
390 } 417 }
391} 418}
392 OUTPUT: 419 OUTPUT:
393 RETVAL 420 RETVAL
394 421
395SV *
396make_histogram (SV *ar)
397 CODE:
398{
399 int i;
400 AV *av, *result;
401
402 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV)
403 croak ("Not an array ref as first argument to make_histogram");
404
405 av = (AV *) SvRV (ar);
406 result = newAV ();
407
408 for (i = 0; i <= av_len (av); ++i)
409 {
410 const int HISTSIZE = 64;
411
412 int j;
413 SV *sv = *av_fetch (av, i, 1);
414 STRLEN len;
415 char *buf = SvPVbyte (sv, len);
416
417 int tmphist[HISTSIZE];
418 float *hist;
419
420 SV *histsv = newSV (HISTSIZE * sizeof (float) + 1);
421 SvPOK_on (histsv);
422 SvCUR_set (histsv, HISTSIZE * sizeof (float));
423 hist = (float *)SvPVX (histsv);
424
425 Zero (tmphist, sizeof (tmphist), char);
426
427 for (j = len; j--; )
428 {
429 unsigned int idx
430 = ((*buf & 0xc0) >> 2)
431 | ((*buf & 0x18) >> 1)
432 | (*buf & 0x03);
433
434 ++tmphist[idx];
435 ++buf;
436 }
437
438 for (j = 0; j < HISTSIZE; ++j)
439 hist[j] = (float)tmphist[j] / (len + 1e-30);
440
441 av_push (result, histsv);
442 }
443
444 RETVAL = newRV_noinc ((SV *)result);
445}
446 OUTPUT:
447 RETVAL
448
449############################################################################# 422#############################################################################
450 423
451MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript 424MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
452 425
453void 426void
576 } 549 }
577} 550}
578 OUTPUT: 551 OUTPUT:
579 RETVAL 552 RETVAL
580 553
554#############################################################################
581 555
556MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Plugin::RCluster
582 557
558SV *
559make_histograms (SV *ar)
560 CODE:
561{
562 int i;
563 AV *av, *result;
564
565 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV)
566 croak ("Not an array ref as first argument to make_histogram");
567
568 av = (AV *) SvRV (ar);
569 result = newAV ();
570
571 for (i = 0; i <= av_len (av); ++i)
572 {
573 const int HISTSIZE = 64;
574
575 int j;
576 SV *sv = *av_fetch (av, i, 1);
577 STRLEN len;
578 char *buf = SvPVbyte (sv, len);
579
580 int tmphist[HISTSIZE];
581 float *hist;
582
583 SV *histsv = newSV (HISTSIZE * sizeof (float) + 1);
584 SvPOK_on (histsv);
585 SvCUR_set (histsv, HISTSIZE * sizeof (float));
586 hist = (float *)SvPVX (histsv);
587
588 Zero (tmphist, sizeof (tmphist), char);
589
590 for (j = len; j--; )
591 {
592 unsigned int idx
593 = ((*buf & 0xc0) >> 2)
594 | ((*buf & 0x18) >> 1)
595 | (*buf & 0x03);
596
597 ++tmphist[idx];
598 ++buf;
599 }
600
601 for (j = 0; j < HISTSIZE; ++j)
602 hist[j] = (float)tmphist[j] / (len + 1e-30);
603
604 av_push (result, histsv);
605 }
606
607 RETVAL = newRV_noinc ((SV *)result);
608}
609 OUTPUT:
610 RETVAL
611
612

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines