Skip to content

Commit

Permalink
io-webp.c: configure decoder output to write in pixbuf
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Ruiz committed Feb 22, 2023
1 parent 219ae4c commit c84d336
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions io-webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

static gpointer
begin_load (GdkPixbufModuleSizeFunc size_func,
GdkPixbufModulePreparedFunc prepare_func,
GdkPixbufModuleUpdatedFunc update_func,
gpointer user_data,
GError **error)
GdkPixbufModulePreparedFunc prepare_func,
GdkPixbufModuleUpdatedFunc update_func,
gpointer user_data,
GError **error)
{
WebPContext *context = g_new0 (WebPContext, 1);
context->size_func = size_func;
Expand Down Expand Up @@ -90,13 +90,22 @@ load_increment (gpointer data, const guchar *buf, guint size, GError **error)

context->deccfg.output.colorspace = features.has_alpha ? MODE_RGBA : MODE_RGB;

guint len = 0;
guint len = 0;
context->deccfg.output.is_external_memory = TRUE;
context->deccfg.output.u.RGBA.rgba
= gdk_pixbuf_get_pixels_with_length (context->pixbuf, &len);
context->deccfg.output.u.RGBA.stride = gdk_pixbuf_get_rowstride (context->pixbuf);
context->deccfg.output.u.RGBA.size = (size_t) len;
context->idec = WebPIDecode (NULL, 0, &context->deccfg);

if (context->idec == NULL)
{
g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
"Could not allocate WebPIDecode");
g_clear_object (&context->pixbuf);
return FALSE;
}

context->prepare_func (context->pixbuf, NULL, context->user_data);
}

Expand Down Expand Up @@ -169,8 +178,6 @@ stop_load (gpointer data, GError **error)
ret = TRUE;
}

WebPFreeDecBuffer (&context->deccfg.output);

g_clear_pointer (&context->idec, WebPIDelete);
g_clear_object (&context->pixbuf);
g_free (context);
Expand Down

0 comments on commit c84d336

Please sign in to comment.