From 995be755ab5fb225325ec912c53dcd49ae1c939a Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Thu, 15 Aug 2013 18:01:13 +0200 Subject: [PATCH] (imagemagick_compute_animated_image): Implement a simple cache (imagemagick_compute_animated_image): Fix some compilation warnings. Implement a very simple cache to make the animation usable at all, but it should be replaced with a per-image cache. --- src/ChangeLog | 3 +++ src/image.c | 21 +++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 888db1f8cf4..b17dec01e2c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -18,6 +18,9 @@ * image.c (imagemagick_compute_animated_image): Implement animated images (bug#14700). + (imagemagick_compute_animated_image): Fix some compilation + warnings. Implement a very simple cache to make the animation + usable at all, but it should be replaced with a per-image cache. 2013-08-15 Dmitry Antipov diff --git a/src/image.c b/src/image.c index c534f181e5c..c9ad4c8ef76 100644 --- a/src/image.c +++ b/src/image.c @@ -7871,19 +7871,26 @@ imagemagick_filename_hint (Lisp_Object spec, char hint_buffer[MaxTextExtent]) compute ann the preceding images to be able to display a particular sub-image. */ +static MagickWand *animation_cache = NULL; +static int animation_index = 0; + static MagickWand * imagemagick_compute_animated_image (MagickWand *super_wand, int ino) { MagickWand *composite_wand; MagickSetIteratorIndex (super_wand, 0); - composite_wand = MagickGetImage (super_wand); - for (int i = 1; i <= ino; i++) { + if (ino == 0 || animation_cache == NULL) + composite_wand = MagickGetImage (super_wand); + else + composite_wand = animation_cache; + + for (int i = max (1, animation_index); i <= ino; i++) { MagickWand *sub_wand; PixelIterator *source_iterator, *dest_iterator; PixelWand **source, **dest; - long source_width, dest_width; + unsigned long source_width, dest_width; MagickPixelPacket pixel; MagickSetIteratorIndex (super_wand, i); @@ -7910,7 +7917,8 @@ imagemagick_compute_animated_image (MagickWand *super_wand, int ino) return NULL; } - while (source = PixelGetNextIteratorRow (source_iterator, &source_width)) { + while ((source = PixelGetNextIteratorRow (source_iterator, &source_width)) + != NULL) { dest = PixelGetNextIteratorRow (dest_iterator, &dest_width); for (int x = 0; x < source_width; x++) { @@ -7929,6 +7937,11 @@ imagemagick_compute_animated_image (MagickWand *super_wand, int ino) DestroyMagickWand (sub_wand); } + /* Cache a copy for the next iteration. The current wand will be + destroyed by the caller. */ + animation_cache = CloneMagickWand (composite_wand); + animation_index = ino; + return composite_wand; } -- 2.11.4.GIT