… | |
… | |
4 | |
4 | |
5 | #include <string.h> |
5 | #include <string.h> |
6 | #include <setjmp.h> |
6 | #include <setjmp.h> |
7 | |
7 | |
8 | #include <jpeglib.h> |
8 | #include <jpeglib.h> |
|
|
9 | #include <glib.h> |
|
|
10 | #include <gtk/gtk.h> |
9 | #include <gdk-pixbuf/gdk-pixbuf.h> |
11 | #include <gdk-pixbuf/gdk-pixbuf.h> |
10 | |
12 | |
11 | #include <gperl.h> |
13 | #include <gperl.h> |
12 | #include <gtk2perl.h> |
14 | #include <gtk2perl.h> |
13 | |
15 | |
… | |
… | |
124 | |
126 | |
125 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV |
127 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV |
126 | |
128 | |
127 | PROTOTYPES: ENABLE |
129 | PROTOTYPES: ENABLE |
128 | |
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 | |
129 | GdkPixbuf_noinc * |
144 | GdkPixbuf_noinc * |
130 | transpose (GdkPixbuf *pb) |
145 | dealpha_expose (GdkPixbuf *pb) |
131 | CODE: |
146 | CODE: |
132 | { |
147 | { |
133 | int w = gdk_pixbuf_get_width (pb); |
148 | int w = gdk_pixbuf_get_width (pb); |
134 | int h = gdk_pixbuf_get_height (pb); |
149 | int h = gdk_pixbuf_get_height (pb); |
135 | int bpp = gdk_pixbuf_get_n_channels (pb); |
150 | int bpp = gdk_pixbuf_get_n_channels (pb); |
136 | int x, y, i; |
151 | int x, y, i; |
137 | guchar *src = gdk_pixbuf_get_pixels (pb), *dst; |
152 | guchar *src = gdk_pixbuf_get_pixels (pb), *dst; |
138 | int sstr = gdk_pixbuf_get_rowstride (pb), dstr; |
153 | int sstr = gdk_pixbuf_get_rowstride (pb), dstr; |
139 | |
154 | |
140 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, h, w); |
155 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
141 | |
156 | |
142 | dst = gdk_pixbuf_get_pixels (RETVAL); |
157 | dst = gdk_pixbuf_get_pixels (RETVAL); |
143 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
158 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
144 | |
159 | |
145 | for (y = 0; y < h; y++) |
|
|
146 | for (x = 0; x < w; x++) |
160 | for (x = 0; x < w; x++) |
|
|
161 | for (y = 0; y < h; y++) |
147 | for (i = 0; i < bpp; i++) |
162 | for (i = 0; i < 3; i++) |
148 | 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]; |
149 | } |
164 | } |
150 | OUTPUT: |
165 | OUTPUT: |
151 | RETVAL |
166 | RETVAL |
152 | |
167 | |
153 | GdkPixbuf_noinc * |
168 | GdkPixbuf_noinc * |
154 | flop (GdkPixbuf *pb) |
169 | transpose (GdkPixbuf *pb) |
155 | CODE: |
170 | CODE: |
156 | { |
171 | { |
157 | int w = gdk_pixbuf_get_width (pb); |
172 | int w = gdk_pixbuf_get_width (pb); |
158 | int h = gdk_pixbuf_get_height (pb); |
173 | int h = gdk_pixbuf_get_height (pb); |
159 | int bpp = gdk_pixbuf_get_n_channels (pb); |
174 | int bpp = gdk_pixbuf_get_n_channels (pb); |
160 | int x, y, i; |
175 | int x, y, i; |
161 | guchar *src = gdk_pixbuf_get_pixels (pb), *dst; |
176 | guchar *src = gdk_pixbuf_get_pixels (pb), *dst; |
162 | int sstr = gdk_pixbuf_get_rowstride (pb), dstr; |
177 | int sstr = gdk_pixbuf_get_rowstride (pb), dstr; |
163 | |
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 | |
164 | 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); |
165 | |
204 | |
166 | dst = gdk_pixbuf_get_pixels (RETVAL); |
205 | dst = gdk_pixbuf_get_pixels (RETVAL); |
167 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
206 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
168 | |
207 | |
… | |
… | |
173 | } |
212 | } |
174 | OUTPUT: |
213 | OUTPUT: |
175 | RETVAL |
214 | RETVAL |
176 | |
215 | |
177 | GdkPixbuf_noinc * |
216 | GdkPixbuf_noinc * |
178 | load_jpeg (char *path, int thumbnail=0) |
217 | load_jpeg (SV *path, int thumbnail=0) |
179 | CODE: |
218 | CODE: |
180 | { |
219 | { |
181 | struct jpeg_decompress_struct cinfo; |
220 | struct jpeg_decompress_struct cinfo; |
182 | struct jpg_err_mgr jerr; |
221 | struct jpg_err_mgr jerr; |
183 | guchar *data; |
222 | guchar *data; |
184 | int rs; |
223 | int rs; |
185 | FILE *fp; |
224 | FILE *fp; |
186 | volatile GdkPixbuf *pb = 0; |
225 | volatile GdkPixbuf *pb = 0; |
|
|
226 | gchar *filename; |
|
|
227 | |
187 | RETVAL = 0; |
228 | RETVAL = 0; |
188 | |
229 | |
189 | 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) |
190 | XSRETURN_UNDEF; |
235 | XSRETURN_UNDEF; |
191 | |
236 | |
192 | cinfo.err = jpeg_std_error (&jerr.err); |
237 | cinfo.err = jpeg_std_error (&jerr.err); |
193 | |
238 | |
194 | jerr.err.error_exit = cv_error_exit; |
239 | jerr.err.error_exit = cv_error_exit; |
… | |
… | |
225 | { |
270 | { |
226 | cinfo.dct_method = JDCT_FASTEST; |
271 | cinfo.dct_method = JDCT_FASTEST; |
227 | cinfo.do_fancy_upsampling = FALSE; |
272 | cinfo.do_fancy_upsampling = FALSE; |
228 | |
273 | |
229 | while (cinfo.scale_denom < 8 |
274 | while (cinfo.scale_denom < 8 |
230 | && (cinfo.output_width >> 1) >= IW |
275 | && cinfo.output_width >= IW*4 |
231 | && (cinfo.output_height >> 1) >= IH) |
276 | && cinfo.output_height >= IH*4) |
232 | { |
277 | { |
233 | cinfo.scale_denom <<= 1; |
278 | cinfo.scale_denom <<= 1; |
234 | jpeg_calc_output_dimensions (&cinfo); |
279 | jpeg_calc_output_dimensions (&cinfo); |
235 | } |
280 | } |
236 | } |
281 | } |
… | |
… | |
275 | foldcase (SV *pathsv) |
320 | foldcase (SV *pathsv) |
276 | PROTOTYPE: $ |
321 | PROTOTYPE: $ |
277 | CODE: |
322 | CODE: |
278 | { |
323 | { |
279 | STRLEN plen; |
324 | STRLEN plen; |
280 | U8 *path = SvPVutf8 (pathsv, plen); |
325 | U8 *path = (U8 *)SvPVutf8 (pathsv, plen); |
281 | U8 *pend = path + plen; |
326 | U8 *pend = path + plen; |
282 | U8 dst [plen * 6 * 3], *dstp = dst; |
327 | U8 dst [plen * 6 * 3], *dstp = dst; |
283 | |
328 | |
284 | while (path < pend) |
329 | while (path < pend) |
285 | { |
330 | { |
|
|
331 | U8 ch = *path; |
|
|
332 | |
286 | if (*path >= '0' && *path <= '9') |
333 | if (ch >= 'a' && ch <= 'z') |
|
|
334 | *dstp++ = *path++; |
|
|
335 | else if (ch >= '0' && ch <= '9') |
287 | { |
336 | { |
288 | STRLEN el, nl = 0; |
337 | STRLEN el, nl = 0; |
289 | while (*path >= '0' && *path <= '9') |
338 | while (*path >= '0' && *path <= '9' && path < pend) |
290 | path++, nl++; |
339 | path++, nl++; |
291 | |
340 | |
292 | for (el = nl; el < 6; el++) |
341 | for (el = nl; el < 6; el++) |
293 | *dstp++ = '0'; |
342 | *dstp++ = '0'; |
294 | |
343 | |
… | |
… | |
302 | dstp += cl; |
351 | dstp += cl; |
303 | path += is_utf8_char (path); |
352 | path += is_utf8_char (path); |
304 | } |
353 | } |
305 | } |
354 | } |
306 | |
355 | |
307 | RETVAL = newSVpvn (dst, dstp - dst); |
356 | RETVAL = newSVpvn ((const char *)dst, dstp - dst); |
308 | } |
357 | } |
309 | OUTPUT: |
358 | OUTPUT: |
310 | RETVAL |
359 | RETVAL |
311 | |
360 | |
312 | GdkPixbuf_noinc * |
361 | GdkPixbuf_noinc * |
313 | p7_to_pb (int w, int h, guchar *src) |
362 | p7_to_pb (int w, int h, SV *src_sv) |
|
|
363 | PROTOTYPE: @ |
314 | CODE: |
364 | CODE: |
315 | { |
365 | { |
316 | int x, y; |
366 | int x, y; |
317 | guchar *dst, *d; |
367 | guchar *dst, *d; |
318 | int dstr; |
368 | int dstr; |
|
|
369 | guchar *src = (guchar *)SvPVbyte_nolen (src_sv); |
319 | |
370 | |
320 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
371 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
321 | dst = gdk_pixbuf_get_pixels (RETVAL); |
372 | dst = gdk_pixbuf_get_pixels (RETVAL); |
322 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
373 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
323 | |
374 | |
… | |
… | |
350 | |
401 | |
351 | RETVAL = newSV (w * h); |
402 | RETVAL = newSV (w * h); |
352 | SvPOK_only (RETVAL); |
403 | SvPOK_only (RETVAL); |
353 | SvCUR_set (RETVAL, w * h); |
404 | SvCUR_set (RETVAL, w * h); |
354 | |
405 | |
355 | dst = SvPVX (RETVAL); |
406 | dst = (guchar *)SvPVX (RETVAL); |
356 | |
407 | |
357 | memset (Er, 0, sizeof (int) * IW); |
408 | memset (Er, 0, sizeof (int) * IW); |
358 | memset (Eg, 0, sizeof (int) * IW); |
409 | memset (Eg, 0, sizeof (int) * IW); |
359 | memset (Eb, 0, sizeof (int) * IW); |
410 | memset (Eb, 0, sizeof (int) * IW); |
360 | |
411 | |
… | |
… | |
388 | *dst++ = r << 5 | g << 2 | b; |
439 | *dst++ = r << 5 | g << 2 | b; |
389 | } |
440 | } |
390 | } |
441 | } |
391 | } |
442 | } |
392 | OUTPUT: |
443 | OUTPUT: |
393 | RETVAL |
|
|
394 | |
|
|
395 | SV * |
|
|
396 | make_histogram (SV *ar) |
|
|
397 | CODE: |
|
|
398 | { |
|
|
399 | int i; |
|
|
400 | AV *av, *result; |
|
|
401 | |
|
|
402 | if (!SvROK (ar) || SvTYPE (SvRV (ar)) != SVt_PVAV) |
|
|
403 | croak ("Not an array ref as first argument to make_histogram"); |
|
|
404 | |
|
|
405 | av = (AV *) SvRV (ar); |
|
|
406 | result = newAV (); |
|
|
407 | |
|
|
408 | for (i = 0; i <= av_len (av); ++i) |
|
|
409 | { |
|
|
410 | const int HISTSIZE = 64; |
|
|
411 | |
|
|
412 | int j; |
|
|
413 | SV *sv = *av_fetch (av, i, 1); |
|
|
414 | STRLEN len; |
|
|
415 | char *buf = SvPVbyte (sv, len); |
|
|
416 | |
|
|
417 | int tmphist[HISTSIZE]; |
|
|
418 | float *hist; |
|
|
419 | |
|
|
420 | SV *histsv = newSV (HISTSIZE * sizeof (float) + 1); |
|
|
421 | SvPOK_on (histsv); |
|
|
422 | SvCUR_set (histsv, HISTSIZE * sizeof (float)); |
|
|
423 | hist = (float *)SvPVX (histsv); |
|
|
424 | |
|
|
425 | Zero (tmphist, sizeof (tmphist), char); |
|
|
426 | |
|
|
427 | for (j = len; j--; ) |
|
|
428 | { |
|
|
429 | unsigned int idx |
|
|
430 | = ((*buf & 0xc0) >> 2) |
|
|
431 | | ((*buf & 0x18) >> 1) |
|
|
432 | | (*buf & 0x03); |
|
|
433 | |
|
|
434 | ++tmphist[idx]; |
|
|
435 | ++buf; |
|
|
436 | } |
|
|
437 | |
|
|
438 | for (j = 0; j < HISTSIZE; ++j) |
|
|
439 | hist[j] = (float)tmphist[j] / (len + 1e-30); |
|
|
440 | |
|
|
441 | av_push (result, histsv); |
|
|
442 | } |
|
|
443 | |
|
|
444 | RETVAL = newRV_noinc ((SV *)result); |
|
|
445 | } |
|
|
446 | OUTPUT: |
|
|
447 | RETVAL |
444 | RETVAL |
448 | |
445 | |
449 | ############################################################################# |
446 | ############################################################################# |
450 | |
447 | |
451 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript |
448 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript |
… | |
… | |
508 | |
505 | |
509 | RETVAL = newSV (6 * 8 * 12 / 8); |
506 | RETVAL = newSV (6 * 8 * 12 / 8); |
510 | SvPOK_only (RETVAL); |
507 | SvPOK_only (RETVAL); |
511 | SvCUR_set (RETVAL, 6 * 8 * 12 / 8); |
508 | SvCUR_set (RETVAL, 6 * 8 * 12 / 8); |
512 | |
509 | |
513 | dst = SvPVX (RETVAL); |
510 | dst = (guchar *)SvPVX (RETVAL); |
514 | |
511 | |
515 | /* some primitive error distribution + random dithering */ |
512 | /* some primitive error distribution + random dithering */ |
516 | |
513 | |
517 | for (y = 0; y < h; y++) |
514 | for (y = 0; y < h; y++) |
518 | { |
515 | { |
… | |
… | |
576 | } |
573 | } |
577 | } |
574 | } |
578 | OUTPUT: |
575 | OUTPUT: |
579 | RETVAL |
576 | RETVAL |
580 | |
577 | |
|
|
578 | ############################################################################# |
581 | |
579 | |
|
|
580 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Plugin::RCluster |
582 | |
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 | |