… | |
… | |
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 | |
|
|
30 | typedef char *octet_string; |
27 | |
31 | |
28 | struct jpg_err_mgr |
32 | struct 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 | |
129 | static guint32 a85_val; |
132 | static guint32 a85_val; |
130 | static guint a85_cnt; |
133 | static guint a85_cnt; |
131 | static guchar a85_buf[LINELENGTH], *a85_ptr; |
134 | static guchar a85_buf[LINELENGTH], *a85_ptr; |
… | |
… | |
203 | |
206 | |
204 | OUTPUT: |
207 | OUTPUT: |
205 | RETVAL |
208 | RETVAL |
206 | |
209 | |
207 | const char * |
210 | const char * |
208 | magic (const char *path) |
211 | magic (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 | |
228 | const char * |
231 | const char * |
229 | magic_mime (const char *path) |
232 | magic_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 | |
|
|
254 | void |
|
|
255 | gdk_window_clear_hints (GdkWindow *window) |
|
|
256 | CODE: |
|
|
257 | gdk_window_set_geometry_hints (window, 0, 0); |
250 | |
258 | |
251 | gboolean |
259 | gboolean |
252 | gdk_net_wm_supports (GdkAtom property) |
260 | gdk_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) |
… | |
… | |
394 | compare (GdkPixbuf *a, GdkPixbuf *b) |
402 | compare (GdkPixbuf *a, GdkPixbuf *b) |
395 | PPCODE: |
403 | PPCODE: |
396 | { |
404 | { |
397 | int w = gdk_pixbuf_get_width (a); |
405 | int w = gdk_pixbuf_get_width (a); |
398 | int h = gdk_pixbuf_get_height (a); |
406 | int h = gdk_pixbuf_get_height (a); |
|
|
407 | |
399 | int sa = gdk_pixbuf_get_rowstride (a); |
408 | int sa = gdk_pixbuf_get_rowstride (a); |
400 | int sb = gdk_pixbuf_get_rowstride (b); |
409 | int sb = gdk_pixbuf_get_rowstride (b); |
401 | |
410 | |
402 | guchar *pa = gdk_pixbuf_get_pixels (a); |
411 | guchar *pa = gdk_pixbuf_get_pixels (a); |
403 | guchar *pb = gdk_pixbuf_get_pixels (b); |
412 | guchar *pb = gdk_pixbuf_get_pixels (b); |
… | |
… | |
436 | |
445 | |
437 | ############################################################################# |
446 | ############################################################################# |
438 | |
447 | |
439 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer |
448 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer |
440 | |
449 | |
|
|
450 | # currently only works for filenames (octet strings) |
|
|
451 | |
441 | SV * |
452 | SV * |
442 | foldcase (SV *pathsv) |
453 | foldcase (SV *pathsv) |
443 | PROTOTYPE: $ |
454 | PROTOTYPE: $ |
444 | CODE: |
455 | CODE: |
445 | { |
456 | { |
446 | STRLEN plen; |
457 | STRLEN plen; |
447 | U8 *path = (U8 *)SvPVutf8 (pathsv, plen); |
458 | U8 *path = (U8 *)SvPV (pathsv, plen); |
448 | U8 *pend = path + plen; |
459 | U8 *pend = path + plen; |
449 | U8 dst [plen * 6 * 3], *dstp = dst; |
460 | U8 dst [plen * 6 * 3], *dstp = dst; |
450 | |
461 | |
451 | while (path < pend) |
462 | while (path < pend) |
452 | { |
463 | { |
453 | U8 ch = *path; |
464 | U8 ch = *path; |
454 | |
465 | |
455 | if (ch >= 'a' && ch <= 'z') |
466 | if (ch >= 'a' && ch <= 'z') |
456 | *dstp++ = *path++; |
467 | *dstp++ = *path++; |
|
|
468 | else if (ch >= 'A' && ch <= 'Z') |
|
|
469 | *dstp++ = *path++ + ('a' - 'A'); |
457 | else if (ch >= '0' && ch <= '9') |
470 | else if (ch >= '0' && ch <= '9') |
458 | { |
471 | { |
459 | STRLEN el, nl = 0; |
472 | STRLEN el, nl = 0; |
460 | while (*path >= '0' && *path <= '9' && path < pend) |
473 | while (*path >= '0' && *path <= '9' && path < pend) |
461 | path++, nl++; |
474 | path++, nl++; |
… | |
… | |
464 | *dstp++ = '0'; |
477 | *dstp++ = '0'; |
465 | |
478 | |
466 | memcpy (dstp, path - nl, nl); |
479 | memcpy (dstp, path - nl, nl); |
467 | dstp += nl; |
480 | dstp += nl; |
468 | } |
481 | } |
|
|
482 | else |
|
|
483 | *dstp++ = *path++; |
|
|
484 | #if 0 |
469 | else |
485 | else |
470 | { |
486 | { |
471 | STRLEN cl; |
487 | STRLEN cl; |
472 | to_utf8_fold (path, dstp, &cl); |
488 | to_utf8_fold (path, dstp, &cl); |
473 | dstp += cl; |
489 | dstp += cl; |
474 | path += is_utf8_char (path); |
490 | path += is_utf8_char (path); |
475 | } |
491 | } |
|
|
492 | #endif |
476 | } |
493 | } |
477 | |
494 | |
478 | RETVAL = newSVpvn ((const char *)dst, dstp - dst); |
495 | RETVAL = newSVpvn ((const char *)dst, dstp - dst); |
479 | } |
496 | } |
480 | OUTPUT: |
497 | OUTPUT: |
… | |
… | |
649 | { |
666 | { |
650 | int i; |
667 | int i; |
651 | AV *av, *result; |
668 | AV *av, *result; |
652 | |
669 | |
653 | if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV) |
670 | if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV) |
654 | croak ("Not an array ref as first argument to make_histogram"); |
671 | croak ("Not an array ref as first argument to extract_features"); |
655 | |
672 | |
656 | av = (AV *) SvRV (ar); |
673 | av = (AV *) SvRV (ar); |
657 | result = newAV (); |
674 | result = newAV (); |
658 | |
675 | |
659 | for (i = 0; i <= av_len (av); ++i) |
676 | for (i = 0; i <= av_len (av); ++i) |
… | |
… | |
712 | feature_finish_pass_2 (&f_v); |
729 | feature_finish_pass_2 (&f_v); |
713 | } |
730 | } |
714 | |
731 | |
715 | hist [0] = f_h.v1 * 2.; hist [1] = f_h.v2 * 2.; hist [2] = f_h.v3 * 2.; |
732 | 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 ; |
733 | 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 ; |
734 | hist [6] = f_v.v1 * .5; hist [7] = f_v.v2 * .5; hist [8] = f_v.v3 * .5; |
718 | |
735 | |
719 | av_push (result, histsv); |
736 | av_push (result, histsv); |
720 | } |
737 | } |
721 | |
738 | |
722 | RETVAL = newRV_noinc ((SV *)result); |
739 | RETVAL = newRV_noinc ((SV *)result); |
723 | } |
740 | } |
724 | OUTPUT: |
741 | OUTPUT: |
725 | RETVAL |
742 | RETVAL |
726 | |
743 | |
727 | SV * |
|
|
728 | make_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 | |
|
|