This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository legacy-imlib2.

View the commit online.

commit 6e2267e7407d7c9aeebf61ce6f27732bd8f397cf
Author: Kim Woelders <[email protected]>
AuthorDate: Sun Oct 9 17:49:12 2022 +0200

    multiframe: Support loop count
---
 src/bin/imlib2_view.c             | 11 +++++++++++
 src/lib/Imlib2.h.in               |  1 +
 src/lib/Imlib2_Loader.h           |  1 +
 src/lib/api.c                     |  1 +
 src/lib/image.h                   |  1 +
 src/modules/loaders/loader_gif.c  |  5 +++--
 src/modules/loaders/loader_jxl.c  | 11 +++++------
 src/modules/loaders/loader_png.c  |  1 +
 src/modules/loaders/loader_webp.c |  5 +++--
 9 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/src/bin/imlib2_view.c b/src/bin/imlib2_view.c
index 6366512..64f4b19 100644
--- a/src/bin/imlib2_view.c
+++ b/src/bin/imlib2_view.c
@@ -45,6 +45,7 @@ static bool         multiframe = false; /* Image has multiple frames     */
 static bool         fixedframe = false; /* We have selected single frame */
 static bool         animated = false;   /* Image has animation sequence  */
 static bool         animate = false;    /* Animation is active           */
+static int          animloop = 0;       /* Animation loop count          */
 
 #define Dprintf(fmt...)  if (debug)        printf(fmt)
 #define Vprintf(fmt...)  if (verbose)      printf(fmt)
@@ -525,6 +526,7 @@ load_image(int no, const char *name)
              animate = true;
              fixedframe = false;
           }
+        animloop = 0;
 
         im = load_image_frame(nbuf, frame, 0);
 
@@ -647,6 +649,15 @@ main(int argc, char **argv)
              im = NULL;
           }
 
