aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-01-23 00:26:22 +0100
committerPřemysl Eric Janouch <p@janouch.name>2022-01-23 00:27:20 +0100
commitb71d5dff571f70066319a20e49a771bb9b0816b1 (patch)
tree1068aca5d57e8b5873a119858df3391794b4bd03
parentc85de6b20f772a832bb72de8976a0175b53f1cbb (diff)
downloadfiv-b71d5dff571f70066319a20e49a771bb9b0816b1.tar.gz
fiv-b71d5dff571f70066319a20e49a771bb9b0816b1.tar.xz
fiv-b71d5dff571f70066319a20e49a771bb9b0816b1.zip
Make truncated WebP parts always transparent
-rw-r--r--fiv-io.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/fiv-io.c b/fiv-io.c
index f141879..fa2da7a 100644
--- a/fiv-io.c
+++ b/fiv-io.c
@@ -1281,18 +1281,35 @@ load_libwebp_nonanimated(WebPDecoderConfig *config, const WebPData *wd,
}
VP8StatusCode err = WebPIUpdate(idec, wd->bytes, wd->size);
+ cairo_surface_mark_dirty(surface);
+ int x = 0, y = 0, w = 0, h = 0;
+ (void) WebPIDecodedArea(idec, &x, &y, &w, &h);
WebPIDelete(idec);
- if (err == VP8_STATUS_SUSPENDED) {
- g_warning("partial WebP");
- } else if (err) {
+ if (err == VP8_STATUS_OK)
+ return surface;
+
+ if (err != VP8_STATUS_SUSPENDED) {
g_set_error(error, FIV_IO_ERROR, FIV_IO_ERROR_OPEN, "%s: %s",
"WebP decoding error", load_libwebp_error(err));
cairo_surface_destroy(surface);
return NULL;
}
- cairo_surface_mark_dirty(surface);
- return surface;
+ g_warning("partial WebP");
+ if (config->input.has_alpha)
+ return surface;
+
+ // Always use transparent black, rather than opaque black.
+ cairo_surface_t *masked = cairo_image_surface_create(
+ CAIRO_FORMAT_ARGB32, config->input.width, config->input.height);
+ cairo_t *cr = cairo_create(masked);
+ cairo_set_source_surface(cr, surface, 0, 0);
+ cairo_rectangle(cr, x, y, w, h);
+ cairo_clip(cr);
+ cairo_paint(cr);
+ cairo_destroy(cr);
+ cairo_surface_destroy(surface);
+ return masked;
}
static cairo_surface_t *