From 381a62a05b7aec5e4b97bcdd5ff3724891532f03 Mon Sep 17 00:00:00 2001 From: Ardel1 Date: Wed, 18 Aug 2021 17:11:01 +0200 Subject: [PATCH] add LoadImageAnimDelays() with int **frameDelays parameter Added a new function LoadImageAnimDelays(), that replaces LoadImageAnim() (which now calls LoadImageAnimDelays() for backwards compatibility). This function is the same as the old LoadImageAnim(), except that it also returns the frame delays of a gif so it is possible to calculate/know when the next frame should be rendered. --- src/raylib.h | 1 + src/textures.c | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index c7b4b282b..094f3b210 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1200,6 +1200,7 @@ RLAPI Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); RLAPI Image LoadImage(const char *fileName); // Load image from file into CPU memory (RAM) RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image from RAW file data RLAPI Image LoadImageAnim(const char *fileName, int *frames); // Load image sequence from file (frames appended to image.data) +RLAPI Image LoadImageAnimDelays(const char *fileName, int *frames, int **frameDelays); // Load image sequence from file and also return delays between image frames RLAPI Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, int dataSize); // Load image from memory buffer, fileType refers to extension: i.e. '.png' RLAPI Image LoadImageFromTexture(Texture2D texture); // Load image from GPU texture data RLAPI Image LoadImageFromScreen(void); // Load image from screen buffer and (screenshot) diff --git a/src/textures.c b/src/textures.c index 6d5c2c5f4..dd1383446 100644 --- a/src/textures.c +++ b/src/textures.c @@ -250,8 +250,8 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int // - Image.data buffer includes all frames: [image#0][image#1][image#2][...] // - Number of frames is returned through 'frames' parameter // - All frames are returned in RGBA format -// - Frames delay data is discarded -Image LoadImageAnim(const char *fileName, int *frames) +// - Frames delay data is returned though 'frameDelays' parameter, a pointer to an array of ints that the function will declare with length equal to the number of frames, that represents the delay per frame in miliseconds +Image LoadImageAnimDelays(const char *fileName, int *frames, int **frameDelays) { Image image = { 0 }; int framesCount = 1; @@ -265,14 +265,12 @@ Image LoadImageAnim(const char *fileName, int *frames) if (fileData != NULL) { int comp = 0; - int **delays = NULL; - image.data = stbi_load_gif_from_memory(fileData, dataSize, delays, &image.width, &image.height, &framesCount, &comp, 4); + image.data = stbi_load_gif_from_memory(fileData, dataSize, frameDelays, &image.width, &image.height, &framesCount, &comp, 4); image.mipmaps = 1; image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8; RL_FREE(fileData); - RL_FREE(delays); // NOTE: Frames delays are discarded } } #else @@ -286,6 +284,18 @@ Image LoadImageAnim(const char *fileName, int *frames) return image; } +// Load animated image data +// - Image.data buffer includes all frames: [image#0][image#1][image#2][...] +// - Number of frames is returned through 'frames' parameter +// - All frames are returned in RGBA format +// - Frames delay data is discarded +Image LoadImageAnim(const char *fileName, int *frames) +{ + int *delays = NULL; + LoadImageAnimDelays(fileName, frames, &delays); + RL_FREE(delays); +} + // Load image from memory buffer, fileType refers to extension: i.e. ".png" Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, int dataSize) {