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.26 by root, Sun Aug 21 02:18:30 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
144GdkPixbuf_noinc *
145dealpha_expose (GdkPixbuf *pb)
146 CODE:
147{
148 int w = gdk_pixbuf_get_width (pb);
149 int h = gdk_pixbuf_get_height (pb);
150 fprintf (stderr, "new %d %d\n", w, h);
151 int bpp = gdk_pixbuf_get_n_channels (pb);
152 int x, y, i;
153 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
154 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
155
156 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
157
158 dst = gdk_pixbuf_get_pixels (RETVAL);
159 dstr = gdk_pixbuf_get_rowstride (RETVAL);
160
161 for (x = 0; x < w; x++)
162 for (y = 0; y < h; y++)
163 for (i = 0; i < 3; i++)
164 dst[x * 3 + y * dstr + i] = src[x * bpp + y * sstr + i];
165}
166 OUTPUT:
167 RETVAL
168
129GdkPixbuf_noinc * 169GdkPixbuf_noinc *
130transpose (GdkPixbuf *pb) 170transpose (GdkPixbuf *pb)
131 CODE: 171 CODE:
132{ 172{
133 int w = gdk_pixbuf_get_width (pb); 173 int w = gdk_pixbuf_get_width (pb);
173} 213}
174 OUTPUT: 214 OUTPUT:
175 RETVAL 215 RETVAL
176 216
177GdkPixbuf_noinc * 217GdkPixbuf_noinc *
178load_jpeg (char *path, int thumbnail=0) 218load_jpeg (SV *path, int thumbnail=0)
179 CODE: 219 CODE:
180{ 220{
181 struct jpeg_decompress_struct cinfo; 221 struct jpeg_decompress_struct cinfo;
182 struct jpg_err_mgr jerr; 222 struct jpg_err_mgr jerr;
183 guchar *data; 223 guchar *data;
184 int rs; 224 int rs;
185 FILE *fp; 225 FILE *fp;
186 volatile GdkPixbuf *pb = 0; 226 volatile GdkPixbuf *pb = 0;
227 gchar *filename;
228
187 RETVAL = 0; 229 RETVAL = 0;
188 230
189 if (!(fp = fopen (path, "rb"))) 231 filename = g_filename_from_utf8 (SvPVutf8_nolen (path), -1, 0, 0, 0);
232 fp = fopen (filename, "rb");
233 g_free (filename);
234
235 if (!fp)
190 XSRETURN_UNDEF; 236 XSRETURN_UNDEF;
191 237
192 cinfo.err = jpeg_std_error (&jerr.err); 238 cinfo.err = jpeg_std_error (&jerr.err);
193 239
194 jerr.err.error_exit = cv_error_exit; 240 jerr.err.error_exit = cv_error_exit;
225 { 271 {
226 cinfo.dct_method = JDCT_FASTEST; 272 cinfo.dct_method = JDCT_FASTEST;
227 cinfo.do_fancy_upsampling = FALSE; 273 cinfo.do_fancy_upsampling = FALSE;
228 274
229 while (cinfo.scale_denom < 8 275 while (cinfo.scale_denom < 8
230 && (cinfo.output_width >> 1) >= IW 276 && cinfo.output_width >= IW*4
231 && (cinfo.output_height >> 1) >= IH) 277 && cinfo.output_height >= IH*4)
232 { 278 {
233 cinfo.scale_denom <<= 1; 279 cinfo.scale_denom <<= 1;
234 jpeg_calc_output_dimensions (&cinfo); 280 jpeg_calc_output_dimensions (&cinfo);
235 } 281 }
236 } 282 }
275foldcase (SV *pathsv) 321foldcase (SV *pathsv)
276 PROTOTYPE: $ 322 PROTOTYPE: $
277 CODE: 323 CODE:
278{ 324{
279 STRLEN plen; 325 STRLEN plen;
280 U8 *path = SvPVutf8 (pathsv, plen); 326 U8 *path = (U8 *)SvPVutf8 (pathsv, plen);
281 U8 *pend = path + plen; 327 U8 *pend = path + plen;
282 U8 dst [plen * 6 * 3], *dstp = dst; 328 U8 dst [plen * 6 * 3], *dstp = dst;
283 329
284 while (path < pend) 330 while (path < pend)
285 { 331 {
332 U8 ch = *path;
333
286 if (*path >= '0' && *path <= '9') 334 if (ch >= 'a' && ch <= 'z')
335 *dstp++ = *path++;
336 else if (ch >= '0' && ch <= '9')
287 { 337 {
288 STRLEN el, nl = 0; 338 STRLEN el, nl = 0;
289 while (*path >= '0' && *path <= '9') 339 while (*path >= '0' && *path <= '9' && path < pend)
290 path++, nl++; 340 path++, nl++;
291 341
292 for (el = nl; el < 6; el++) 342 for (el = nl; el < 6; el++)
293 *dstp++ = '0'; 343 *dstp++ = '0';
294 344
302 dstp += cl; 352 dstp += cl;
303 path += is_utf8_char (path); 353 path += is_utf8_char (path);
304 } 354 }
305 } 355 }
306 356
307 RETVAL = newSVpvn (dst, dstp - dst); 357 RETVAL = newSVpvn ((const char *)dst, dstp - dst);
308} 358}
309 OUTPUT: 359 OUTPUT:
310 RETVAL 360 RETVAL
311 361
312GdkPixbuf_noinc * 362GdkPixbuf_noinc *
313p7_to_pb (int w, int h, guchar *src) 363p7_to_pb (int w, int h, SV *src_sv)
364 PROTOTYPE: @
314 CODE: 365 CODE:
315{ 366{
316 int x, y; 367 int x, y;
317 guchar *dst, *d; 368 guchar *dst, *d;
318 int dstr; 369 int dstr;
370 guchar *src = (guchar *)SvPVbyte_nolen (src_sv);
319 371
320 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); 372 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
321 dst = gdk_pixbuf_get_pixels (RETVAL); 373 dst = gdk_pixbuf_get_pixels (RETVAL);
322 dstr = gdk_pixbuf_get_rowstride (RETVAL); 374 dstr = gdk_pixbuf_get_rowstride (RETVAL);
323 375
350 402
351 RETVAL = newSV (w * h); 403 RETVAL = newSV (w * h);
352 SvPOK_only (RETVAL); 404 SvPOK_only (RETVAL);
353 SvCUR_set (RETVAL, w * h); 405 SvCUR_set (RETVAL, w * h);
354 406
355 dst = SvPVX (RETVAL); 407 dst = (guchar *)SvPVX (RETVAL);
356 408
357 memset (Er, 0, sizeof (int) * IW); 409 memset (Er, 0, sizeof (int) * IW);
358 memset (Eg, 0, sizeof (int) * IW); 410 memset (Eg, 0, sizeof (int) * IW);
359 memset (Eb, 0, sizeof (int) * IW); 411 memset (Eb, 0, sizeof (int) * IW);
360 412
388 *dst++ = r << 5 | g << 2 | b; 440 *dst++ = r << 5 | g << 2 | b;
389 } 441 }
390 } 442 }
391} 443}
392 OUTPUT: 444 OUTPUT:
393 RETVAL
394
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 445 RETVAL
448 446
449############################################################################# 447#############################################################################
450 448
451MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript 449MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
508 506
509 RETVAL = newSV (6 * 8 * 12 / 8); 507 RETVAL = newSV (6 * 8 * 12 / 8);
510 SvPOK_only (RETVAL); 508 SvPOK_only (RETVAL);
511 SvCUR_set (RETVAL, 6 * 8 * 12 / 8); 509 SvCUR_set (RETVAL, 6 * 8 * 12 / 8);
512 510
513 dst = SvPVX (RETVAL); 511 dst = (guchar *)SvPVX (RETVAL);
514 512
515 /* some primitive error distribution + random dithering */ 513 /* some primitive error distribution + random dithering */
516 514
517 for (y = 0; y < h; y++) 515 for (y = 0; y < h; y++)
518 { 516 {
576 } 574 }
577} 575}
578 OUTPUT: 576 OUTPUT:
579 RETVAL 577 RETVAL
580 578
579#############################################################################
581 580
581MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Plugin::RCluster
582 582
583SV *
584make_histograms (SV *ar)
585 CODE:
586{
587 int i;
588 AV *av, *result;
589
590 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV)
591 croak ("Not an array ref as first argument to make_histogram");
592
593 av = (AV *) SvRV (ar);
594 result = newAV ();
595
596 for (i = 0; i <= av_len (av); ++i)
597 {
598 const int HISTSIZE = 64;
599
600 int j;
601 SV *sv = *av_fetch (av, i, 1);
602 STRLEN len;
603 char *buf = SvPVbyte (sv, len);
604
605 int tmphist[HISTSIZE];
606 float *hist;
607
608 SV *histsv = newSV (HISTSIZE * sizeof (float) + 1);
609 SvPOK_on (histsv);
610 SvCUR_set (histsv, HISTSIZE * sizeof (float));
611 hist = (float *)SvPVX (histsv);
612
613 Zero (tmphist, sizeof (tmphist), char);
614
615 for (j = len; j--; )
616 {
617 unsigned int idx
618 = ((*buf & 0xc0) >> 2)
619 | ((*buf & 0x18) >> 1)
620 | (*buf & 0x03);
621
622 ++tmphist[idx];
623 ++buf;
624 }
625
626 for (j = 0; j < HISTSIZE; ++j)
627 hist[j] = (float)tmphist[j] / (len + 1e-30);
628
629 av_push (result, histsv);
630 }
631
632 RETVAL = newRV_noinc ((SV *)result);
633}
634 OUTPUT:
635 RETVAL
636
637

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines