1 | #include "EXTERN.h" |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
4 | |
4 | |
|
|
5 | #include <string.h> |
5 | #include <setjmp.h> |
6 | #include <setjmp.h> |
6 | |
7 | |
7 | #include <jpeglib.h> |
8 | #include <jpeglib.h> |
8 | #include <gdk-pixbuf/gdk-pixbuf.h> |
9 | #include <gdk-pixbuf/gdk-pixbuf.h> |
9 | |
10 | |
… | |
… | |
268 | |
269 | |
269 | ############################################################################# |
270 | ############################################################################# |
270 | |
271 | |
271 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer |
272 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer |
272 | |
273 | |
|
|
274 | SV * |
|
|
275 | foldcase (SV *pathsv) |
|
|
276 | PROTOTYPE: $ |
|
|
277 | CODE: |
|
|
278 | { |
|
|
279 | STRLEN plen; |
|
|
280 | U8 *path = SvPVutf8 (pathsv, plen); |
|
|
281 | U8 *pend = path + plen; |
|
|
282 | U8 dst [plen * 6 * 3], *dstp = dst; |
|
|
283 | |
|
|
284 | while (path < pend) |
|
|
285 | { |
|
|
286 | U8 ch = *path; |
|
|
287 | |
|
|
288 | if (ch >= 'a' && ch <= 'z') |
|
|
289 | *dstp++ = *path++; |
|
|
290 | else if (ch >= '0' && ch <= '9') |
|
|
291 | { |
|
|
292 | STRLEN el, nl = 0; |
|
|
293 | while (*path >= '0' && *path <= '9' && path < pend) |
|
|
294 | path++, nl++; |
|
|
295 | |
|
|
296 | for (el = nl; el < 6; el++) |
|
|
297 | *dstp++ = '0'; |
|
|
298 | |
|
|
299 | memcpy (dstp, path - nl, nl); |
|
|
300 | dstp += nl; |
|
|
301 | } |
|
|
302 | else |
|
|
303 | { |
|
|
304 | STRLEN cl; |
|
|
305 | to_utf8_fold (path, dstp, &cl); |
|
|
306 | dstp += cl; |
|
|
307 | path += is_utf8_char (path); |
|
|
308 | } |
|
|
309 | } |
|
|
310 | |
|
|
311 | RETVAL = newSVpvn (dst, dstp - dst); |
|
|
312 | } |
|
|
313 | OUTPUT: |
|
|
314 | RETVAL |
|
|
315 | |
273 | GdkPixbuf_noinc * |
316 | GdkPixbuf_noinc * |
274 | p7_to_pb (int w, int h, guchar *src) |
317 | p7_to_pb (int w, int h, guchar *src) |
275 | CODE: |
318 | CODE: |
276 | { |
319 | { |
277 | int x, y; |
320 | int x, y; |
… | |
… | |
351 | } |
394 | } |
352 | } |
395 | } |
353 | OUTPUT: |
396 | OUTPUT: |
354 | RETVAL |
397 | RETVAL |
355 | |
398 | |
356 | SV * |
|
|
357 | make_histogram (SV *ar) |
|
|
358 | CODE: |
|
|
359 | { |
|
|
360 | int i; |
|
|
361 | AV *av, *result; |
|
|
362 | |
|
|
363 | if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV) |
|
|
364 | croak ("Not an array ref as first argument to make_histogram"); |
|
|
365 | |
|
|
366 | av = (AV *) SvRV (ar); |
|
|
367 | result = newAV (); |
|
|
368 | |
|
|
369 | for (i = 0; i <= av_len (av); ++i) |
|
|
370 | { |
|
|
371 | const int HISTSIZE = 64; |
|
|
372 | |
|
|
373 | int j; |
|
|
374 | SV *sv = *av_fetch (av, i, 1); |
|
|
375 | STRLEN len; |
|
|
376 | char *buf = SvPVbyte (sv, len); |
|
|
377 | |
|
|
378 | int tmphist[HISTSIZE]; |
|
|
379 | float *hist; |
|
|
380 | |
|
|
381 | SV *histsv = newSV (HISTSIZE * sizeof (float) + 1); |
|
|
382 | SvPOK_on (histsv); |
|
|
383 | SvCUR_set (histsv, HISTSIZE * sizeof (float)); |
|
|
384 | hist = (float *)SvPVX (histsv); |
|
|
385 | |
|
|
386 | Zero (tmphist, sizeof (tmphist), char); |
|
|
387 | |
|
|
388 | for (j = len; j--; ) |
|
|
389 | { |
|
|
390 | unsigned int idx |
|
|
391 | = ((*buf & 0xc0) >> 2) |
|
|
392 | | ((*buf & 0x18) >> 1) |
|
|
393 | | (*buf & 0x03); |
|
|
394 | |
|
|
395 | ++tmphist[idx]; |
|
|
396 | ++buf; |
|
|
397 | } |
|
|
398 | |
|
|
399 | for (j = 0; j < HISTSIZE; ++j) |
|
|
400 | hist[j] = (float)tmphist[j] / (len + 1e-30); |
|
|
401 | |
|
|
402 | av_push (result, histsv); |
|
|
403 | } |
|
|
404 | |
|
|
405 | RETVAL = newRV_noinc ((SV *)result); |
|
|
406 | } |
|
|
407 | OUTPUT: |
|
|
408 | RETVAL |
|
|
409 | |
|
|
410 | ############################################################################# |
399 | ############################################################################# |
411 | |
400 | |
412 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript |
401 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript |
413 | |
402 | |
414 | void |
403 | void |
… | |
… | |
537 | } |
526 | } |
538 | } |
527 | } |
539 | OUTPUT: |
528 | OUTPUT: |
540 | RETVAL |
529 | RETVAL |
541 | |
530 | |
|
|
531 | ############################################################################# |
542 | |
532 | |
|
|
533 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Plugin::RCluster |
543 | |
534 | |
|
|
535 | SV * |
|
|
536 | make_histograms (SV *ar) |
|
|
537 | CODE: |
|
|
538 | { |
|
|
539 | int i; |
|
|
540 | AV *av, *result; |
|
|
541 | |
|
|
542 | if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV) |
|
|
543 | croak ("Not an array ref as first argument to make_histogram"); |
|
|
544 | |
|
|
545 | av = (AV *) SvRV (ar); |
|
|
546 | result = newAV (); |
|
|
547 | |
|
|
548 | for (i = 0; i <= av_len (av); ++i) |
|
|
549 | { |
|
|
550 | const int HISTSIZE = 64; |
|
|
551 | |
|
|
552 | int j; |
|
|
553 | SV *sv = *av_fetch (av, i, 1); |
|
|
554 | STRLEN len; |
|
|
555 | char *buf = SvPVbyte (sv, len); |
|
|
556 | |
|
|
557 | int tmphist[HISTSIZE]; |
|
|
558 | float *hist; |
|
|
559 | |
|
|
560 | SV *histsv = newSV (HISTSIZE * sizeof (float) + 1); |
|
|
561 | SvPOK_on (histsv); |
|
|
562 | SvCUR_set (histsv, HISTSIZE * sizeof (float)); |
|
|
563 | hist = (float *)SvPVX (histsv); |
|
|
564 | |
|
|
565 | Zero (tmphist, sizeof (tmphist), char); |
|
|
566 | |
|
|
567 | for (j = len; j--; ) |
|
|
568 | { |
|
|
569 | unsigned int idx |
|
|
570 | = ((*buf & 0xc0) >> 2) |
|
|
571 | | ((*buf & 0x18) >> 1) |
|
|
572 | | (*buf & 0x03); |
|
|
573 | |
|
|
574 | ++tmphist[idx]; |
|
|
575 | ++buf; |
|
|
576 | } |
|
|
577 | |
|
|
578 | for (j = 0; j < HISTSIZE; ++j) |
|
|
579 | hist[j] = (float)tmphist[j] / (len + 1e-30); |
|
|
580 | |
|
|
581 | av_push (result, histsv); |
|
|
582 | } |
|
|
583 | |
|
|
584 | RETVAL = newRV_noinc ((SV *)result); |
|
|
585 | } |
|
|
586 | OUTPUT: |
|
|
587 | RETVAL |
|
|
588 | |
|
|
589 | |