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

Comparing CV/CV.xs (file contents):
Revision 1.37 by root, Thu Jun 22 22:01:26 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;
202 206
203 OUTPUT: 207 OUTPUT:
204 RETVAL 208 RETVAL
205 209
206const char * 210const char *
207magic (const char *path) 211magic (octet_string path)
208 CODE: 212 CODE:
209{ 213{
210 static magic_t cookie; 214 static magic_t cookie;
211 215
212 if (!cookie) 216 if (!cookie)
223} 227}
224 OUTPUT: 228 OUTPUT:
225 RETVAL 229 RETVAL
226 230
227const char * 231const char *
228magic_mime (const char *path) 232magic_mime (octet_string path)
229 CODE: 233 CODE:
230{ 234{
231 static magic_t cookie; 235 static magic_t cookie;
232 236
233 if (!cookie) 237 if (!cookie)
243 RETVAL = magic_file (cookie, path); 247 RETVAL = magic_file (cookie, path);
244} 248}
245 OUTPUT: 249 OUTPUT:
246 RETVAL 250 RETVAL
247 251
248# 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);
249 258
250gboolean 259gboolean
251gdk_net_wm_supports (GdkAtom property) 260gdk_net_wm_supports (GdkAtom property)
252 CODE: 261 CODE:
253#if defined(GDK_WINDOWING_X11) && !defined(GDK_MULTIHEAD_SAFE) 262#if defined(GDK_WINDOWING_X11) && !defined(GDK_MULTIHEAD_SAFE)
283 RETVAL 292 RETVAL
284 293
285GdkPixbuf_noinc * 294GdkPixbuf_noinc *
286rotate (GdkPixbuf *pb, int angle) 295rotate (GdkPixbuf *pb, int angle)
287 CODE: 296 CODE:
297 if (angle < 0)
298 angle += 360;
288 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
289 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE 300 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
290 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN 301 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN
291 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE 302 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE
292 : angle); 303 : angle);
393compare (GdkPixbuf *a, GdkPixbuf *b) 404compare (GdkPixbuf *a, GdkPixbuf *b)
394 PPCODE: 405 PPCODE:
395{ 406{
396 int w = gdk_pixbuf_get_width (a); 407 int w = gdk_pixbuf_get_width (a);
397 int h = gdk_pixbuf_get_height (a); 408 int h = gdk_pixbuf_get_height (a);
409
398 int sa = gdk_pixbuf_get_rowstride (a); 410 int sa = gdk_pixbuf_get_rowstride (a);
399 int sb = gdk_pixbuf_get_rowstride (b); 411 int sb = gdk_pixbuf_get_rowstride (b);
400 412
401 guchar *pa = gdk_pixbuf_get_pixels (a); 413 guchar *pa = gdk_pixbuf_get_pixels (a);
402 guchar *pb = gdk_pixbuf_get_pixels (b); 414 guchar *pb = gdk_pixbuf_get_pixels (b);
435 447
436############################################################################# 448#############################################################################
437 449
438MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer 450MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer
439 451
452# currently only works for filenames (octet strings)
453
440SV * 454SV *
441foldcase (SV *pathsv) 455foldcase (SV *pathsv)
442 PROTOTYPE: $ 456 PROTOTYPE: $
443 CODE: 457 CODE:
444{ 458{
445 STRLEN plen; 459 STRLEN plen;
446 U8 *path = (U8 *)SvPVutf8 (pathsv, plen); 460 U8 *path = (U8 *)SvPV (pathsv, plen);
447 U8 *pend = path + plen; 461 U8 *pend = path + plen;
448 U8 dst [plen * 6 * 3], *dstp = dst; 462 U8 dst [plen * 6 * 3], *dstp = dst;
449 463
450 while (path < pend) 464 while (path < pend)
451 { 465 {
452 U8 ch = *path; 466 U8 ch = *path;
453 467
454 if (ch >= 'a' && ch <= 'z') 468 if (ch >= 'a' && ch <= 'z')
455 *dstp++ = *path++; 469 *dstp++ = *path++;
470 else if (ch >= 'A' && ch <= 'Z')
471 *dstp++ = *path++ + ('a' - 'A');
456 else if (ch >= '0' && ch <= '9') 472 else if (ch >= '0' && ch <= '9')
457 { 473 {
458 STRLEN el, nl = 0; 474 STRLEN el, nl = 0;
459 while (*path >= '0' && *path <= '9' && path < pend) 475 while (*path >= '0' && *path <= '9' && path < pend)
460 path++, nl++; 476 path++, nl++;
463 *dstp++ = '0'; 479 *dstp++ = '0';
464 480
465 memcpy (dstp, path - nl, nl); 481 memcpy (dstp, path - nl, nl);
466 dstp += nl; 482 dstp += nl;
467 } 483 }
484 else
485 *dstp++ = *path++;
486#if 0
468 else 487 else
469 { 488 {
470 STRLEN cl; 489 STRLEN cl;
471 to_utf8_fold (path, dstp, &cl); 490 to_utf8_fold (path, dstp, &cl);
472 dstp += cl; 491 dstp += cl;
473 path += is_utf8_char (path); 492 path += is_utf8_char (path);
474 } 493 }
494#endif
475 } 495 }
476 496
477 RETVAL = newSVpvn ((const char *)dst, dstp - dst); 497 RETVAL = newSVpvn ((const char *)dst, dstp - dst);
478} 498}
479 OUTPUT: 499 OUTPUT:
648{ 668{
649 int i; 669 int i;
650 AV *av, *result; 670 AV *av, *result;
651 671
652 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV) 672 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV)
653 croak ("Not an array ref as first argument to make_histogram"); 673 croak ("Not an array ref as first argument to extract_features");
654 674
655 av = (AV *) SvRV (ar); 675 av = (AV *) SvRV (ar);
656 result = newAV (); 676 result = newAV ();
657 677
658 for (i = 0; i <= av_len (av); ++i) 678 for (i = 0; i <= av_len (av); ++i)
711 feature_finish_pass_2 (&f_v); 731 feature_finish_pass_2 (&f_v);
712 } 732 }
713 733
714 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.;
715 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 ;
716 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;
717 737
718 av_push (result, histsv); 738 av_push (result, histsv);
719 } 739 }
720 740
721 RETVAL = newRV_noinc ((SV *)result); 741 RETVAL = newRV_noinc ((SV *)result);
722} 742}
723 OUTPUT: 743 OUTPUT:
724 RETVAL 744 RETVAL
725 745
726SV *
727make_histograms (SV *ar)
728 CODE:
729{
730 int i;
731 AV *av, *result;
732
733 if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV)
734 croak ("Not an array ref as first argument to make_histogram");
735
736 av = (AV *) SvRV (ar);
737 result = newAV ();
738
739 for (i = 0; i <= av_len (av); ++i)
740 {
741 const int HISTSIZE = 64;
742
743 int j;
744 SV *sv = *av_fetch (av, i, 1);
745 STRLEN len;
746 char *buf = SvPVbyte (sv, len);
747
748 int tmphist[HISTSIZE];
749 float *hist;
750
751 SV *histsv = newSV (HISTSIZE * sizeof (float) + 1);
752 SvPOK_on (histsv);
753 SvCUR_set (histsv, HISTSIZE * sizeof (float));
754 hist = (float *)SvPVX (histsv);
755
756 Zero (tmphist, sizeof (tmphist), char);
757
758 for (j = len; j--; )
759 {
760 unsigned int idx
761 = ((*buf & 0xc0) >> 2)
762 | ((*buf & 0x18) >> 1)
763 | (*buf & 0x03);
764
765 ++tmphist[idx];
766 ++buf;
767 }
768
769 for (j = 0; j < HISTSIZE; ++j)
770 hist[j] = (float)tmphist[j] / (len + 1e-30);
771
772 av_push (result, histsv);
773 }
774
775 RETVAL = newRV_noinc ((SV *)result);
776}
777 OUTPUT:
778 RETVAL
779
780

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines