… | |
… | |
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 | transpose (GdkPixbuf *pb) |
131 | CODE: |
146 | CODE: |
132 | { |
147 | { |
133 | int w = gdk_pixbuf_get_width (pb); |
148 | int w = gdk_pixbuf_get_width (pb); |
… | |
… | |
173 | } |
188 | } |
174 | OUTPUT: |
189 | OUTPUT: |
175 | RETVAL |
190 | RETVAL |
176 | |
191 | |
177 | GdkPixbuf_noinc * |
192 | GdkPixbuf_noinc * |
178 | load_jpeg (char *path, int thumbnail=0) |
193 | load_jpeg (SV *path, int thumbnail=0) |
179 | CODE: |
194 | CODE: |
180 | { |
195 | { |
181 | struct jpeg_decompress_struct cinfo; |
196 | struct jpeg_decompress_struct cinfo; |
182 | struct jpg_err_mgr jerr; |
197 | struct jpg_err_mgr jerr; |
183 | guchar *data; |
198 | guchar *data; |
184 | int rs; |
199 | int rs; |
185 | FILE *fp; |
200 | FILE *fp; |
186 | volatile GdkPixbuf *pb = 0; |
201 | volatile GdkPixbuf *pb = 0; |
|
|
202 | gchar *filename; |
|
|
203 | |
187 | RETVAL = 0; |
204 | RETVAL = 0; |
188 | |
205 | |
189 | if (!(fp = fopen (path, "rb"))) |
206 | filename = g_filename_from_utf8 (SvPVutf8_nolen (path), -1, 0, 0, 0); |
|
|
207 | fp = fopen (filename, "rb"); |
|
|
208 | g_free (filename); |
|
|
209 | |
|
|
210 | if (!fp) |
190 | XSRETURN_UNDEF; |
211 | XSRETURN_UNDEF; |
191 | |
212 | |
192 | cinfo.err = jpeg_std_error (&jerr.err); |
213 | cinfo.err = jpeg_std_error (&jerr.err); |
193 | |
214 | |
194 | jerr.err.error_exit = cv_error_exit; |
215 | jerr.err.error_exit = cv_error_exit; |
… | |
… | |
275 | foldcase (SV *pathsv) |
296 | foldcase (SV *pathsv) |
276 | PROTOTYPE: $ |
297 | PROTOTYPE: $ |
277 | CODE: |
298 | CODE: |
278 | { |
299 | { |
279 | STRLEN plen; |
300 | STRLEN plen; |
280 | U8 *path = SvPVutf8 (pathsv, plen); |
301 | U8 *path = (U8 *)SvPVutf8 (pathsv, plen); |
281 | U8 *pend = path + plen; |
302 | U8 *pend = path + plen; |
282 | U8 dst [plen * 6 * 3], *dstp = dst; |
303 | U8 dst [plen * 6 * 3], *dstp = dst; |
283 | |
304 | |
284 | while (path < pend) |
305 | while (path < pend) |
285 | { |
306 | { |
… | |
… | |
306 | dstp += cl; |
327 | dstp += cl; |
307 | path += is_utf8_char (path); |
328 | path += is_utf8_char (path); |
308 | } |
329 | } |
309 | } |
330 | } |
310 | |
331 | |
311 | RETVAL = newSVpvn (dst, dstp - dst); |
332 | RETVAL = newSVpvn ((const char *)dst, dstp - dst); |
312 | } |
333 | } |
313 | OUTPUT: |
334 | OUTPUT: |
314 | RETVAL |
335 | RETVAL |
315 | |
336 | |
316 | GdkPixbuf_noinc * |
337 | GdkPixbuf_noinc * |
317 | p7_to_pb (int w, int h, guchar *src) |
338 | p7_to_pb (int w, int h, SV *src_sv) |
318 | PROTOTYPE: @ |
339 | PROTOTYPE: @ |
319 | CODE: |
340 | CODE: |
320 | { |
341 | { |
321 | int x, y; |
342 | int x, y; |
322 | guchar *dst, *d; |
343 | guchar *dst, *d; |
323 | int dstr; |
344 | int dstr; |
|
|
345 | guchar *src = (guchar *)SvPVbyte_nolen (src_sv); |
324 | |
346 | |
325 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
347 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
326 | dst = gdk_pixbuf_get_pixels (RETVAL); |
348 | dst = gdk_pixbuf_get_pixels (RETVAL); |
327 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
349 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
328 | |
350 | |
… | |
… | |
355 | |
377 | |
356 | RETVAL = newSV (w * h); |
378 | RETVAL = newSV (w * h); |
357 | SvPOK_only (RETVAL); |
379 | SvPOK_only (RETVAL); |
358 | SvCUR_set (RETVAL, w * h); |
380 | SvCUR_set (RETVAL, w * h); |
359 | |
381 | |
360 | dst = SvPVX (RETVAL); |
382 | dst = (guchar *)SvPVX (RETVAL); |
361 | |
383 | |
362 | memset (Er, 0, sizeof (int) * IW); |
384 | memset (Er, 0, sizeof (int) * IW); |
363 | memset (Eg, 0, sizeof (int) * IW); |
385 | memset (Eg, 0, sizeof (int) * IW); |
364 | memset (Eb, 0, sizeof (int) * IW); |
386 | memset (Eb, 0, sizeof (int) * IW); |
365 | |
387 | |
… | |
… | |
459 | |
481 | |
460 | RETVAL = newSV (6 * 8 * 12 / 8); |
482 | RETVAL = newSV (6 * 8 * 12 / 8); |
461 | SvPOK_only (RETVAL); |
483 | SvPOK_only (RETVAL); |
462 | SvCUR_set (RETVAL, 6 * 8 * 12 / 8); |
484 | SvCUR_set (RETVAL, 6 * 8 * 12 / 8); |
463 | |
485 | |
464 | dst = SvPVX (RETVAL); |
486 | dst = (guchar *)SvPVX (RETVAL); |
465 | |
487 | |
466 | /* some primitive error distribution + random dithering */ |
488 | /* some primitive error distribution + random dithering */ |
467 | |
489 | |
468 | for (y = 0; y < h; y++) |
490 | for (y = 0; y < h; y++) |
469 | { |
491 | { |