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> |
|
|
9 | #include <glib.h> |
|
|
10 | #include <gtk/gtk.h> |
8 | #include <gdk-pixbuf/gdk-pixbuf.h> |
11 | #include <gdk-pixbuf/gdk-pixbuf.h> |
9 | |
12 | |
10 | #include <gperl.h> |
13 | #include <gperl.h> |
11 | #include <gtk2perl.h> |
14 | #include <gtk2perl.h> |
12 | |
15 | |
… | |
… | |
123 | |
126 | |
124 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV |
127 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV |
125 | |
128 | |
126 | PROTOTYPES: ENABLE |
129 | PROTOTYPES: ENABLE |
127 | |
130 | |
|
|
131 | # missing in Gtk2 perl module |
|
|
132 | |
|
|
133 | gboolean |
|
|
134 | gdk_net_wm_supports (GdkAtom property) |
|
|
135 | CODE: |
|
|
136 | #if defined(GDK_WINDOWING_X11) && !defined(GDK_MULTIHEAD_SAFE) |
|
|
137 | RETVAL = gdk_net_wm_supports (property); |
|
|
138 | #else |
|
|
139 | RETVAL = 0; |
|
|
140 | #endif |
|
|
141 | OUTPUT: |
|
|
142 | RETVAL |
|
|
143 | |
128 | GdkPixbuf_noinc * |
144 | GdkPixbuf_noinc * |
129 | transpose (GdkPixbuf *pb) |
145 | dealpha_expose (GdkPixbuf *pb) |
130 | CODE: |
146 | CODE: |
131 | { |
147 | { |
132 | int w = gdk_pixbuf_get_width (pb); |
148 | int w = gdk_pixbuf_get_width (pb); |
133 | int h = gdk_pixbuf_get_height (pb); |
149 | int h = gdk_pixbuf_get_height (pb); |
134 | int bpp = gdk_pixbuf_get_n_channels (pb); |
150 | int bpp = gdk_pixbuf_get_n_channels (pb); |
135 | int x, y, i; |
151 | int x, y, i; |
136 | guchar *src = gdk_pixbuf_get_pixels (pb), *dst; |
152 | guchar *src = gdk_pixbuf_get_pixels (pb), *dst; |
137 | int sstr = gdk_pixbuf_get_rowstride (pb), dstr; |
153 | int sstr = gdk_pixbuf_get_rowstride (pb), dstr; |
138 | |
154 | |
139 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, h, w); |
155 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
140 | |
156 | |
141 | dst = gdk_pixbuf_get_pixels (RETVAL); |
157 | dst = gdk_pixbuf_get_pixels (RETVAL); |
142 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
158 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
143 | |
159 | |
144 | for (y = 0; y < h; y++) |
|
|
145 | for (x = 0; x < w; x++) |
160 | for (x = 0; x < w; x++) |
|
|
161 | for (y = 0; y < h; y++) |
146 | for (i = 0; i < bpp; i++) |
162 | for (i = 0; i < 3; i++) |
147 | dst[y * bpp + x * dstr + i] = src[x * bpp + y * sstr + i]; |
163 | dst[x * 3 + y * dstr + i] = src[x * bpp + y * sstr + i]; |
148 | } |
164 | } |
149 | OUTPUT: |
165 | OUTPUT: |
150 | RETVAL |
166 | RETVAL |
151 | |
167 | |
152 | GdkPixbuf_noinc * |
168 | GdkPixbuf_noinc * |
153 | flop (GdkPixbuf *pb) |
169 | transpose (GdkPixbuf *pb) |
154 | CODE: |
170 | CODE: |
155 | { |
171 | { |
156 | int w = gdk_pixbuf_get_width (pb); |
172 | int w = gdk_pixbuf_get_width (pb); |
157 | int h = gdk_pixbuf_get_height (pb); |
173 | int h = gdk_pixbuf_get_height (pb); |
158 | int bpp = gdk_pixbuf_get_n_channels (pb); |
174 | int bpp = gdk_pixbuf_get_n_channels (pb); |
159 | int x, y, i; |
175 | int x, y, i; |
160 | guchar *src = gdk_pixbuf_get_pixels (pb), *dst; |
176 | guchar *src = gdk_pixbuf_get_pixels (pb), *dst; |
161 | int sstr = gdk_pixbuf_get_rowstride (pb), dstr; |
177 | int sstr = gdk_pixbuf_get_rowstride (pb), dstr; |
162 | |
178 | |
|
|
179 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, h, w); |
|
|
180 | |
|
|
181 | dst = gdk_pixbuf_get_pixels (RETVAL); |
|
|
182 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
|
|
183 | |
|
|
184 | for (y = 0; y < h; y++) |
|
|
185 | for (x = 0; x < w; x++) |
|
|
186 | for (i = 0; i < bpp; i++) |
|
|
187 | dst[y * bpp + x * dstr + i] = src[x * bpp + y * sstr + i]; |
|
|
188 | } |
|
|
189 | OUTPUT: |
|
|
190 | RETVAL |
|
|
191 | |
|
|
192 | GdkPixbuf_noinc * |
|
|
193 | flop (GdkPixbuf *pb) |
|
|
194 | CODE: |
|
|
195 | { |
|
|
196 | int w = gdk_pixbuf_get_width (pb); |
|
|
197 | int h = gdk_pixbuf_get_height (pb); |
|
|
198 | int bpp = gdk_pixbuf_get_n_channels (pb); |
|
|
199 | int x, y, i; |
|
|
200 | guchar *src = gdk_pixbuf_get_pixels (pb), *dst; |
|
|
201 | int sstr = gdk_pixbuf_get_rowstride (pb), dstr; |
|
|
202 | |
163 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, w, h); |
203 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, w, h); |
164 | |
204 | |
165 | dst = gdk_pixbuf_get_pixels (RETVAL); |
205 | dst = gdk_pixbuf_get_pixels (RETVAL); |
166 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
206 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
167 | |
207 | |
… | |
… | |
172 | } |
212 | } |
173 | OUTPUT: |
213 | OUTPUT: |
174 | RETVAL |
214 | RETVAL |
175 | |
215 | |
176 | GdkPixbuf_noinc * |
216 | GdkPixbuf_noinc * |
177 | load_jpeg (char *path, int thumbnail=0) |
217 | load_jpeg (SV *path, int thumbnail=0) |
178 | CODE: |
218 | CODE: |
179 | { |
219 | { |
180 | struct jpeg_decompress_struct cinfo; |
220 | struct jpeg_decompress_struct cinfo; |
181 | struct jpg_err_mgr jerr; |
221 | struct jpg_err_mgr jerr; |
182 | guchar *data; |
222 | guchar *data; |
183 | int rs; |
223 | int rs; |
184 | FILE *fp; |
224 | FILE *fp; |
185 | volatile GdkPixbuf *pb = 0; |
225 | volatile GdkPixbuf *pb = 0; |
|
|
226 | gchar *filename; |
|
|
227 | |
186 | RETVAL = 0; |
228 | RETVAL = 0; |
187 | |
229 | |
188 | if (!(fp = fopen (path, "rb"))) |
230 | filename = g_filename_from_utf8 (SvPVutf8_nolen (path), -1, 0, 0, 0); |
|
|
231 | fp = fopen (filename, "rb"); |
|
|
232 | g_free (filename); |
|
|
233 | |
|
|
234 | if (!fp) |
189 | XSRETURN_UNDEF; |
235 | XSRETURN_UNDEF; |
190 | |
236 | |
191 | cinfo.err = jpeg_std_error (&jerr.err); |
237 | cinfo.err = jpeg_std_error (&jerr.err); |
192 | |
238 | |
193 | jerr.err.error_exit = cv_error_exit; |
239 | jerr.err.error_exit = cv_error_exit; |
… | |
… | |
224 | { |
270 | { |
225 | cinfo.dct_method = JDCT_FASTEST; |
271 | cinfo.dct_method = JDCT_FASTEST; |
226 | cinfo.do_fancy_upsampling = FALSE; |
272 | cinfo.do_fancy_upsampling = FALSE; |
227 | |
273 | |
228 | while (cinfo.scale_denom < 8 |
274 | while (cinfo.scale_denom < 8 |
229 | && (cinfo.output_width >> 1) >= IW |
275 | && cinfo.output_width >= IW*4 |
230 | && (cinfo.output_height >> 1) >= IH) |
276 | && cinfo.output_height >= IH*4) |
231 | { |
277 | { |
232 | cinfo.scale_denom <<= 1; |
278 | cinfo.scale_denom <<= 1; |
233 | jpeg_calc_output_dimensions (&cinfo); |
279 | jpeg_calc_output_dimensions (&cinfo); |
234 | } |
280 | } |
235 | } |
281 | } |
… | |
… | |
268 | |
314 | |
269 | ############################################################################# |
315 | ############################################################################# |
270 | |
316 | |
271 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer |
317 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer |
272 | |
318 | |
|
|
319 | SV * |
|
|
320 | foldcase (SV *pathsv) |
|
|
321 | PROTOTYPE: $ |
|
|
322 | CODE: |
|
|
323 | { |
|
|
324 | STRLEN plen; |
|
|
325 | U8 *path = (U8 *)SvPVutf8 (pathsv, plen); |
|
|
326 | U8 *pend = path + plen; |
|
|
327 | U8 dst [plen * 6 * 3], *dstp = dst; |
|
|
328 | |
|
|
329 | while (path < pend) |
|
|
330 | { |
|
|
331 | U8 ch = *path; |
|
|
332 | |
|
|
333 | if (ch >= 'a' && ch <= 'z') |
|
|
334 | *dstp++ = *path++; |
|
|
335 | else if (ch >= '0' && ch <= '9') |
|
|
336 | { |
|
|
337 | STRLEN el, nl = 0; |
|
|
338 | while (*path >= '0' && *path <= '9' && path < pend) |
|
|
339 | path++, nl++; |
|
|
340 | |
|
|
341 | for (el = nl; el < 6; el++) |
|
|
342 | *dstp++ = '0'; |
|
|
343 | |
|
|
344 | memcpy (dstp, path - nl, nl); |
|
|
345 | dstp += nl; |
|
|
346 | } |
|
|
347 | else |
|
|
348 | { |
|
|
349 | STRLEN cl; |
|
|
350 | to_utf8_fold (path, dstp, &cl); |
|
|
351 | dstp += cl; |
|
|
352 | path += is_utf8_char (path); |
|
|
353 | } |
|
|
354 | } |
|
|
355 | |
|
|
356 | RETVAL = newSVpvn ((const char *)dst, dstp - dst); |
|
|
357 | } |
|
|
358 | OUTPUT: |
|
|
359 | RETVAL |
|
|
360 | |
273 | GdkPixbuf_noinc * |
361 | GdkPixbuf_noinc * |
274 | p7_to_pb (int w, int h, guchar *src) |
362 | p7_to_pb (int w, int h, SV *src_sv) |
|
|
363 | PROTOTYPE: @ |
275 | CODE: |
364 | CODE: |
276 | { |
365 | { |
277 | int x, y; |
366 | int x, y; |
278 | guchar *dst, *d; |
367 | guchar *dst, *d; |
279 | int dstr; |
368 | int dstr; |
|
|
369 | guchar *src = (guchar *)SvPVbyte_nolen (src_sv); |
280 | |
370 | |
281 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
371 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
282 | dst = gdk_pixbuf_get_pixels (RETVAL); |
372 | dst = gdk_pixbuf_get_pixels (RETVAL); |
283 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
373 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
284 | |
374 | |
… | |
… | |
311 | |
401 | |
312 | RETVAL = newSV (w * h); |
402 | RETVAL = newSV (w * h); |
313 | SvPOK_only (RETVAL); |
403 | SvPOK_only (RETVAL); |
314 | SvCUR_set (RETVAL, w * h); |
404 | SvCUR_set (RETVAL, w * h); |
315 | |
405 | |
316 | dst = SvPVX (RETVAL); |
406 | dst = (guchar *)SvPVX (RETVAL); |
317 | |
407 | |
318 | memset (Er, 0, sizeof (int) * IW); |
408 | memset (Er, 0, sizeof (int) * IW); |
319 | memset (Eg, 0, sizeof (int) * IW); |
409 | memset (Eg, 0, sizeof (int) * IW); |
320 | memset (Eb, 0, sizeof (int) * IW); |
410 | memset (Eb, 0, sizeof (int) * IW); |
321 | |
411 | |
… | |
… | |
349 | *dst++ = r << 5 | g << 2 | b; |
439 | *dst++ = r << 5 | g << 2 | b; |
350 | } |
440 | } |
351 | } |
441 | } |
352 | } |
442 | } |
353 | OUTPUT: |
443 | OUTPUT: |
354 | RETVAL |
|
|
355 | |
|
|
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 |
444 | RETVAL |
409 | |
445 | |
410 | ############################################################################# |
446 | ############################################################################# |
411 | |
447 | |
412 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript |
448 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript |
… | |
… | |
469 | |
505 | |
470 | RETVAL = newSV (6 * 8 * 12 / 8); |
506 | RETVAL = newSV (6 * 8 * 12 / 8); |
471 | SvPOK_only (RETVAL); |
507 | SvPOK_only (RETVAL); |
472 | SvCUR_set (RETVAL, 6 * 8 * 12 / 8); |
508 | SvCUR_set (RETVAL, 6 * 8 * 12 / 8); |
473 | |
509 | |
474 | dst = SvPVX (RETVAL); |
510 | dst = (guchar *)SvPVX (RETVAL); |
475 | |
511 | |
476 | /* some primitive error distribution + random dithering */ |
512 | /* some primitive error distribution + random dithering */ |
477 | |
513 | |
478 | for (y = 0; y < h; y++) |
514 | for (y = 0; y < h; y++) |
479 | { |
515 | { |
… | |
… | |
537 | } |
573 | } |
538 | } |
574 | } |
539 | OUTPUT: |
575 | OUTPUT: |
540 | RETVAL |
576 | RETVAL |
541 | |
577 | |
|
|
578 | ############################################################################# |
542 | |
579 | |
|
|
580 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Plugin::RCluster |
543 | |
581 | |
|
|
582 | SV * |
|
|
583 | make_histograms (SV *ar) |
|
|
584 | CODE: |
|
|
585 | { |
|
|
586 | int i; |
|
|
587 | AV *av, *result; |
|
|
588 | |
|
|
589 | if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV) |
|
|
590 | croak ("Not an array ref as first argument to make_histogram"); |
|
|
591 | |
|
|
592 | av = (AV *) SvRV (ar); |
|
|
593 | result = newAV (); |
|
|
594 | |
|
|
595 | for (i = 0; i <= av_len (av); ++i) |
|
|
596 | { |
|
|
597 | const int HISTSIZE = 64; |
|
|
598 | |
|
|
599 | int j; |
|
|
600 | SV *sv = *av_fetch (av, i, 1); |
|
|
601 | STRLEN len; |
|
|
602 | char *buf = SvPVbyte (sv, len); |
|
|
603 | |
|
|
604 | int tmphist[HISTSIZE]; |
|
|
605 | float *hist; |
|
|
606 | |
|
|
607 | SV *histsv = newSV (HISTSIZE * sizeof (float) + 1); |
|
|
608 | SvPOK_on (histsv); |
|
|
609 | SvCUR_set (histsv, HISTSIZE * sizeof (float)); |
|
|
610 | hist = (float *)SvPVX (histsv); |
|
|
611 | |
|
|
612 | Zero (tmphist, sizeof (tmphist), char); |
|
|
613 | |
|
|
614 | for (j = len; j--; ) |
|
|
615 | { |
|
|
616 | unsigned int idx |
|
|
617 | = ((*buf & 0xc0) >> 2) |
|
|
618 | | ((*buf & 0x18) >> 1) |
|
|
619 | | (*buf & 0x03); |
|
|
620 | |
|
|
621 | ++tmphist[idx]; |
|
|
622 | ++buf; |
|
|
623 | } |
|
|
624 | |
|
|
625 | for (j = 0; j < HISTSIZE; ++j) |
|
|
626 | hist[j] = (float)tmphist[j] / (len + 1e-30); |
|
|
627 | |
|
|
628 | av_push (result, histsv); |
|
|
629 | } |
|
|
630 | |
|
|
631 | RETVAL = newRV_noinc ((SV *)result); |
|
|
632 | } |
|
|
633 | OUTPUT: |
|
|
634 | RETVAL |
|
|
635 | |
|
|
636 | |