From a0c8c274d354f3901f076d163d3828ae55d13a2d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Juan=20Jos=C3=A9=20Garc=C3=ADa-Ripoll?= Date: Sat, 18 Apr 2020 10:41:42 +0200 Subject: [PATCH] Fix loading multi-frame TIFF images via GDI+ * src/w32image.c (w32_frame_delay): Don't try to compute frame delay if GdipGetPropertyItemSize fails for PropertyTagFrameDelay. (w32_load_image): Don't add 'delay' member to metadata if the delay could not be determined. --- src/w32image.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/w32image.c b/src/w32image.c index 0a2a55d3f6f..95d8ddfe117 100644 --- a/src/w32image.c +++ b/src/w32image.c @@ -245,27 +245,33 @@ w32_frame_delay (GpBitmap *pBitmap, int frame) { UINT size; PropertyItem *propertyItem; - double delay = 0.0; + double delay = -1.0; /* Assume that the image has a property item of type PropertyItemEquipMake. - Get the size of that property item. */ - GdipGetPropertyItemSize (pBitmap, PropertyTagFrameDelay, &size); + Get the size of that property item. This can fail for multi-frame TIFF + images. */ + GpStatus status = GdipGetPropertyItemSize (pBitmap, PropertyTagFrameDelay, + &size); - /* Allocate a buffer to receive the property item. */ - propertyItem = malloc (size); - if (propertyItem != NULL) + if (status == Ok) { - /* Get the property item. */ - GdipGetPropertyItem (pBitmap, PropertyTagFrameDelay, size, propertyItem); - delay = decode_delay (propertyItem, frame); - if (delay <= 0) - { - /* In GIF files, unfortunately, delay is only specified for the first - frame. */ - delay = decode_delay (propertyItem, 0); - } - delay /= 100.0; - free (propertyItem); + /* Allocate a buffer to receive the property item. */ + propertyItem = malloc (size); + if (propertyItem != NULL) + { + /* Get the property item. */ + GdipGetPropertyItem (pBitmap, PropertyTagFrameDelay, size, + propertyItem); + delay = decode_delay (propertyItem, frame); + if (delay <= 0) + { + /* In GIF files, unfortunately, delay is only specified + for the first frame. */ + delay = decode_delay (propertyItem, 0); + } + delay /= 100.0; + free (propertyItem); + } } return delay; } @@ -372,7 +378,7 @@ w32_load_image (struct frame *f, struct image *img, { if (nframes > 1) metadata = Fcons (Qcount, Fcons (make_fixnum (nframes), metadata)); - if (delay) + if (delay >= 0) metadata = Fcons (Qdelay, Fcons (make_float (delay), metadata)); } else if (status == Win32Error) /* FIXME! */ -- 2.39.2