summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-12-05 22:54:15 +0100
committerKim Woelders <kim@woelders.dk>2021-12-19 14:58:43 +0100
commit1a57db7dcb21b48a960c0e67621e9f3f80a2a076 (patch)
tree36f610e4e37541110c7036166675d8d7c9fcf44c
parentd792aaa130fc346d58fa33e4eaf5d51092a590ab (diff)
downloadimlib2-1a57db7dcb21b48a960c0e67621e9f3f80a2a076.tar.gz
Add support for multiframe (animated) images
-rw-r--r--src/lib/Imlib2.h.in17
-rw-r--r--src/lib/api.c43
-rw-r--r--src/lib/image.c1
-rw-r--r--src/lib/image.h13
4 files changed, 74 insertions, 0 deletions
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
@@ -1337,6 +1337,49 @@ imlib_load_image_with_error_return(const char *file,
}
/**
+ * @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.
*/
EAPI void
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);