+        if (animate)
+          {
+             if (finfo.frame_num == 1)
+                animloop++;
+             if (finfo.loop_count == animloop &&
+                 finfo.frame_num == finfo.frame_count)
+                animate = false;
+          }
+
         if (animate)
           {
              usleep(1e3 * finfo.frame_delay);
diff --git a/src/lib/Imlib2.h.in b/src/lib/Imlib2.h.in
index 00f56ef..08e52c9 100644
--- a/src/lib/Imlib2.h.in
+++ b/src/lib/Imlib2.h.in
@@ -2833,6 +2833,7 @@ typedef struct {
    int                 frame_w, frame_h;        /* Frame size   */
    int                 frame_flags;     /* Frame info flags */
    int                 frame_delay;     /* Frame delay (ms) */
+   int                 loop_count;      /* Number of animation loops */
 } Imlib_Frame_Info;
 
 /* frame info flags */
diff --git a/src/lib/Imlib2_Loader.h b/src/lib/Imlib2_Loader.h
index 5f826d0..ca79d56 100644
--- a/src/lib/Imlib2_Loader.h
+++ b/src/lib/Imlib2_Loader.h
@@ -148,6 +148,7 @@ struct _ImlibImage {
    int                 frame_y;
    int                 frame_flags;     /* Frame flags      */
    int                 frame_delay;     /* Frame delay (ms) */
+   int                 loop_count;      /* Animation loops  */
 };
 
 /* Must match the ones in Imlib2.h.in */
diff --git a/src/lib/api.c b/src/lib/api.c
index 2700705..7a8d994 100644
--- a/src/lib/api.c
+++ b/src/lib/api.c
@@ -681,6 +681,7 @@ imlib_image_get_frame_info(Imlib_Frame_Info * info)
    CHECK_PARAM_POINTER("image", ctx->image);
    CAST_IMAGE(im, ctx->image);
 
+   info->loop_count = im->loop_count;
    info->frame_count = im->frame_count;
    info->frame_num = im->frame_num;
    info->canvas_w = im->canvas_w ? im->canvas_w : im->w;
diff --git a/src/lib/image.h b/src/lib/image.h
index 7b10ba0..44816e5 100644
--- a/src/lib/image.h
+++ b/src/lib/image.h
@@ -59,6 +59,7 @@ struct _ImlibImage {
    int                 frame_y;
    int                 frame_flags;     /* Frame flags      */
    int                 frame_delay;     /* Frame delay (ms) */
+   int                 loop_count;      /* Animation loops  */
 
    /* vvv Private vvv */
    ImlibLoader        *loader;
diff --git a/src/modules/loaders/loader_gif.c b/src/modules/loaders/loader_gif.c
index 1ccba8b..6cf1ddc 100644
--- a/src/modules/loaders/loader_gif.c
+++ b/src/modules/loaders/loader_gif.c
@@ -89,13 +89,14 @@ _load(ImlibImage * im, int load_data)
      {
         frame = im->frame_num;
         im->frame_count = gif->ImageCount;
+        im->loop_count = 0;     /* Loop forever */
         if (im->frame_count > 1)
            im->frame_flags |= FF_IMAGE_ANIMATED;
         im->canvas_w = gif->SWidth;
         im->canvas_h = gif->SHeight;
 
-        D("Canvas WxH=%dx%d frames=%d\n",
-          im->canvas_w, im->canvas_h, im->frame_count);
+        D("Canvas WxH=%dx%d frames=%d repeat=%d\n",
+          im->canvas_w, im->canvas_h, im->frame_count, im->loop_count);
 
 #if 0
         if (frame > 1 && frame > im->frame_count)
diff --git a/src/modules/loaders/loader_jxl.c b/src/modules/loaders/loader_jxl.c
index 7ddeaf3..7868b0a 100644
--- a/src/modules/loaders/loader_jxl.c
+++ b/src/modules/loaders/loader_jxl.c
@@ -144,17 +144,16 @@ _load(ImlibImage * im, int load_data)
                   frame = im->frame_num;
                   if (info.have_animation)
                     {
-                       if (info.animation.num_loops > 0)
-                          im->frame_count = info.animation.num_loops;
-                       else
-                          im->frame_count = 1234567890; // FIXME - Hack
+                       im->frame_count = 1234567890;    // FIXME - Hack
+                       im->loop_count = info.animation.num_loops;
                        im->frame_flags |= FF_IMAGE_ANIMATED;
                        im->canvas_w = info.xsize;
                        im->canvas_h = info.ysize;
                     }
 
-                  D("Canvas WxH=%dx%d frames=%d\n",
-                    im->canvas_w, im->canvas_h, im->frame_count);
+                  D("Canvas WxH=%dx%d frames=%d repeat=%d\n",
+                    im->canvas_w, im->canvas_h,
+                    im->frame_count, im->loop_count);
 
                   if (frame > 1 && im->frame_count > 0
                       && frame > im->frame_count)
diff --git a/src/modules/loaders/loader_png.c b/src/modules/loaders/loader_png.c
index bbec8d2..fc7045f 100644
--- a/src/modules/loaders/loader_png.c
+++ b/src/modules/loaders/loader_png.c
@@ -368,6 +368,7 @@ _load(ImlibImage * im, int load_data)
           case PNG_TYPE_acTL:
 #define P (&chunk->actl)
              im->frame_count = htonl(P->num_frames);
+             im->loop_count = htonl(P->num_plays);
              D("num_frames=%d num_plays=%d\n", im->frame_count,
                htonl(P->num_plays));
              if (im->frame_num > im->frame_count)
diff --git a/src/modules/loaders/loader_webp.c b/src/modules/loaders/loader_webp.c
index 053a11a..1269768 100644
--- a/src/modules/loaders/loader_webp.c
+++ b/src/modules/loaders/loader_webp.c
@@ -38,13 +38,14 @@ _load(ImlibImage * im, int load_data)
      {
         frame = im->frame_num;
         im->frame_count = WebPDemuxGetI(demux, WEBP_FF_FRAME_COUNT);
+        im->loop_count = WebPDemuxGetI(demux, WEBP_FF_LOOP_COUNT);
         if (im->frame_count > 1)
            im->frame_flags |= FF_IMAGE_ANIMATED;
         im->canvas_w = WebPDemuxGetI(demux, WEBP_FF_CANVAS_WIDTH);
         im->canvas_h = WebPDemuxGetI(demux, WEBP_FF_CANVAS_HEIGHT);
 
-        D("Canvas WxH=%dx%d frames=%d\n",
-          im->canvas_w, im->canvas_h, im->frame_count);
+        D("Canvas WxH=%dx%d frames=%d repeat=%d\n",
+          im->canvas_w, im->canvas_h, im->frame_count, im->loop_count);
 
         if (frame > 1 && frame > im->frame_count)
            QUIT_WITH_RC(LOAD_BADFRAME);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to