aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-12-28 07:46:40 +0100
committerPřemysl Eric Janouch <p@janouch.name>2023-12-28 07:48:11 +0100
commitc04c4063e4a4feabf0eb23b3a38630e4fce1456b (patch)
treeee7659fcce11508cf80bf076fe4c3d25d701dcc6
parentaed6ae6b83454a8633b2ffd45ecfef1509354f29 (diff)
downloadfiv-c04c4063e4a4feabf0eb23b3a38630e4fce1456b.tar.gz
fiv-c04c4063e4a4feabf0eb23b3a38630e4fce1456b.tar.xz
fiv-c04c4063e4a4feabf0eb23b3a38630e4fce1456b.zip
Fix a class of animated transparent WebPs
-rw-r--r--fiv-io.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/fiv-io.c b/fiv-io.c
index 4ad4812..46cc6c8 100644
--- a/fiv-io.c
+++ b/fiv-io.c
@@ -1741,10 +1741,8 @@ load_libwebp_frame(WebPAnimDecoder *dec, const WebPAnimInfo *info,
return NULL;
}
- bool is_opaque = (info->bgcolor & 0xFF) == 0xFF;
uint64_t area = info->canvas_width * info->canvas_height;
- FivIoImage *image = fiv_io_image_new(
- is_opaque ? CAIRO_FORMAT_RGB24 : CAIRO_FORMAT_ARGB32,
+ FivIoImage *image = fiv_io_image_new(CAIRO_FORMAT_RGB24,
info->canvas_width, info->canvas_height);
if (!image) {
set_error(error, "image allocation failure");
@@ -1760,6 +1758,13 @@ load_libwebp_frame(WebPAnimDecoder *dec, const WebPAnimInfo *info,
*dst++ = GUINT32_FROM_LE(*src++);
}
+ // info->bgcolor is not reliable.
+ for (const uint32_t *p = dst, *end = dst + area; p < end; p++)
+ if ((~*p & 0xff000000)) {
+ image->format = CAIRO_FORMAT_ARGB32;
+ break;
+ }
+
// This API is confusing and awkward.
image->frame_duration = timestamp - *last_timestamp;
*last_timestamp = timestamp;