summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2020-07-10 13:59:01 +0200
committerraysan5 <[email protected]>2020-07-10 13:59:01 +0200
commitc57323f29ccc207f53c52cfe3df7ac0db5f5c113 (patch)
treecfc9b78061b7765fa580679de3350f7d730aa624 /src
parentfa7799143e7381bc9334c54b77266367532a8dc0 (diff)
downloadraylib-c57323f29ccc207f53c52cfe3df7ac0db5f5c113.tar.gz
raylib-c57323f29ccc207f53c52cfe3df7ac0db5f5c113.zip
ADDED: LoadImageAnim() to load animated sequence of images
Diffstat (limited to 'src')
-rw-r--r--src/raylib.h1
-rw-r--r--src/textures.c71
2 files changed, 41 insertions, 31 deletions
diff --git a/src/raylib.h b/src/raylib.h
index 4359147a..49c7ba6a 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -1099,6 +1099,7 @@ RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Ve
RLAPI Image LoadImage(const char *fileName); // Load image from file into CPU memory (RAM)
RLAPI Image LoadImageEx(Color *pixels, int width, int height); // Load image from Color array data (RGBA - 32bit)
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 void UnloadImage(Image image); // Unload image from CPU memory (RAM)
RLAPI void ExportImage(Image image, const char *fileName); // Export image data to file
RLAPI void ExportImageAsCode(Image image, const char *fileName); // Export image as code file defining an array of bytes
diff --git a/src/textures.c b/src/textures.c
index 52177b43..087352c7 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -170,9 +170,6 @@
//----------------------------------------------------------------------------------
// Module specific Functions Declaration
//----------------------------------------------------------------------------------
-#if defined(SUPPORT_FILEFORMAT_GIF)
-static Image LoadAnimatedGIF(const char *fileName, int *frames, int **delays); // Load animated GIF file
-#endif
#if defined(SUPPORT_FILEFORMAT_DDS)
static Image LoadDDS(const char *fileName); // Load DDS file
#endif
@@ -363,6 +360,46 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int
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)
+{
+ Image image = { 0 };
+ int framesCount = 1;
+
+#if defined(SUPPORT_FILEFORMAT_GIF)
+ if (IsFileExtension(fileName, ".gif"))
+#else
+ if (false)
+#endif
+ {
+ unsigned int dataSize = 0;
+ unsigned char *fileData = LoadFileData(fileName, &dataSize);
+
+ 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.mipmaps = 1;
+ image.format = UNCOMPRESSED_R8G8B8A8;
+
+ RL_FREE(fileData);
+ RL_FREE(delays); // NOTE: Frames delays are discarded
+ }
+ }
+ else image = LoadImage(fileName);
+
+ // TODO: Support APNG animated images?
+
+ *frames = framesCount;
+ return image;
+}
+
// Unload image from CPU memory (RAM)
void UnloadImage(Image image)
{
@@ -3706,34 +3743,6 @@ int GetPixelDataSize(int width, int height, int format)
//----------------------------------------------------------------------------------
// Module specific Functions Definition
//----------------------------------------------------------------------------------
-#if defined(SUPPORT_FILEFORMAT_GIF)
-// 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 };
-
- unsigned int dataSize = 0;
- unsigned char *fileData = LoadFileData(fileName, &dataSize);
-
- if (fileData != NULL)
- {
- int comp = 0;
- image.data = stbi_load_gif_from_memory(fileData, dataSize, delays, &image.width, &image.height, frames, &comp, 4);
-
- image.mipmaps = 1;
- image.format = UNCOMPRESSED_R8G8B8A8;
-
- RL_FREE(fileData);
- }
-
- return image;
-}
-#endif
-
#if defined(SUPPORT_FILEFORMAT_DDS)
// Loading DDS image data (compressed or uncompressed)
static Image LoadDDS(const char *fileName)