aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--image.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/image.c b/image.c
index 062f7ad..4440497 100644
--- a/image.c
+++ b/image.c
@@ -380,12 +380,18 @@ bool img_load_webp(const fileinfo_t *file, Imlib_Image *fframe, img_t *img)
flags = WebPDemuxGetI(demux, WEBP_FF_FORMAT_FLAGS);
img->w = WebPDemuxGetI(demux, WEBP_FF_CANVAS_WIDTH);
img->h = WebPDemuxGetI(demux, WEBP_FF_CANVAS_HEIGHT);
- img->multi.cap = info.frame_count;
- img->multi.sel = 0;
- img->multi.frames = emalloc(info.frame_count * sizeof(img_frame_t));
+
+ if (img->multi.cap == 0) {
+ img->multi.cap = info.frame_count;
+ img->multi.frames = emalloc(img->multi.cap * sizeof(img_frame_t));
+ } else if (info.frame_count > img->multi.cap) {
+ img->multi.cap = info.frame_count;
+ img->multi.frames = erealloc(img->multi.frames,
+ img->multi.cap * sizeof(img_frame_t));
+ }
/* Load and decode frames (also works on images with only 1 frame) */
- img->multi.cnt = 0;
+ img->multi.cnt = img->multi.sel = 0;
while (WebPAnimDecoderGetNext(dec, &buf, &ts)) {
im = imlib_create_image_using_copied_data(
info.canvas_width, info.canvas_height, (DATA32*)buf);