aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2019-09-19 16:09:36 +0200
committerRay <raysan5@gmail.com>2019-09-19 16:09:36 +0200
commitd089e1cd34fdae4a17aa589ff20ea0af19b11410 (patch)
tree6f50988809bbbf17d9d81cde5eb761bfdf35383a
parent741afde3bcc337f60c50337fef05531363ece120 (diff)
downloadraylib-d089e1cd34fdae4a17aa589ff20ea0af19b11410.tar.gz
raylib-d089e1cd34fdae4a17aa589ff20ea0af19b11410.zip
ADDED: LoadAnimatedGIF() -WIP-
Still looking for a better way to integrate it into raylib API, maybe add a LoadImageAnim()?
-rw-r--r--src/textures.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/textures.c b/src/textures.c
index 70e4a0e9..a6ace294 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -161,6 +161,9 @@
//----------------------------------------------------------------------------------
// Module specific Functions Declaration
//----------------------------------------------------------------------------------
+
+static Image LoadAnimatedGIF(const char *fileName, int *frames, int **delays); // Load animated GIF file
+
#if defined(SUPPORT_FILEFORMAT_DDS)
static Image LoadDDS(const char *fileName); // Load DDS file
#endif
@@ -2961,6 +2964,44 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle destR
// Module specific Functions Definition
//----------------------------------------------------------------------------------
+// Load animated GIF data
+// - Image.data buffer includes all frames: [image#0][image#1][image#2][...]
+// - Number of frames is returned through 'frames' parameter
+// - Frames delay is returned through 'delays' parameter (int array)
+// - All frames are returned in RGBA format
+static Image LoadAnimatedGIF(const char *fileName, int *frames, int **delays)
+{
+ Image image = { 0 };
+
+ FILE *gifFile = fopen(fileName, "rb");
+
+ if (gifFile == NULL)
+ {
+ TraceLog(LOG_WARNING, "[%s] Animated GIF file could not be opened", fileName);
+ }
+ else
+ {
+ fseek(gifFile, 0L, SEEK_END);
+ int size = ftell(gifFile);
+ fseek(gifFile, 0L, SEEK_SET);
+
+ char *buffer = (char *)RL_CALLOC(size, sizeof(char));
+ fread(buffer, sizeof(char), size, gifFile);
+
+ fclose(gifFile); // Close file pointer
+
+ int comp = 0;
+ image.data = stbi_load_gif_from_memory(buffer, size, delays, &image.width, &image.height, frames, &comp, 4);
+
+ image.mipmaps = 1;
+ image.format = UNCOMPRESSED_R8G8B8A8;
+
+ free(buffer);
+ }
+
+ return image;
+}
+
#if defined(SUPPORT_FILEFORMAT_DDS)
// Loading DDS image data (compressed or uncompressed)
static Image LoadDDS(const char *fileName)