ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CV/CV.xs
(Generate patch)

Comparing CV/CV.xs (file contents):
Revision 1.52 by root, Sat Dec 23 04:25:50 2017 UTC vs.
Revision 1.53 by root, Sat Dec 23 05:27:04 2017 UTC

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
206static void cv_ms_init (j_decompress_ptr cinfo)
207{
208}
209
210static void cv_ms_term (j_decompress_ptr cinfo)
211{
212}
213
214static boolean cv_ms_fill (j_decompress_ptr cinfo)
215{
216 ERREXIT (cinfo, JERR_INPUT_EMPTY);
217
218 return TRUE;
219}
220
221static 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
232static 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
204MODULE = Gtk2::CV PACKAGE = Gtk2::CV 254MODULE = Gtk2::CV PACKAGE = Gtk2::CV
205 255
206PROTOTYPES: ENABLE 256PROTOTYPES: ENABLE
207 257
208# missing function in perl. really :) 258# missing function in perl. really :)
310 : angle); 360 : angle);
311 perlinterp_acquire (); 361 perlinterp_acquire ();
312 OUTPUT: 362 OUTPUT:
313 RETVAL 363 RETVAL
314 364
365const char *
366filetype (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
315GdkPixbuf_noinc * 403GdkPixbuf_noinc *
316decode_webp (SV *image_data, int thumbnail = 0, int iw = 0, int ih = 0) 404decode_webp (SV *image_data, int thumbnail = 0, int iw = 0, int ih = 0)
317 CODE: 405 CODE:
318{ 406{
319#if WEBP 407#if WEBP
387} 475}
388 OUTPUT: 476 OUTPUT:
389 RETVAL 477 RETVAL
390 478
391GdkPixbuf_noinc * 479GdkPixbuf_noinc *
392load_jpeg (SV *path, int thumbnail = 0, int iw = 0, int ih = 0) 480decode_jpeg (SV *image_data, int thumbnail = 0, int iw = 0, int ih = 0)
393 CODE: 481 CODE:
394{ 482{
395 struct jpeg_decompress_struct cinfo; 483 struct jpeg_decompress_struct cinfo;
396 struct jpg_err_mgr jerr; 484 struct jpg_err_mgr jerr;
397 guchar *data;
398 int rs; 485 int rs;
399 FILE *fp;
400 volatile GdkPixbuf *pb = 0; 486 volatile GdkPixbuf *pb = 0;
487 STRLEN data_len;
488 guchar *data = SvPVbyte (image_data, data_len);
401 489
402 RETVAL = 0; 490 RETVAL = 0;
403
404 fp = fopen (SvPVbyte_nolen (path), "rb");
405
406 if (!fp)
407 XSRETURN_UNDEF;
408 491
409 perlinterp_release (); 492 perlinterp_release ();
410 493
411 cinfo.err = jpeg_std_error (&jerr.err); 494 cinfo.err = jpeg_std_error (&jerr.err);
412 495
413 jerr.err.error_exit = cv_error_exit; 496 jerr.err.error_exit = cv_error_exit;
414 jerr.err.output_message = cv_error_output; 497 jerr.err.output_message = cv_error_output;
415 498
416 if ((rs = setjmp (jerr.setjmp_buffer))) 499 if ((rs = setjmp (jerr.setjmp_buffer)))
417 { 500 {
418 fclose (fp);
419 jpeg_destroy_decompress (&cinfo); 501 jpeg_destroy_decompress (&cinfo);
420 502
421 if (pb) 503 if (pb)
422 g_object_unref ((gpointer)pb); 504 g_object_unref ((gpointer)pb);
423 505
424 perlinterp_acquire (); 506 perlinterp_acquire ();
425 XSRETURN_UNDEF; 507 XSRETURN_UNDEF;
426 } 508 }
427 509
428 jpeg_create_decompress (&cinfo); 510 jpeg_create_decompress (&cinfo);
511 cv_jpeg_mem_src (&cinfo, data, data_len);
429 512
430 jpeg_stdio_src (&cinfo, fp);
431 jpeg_read_header (&cinfo, TRUE); 513 jpeg_read_header (&cinfo, TRUE);
432 514
433 cinfo.dct_method = JDCT_DEFAULT; 515 cinfo.dct_method = JDCT_DEFAULT;
434 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 */
435 cinfo.do_block_smoothing = FALSE; 517 cinfo.do_block_smoothing = FALSE;
514 data += 4; 596 data += 4;
515 } 597 }
516 } 598 }
517 599
518 jpeg_finish_decompress (&cinfo); 600 jpeg_finish_decompress (&cinfo);
519 fclose (fp);
520 jpeg_destroy_decompress (&cinfo); 601 jpeg_destroy_decompress (&cinfo);
521 perlinterp_acquire (); 602 perlinterp_acquire ();
522} 603}
523 OUTPUT: 604 OUTPUT:
524 RETVAL 605 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines