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

Comparing CV/CV.xs (file contents):
Revision 1.35 by root, Tue Mar 7 16:45:53 2006 UTC vs.
Revision 1.40 by root, Sat Nov 25 15:00:51 2006 UTC

68 68
69 *h &= 255; 69 *h &= 255;
70 } 70 }
71} 71}
72 72
73struct feature {
74 float v1, v2, v3; // mean, square, cube
75 int n;
76};
77
78static void
79feature_init (struct feature *f)
80{
81 f->v1 = 0.;
82 f->v2 = 0.;
83 f->v3 = 0.;
84 f->n = 0;
85}
86
87// didn't find an algorithm to neatly do mean, variance and skew in one pass.
88// elmex ist schuld.
89static void
90feature_update_pass_1 (struct feature *f, unsigned int v)
91{
92 f->v1 += v;
93 f->n += 1;
94}
95
96static void
97feature_finish_pass_1 (struct feature *f)
98{
99 if (f->n < 1)
100 return;
101
102 f->v1 /= f->n;
103}
104
105static void
106feature_update_pass_2 (struct feature *f, unsigned int v)
107{
108 float d = v - f->v1;
109
110 f->v2 += d * d;
111 f->v3 += d * d * d;
112}
113
114static void
115feature_finish_pass_2 (struct feature *f)
116{
117 if (f->n < 1)
118 return;
119
120 f->v2 /= f->n;
121 f->v3 /= f->n;
122
123 f->v1 /= 255.;
124 f->v2 /= 255. * 255.; f->v2 = sqrtf (f->v2);
125 f->v3 /= 255. * 255. * 255.; f->v3 = powf (fabsf (f->v3), 1./3.);
126}
127
73static guint32 a85_val; 128static guint32 a85_val;
74static guint a85_cnt; 129static guint a85_cnt;
75static guchar a85_buf[LINELENGTH], *a85_ptr; 130static guchar a85_buf[LINELENGTH], *a85_ptr;
76 131
77static void 132static void
188 RETVAL = magic_file (cookie, path); 243 RETVAL = magic_file (cookie, path);
189} 244}
190 OUTPUT: 245 OUTPUT:
191 RETVAL 246 RETVAL
192 247
193# missing in Gtk2 perl module 248# missing/broken in Gtk2 perl module
249
250void
251gdk_window_clear_hints (GdkWindow *window)
252 CODE:
253 gdk_window_set_geometry_hints (window, 0, 0);
194 254
195gboolean 255gboolean
196gdk_net_wm_supports (GdkAtom property) 256gdk_net_wm_supports (GdkAtom property)
197 CODE: 257 CODE:
198#if defined(GDK_WINDOWING_X11) && !defined(GDK_MULTIHEAD_SAFE) 258#if defined(GDK_WINDOWING_X11) && !defined(GDK_MULTIHEAD_SAFE)
586############################################################################# 646#############################################################################
587 647
588MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Plugin::RCluster 648MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Plugin::RCluster
589 649
590SV * 650SV *
591make_histograms (SV *ar) 651extract_features (SV *ar)
592 CODE: 652 CODE:
593{ 653{
594 int i; 654 int i;
595 AV *av, *result; 655 AV *av, *result;
596 656
597 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV) 657 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV)
598 croak ("Not an array ref as first argument to make_histogram"); 658 croak ("Not an array ref as first argument to extract_features");
599 659
600 av = (AV *) SvRV (ar); 660 av = (AV *) SvRV (ar);
601 result = newAV (); 661 result = newAV ();
602 662
603 for (i = 0; i <= av_len (av); ++i) 663 for (i = 0; i <= av_len (av); ++i)
604 { 664 {
605 const int HISTSIZE = 64;
606
607 int j;
608 SV *sv = *av_fetch (av, i, 1); 665 SV *sv = *av_fetch (av, i, 1);
609 STRLEN len;
610 char *buf = SvPVbyte (sv, len);
611
612 int tmphist[HISTSIZE];
613 float *hist;
614
615 SV *histsv = newSV (HISTSIZE * sizeof (float) + 1); 666 SV *histsv = newSV (9 * sizeof (float) + 1);
667
616 SvPOK_on (histsv); 668 SvPOK_on (histsv);
617 SvCUR_set (histsv, HISTSIZE * sizeof (float)); 669 SvCUR_set (histsv, 9 * sizeof (float));
618 hist = (float *)SvPVX (histsv); 670 float *hist = (float *)SvPVX (histsv);
619 671
620 Zero (tmphist, sizeof (tmphist), char); 672 struct feature f_h, f_s, f_v;
673 feature_init (&f_h);
674 feature_init (&f_s);
675 feature_init (&f_v);
621 676
622 for (j = len; j--; )
623 {
624 unsigned int idx
625 = ((*buf & 0xc0) >> 2)
626 | ((*buf & 0x18) >> 1)
627 | (*buf & 0x03);
628
629 ++tmphist[idx];
630 ++buf;
631 }
632 677 {
633 for (j = 0; j < HISTSIZE; ++j) 678 STRLEN len;
634 hist[j] = (float)tmphist[j] / (len + 1e-30); 679 unsigned char *buf = (unsigned char *)SvPVbyte (sv, len);
680 while (len >= 3)
681 {
682 unsigned int r, g, b, h, s, v;
683 r = *buf++; g = *buf++; b = *buf++;
684 rgb_to_hsv (r, g, b, &h, &s, &v);
685
686 feature_update_pass_1 (&f_h, h);
687 feature_update_pass_1 (&f_s, s);
688 feature_update_pass_1 (&f_v, v);
689
690 len -= 3;
691 }
692
693 feature_finish_pass_1 (&f_h);
694 feature_finish_pass_1 (&f_s);
695 feature_finish_pass_1 (&f_v);
696 }
697
698 {
699 STRLEN len;
700 unsigned char *buf = (unsigned char *)SvPVbyte (sv, len);
701 while (len >= 3)
702 {
703 unsigned int r, g, b, h, s, v;
704 r = *buf++; g = *buf++; b = *buf++;
705 rgb_to_hsv (r, g, b, &h, &s, &v);
706
707 feature_update_pass_2 (&f_h, h);
708 feature_update_pass_2 (&f_s, s);
709 feature_update_pass_2 (&f_v, v);
710
711 len -= 3;
712 }
713
714 feature_finish_pass_2 (&f_h);
715 feature_finish_pass_2 (&f_s);
716 feature_finish_pass_2 (&f_v);
717 }
718
719 hist [0] = f_h.v1 * 2.; hist [1] = f_h.v2 * 2.; hist [2] = f_h.v3 * 2.;
720 hist [3] = f_s.v1 ; hist [4] = f_s.v2 ; hist [5] = f_s.v3 ;
721 hist [6] = f_v.v1 * .5; hist [7] = f_v.v2 * .5; hist [8] = f_v.v3 * .5;
635 722
636 av_push (result, histsv); 723 av_push (result, histsv);
637 } 724 }
638 725
639 RETVAL = newRV_noinc ((SV *)result); 726 RETVAL = newRV_noinc ((SV *)result);
640} 727}
641 OUTPUT: 728 OUTPUT:
642 RETVAL 729 RETVAL
643 730
644

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines