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.44 by root, Sun Dec 30 16:23:23 2012 UTC

14#include <gdk-pixbuf/gdk-pixbuf.h> 14#include <gdk-pixbuf/gdk-pixbuf.h>
15 15
16#include <gperl.h> 16#include <gperl.h>
17#include <gtk2perl.h> 17#include <gtk2perl.h>
18 18
19#include <assert.h>
20
19#define IW 80 /* MUST match Schnauzer.pm! */ 21#define IW 80 /* MUST match Schnauzer.pm! */
20#define IH 60 /* MUST match Schnauzer.pm! */ 22#define IH 60 /* MUST match Schnauzer.pm! */
21 23
22#define RAND (seed = (seed + 7141) * 54773 % 134456) 24#define RAND (seed = (seed + 7141) * 54773 % 134456)
23 25
24#define LINELENGTH 240 26#define LINELENGTH 240
25 27
26#define ELLIPSIS "\xe2\x80\xa6" 28#define ELLIPSIS "\xe2\x80\xa6"
29
30typedef char *octet_string;
27 31
28struct jpg_err_mgr 32struct jpg_err_mgr
29{ 33{
30 struct jpeg_error_mgr err; 34 struct jpeg_error_mgr err;
31 jmp_buf setjmp_buffer; 35 jmp_buf setjmp_buffer;
118 return; 122 return;
119 123
120 f->v2 /= f->n; 124 f->v2 /= f->n;
121 f->v3 /= f->n; 125 f->v3 /= f->n;
122 126
123 // this is a peculiar weightung, but it works fine
124 f->v1 /= 255.; 127 f->v1 /= 255.;
125 f->v2 /= 128. * 128.; 128 f->v2 /= 255. * 255.; f->v2 = sqrtf (f->v2);
126 f->v3 /= 128. * 128. * 64.; 129 f->v3 /= 255. * 255. * 255.; f->v3 = powf (fabsf (f->v3), 1./3.);
127} 130}
128 131
129static guint32 a85_val; 132static guint32 a85_val;
130static guint a85_cnt; 133static guint a85_cnt;
131static guchar a85_buf[LINELENGTH], *a85_ptr; 134static guchar a85_buf[LINELENGTH], *a85_ptr;
203 206
204 OUTPUT: 207 OUTPUT:
205 RETVAL 208 RETVAL
206 209
207const char * 210const char *
208magic (const char *path) 211magic (octet_string path)
209 CODE: 212 CODE:
210{ 213{
211 static magic_t cookie; 214 static magic_t cookie;
212 215
213 if (!cookie) 216 if (!cookie)
224} 227}
225 OUTPUT: 228 OUTPUT:
226 RETVAL 229 RETVAL
227 230
228const char * 231const char *
229magic_mime (const char *path) 232magic_mime (octet_string path)
230 CODE: 233 CODE:
231{ 234{
232 static magic_t cookie; 235 static magic_t cookie;
233 236
234 if (!cookie) 237 if (!cookie)
244 RETVAL = magic_file (cookie, path); 247 RETVAL = magic_file (cookie, path);
245} 248}
246 OUTPUT: 249 OUTPUT:
247 RETVAL 250 RETVAL
248 251
249# missing in Gtk2 perl module 252# missing/broken in Gtk2 perl module
253
254void
255gdk_window_clear_hints (GdkWindow *window)
256 CODE:
257 gdk_window_set_geometry_hints (window, 0, 0);
250 258
251gboolean 259gboolean
252gdk_net_wm_supports (GdkAtom property) 260gdk_net_wm_supports (GdkAtom property)
253 CODE: 261 CODE:
254#if defined(GDK_WINDOWING_X11) && !defined(GDK_MULTIHEAD_SAFE) 262#if defined(GDK_WINDOWING_X11) && !defined(GDK_MULTIHEAD_SAFE)
284 RETVAL 292 RETVAL
285 293
286GdkPixbuf_noinc * 294GdkPixbuf_noinc *
287rotate (GdkPixbuf *pb, int angle) 295rotate (GdkPixbuf *pb, int angle)
288 CODE: 296 CODE:
297 if (angle < 0)
298 angle += 360;
289 RETVAL = gdk_pixbuf_rotate_simple (pb, angle == 0 ? GDK_PIXBUF_ROTATE_NONE 299 RETVAL = gdk_pixbuf_rotate_simple (pb, angle == 0 ? GDK_PIXBUF_ROTATE_NONE
290 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE 300 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
291 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN 301 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN
292 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE 302 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE
293 : angle); 303 : angle);
394compare (GdkPixbuf *a, GdkPixbuf *b) 404compare (GdkPixbuf *a, GdkPixbuf *b)
395 PPCODE: 405 PPCODE:
396{ 406{
397 int w = gdk_pixbuf_get_width (a); 407 int w = gdk_pixbuf_get_width (a);
398 int h = gdk_pixbuf_get_height (a); 408 int h = gdk_pixbuf_get_height (a);
409
399 int sa = gdk_pixbuf_get_rowstride (a); 410 int sa = gdk_pixbuf_get_rowstride (a);
400 int sb = gdk_pixbuf_get_rowstride (b); 411 int sb = gdk_pixbuf_get_rowstride (b);
401 412
402 guchar *pa = gdk_pixbuf_get_pixels (a); 413 guchar *pa = gdk_pixbuf_get_pixels (a);
403 guchar *pb = gdk_pixbuf_get_pixels (b); 414 guchar *pb = gdk_pixbuf_get_pixels (b);
436 447
437############################################################################# 448#############################################################################
438 449
439MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer 450MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer
440 451
452# currently only works for filenames (octet strings)
453
441SV * 454SV *
442foldcase (SV *pathsv) 455foldcase (SV *pathsv)
443 PROTOTYPE: $ 456 PROTOTYPE: $
444 CODE: 457 CODE:
445{ 458{
446 STRLEN plen; 459 STRLEN plen;
447 U8 *path = (U8 *)SvPVutf8 (pathsv, plen); 460 U8 *path = (U8 *)SvPV (pathsv, plen);
448 U8 *pend = path + plen; 461 U8 *pend = path + plen;
449 U8 dst [plen * 6 * 3], *dstp = dst; 462 U8 dst [plen * 6 * 3], *dstp = dst;
450 463
451 while (path < pend) 464 while (path < pend)
452 { 465 {
453 U8 ch = *path; 466 U8 ch = *path;
454 467
455 if (ch >= 'a' && ch <= 'z') 468 if (ch >= 'a' && ch <= 'z')
456 *dstp++ = *path++; 469 *dstp++ = *path++;
470 else if (ch >= 'A' && ch <= 'Z')
471 *dstp++ = *path++ + ('a' - 'A');
457 else if (ch >= '0' && ch <= '9') 472 else if (ch >= '0' && ch <= '9')
458 { 473 {
459 STRLEN el, nl = 0; 474 STRLEN el, nl = 0;
460 while (*path >= '0' && *path <= '9' && path < pend) 475 while (*path >= '0' && *path <= '9' && path < pend)
461 path++, nl++; 476 path++, nl++;
464 *dstp++ = '0'; 479 *dstp++ = '0';
465 480
466 memcpy (dstp, path - nl, nl); 481 memcpy (dstp, path - nl, nl);
467 dstp += nl; 482 dstp += nl;
468 } 483 }
484 else
485 *dstp++ = *path++;
486#if 0
469 else 487 else
470 { 488 {
471 STRLEN cl; 489 STRLEN cl;
472 to_utf8_fold (path, dstp, &cl); 490 to_utf8_fold (path, dstp, &cl);
473 dstp += cl; 491 dstp += cl;
474 path += is_utf8_char (path); 492 path += is_utf8_char (path);
475 } 493 }
494#endif
476 } 495 }
477 496
478 RETVAL = newSVpvn ((const char *)dst, dstp - dst); 497 RETVAL = newSVpvn ((const char *)dst, dstp - dst);
479} 498}
480 OUTPUT: 499 OUTPUT:
649{ 668{
650 int i; 669 int i;
651 AV *av, *result; 670 AV *av, *result;
652 671
653 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV) 672 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV)
654 croak ("Not an array ref as first argument to make_histogram"); 673 croak ("Not an array ref as first argument to extract_features");
655 674
656 av = (AV *) SvRV (ar); 675 av = (AV *) SvRV (ar);
657 result = newAV (); 676 result = newAV ();
658 677
659 for (i = 0; i <= av_len (av); ++i) 678 for (i = 0; i <= av_len (av); ++i)
712 feature_finish_pass_2 (&f_v); 731 feature_finish_pass_2 (&f_v);
713 } 732 }
714 733
715 hist [0] = f_h.v1 * 2.; hist [1] = f_h.v2 * 2.; hist [2] = f_h.v3 * 2.; 734 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 ; 735 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 ; 736 hist [6] = f_v.v1 * .5; hist [7] = f_v.v2 * .5; hist [8] = f_v.v3 * .5;
718 737
719 av_push (result, histsv); 738 av_push (result, histsv);
720 } 739 }
721 740
722 RETVAL = newRV_noinc ((SV *)result); 741 RETVAL = newRV_noinc ((SV *)result);
723} 742}
724 OUTPUT: 743 OUTPUT:
725 RETVAL 744 RETVAL
726 745
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