kwo pushed a commit to branch master.

http://git.enlightenment.org/legacy/imlib2.git/commit/?id=1a57db7dcb21b48a960c0e67621e9f3f80a2a076

commit 1a57db7dcb21b48a960c0e67621e9f3f80a2a076
Author: Kim Woelders <[email protected]>
Date:   Sun Dec 5 22:54:15 2021 +0100

    Add support for multiframe (animated) images
---
 src/lib/Imlib2.h.in | 17 +++++++++++++++++
 src/lib/api.c       | 43 +++++++++++++++++++++++++++++++++++++++++++
 src/lib/image.c     |  1 +
 src/lib/image.h     | 13 +++++++++++++
 4 files changed, 74 insertions(+)

diff --git a/src/lib/Imlib2.h.in b/src/lib/Imlib2.h.in
index 376eb8f..697ad1b 100644
--- a/src/lib/Imlib2.h.in
+++ b/src/lib/Imlib2.h.in
@@ -609,6 +609,23 @@ EAPI void           imlib_apply_filter(const char *script, 
...);
 EAPI void           imlib_image_clear(void);
 EAPI void           imlib_image_clear_color(int r, int g, int b, int a);
 
+typedef struct {
+   int                 frame_count;     /* Number of frames in image      */
+   int                 frame_num;       /* Current frame (1..frame_count) */
+   int                 canvas_w, canvas_h;      /* Canvas size  */
+   int                 frame_x, frame_y;        /* Frame origin */
+   int                 frame_w, frame_h;        /* Frame size   */
+   int                 frame_flags;     /* Frame info flags */
+   int                 frame_delay;     /* Frame delay (ms) */
+} Imlib_Frame_Info;
+
+/* frame info flags */
+#define IMLIB_IMAGE_ANIMATED    (1 << 0)        /* Frames are an animated 
sequence */
+#define IMLIB_FRAME_CLEAR       (1 << 1)        /* Clear before rendering 
frame    */
+
+EAPI Imlib_Image    imlib_load_image_frame(const char *file, int frame);
+EAPI void           imlib_image_get_frame_info(Imlib_Frame_Info * info);
+
 /* *INDENT-OFF* */
 #ifdef __cplusplus
 }
diff --git a/src/lib/api.c b/src/lib/api.c
index e17c8c8..4a5077c 100644
--- a/src/lib/api.c
+++ b/src/lib/api.c
@@ -1336,6 +1336,49 @@ imlib_load_image_with_error_return(const char *file,
    return im;
 }
 
+/**
+ * @param file Image file.
+ * @param frame Frame number.
+ * @return An image handle.
+ *
+ * Loads the specified frame within the image.
+ * On success an image handle is returned, otherwise NULL is returned
+ * (e.g. if the requested frame does not exist).
+ * The image is loaded immediately and will not be cached.
+ */
+EAPI                Imlib_Image
+imlib_load_image_frame(const char *file, int frame)
+{
+   ImlibImage         *im;
+   ImlibLoadArgs       ila = { ILA0(ctx, 1, 1),.frame = frame };
+
+   CHECK_PARAM_POINTER_RETURN("file", file, NULL);
+
+   im = __imlib_LoadImage(file, &ila);
+
+   return (Imlib_Image) im;
+}
+
+EAPI void
+imlib_image_get_frame_info(Imlib_Frame_Info * info)
+{
+   ImlibImage         *im;
+
+   CHECK_PARAM_POINTER("image", ctx->image);
+   CAST_IMAGE(im, ctx->image);
+
+   info->frame_count = im->frame_count;
+   info->frame_num = im->frame_num;
+   info->canvas_w = im->canvas_w ? im->canvas_w : im->w;
+   info->canvas_h = im->canvas_h ? im->canvas_h : im->h;
+   info->frame_x = im->frame_x;
+   info->frame_y = im->frame_y;
+   info->frame_w = im->w;
+   info->frame_h = im->h;
+   info->frame_flags = im->frame_flags;
+   info->frame_delay = im->frame_delay ? im->frame_delay : 100;
+}
+
 /**
  * Frees the image that is set as the current image in Imlib2's context.
  */
diff --git a/src/lib/image.c b/src/lib/image.c
index 7e59280..6981b20 100644
--- a/src/lib/image.c
+++ b/src/lib/image.c
@@ -519,6 +519,7 @@ __imlib_LoadImage(const char *file, ImlibLoadArgs * ila)
    im->fsize = st.st_size;
    im->real_file = im_file ? im_file : im->file;
    im->key = im_key;
+   im->frame_num = ila->frame;
 
    if (ila->fp)
       im->fp = ila->fp;
diff --git a/src/lib/image.h b/src/lib/image.h
index bc0e549..77e9a38 100644
--- a/src/lib/image.h
+++ b/src/lib/image.h
@@ -32,6 +32,10 @@ enum _iflags {
 
 typedef enum _iflags ImlibImageFlags;
 
+/* Must match the ones in Imlib2.h.in */
+#define FF_IMAGE_ANIMATED   (1 << 0)    /* Frames are an animated sequence */
+#define FF_FRAME_CLEAR      (1 << 1)    /* Clear before rendering frame    */
+
 struct _imlibborder {
    int                 left, right, top, bottom;
 };
@@ -62,6 +66,14 @@ struct _imlibimage {
    ImlibLdCtx         *lc;
    FILE               *fp;
    off_t               fsize;
+   int                 canvas_w;        /* Canvas size      */
+   int                 canvas_h;
+   int                 frame_count;     /* Number of frames */
+   int                 frame_num;       /* Current frame    */
+   int                 frame_x; /* Frame origin     */
+   int                 frame_y;
+   int                 frame_flags;     /* Frame flags      */
+   int                 frame_delay;     /* Frame delay (ms) */
 };
 
 typedef struct {
@@ -71,6 +83,7 @@ typedef struct {
    char                immed;
    char                nocache;
    int                 err;
+   int                 frame;
 } ImlibLoadArgs;
 
 void                __imlib_RemoveAllLoaders(void);

-- 


Reply via email to