… | |
… | |
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 | |
… | |
… | |
186 | } |
188 | } |
187 | OUTPUT: |
189 | OUTPUT: |
188 | RETVAL |
190 | RETVAL |
189 | |
191 | |
190 | GdkPixbuf_noinc * |
192 | GdkPixbuf_noinc * |
191 | load_jpeg (char *path, int thumbnail=0) |
193 | load_jpeg (SV *path, int thumbnail=0) |
192 | CODE: |
194 | CODE: |
193 | { |
195 | { |
194 | struct jpeg_decompress_struct cinfo; |
196 | struct jpeg_decompress_struct cinfo; |
195 | struct jpg_err_mgr jerr; |
197 | struct jpg_err_mgr jerr; |
196 | guchar *data; |
198 | guchar *data; |
197 | int rs; |
199 | int rs; |
198 | FILE *fp; |
200 | FILE *fp; |
199 | volatile GdkPixbuf *pb = 0; |
201 | volatile GdkPixbuf *pb = 0; |
|
|
202 | gchar *filename; |
|
|
203 | |
200 | RETVAL = 0; |
204 | RETVAL = 0; |
201 | |
205 | |
202 | 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) |
203 | XSRETURN_UNDEF; |
211 | XSRETURN_UNDEF; |
204 | |
212 | |
205 | cinfo.err = jpeg_std_error (&jerr.err); |
213 | cinfo.err = jpeg_std_error (&jerr.err); |
206 | |
214 | |
207 | jerr.err.error_exit = cv_error_exit; |
215 | jerr.err.error_exit = cv_error_exit; |
… | |
… | |
288 | foldcase (SV *pathsv) |
296 | foldcase (SV *pathsv) |
289 | PROTOTYPE: $ |
297 | PROTOTYPE: $ |
290 | CODE: |
298 | CODE: |
291 | { |
299 | { |
292 | STRLEN plen; |
300 | STRLEN plen; |
293 | U8 *path = SvPVutf8 (pathsv, plen); |
301 | U8 *path = (U8 *)SvPVutf8 (pathsv, plen); |
294 | U8 *pend = path + plen; |
302 | U8 *pend = path + plen; |
295 | U8 dst [plen * 6 * 3], *dstp = dst; |
303 | U8 dst [plen * 6 * 3], *dstp = dst; |
296 | |
304 | |
297 | while (path < pend) |
305 | while (path < pend) |
298 | { |
306 | { |
… | |
… | |
319 | dstp += cl; |
327 | dstp += cl; |
320 | path += is_utf8_char (path); |
328 | path += is_utf8_char (path); |
321 | } |
329 | } |
322 | } |
330 | } |
323 | |
331 | |
324 | RETVAL = newSVpvn (dst, dstp - dst); |
332 | RETVAL = newSVpvn ((const char *)dst, dstp - dst); |
325 | } |
333 | } |
326 | OUTPUT: |
334 | OUTPUT: |
327 | RETVAL |
335 | RETVAL |
328 | |
336 | |
329 | GdkPixbuf_noinc * |
337 | GdkPixbuf_noinc * |
330 | p7_to_pb (int w, int h, guchar *src) |
338 | p7_to_pb (int w, int h, SV *src_sv) |
331 | PROTOTYPE: @ |
339 | PROTOTYPE: @ |
332 | CODE: |
340 | CODE: |
333 | { |
341 | { |
334 | int x, y; |
342 | int x, y; |
335 | guchar *dst, *d; |
343 | guchar *dst, *d; |
336 | int dstr; |
344 | int dstr; |
|
|
345 | guchar *src = (guchar *)SvPVbyte_nolen (src_sv); |
337 | |
346 | |
338 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
347 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
339 | dst = gdk_pixbuf_get_pixels (RETVAL); |
348 | dst = gdk_pixbuf_get_pixels (RETVAL); |
340 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
349 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
341 | |
350 | |
… | |
… | |
368 | |
377 | |
369 | RETVAL = newSV (w * h); |
378 | RETVAL = newSV (w * h); |
370 | SvPOK_only (RETVAL); |
379 | SvPOK_only (RETVAL); |
371 | SvCUR_set (RETVAL, w * h); |
380 | SvCUR_set (RETVAL, w * h); |
372 | |
381 | |
373 | dst = SvPVX (RETVAL); |
382 | dst = (guchar *)SvPVX (RETVAL); |
374 | |
383 | |
375 | memset (Er, 0, sizeof (int) * IW); |
384 | memset (Er, 0, sizeof (int) * IW); |
376 | memset (Eg, 0, sizeof (int) * IW); |
385 | memset (Eg, 0, sizeof (int) * IW); |
377 | memset (Eb, 0, sizeof (int) * IW); |
386 | memset (Eb, 0, sizeof (int) * IW); |
378 | |
387 | |
… | |
… | |
472 | |
481 | |
473 | RETVAL = newSV (6 * 8 * 12 / 8); |
482 | RETVAL = newSV (6 * 8 * 12 / 8); |
474 | SvPOK_only (RETVAL); |
483 | SvPOK_only (RETVAL); |
475 | SvCUR_set (RETVAL, 6 * 8 * 12 / 8); |
484 | SvCUR_set (RETVAL, 6 * 8 * 12 / 8); |
476 | |
485 | |
477 | dst = SvPVX (RETVAL); |
486 | dst = (guchar *)SvPVX (RETVAL); |
478 | |
487 | |
479 | /* some primitive error distribution + random dithering */ |
488 | /* some primitive error distribution + random dithering */ |
480 | |
489 | |
481 | for (y = 0; y < h; y++) |
490 | for (y = 0; y < h; y++) |
482 | { |
491 | { |