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

Comparing CV/CV.xs (file contents):
Revision 1.36 by root, Thu Jun 22 20:50:05 2006 UTC vs.
Revision 1.42 by root, Sun Sep 14 12:47:59 2008 UTC

22#define RAND (seed = (seed + 7141) * 54773 % 134456) 22#define RAND (seed = (seed + 7141) * 54773 % 134456)
23 23
24#define LINELENGTH 240 24#define LINELENGTH 240
25 25
26#define ELLIPSIS "\xe2\x80\xa6" 26#define ELLIPSIS "\xe2\x80\xa6"
27
28typedef char *octet_string;
27 29
28struct jpg_err_mgr 30struct jpg_err_mgr
29{ 31{
30 struct jpeg_error_mgr err; 32 struct jpeg_error_mgr err;
31 jmp_buf setjmp_buffer; 33 jmp_buf setjmp_buffer;
118 return; 120 return;
119 121
120 f->v2 /= f->n; 122 f->v2 /= f->n;
121 f->v3 /= f->n; 123 f->v3 /= f->n;
122 124
123 // this is a peculiar weightung, but it works fine
124 f->v1 /= 255.; 125 f->v1 /= 255.;
125 f->v2 /= 128. * 128.; 126 f->v2 /= 255. * 255.; f->v2 = sqrtf (f->v2);
126 f->v3 /= 128. * 128. * 64.; 127 f->v3 /= 255. * 255. * 255.; f->v3 = powf (fabsf (f->v3), 1./3.);
127} 128}
128 129
129static guint32 a85_val; 130static guint32 a85_val;
130static guint a85_cnt; 131static guint a85_cnt;
131static guchar a85_buf[LINELENGTH], *a85_ptr; 132static guchar a85_buf[LINELENGTH], *a85_ptr;
203 204
204 OUTPUT: 205 OUTPUT:
205 RETVAL 206 RETVAL
206 207
207const char * 208const char *
208magic (const char *path) 209magic (octet_string path)
209 CODE: 210 CODE:
210{ 211{
211 static magic_t cookie; 212 static magic_t cookie;
212 213
213 if (!cookie) 214 if (!cookie)
224} 225}
225 OUTPUT: 226 OUTPUT:
226 RETVAL 227 RETVAL
227 228
228const char * 229const char *
229magic_mime (const char *path) 230magic_mime (octet_string path)
230 CODE: 231 CODE:
231{ 232{
232 static magic_t cookie; 233 static magic_t cookie;
233 234
234 if (!cookie) 235 if (!cookie)
244 RETVAL = magic_file (cookie, path); 245 RETVAL = magic_file (cookie, path);
245} 246}
246 OUTPUT: 247 OUTPUT:
247 RETVAL 248 RETVAL
248 249
249# missing in Gtk2 perl module 250# missing/broken in Gtk2 perl module
251
252void
253gdk_window_clear_hints (GdkWindow *window)
254 CODE:
255 gdk_window_set_geometry_hints (window, 0, 0);
250 256
251gboolean 257gboolean
252gdk_net_wm_supports (GdkAtom property) 258gdk_net_wm_supports (GdkAtom property)
253 CODE: 259 CODE:
254#if defined(GDK_WINDOWING_X11) && !defined(GDK_MULTIHEAD_SAFE) 260#if defined(GDK_WINDOWING_X11) && !defined(GDK_MULTIHEAD_SAFE)
436 442
437############################################################################# 443#############################################################################
438 444
439MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer 445MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer
440 446
447# currently only works for filenames (octet strings)
448
441SV * 449SV *
442foldcase (SV *pathsv) 450foldcase (SV *pathsv)
443 PROTOTYPE: $ 451 PROTOTYPE: $
444 CODE: 452 CODE:
445{ 453{
446 STRLEN plen; 454 STRLEN plen;
447 U8 *path = (U8 *)SvPVutf8 (pathsv, plen); 455 U8 *path = (U8 *)SvPV (pathsv, plen);
448 U8 *pend = path + plen; 456 U8 *pend = path + plen;
449 U8 dst [plen * 6 * 3], *dstp = dst; 457 U8 dst [plen * 6 * 3], *dstp = dst;
450 458
451 while (path < pend) 459 while (path < pend)
452 { 460 {
453 U8 ch = *path; 461 U8 ch = *path;
454 462
455 if (ch >= 'a' && ch <= 'z') 463 if (ch >= 'a' && ch <= 'z')
456 *dstp++ = *path++; 464 *dstp++ = *path++;
465 else if (ch >= 'A' && ch <= 'Z')
466 *dstp++ = *path++ + ('a' - 'A');
457 else if (ch >= '0' && ch <= '9') 467 else if (ch >= '0' && ch <= '9')
458 { 468 {
459 STRLEN el, nl = 0; 469 STRLEN el, nl = 0;
460 while (*path >= '0' && *path <= '9' && path < pend) 470 while (*path >= '0' && *path <= '9' && path < pend)
461 path++, nl++; 471 path++, nl++;
464 *dstp++ = '0'; 474 *dstp++ = '0';
465 475
466 memcpy (dstp, path - nl, nl); 476 memcpy (dstp, path - nl, nl);
467 dstp += nl; 477 dstp += nl;
468 } 478 }
479 else
480 *dstp++ = *path++;
481#if 0
469 else 482 else
470 { 483 {
471 STRLEN cl; 484 STRLEN cl;
472 to_utf8_fold (path, dstp, &cl); 485 to_utf8_fold (path, dstp, &cl);
473 dstp += cl; 486 dstp += cl;
474 path += is_utf8_char (path); 487 path += is_utf8_char (path);
475 } 488 }
489#endif
476 } 490 }
477 491
478 RETVAL = newSVpvn ((const char *)dst, dstp - dst); 492 RETVAL = newSVpvn ((const char *)dst, dstp - dst);
479} 493}
480 OUTPUT: 494 OUTPUT:
649{ 663{
650 int i; 664 int i;
651 AV *av, *result; 665 AV *av, *result;
652 666
653 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV) 667 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV)
654 croak ("Not an array ref as first argument to make_histogram"); 668 croak ("Not an array ref as first argument to extract_features");
655 669
656 av = (AV *) SvRV (ar); 670 av = (AV *) SvRV (ar);
657 result = newAV (); 671 result = newAV ();
658 672
659 for (i = 0; i <= av_len (av); ++i) 673 for (i = 0; i <= av_len (av); ++i)
712 feature_finish_pass_2 (&f_v); 726 feature_finish_pass_2 (&f_v);
713 } 727 }
714 728
715 hist [0] = f_h.v1 * 2.; hist [1] = f_h.v2 * 2.; hist [2] = f_h.v3 * 2.; 729 hist [0] = f_h.v1 * 2.; hist [1] = f_h.v2 * 2.; hist [2] = f_h.v3 * 2.;
716 hist [3] = f_s.v1 ; hist [4] = f_s.v2 ; hist [5] = f_s.v3 ; 730 hist [3] = f_s.v1 ; hist [4] = f_s.v2 ; hist [5] = f_s.v3 ;
717 hist [6] = f_v.v1 ; hist [7] = f_v.v2 ; hist [8] = f_v.v3 ; 731 hist [6] = f_v.v1 * .5; hist [7] = f_v.v2 * .5; hist [8] = f_v.v3 * .5;
718 732
719 av_push (result, histsv); 733 av_push (result, histsv);
720 } 734 }
721 735
722 RETVAL = newRV_noinc ((SV *)result); 736 RETVAL = newRV_noinc ((SV *)result);
723} 737}
724 OUTPUT: 738 OUTPUT:
725 RETVAL 739 RETVAL
726 740
727SV *
728make_histograms (SV *ar)
729 CODE:
730{
731 int i;
732 AV *av, *result;
733
734 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV)
735 croak ("Not an array ref as first argument to make_histogram");
736
737 av = (AV *) SvRV (ar);
738 result = newAV ();
739
740 for (i = 0; i <= av_len (av); ++i)
741 {
742 const int HISTSIZE = 64;
743
744 int j;
745 SV *sv = *av_fetch (av, i, 1);
746 STRLEN len;
747 char *buf = SvPVbyte (sv, len);
748
749 int tmphist[HISTSIZE];
750 float *hist;
751
752 SV *histsv = newSV (HISTSIZE * sizeof (float) + 1);
753 SvPOK_on (histsv);
754 SvCUR_set (histsv, HISTSIZE * sizeof (float));
755 hist = (float *)SvPVX (histsv);
756
757 Zero (tmphist, sizeof (tmphist), char);
758
759 for (j = len; j--; )
760 {
761 unsigned int idx
762 = ((*buf & 0xc0) >> 2)
763 | ((*buf & 0x18) >> 1)
764 | (*buf & 0x03);
765
766 ++tmphist[idx];
767 ++buf;
768 }
769
770 for (j = 0; j < HISTSIZE; ++j)
771 hist[j] = (float)tmphist[j] / (len + 1e-30);
772
773 av_push (result, histsv);
774 }
775
776 RETVAL = newRV_noinc ((SV *)result);
777}
778 OUTPUT:
779 RETVAL
780
781

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines