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.26 by root, Sun Aug 21 02:18:30 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
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
128GdkPixbuf_noinc * 169GdkPixbuf_noinc *
129transpose (GdkPixbuf *pb) 170transpose (GdkPixbuf *pb)
130 CODE: 171 CODE:
131{ 172{
132 int w = gdk_pixbuf_get_width (pb); 173 int w = gdk_pixbuf_get_width (pb);
172} 213}
173 OUTPUT: 214 OUTPUT:
174 RETVAL 215 RETVAL
175 216
176GdkPixbuf_noinc * 217GdkPixbuf_noinc *
177load_jpeg (char *path, int thumbnail=0) 218load_jpeg (SV *path, int thumbnail=0)
178 CODE: 219 CODE:
179{ 220{
180 struct jpeg_decompress_struct cinfo; 221 struct jpeg_decompress_struct cinfo;
181 struct jpg_err_mgr jerr; 222 struct jpg_err_mgr jerr;
182 guchar *data; 223 guchar *data;
183 int rs; 224 int rs;
184 FILE *fp; 225 FILE *fp;
185 volatile GdkPixbuf *pb = 0; 226 volatile GdkPixbuf *pb = 0;
227 gchar *filename;
228
186 RETVAL = 0; 229 RETVAL = 0;
187 230
188 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)
189 XSRETURN_UNDEF; 236 XSRETURN_UNDEF;
190 237
191 cinfo.err = jpeg_std_error (&jerr.err); 238 cinfo.err = jpeg_std_error (&jerr.err);
192 239
193 jerr.err.error_exit = cv_error_exit; 240 jerr.err.error_exit = cv_error_exit;
224 { 271 {
225 cinfo.dct_method = JDCT_FASTEST; 272 cinfo.dct_method = JDCT_FASTEST;
226 cinfo.do_fancy_upsampling = FALSE; 273 cinfo.do_fancy_upsampling = FALSE;
227 274
228 while (cinfo.scale_denom < 8 275 while (cinfo.scale_denom < 8
229 && (cinfo.output_width >> 1) >= IW 276 && cinfo.output_width >= IW*4
230 && (cinfo.output_height >> 1) >= IH) 277 && cinfo.output_height >= IH*4)
231 { 278 {
232 cinfo.scale_denom <<= 1; 279 cinfo.scale_denom <<= 1;
233 jpeg_calc_output_dimensions (&cinfo); 280 jpeg_calc_output_dimensions (&cinfo);
234 } 281 }
235 } 282 }
268 315
269############################################################################# 316#############################################################################
270 317
271MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer 318MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer
272 319
320SV *
321foldcase (SV *pathsv)
322 PROTOTYPE: $
323 CODE:
324{
325 STRLEN plen;
326 U8 *path = (U8 *)SvPVutf8 (pathsv, plen);
327 U8 *pend = path + plen;
328 U8 dst [plen * 6 * 3], *dstp = dst;
329
330 while (path < pend)
331 {
332 U8 ch = *path;
333
334 if (ch >= 'a' && ch <= 'z')
335 *dstp++ = *path++;
336 else if (ch >= '0' && ch <= '9')
337 {
338 STRLEN el, nl = 0;
339 while (*path >= '0' && *path <= '9' && path < pend)
340 path++, nl++;
341
342 for (el = nl; el < 6; el++)
343 *dstp++ = '0';
344
345 memcpy (dstp, path - nl, nl);
346 dstp += nl;
347 }
348 else
349 {
350 STRLEN cl;
351 to_utf8_fold (path, dstp, &cl);
352 dstp += cl;
353 path += is_utf8_char (path);
354 }
355 }
356
357 RETVAL = newSVpvn ((const char *)dst, dstp - dst);
358}
359 OUTPUT:
360 RETVAL
361
273GdkPixbuf_noinc * 362GdkPixbuf_noinc *
274p7_to_pb (int w, int h, guchar *src) 363p7_to_pb (int w, int h, SV *src_sv)
364 PROTOTYPE: @
275 CODE: 365 CODE:
276{ 366{
277 int x, y; 367 int x, y;
278 guchar *dst, *d; 368 guchar *dst, *d;
279 int dstr; 369 int dstr;
370 guchar *src = (guchar *)SvPVbyte_nolen (src_sv);
280 371
281 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); 372 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
282 dst = gdk_pixbuf_get_pixels (RETVAL); 373 dst = gdk_pixbuf_get_pixels (RETVAL);
283 dstr = gdk_pixbuf_get_rowstride (RETVAL); 374 dstr = gdk_pixbuf_get_rowstride (RETVAL);
284 375
311 402
312 RETVAL = newSV (w * h); 403 RETVAL = newSV (w * h);
313 SvPOK_only (RETVAL); 404 SvPOK_only (RETVAL);
314 SvCUR_set (RETVAL, w * h); 405 SvCUR_set (RETVAL, w * h);
315 406
316 dst = SvPVX (RETVAL); 407 dst = (guchar *)SvPVX (RETVAL);
317 408
318 memset (Er, 0, sizeof (int) * IW); 409 memset (Er, 0, sizeof (int) * IW);
319 memset (Eg, 0, sizeof (int) * IW); 410 memset (Eg, 0, sizeof (int) * IW);
320 memset (Eb, 0, sizeof (int) * IW); 411 memset (Eb, 0, sizeof (int) * IW);
321 412
349 *dst++ = r << 5 | g << 2 | b; 440 *dst++ = r << 5 | g << 2 | b;
350 } 441 }
351 } 442 }
352} 443}
353 OUTPUT: 444 OUTPUT:
354 RETVAL
355
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 445 RETVAL
409 446
410############################################################################# 447#############################################################################
411 448
412MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript 449MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
469 506
470 RETVAL = newSV (6 * 8 * 12 / 8); 507 RETVAL = newSV (6 * 8 * 12 / 8);
471 SvPOK_only (RETVAL); 508 SvPOK_only (RETVAL);
472 SvCUR_set (RETVAL, 6 * 8 * 12 / 8); 509 SvCUR_set (RETVAL, 6 * 8 * 12 / 8);
473 510
474 dst = SvPVX (RETVAL); 511 dst = (guchar *)SvPVX (RETVAL);
475 512
476 /* some primitive error distribution + random dithering */ 513 /* some primitive error distribution + random dithering */
477 514
478 for (y = 0; y < h; y++) 515 for (y = 0; y < h; y++)
479 { 516 {
537 } 574 }
538} 575}
539 OUTPUT: 576 OUTPUT:
540 RETVAL 577 RETVAL
541 578
579#############################################################################
542 580
581MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Plugin::RCluster
543 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