ADDED: LoadImageAnim() to load animated sequence of images
This commit is contained in:
parent
fa7799143e
commit
c57323f29c
2 changed files with 41 additions and 31 deletions
|
@ -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 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 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 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 UnloadImage(Image image); // Unload image from CPU memory (RAM)
|
||||||
RLAPI void ExportImage(Image image, const char *fileName); // Export image data to file
|
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
|
RLAPI void ExportImageAsCode(Image image, const char *fileName); // Export image as code file defining an array of bytes
|
||||||
|
|
|
@ -170,9 +170,6 @@
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module specific Functions Declaration
|
// 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)
|
#if defined(SUPPORT_FILEFORMAT_DDS)
|
||||||
static Image LoadDDS(const char *fileName); // Load DDS file
|
static Image LoadDDS(const char *fileName); // Load DDS file
|
||||||
#endif
|
#endif
|
||||||
|
@ -363,6 +360,46 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int
|
||||||
return image;
|
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)
|
// Unload image from CPU memory (RAM)
|
||||||
void UnloadImage(Image image)
|
void UnloadImage(Image image)
|
||||||
{
|
{
|
||||||
|
@ -3706,34 +3743,6 @@ int GetPixelDataSize(int width, int height, int format)
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module specific Functions Definition
|
// 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)
|
#if defined(SUPPORT_FILEFORMAT_DDS)
|
||||||
// Loading DDS image data (compressed or uncompressed)
|
// Loading DDS image data (compressed or uncompressed)
|
||||||
static Image LoadDDS(const char *fileName)
|
static Image LoadDDS(const char *fileName)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue