multiframe: Support loop count
This commit is contained in:
parent
272c737cc3
commit
6e2267e740
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue