… | |
… | |
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 | |
|
|
144 | GdkPixbuf_noinc * |
|
|
145 | dealpha_expose (GdkPixbuf *pb) |
|
|
146 | CODE: |
|
|
147 | { |
|
|
148 | int w = gdk_pixbuf_get_width (pb); |
|
|
149 | int h = gdk_pixbuf_get_height (pb); |
|
|
150 | fprintf (stderr, "new %d %d\n", w, h); |
|
|
151 | int bpp = gdk_pixbuf_get_n_channels (pb); |
|
|
152 | int x, y, i; |
|
|
153 | guchar *src = gdk_pixbuf_get_pixels (pb), *dst; |
|
|
154 | int sstr = gdk_pixbuf_get_rowstride (pb), dstr; |
|
|
155 | |
|
|
156 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
|
|
157 | |
|
|
158 | dst = gdk_pixbuf_get_pixels (RETVAL); |
|
|
159 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
|
|
160 | |
|
|
161 | for (x = 0; x < w; x++) |
|
|
162 | for (y = 0; y < h; y++) |
|
|
163 | for (i = 0; i < 3; i++) |
|
|
164 | dst[x * 3 + y * dstr + i] = src[x * bpp + y * sstr + i]; |
|
|
165 | } |
|
|
166 | OUTPUT: |
|
|
167 | RETVAL |
|
|
168 | |
129 | GdkPixbuf_noinc * |
169 | GdkPixbuf_noinc * |
130 | transpose (GdkPixbuf *pb) |
170 | transpose (GdkPixbuf *pb) |
131 | CODE: |
171 | CODE: |
132 | { |
172 | { |
133 | int w = gdk_pixbuf_get_width (pb); |
173 | int w = gdk_pixbuf_get_width (pb); |
… | |
… | |
173 | } |
213 | } |
174 | OUTPUT: |
214 | OUTPUT: |
175 | RETVAL |
215 | RETVAL |
176 | |
216 | |
177 | GdkPixbuf_noinc * |
217 | GdkPixbuf_noinc * |
178 | load_jpeg (char *path, int thumbnail=0) |
218 | load_jpeg (SV *path, int thumbnail=0) |
179 | CODE: |
219 | CODE: |
180 | { |
220 | { |
181 | struct jpeg_decompress_struct cinfo; |
221 | struct jpeg_decompress_struct cinfo; |
182 | struct jpg_err_mgr jerr; |
222 | struct jpg_err_mgr jerr; |
183 | guchar *data; |
223 | guchar *data; |
184 | int rs; |
224 | int rs; |
185 | FILE *fp; |
225 | FILE *fp; |
186 | volatile GdkPixbuf *pb = 0; |
226 | volatile GdkPixbuf *pb = 0; |
|
|
227 | gchar *filename; |
|
|
228 | |
187 | RETVAL = 0; |
229 | RETVAL = 0; |
188 | |
230 | |
189 | if (!(fp = fopen (path, "rb"))) |
231 | filename = g_filename_from_utf8 (SvPVutf8_nolen (path), -1, 0, 0, 0); |
|
|
232 | fp = fopen (filename, "rb"); |
|
|
233 | g_free (filename); |
|
|
234 | |
|
|
235 | if (!fp) |
190 | XSRETURN_UNDEF; |
236 | XSRETURN_UNDEF; |
191 | |
237 | |
192 | cinfo.err = jpeg_std_error (&jerr.err); |
238 | cinfo.err = jpeg_std_error (&jerr.err); |
193 | |
239 | |
194 | jerr.err.error_exit = cv_error_exit; |
240 | jerr.err.error_exit = cv_error_exit; |
… | |
… | |
225 | { |
271 | { |
226 | cinfo.dct_method = JDCT_FASTEST; |
272 | cinfo.dct_method = JDCT_FASTEST; |
227 | cinfo.do_fancy_upsampling = FALSE; |
273 | cinfo.do_fancy_upsampling = FALSE; |
228 | |
274 | |
229 | while (cinfo.scale_denom < 8 |
275 | while (cinfo.scale_denom < 8 |
230 | && (cinfo.output_width >> 1) >= IW |
276 | && cinfo.output_width >= IW*4 |
231 | && (cinfo.output_height >> 1) >= IH) |
277 | && cinfo.output_height >= IH*4) |
232 | { |
278 | { |
233 | cinfo.scale_denom <<= 1; |
279 | cinfo.scale_denom <<= 1; |
234 | jpeg_calc_output_dimensions (&cinfo); |
280 | jpeg_calc_output_dimensions (&cinfo); |
235 | } |
281 | } |
236 | } |
282 | } |
… | |
… | |
275 | foldcase (SV *pathsv) |
321 | foldcase (SV *pathsv) |
276 | PROTOTYPE: $ |
322 | PROTOTYPE: $ |
277 | CODE: |
323 | CODE: |
278 | { |
324 | { |
279 | STRLEN plen; |
325 | STRLEN plen; |
280 | U8 *path = SvPVutf8 (pathsv, plen); |
326 | U8 *path = (U8 *)SvPVutf8 (pathsv, plen); |
281 | U8 *pend = path + plen; |
327 | U8 *pend = path + plen; |
282 | U8 dst [plen * 6 * 3], *dstp = dst; |
328 | U8 dst [plen * 6 * 3], *dstp = dst; |
283 | |
329 | |
284 | while (path < pend) |
330 | while (path < pend) |
285 | { |
331 | { |
… | |
… | |
306 | dstp += cl; |
352 | dstp += cl; |
307 | path += is_utf8_char (path); |
353 | path += is_utf8_char (path); |
308 | } |
354 | } |
309 | } |
355 | } |
310 | |
356 | |
311 | RETVAL = newSVpvn (dst, dstp - dst); |
357 | RETVAL = newSVpvn ((const char *)dst, dstp - dst); |
312 | } |
358 | } |
313 | OUTPUT: |
359 | OUTPUT: |
314 | RETVAL |
360 | RETVAL |
315 | |
361 | |
316 | GdkPixbuf_noinc * |
362 | GdkPixbuf_noinc * |
317 | p7_to_pb (int w, int h, guchar *src) |
363 | p7_to_pb (int w, int h, SV *src_sv) |
|
|
364 | PROTOTYPE: @ |
318 | CODE: |
365 | CODE: |
319 | { |
366 | { |
320 | int x, y; |
367 | int x, y; |
321 | guchar *dst, *d; |
368 | guchar *dst, *d; |
322 | int dstr; |
369 | int dstr; |
|
|
370 | guchar *src = (guchar *)SvPVbyte_nolen (src_sv); |
323 | |
371 | |
324 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
372 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
325 | dst = gdk_pixbuf_get_pixels (RETVAL); |
373 | dst = gdk_pixbuf_get_pixels (RETVAL); |
326 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
374 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
327 | |
375 | |
… | |
… | |
354 | |
402 | |
355 | RETVAL = newSV (w * h); |
403 | RETVAL = newSV (w * h); |
356 | SvPOK_only (RETVAL); |
404 | SvPOK_only (RETVAL); |
357 | SvCUR_set (RETVAL, w * h); |
405 | SvCUR_set (RETVAL, w * h); |
358 | |
406 | |
359 | dst = SvPVX (RETVAL); |
407 | dst = (guchar *)SvPVX (RETVAL); |
360 | |
408 | |
361 | memset (Er, 0, sizeof (int) * IW); |
409 | memset (Er, 0, sizeof (int) * IW); |
362 | memset (Eg, 0, sizeof (int) * IW); |
410 | memset (Eg, 0, sizeof (int) * IW); |
363 | memset (Eb, 0, sizeof (int) * IW); |
411 | memset (Eb, 0, sizeof (int) * IW); |
364 | |
412 | |
… | |
… | |
458 | |
506 | |
459 | RETVAL = newSV (6 * 8 * 12 / 8); |
507 | RETVAL = newSV (6 * 8 * 12 / 8); |
460 | SvPOK_only (RETVAL); |
508 | SvPOK_only (RETVAL); |
461 | SvCUR_set (RETVAL, 6 * 8 * 12 / 8); |
509 | SvCUR_set (RETVAL, 6 * 8 * 12 / 8); |
462 | |
510 | |
463 | dst = SvPVX (RETVAL); |
511 | dst = (guchar *)SvPVX (RETVAL); |
464 | |
512 | |
465 | /* some primitive error distribution + random dithering */ |
513 | /* some primitive error distribution + random dithering */ |
466 | |
514 | |
467 | for (y = 0; y < h; y++) |
515 | for (y = 0; y < h; y++) |
468 | { |
516 | { |