… | |
… | |
7 | #include <math.h> |
7 | #include <math.h> |
8 | |
8 | |
9 | #include <magic.h> |
9 | #include <magic.h> |
10 | |
10 | |
11 | #include <jpeglib.h> |
11 | #include <jpeglib.h> |
|
|
12 | #include <jerror.h> |
|
|
13 | |
12 | #include <glib.h> |
14 | #include <glib.h> |
13 | #include <gtk/gtk.h> |
15 | #include <gtk/gtk.h> |
14 | #include <gdk/gdkx.h> |
16 | #include <gdk/gdkx.h> |
15 | #include <gdk-pixbuf/gdk-pixbuf.h> |
17 | #include <gdk-pixbuf/gdk-pixbuf.h> |
16 | |
18 | |
… | |
… | |
199 | PerlIO_write (fp, a85_buf, a85_ptr - a85_buf); |
201 | PerlIO_write (fp, a85_buf, a85_ptr - a85_buf); |
200 | } |
202 | } |
201 | |
203 | |
202 | ///////////////////////////////////////////////////////////////////////////// |
204 | ///////////////////////////////////////////////////////////////////////////// |
203 | |
205 | |
|
|
206 | static void cv_ms_init (j_decompress_ptr cinfo) |
|
|
207 | { |
|
|
208 | } |
|
|
209 | |
|
|
210 | static void cv_ms_term (j_decompress_ptr cinfo) |
|
|
211 | { |
|
|
212 | } |
|
|
213 | |
|
|
214 | static boolean cv_ms_fill (j_decompress_ptr cinfo) |
|
|
215 | { |
|
|
216 | ERREXIT (cinfo, JERR_INPUT_EMPTY); |
|
|
217 | |
|
|
218 | return TRUE; |
|
|
219 | } |
|
|
220 | |
|
|
221 | static void cv_ms_skip (j_decompress_ptr cinfo, long num_bytes) |
|
|
222 | { |
|
|
223 | if (num_bytes > 0) |
|
|
224 | { |
|
|
225 | struct jpeg_source_mgr *src = (struct jpeg_source_mgr *)cinfo->src; |
|
|
226 | |
|
|
227 | src->next_input_byte += num_bytes; |
|
|
228 | src->bytes_in_buffer -= num_bytes; |
|
|
229 | } |
|
|
230 | } |
|
|
231 | |
|
|
232 | static void cv_jpeg_mem_src (j_decompress_ptr cinfo, void *buf, size_t buflen) |
|
|
233 | { |
|
|
234 | struct jpeg_source_mgr *src; |
|
|
235 | |
|
|
236 | if (!cinfo->src) |
|
|
237 | cinfo->src = (struct jpeg_source_mgr *) |
|
|
238 | (*cinfo->mem->alloc_small) ( |
|
|
239 | (j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof (struct jpeg_source_mgr) |
|
|
240 | ); |
|
|
241 | |
|
|
242 | src = (struct jpeg_source_mgr *)cinfo->src; |
|
|
243 | src->init_source = cv_ms_init; |
|
|
244 | src->fill_input_buffer = cv_ms_fill; |
|
|
245 | src->skip_input_data = cv_ms_skip; |
|
|
246 | src->resync_to_restart = jpeg_resync_to_restart; |
|
|
247 | src->term_source = cv_ms_term; |
|
|
248 | src->next_input_byte = (JOCTET *)buf; |
|
|
249 | src->bytes_in_buffer = buflen; |
|
|
250 | } |
|
|
251 | |
|
|
252 | ///////////////////////////////////////////////////////////////////////////// |
|
|
253 | |
204 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV |
254 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV |
205 | |
255 | |
206 | PROTOTYPES: ENABLE |
256 | PROTOTYPES: ENABLE |
207 | |
257 | |
208 | # missing function in perl. really :) |
258 | # missing function in perl. really :) |
… | |
… | |
232 | CODE: |
282 | CODE: |
233 | { |
283 | { |
234 | STRLEN len; |
284 | STRLEN len; |
235 | char *data = SvPVbyte (path_or_data, len); |
285 | char *data = SvPVbyte (path_or_data, len); |
236 | |
286 | |
237 | perlinterp_release (); |
|
|
238 | |
|
|
239 | if (!magic_cookie[0]) |
287 | if (!magic_cookie[0]) |
240 | { |
288 | { |
241 | magic_cookie[0] = magic_open (MAGIC_SYMLINK); |
289 | magic_cookie[0] = magic_open (MAGIC_SYMLINK); |
242 | magic_cookie[1] = magic_open (MAGIC_SYMLINK | MAGIC_MIME); |
290 | magic_cookie[1] = magic_open (MAGIC_SYMLINK | MAGIC_MIME_TYPE); |
|
|
291 | magic_load (magic_cookie[0], 0); |
|
|
292 | magic_load (magic_cookie[1], 0); |
243 | } |
293 | } |
|
|
294 | |
|
|
295 | perlinterp_release (); |
244 | |
296 | |
245 | RETVAL = ix & 2 |
297 | RETVAL = ix & 2 |
246 | ? magic_buffer (magic_cookie[ix], data, len) |
298 | ? magic_buffer (magic_cookie[ix & 1], data, len) |
247 | : magic_file (magic_cookie[ix], data); |
299 | : magic_file (magic_cookie[ix & 1], data); |
248 | |
300 | |
249 | perlinterp_acquire (); |
301 | perlinterp_acquire (); |
250 | } |
302 | } |
251 | OUTPUT: |
303 | OUTPUT: |
252 | RETVAL |
304 | RETVAL |
… | |
… | |
308 | : angle); |
360 | : angle); |
309 | perlinterp_acquire (); |
361 | perlinterp_acquire (); |
310 | OUTPUT: |
362 | OUTPUT: |
311 | RETVAL |
363 | RETVAL |
312 | |
364 | |
|
|
365 | const char * |
|
|
366 | filetype (SV *image_data) |
|
|
367 | CODE: |
|
|
368 | { |
|
|
369 | STRLEN data_len; |
|
|
370 | U8 *data = SvPVbyte (image_data, data_len); |
|
|
371 | |
|
|
372 | if (data_len >= 20 |
|
|
373 | && data[0] == 0xff |
|
|
374 | && data[1] == 0xd8 |
|
|
375 | && data[2] == 0xff) |
|
|
376 | RETVAL = "jpg"; |
|
|
377 | else if (data_len >= 12 |
|
|
378 | && data[ 0] == (U8)'R' |
|
|
379 | && data[ 1] == (U8)'I' |
|
|
380 | && data[ 2] == (U8)'F' |
|
|
381 | && data[ 3] == (U8)'F' |
|
|
382 | && data[ 8] == (U8)'W' |
|
|
383 | && data[ 9] == (U8)'E' |
|
|
384 | && data[10] == (U8)'B' |
|
|
385 | && data[11] == (U8)'P') |
|
|
386 | RETVAL = "webp"; |
|
|
387 | else if (data_len >= 16 |
|
|
388 | && data[ 0] == 0x89 |
|
|
389 | && data[ 1] == (U8)'P' |
|
|
390 | && data[ 2] == (U8)'N' |
|
|
391 | && data[ 3] == (U8)'G' |
|
|
392 | && data[ 4] == 0x0d |
|
|
393 | && data[ 5] == 0x0a |
|
|
394 | && data[ 6] == 0x1a |
|
|
395 | && data[ 7] == 0x0a) |
|
|
396 | RETVAL = "png"; |
|
|
397 | else |
|
|
398 | RETVAL = "other"; |
|
|
399 | } |
|
|
400 | OUTPUT: |
|
|
401 | RETVAL |
|
|
402 | |
313 | GdkPixbuf_noinc * |
403 | GdkPixbuf_noinc * |
314 | decode_webp (SV *image_data, int thumbnail = 0, int iw = 0, int ih = 0) |
404 | decode_webp (SV *image_data, int thumbnail = 0, int iw = 0, int ih = 0) |
315 | CODE: |
405 | CODE: |
316 | { |
406 | { |
317 | #if WEBP |
407 | #if WEBP |
… | |
… | |
385 | } |
475 | } |
386 | OUTPUT: |
476 | OUTPUT: |
387 | RETVAL |
477 | RETVAL |
388 | |
478 | |
389 | GdkPixbuf_noinc * |
479 | GdkPixbuf_noinc * |
390 | load_jpeg (SV *path, int thumbnail = 0, int iw = 0, int ih = 0) |
480 | decode_jpeg (SV *image_data, int thumbnail = 0, int iw = 0, int ih = 0) |
391 | CODE: |
481 | CODE: |
392 | { |
482 | { |
393 | struct jpeg_decompress_struct cinfo; |
483 | struct jpeg_decompress_struct cinfo; |
394 | struct jpg_err_mgr jerr; |
484 | struct jpg_err_mgr jerr; |
395 | guchar *data; |
|
|
396 | int rs; |
485 | int rs; |
397 | FILE *fp; |
|
|
398 | volatile GdkPixbuf *pb = 0; |
486 | volatile GdkPixbuf *pb = 0; |
|
|
487 | STRLEN data_len; |
|
|
488 | guchar *data = SvPVbyte (image_data, data_len); |
399 | |
489 | |
400 | RETVAL = 0; |
490 | RETVAL = 0; |
401 | |
|
|
402 | fp = fopen (SvPVbyte_nolen (path), "rb"); |
|
|
403 | |
|
|
404 | if (!fp) |
|
|
405 | XSRETURN_UNDEF; |
|
|
406 | |
491 | |
407 | perlinterp_release (); |
492 | perlinterp_release (); |
408 | |
493 | |
409 | cinfo.err = jpeg_std_error (&jerr.err); |
494 | cinfo.err = jpeg_std_error (&jerr.err); |
410 | |
495 | |
411 | jerr.err.error_exit = cv_error_exit; |
496 | jerr.err.error_exit = cv_error_exit; |
412 | jerr.err.output_message = cv_error_output; |
497 | jerr.err.output_message = cv_error_output; |
413 | |
498 | |
414 | if ((rs = setjmp (jerr.setjmp_buffer))) |
499 | if ((rs = setjmp (jerr.setjmp_buffer))) |
415 | { |
500 | { |
416 | fclose (fp); |
|
|
417 | jpeg_destroy_decompress (&cinfo); |
501 | jpeg_destroy_decompress (&cinfo); |
418 | |
502 | |
419 | if (pb) |
503 | if (pb) |
420 | g_object_unref ((gpointer)pb); |
504 | g_object_unref ((gpointer)pb); |
421 | |
505 | |
422 | perlinterp_acquire (); |
506 | perlinterp_acquire (); |
423 | XSRETURN_UNDEF; |
507 | XSRETURN_UNDEF; |
424 | } |
508 | } |
425 | |
509 | |
426 | jpeg_create_decompress (&cinfo); |
510 | jpeg_create_decompress (&cinfo); |
|
|
511 | cv_jpeg_mem_src (&cinfo, data, data_len); |
427 | |
512 | |
428 | jpeg_stdio_src (&cinfo, fp); |
|
|
429 | jpeg_read_header (&cinfo, TRUE); |
513 | jpeg_read_header (&cinfo, TRUE); |
430 | |
514 | |
431 | cinfo.dct_method = JDCT_DEFAULT; |
515 | cinfo.dct_method = JDCT_DEFAULT; |
432 | cinfo.do_fancy_upsampling = FALSE; /* worse quality, but nobody compained so far, and gdk-pixbuf does the same */ |
516 | cinfo.do_fancy_upsampling = FALSE; /* worse quality, but nobody compained so far, and gdk-pixbuf does the same */ |
433 | cinfo.do_block_smoothing = FALSE; |
517 | cinfo.do_block_smoothing = FALSE; |
… | |
… | |
512 | data += 4; |
596 | data += 4; |
513 | } |
597 | } |
514 | } |
598 | } |
515 | |
599 | |
516 | jpeg_finish_decompress (&cinfo); |
600 | jpeg_finish_decompress (&cinfo); |
517 | fclose (fp); |
|
|
518 | jpeg_destroy_decompress (&cinfo); |
601 | jpeg_destroy_decompress (&cinfo); |
519 | perlinterp_acquire (); |
602 | perlinterp_acquire (); |
520 | } |
603 | } |
521 | OUTPUT: |
604 | OUTPUT: |
522 | RETVAL |
605 | RETVAL |