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.54 by root, Sat Dec 23 08:04:48 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
403GdkPixbuf_noinc * 404GdkPixbuf_noinc *
404decode_webp (SV *image_data, int thumbnail = 0, int iw = 0, int ih = 0) 405decode_webp (SV *image_data, int thumbnail = 0, int iw = 0, int ih = 0)
405 CODE: 406 CODE:
406{ 407{
407#if WEBP 408#if WEBP
408 guchar *data;
409 STRLEN data_size; 409 STRLEN data_size;
410 int alpha; 410 int alpha;
411 WebPData data;
412 WebPDemuxer *demux;
413 WebPIterator iter;
411 WebPDecoderConfig config; 414 WebPDecoderConfig config;
412 int inw, inh; 415 int inw, inh;
413 416
414 data = SvPVbyte (image_data, data_size); 417 data.bytes = (uint8_t *)SvPVbyte (image_data, data_size);
418 data.size = data_size;
415 419
416 perlinterp_release (); 420 perlinterp_release ();
417 421
418 RETVAL = 0; 422 RETVAL = 0;
419 423
424 if (!(demux = WebPDemux (&data)))
425 goto err_demux;
426
427 if (!WebPDemuxGetFrame (demux, 1, &iter))
428 goto err_iter;
429
420 if (!WebPInitDecoderConfig (&config)) 430 if (!WebPInitDecoderConfig (&config))
421 goto err; 431 goto err_iter;
422 432
423 config.options.use_threads = 1; 433 config.options.use_threads = 1;
424 434
425 if (WebPGetFeatures (data, data_size, &config.input) != VP8_STATUS_OK) 435 if (WebPGetFeatures (iter.fragment.bytes, iter.fragment.size, &config.input) != VP8_STATUS_OK)
426 goto err; 436 goto err_iter;
427 437
428 inw = config.input.width; 438 inw = config.input.width;
429 inh = config.input.height; 439 inh = config.input.height;
430 440
431 if (thumbnail) 441 if (thumbnail)
446 { 456 {
447 iw = inw; 457 iw = inw;
448 ih = inh; 458 ih = inh;
449 } 459 }
450 460
451 alpha = config.input.has_alpha; 461 alpha = !!config.input.has_alpha;
452 462
453 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, !!alpha, 8, iw, ih); 463 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, alpha, 8, iw, ih);
454 if (!RETVAL) 464 if (!RETVAL)
455 goto err; 465 goto err_iter;
456 466
457 config.output.colorspace = alpha ? MODE_RGBA : MODE_RGB; 467 config.output.colorspace = alpha ? MODE_RGBA : MODE_RGB;
458 config.output.u.RGBA.rgba = gdk_pixbuf_get_pixels (RETVAL); 468 config.output.u.RGBA.rgba = gdk_pixbuf_get_pixels (RETVAL);
459 config.output.u.RGBA.stride = gdk_pixbuf_get_rowstride (RETVAL); 469 config.output.u.RGBA.stride = gdk_pixbuf_get_rowstride (RETVAL);
460 config.output.u.RGBA.size = gdk_pixbuf_get_byte_length (RETVAL); 470 config.output.u.RGBA.size = gdk_pixbuf_get_byte_length (RETVAL);
461 config.output.is_external_memory = 1; 471 config.output.is_external_memory = 1;
462 472
463 if (WebPDecode (data, data_size, &config) != VP8_STATUS_OK) 473 if (WebPDecode (iter.fragment.bytes, iter.fragment.size, &config) != VP8_STATUS_OK)
464 { 474 {
465 g_object_unref (RETVAL); 475 g_object_unref (RETVAL);
466 RETVAL = 0; 476 RETVAL = 0;
467 goto err; 477 goto err_iter;
468 } 478 }
469 479
470 err: 480 err_iter:
481 WebPDemuxReleaseIterator (&iter);
482 err_demux:
483
471 perlinterp_acquire (); 484 perlinterp_acquire ();
472#else 485#else
473 croak ("load_webp: webp not enabled at compile time"); 486 croak ("load_webp: webp not enabled at compile time");
474#endif 487#endif
475} 488}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines