25#include <webp/decode.h>
27static const char*
const kStatusMessages[] = {
28 "OK",
"OUT_OF_MEMORY",
"INVALID_PARAM",
"BITSTREAM_ERROR",
29 "UNSUPPORTED_FEATURE",
"SUSPENDED",
"USER_ABORT",
"NOT_ENOUGH_DATA"
38 cairo_surface_destroy(us->
data);
41static cairo_surface_t* webp_really_loadimage(
const char *in_file, FILE*
const in)
43 WebPDecoderConfig config;
44 WebPDecBuffer*
const output_buffer = &config.output;
45 WebPBitstreamFeatures*
const bitstream = &config.input;
46 VP8StatusCode status = VP8_STATUS_OK;
47 cairo_surface_t *surface =
NULL;
51 if (!WebPInitDecoderConfig(&config)) {
52 fprintf(stderr,
"Error: WebP library version mismatch!\n");
56 fseek(in, 0, SEEK_END);
57 long size = ftell(in);
59 fprintf(stderr,
"Error: WebP could not determine %s size\n", in_file);
62 size_t data_size = (size_t)size;
65 ok = data_size == 0 || (
data !=
NULL && fread(
data, data_size, 1, in) == 1);
67 fprintf(stderr,
"Error: WebP could not read %" PRISIZE_T
68 " bytes of data from %s\n", data_size, in_file);
73 status = WebPGetFeatures(
data, data_size, bitstream);
74 if (status != VP8_STATUS_OK) {
78 output_buffer->colorspace = MODE_RGBA;
79 status = WebPDecode(
data, data_size, &config);
82 if (! bitstream->has_alpha) {
86 for (y = 0; y < output_buffer->height; y++) {
87 p = output_buffer->u.RGBA.rgba + output_buffer->u.RGBA.stride * y;
88 for (x = 0; x < output_buffer->width; x++) {
99 ok = status == VP8_STATUS_OK;
101 fprintf(stderr,
"Error: WebP decoding of %s failed.\n", in_file);
102 fprintf(stderr,
"Status: %d (%s)\n", status, kStatusMessages[status]);
106 surface = cairo_image_surface_create_for_data (
107 output_buffer->u.RGBA.rgba,
109 output_buffer->width,
110 output_buffer->height,
111 output_buffer->u.RGBA.stride);
119 cairo_surface_t *surface =
NULL;
139 if ((surface = webp_really_loadimage(us->
name, us->
f)))
140 cairo_surface_reference(surface);
160 cairo_surface_t *surface;
162 surface = webp_loadimage(job, us);
165 cairo_translate(cr, b.
LL.
x, -b.
UR.
y);
166 cairo_scale(cr, (b.
UR.
x - b.
LL.
x) / us->
w, (b.
UR.
y - b.
LL.
y) / us->
h);
167 cairo_set_source_surface (cr, surface, 0, 0);
181#ifdef HAVE_PANGOCAIRO
182 {FORMAT_WEBP_CAIRO,
"webp:cairo", 1, &engine_webp,
NULL},
void gvusershape_file_release(usershape_t *us)
bool gvusershape_file_access(usershape_t *us)
gvplugin_installed_t gvloadimage_webp_types[]
#define PRISIZE_T
PRIu64 alike for printing size_t
void(* datafree)(usershape_t *us)