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

Comparing CV/CV.xs (file contents):
Revision 1.19 by root, Wed Jul 20 22:33:01 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 {
306 dstp += cl; 352 dstp += cl;
307 path += is_utf8_char (path); 353 path += is_utf8_char (path);
308 } 354 }
309 } 355 }
310 356
311 RETVAL = newSVpvn (dst, dstp - dst); 357 RETVAL = newSVpvn ((const char *)dst, dstp - dst);
312} 358}
313 OUTPUT: 359 OUTPUT:
314 RETVAL 360 RETVAL
315 361
316GdkPixbuf_noinc * 362GdkPixbuf_noinc *
317p7_to_pb (int w, int h, guchar *src) 363p7_to_pb (int w, int h, SV *src_sv)
364 PROTOTYPE: @
318 CODE: 365 CODE:
319{ 366{
320 int x, y; 367 int x, y;
321 guchar *dst, *d; 368 guchar *dst, *d;
322 int dstr; 369 int dstr;
370 guchar *src = (guchar *)SvPVbyte_nolen (src_sv);
323 371
324 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); 372 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
325 dst = gdk_pixbuf_get_pixels (RETVAL); 373 dst = gdk_pixbuf_get_pixels (RETVAL);
326 dstr = gdk_pixbuf_get_rowstride (RETVAL); 374 dstr = gdk_pixbuf_get_rowstride (RETVAL);
327 375
354 402
355 RETVAL = newSV (w * h); 403 RETVAL = newSV (w * h);
356 SvPOK_only (RETVAL); 404 SvPOK_only (RETVAL);
357 SvCUR_set (RETVAL, w * h); 405 SvCUR_set (RETVAL, w * h);
358 406
359 dst = SvPVX (RETVAL); 407 dst = (guchar *)SvPVX (RETVAL);
360 408
361 memset (Er, 0, sizeof (int) * IW); 409 memset (Er, 0, sizeof (int) * IW);
362 memset (Eg, 0, sizeof (int) * IW); 410 memset (Eg, 0, sizeof (int) * IW);
363 memset (Eb, 0, sizeof (int) * IW); 411 memset (Eb, 0, sizeof (int) * IW);
364 412
392 *dst++ = r << 5 | g << 2 | b; 440 *dst++ = r << 5 | g << 2 | b;
393 } 441 }
394 } 442 }
395} 443}
396 OUTPUT: 444 OUTPUT:
397 RETVAL
398
399SV *
400make_histogram (SV *ar)
401 CODE:
402{
403 int i;
404 AV *av, *result;
405
406 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV)
407 croak ("Not an array ref as first argument to make_histogram");
408
409 av = (AV *) SvRV (ar);
410 result = newAV ();
411
412 for (i = 0; i <= av_len (av); ++i)
413 {
414 const int HISTSIZE = 64;
415
416 int j;
417 SV *sv = *av_fetch (av, i, 1);
418 STRLEN len;
419 char *buf = SvPVbyte (sv, len);
420
421 int tmphist[HISTSIZE];
422 float *hist;
423
424 SV *histsv = newSV (HISTSIZE * sizeof (float) + 1);
425 SvPOK_on (histsv);
426 SvCUR_set (histsv, HISTSIZE * sizeof (float));
427 hist = (float *)SvPVX (histsv);
428
429 Zero (tmphist, sizeof (tmphist), char);
430
431 for (j = len; j--; )
432 {
433 unsigned int idx
434 = ((*buf & 0xc0) >> 2)
435 | ((*buf & 0x18) >> 1)
436 | (*buf & 0x03);
437
438 ++tmphist[idx];
439 ++buf;
440 }
441
442 for (j = 0; j < HISTSIZE; ++j)
443 hist[j] = (float)tmphist[j] / (len + 1e-30);
444
445 av_push (result, histsv);
446 }
447
448 RETVAL = newRV_noinc ((SV *)result);
449}
450 OUTPUT:
451 RETVAL 445 RETVAL
452 446
453############################################################################# 447#############################################################################
454 448
455MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript 449MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
512 506
513 RETVAL = newSV (6 * 8 * 12 / 8); 507 RETVAL = newSV (6 * 8 * 12 / 8);
514 SvPOK_only (RETVAL); 508 SvPOK_only (RETVAL);
515 SvCUR_set (RETVAL, 6 * 8 * 12 / 8); 509 SvCUR_set (RETVAL, 6 * 8 * 12 / 8);
516 510
517 dst = SvPVX (RETVAL); 511 dst = (guchar *)SvPVX (RETVAL);
518 512
519 /* some primitive error distribution + random dithering */ 513 /* some primitive error distribution + random dithering */
520 514
521 for (y = 0; y < h; y++) 515 for (y = 0; y < h; y++)
522 { 516 {
580 } 574 }
581} 575}
582 OUTPUT: 576 OUTPUT:
583 RETVAL 577 RETVAL
584 578
579#############################################################################
585 580
581MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Plugin::RCluster
586 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