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

Comparing CV/CV.xs (file contents):
Revision 1.53 by root, Sat Dec 23 05:27:04 2017 UTC vs.
Revision 1.56 by root, Wed Dec 27 17:48:16 2017 UTC

20#include <gtk2perl.h> 20#include <gtk2perl.h>
21 21
22#include <assert.h> 22#include <assert.h>
23 23
24#if WEBP 24#if WEBP
25#include <webp/demux.h>
25#include <webp/decode.h> 26#include <webp/decode.h>
26#endif 27#endif
27 28
28#include "perlmulticore.h" 29#include "perlmulticore.h"
29 30
200 201
201 PerlIO_write (fp, a85_buf, a85_ptr - a85_buf); 202 PerlIO_write (fp, a85_buf, a85_ptr - a85_buf);
202} 203}
203 204
204///////////////////////////////////////////////////////////////////////////// 205/////////////////////////////////////////////////////////////////////////////
206// memory source for libjpeg
205 207
206static void cv_ms_init (j_decompress_ptr cinfo) 208static void cv_ms_init (j_decompress_ptr cinfo)
207{ 209{
208} 210}
209 211
253 255
254MODULE = Gtk2::CV PACKAGE = Gtk2::CV 256MODULE = Gtk2::CV PACKAGE = Gtk2::CV
255 257
256PROTOTYPES: ENABLE 258PROTOTYPES: ENABLE
257 259
260# calculate the common prefix length of two strings
258# missing function in perl. really :) 261# missing function in perl. really :)
259int 262int
260common_prefix_length (a, b) 263common_prefix_length (a, b)
261 unsigned char *a = (unsigned char *)SvPVutf8_nolen ($arg); 264 unsigned char *a = (unsigned char *)SvPVutf8_nolen ($arg);
262 unsigned char *b = (unsigned char *)SvPVutf8_nolen ($arg); 265 unsigned char *b = (unsigned char *)SvPVutf8_nolen ($arg);
403GdkPixbuf_noinc * 406GdkPixbuf_noinc *
404decode_webp (SV *image_data, int thumbnail = 0, int iw = 0, int ih = 0) 407decode_webp (SV *image_data, int thumbnail = 0, int iw = 0, int ih = 0)
405 CODE: 408 CODE:
406{ 409{
407#if WEBP 410#if WEBP
408 guchar *data;
409 STRLEN data_size; 411 STRLEN data_size;
410 int alpha; 412 int alpha;
413 WebPData data;
414 WebPDemuxer *demux;
415 WebPIterator iter;
411 WebPDecoderConfig config; 416 WebPDecoderConfig config;
412 int inw, inh; 417 int inw, inh;
413 418
414 data = SvPVbyte (image_data, data_size); 419 data.bytes = (uint8_t *)SvPVbyte (image_data, data_size);
420 data.size = data_size;
415 421
416 perlinterp_release (); 422 perlinterp_release ();
417 423
418 RETVAL = 0; 424 RETVAL = 0;
419 425
426 if (!(demux = WebPDemux (&data)))
427 goto err_demux;
428
429 if (!WebPDemuxGetFrame (demux, 1, &iter))
430 goto err_iter;
431
420 if (!WebPInitDecoderConfig (&config)) 432 if (!WebPInitDecoderConfig (&config))
421 goto err; 433 goto err_iter;
422 434
423 config.options.use_threads = 1; 435 config.options.use_threads = 1;
424 436
425 if (WebPGetFeatures (data, data_size, &config.input) != VP8_STATUS_OK) 437 if (WebPGetFeatures (iter.fragment.bytes, iter.fragment.size, &config.input) != VP8_STATUS_OK)
426 goto err; 438 goto err_iter;
427 439
428 inw = config.input.width; 440 inw = config.input.width;
429 inh = config.input.height; 441 inh = config.input.height;
430 442
431 if (thumbnail) 443 if (thumbnail)
446 { 458 {
447 iw = inw; 459 iw = inw;
448 ih = inh; 460 ih = inh;
449 } 461 }
450 462
451 alpha = config.input.has_alpha; 463 alpha = !!config.input.has_alpha;
452 464
453 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, !!alpha, 8, iw, ih); 465 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, alpha, 8, iw, ih);
454 if (!RETVAL) 466 if (!RETVAL)
455 goto err; 467 goto err_iter;
456 468
457 config.output.colorspace = alpha ? MODE_RGBA : MODE_RGB; 469 config.output.colorspace = alpha ? MODE_RGBA : MODE_RGB;
458 config.output.u.RGBA.rgba = gdk_pixbuf_get_pixels (RETVAL); 470 config.output.u.RGBA.rgba = gdk_pixbuf_get_pixels (RETVAL);
459 config.output.u.RGBA.stride = gdk_pixbuf_get_rowstride (RETVAL); 471 config.output.u.RGBA.stride = gdk_pixbuf_get_rowstride (RETVAL);
460 config.output.u.RGBA.size = gdk_pixbuf_get_byte_length (RETVAL); 472 config.output.u.RGBA.size = gdk_pixbuf_get_byte_length (RETVAL);
461 config.output.is_external_memory = 1; 473 config.output.is_external_memory = 1;
462 474
463 if (WebPDecode (data, data_size, &config) != VP8_STATUS_OK) 475 if (WebPDecode (iter.fragment.bytes, iter.fragment.size, &config) != VP8_STATUS_OK)
464 { 476 {
465 g_object_unref (RETVAL); 477 g_object_unref (RETVAL);
466 RETVAL = 0; 478 RETVAL = 0;
467 goto err; 479 goto err_iter;
468 } 480 }
469 481
470 err: 482 err_iter:
483 WebPDemuxReleaseIterator (&iter);
484 err_demux:
485 WebPDemuxDelete (demux);
486
471 perlinterp_acquire (); 487 perlinterp_acquire ();
472#else 488#else
473 croak ("load_webp: webp not enabled at compile time"); 489 croak ("load_webp: webp not enabled at compile time");
474#endif 490#endif
475} 491}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines