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.
This commit is contained in:
Ardel1 2021-08-18 17:11:01 +02:00
parent a5beb940f8
commit 381a62a05b
2 changed files with 16 additions and 5 deletions

View File

@ -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 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 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 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 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 LoadImageFromTexture(Texture2D texture); // Load image from GPU texture data
RLAPI Image LoadImageFromScreen(void); // Load image from screen buffer and (screenshot) RLAPI Image LoadImageFromScreen(void); // Load image from screen buffer and (screenshot)

View File

@ -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][...] // - Image.data buffer includes all frames: [image#0][image#1][image#2][...]
// - Number of frames is returned through 'frames' parameter // - Number of frames is returned through 'frames' parameter
// - All frames are returned in RGBA format // - All frames are returned in RGBA format
// - Frames delay data is discarded // - 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 LoadImageAnim(const char *fileName, int *frames) Image LoadImageAnimDelays(const char *fileName, int *frames, int **frameDelays)
{ {
Image image = { 0 }; Image image = { 0 };
int framesCount = 1; int framesCount = 1;
@ -265,14 +265,12 @@ Image LoadImageAnim(const char *fileName, int *frames)
if (fileData != NULL) if (fileData != NULL)
{ {
int comp = 0; int comp = 0;
int **delays = NULL; image.data = stbi_load_gif_from_memory(fileData, dataSize, frameDelays, &image.width, &image.height, &framesCount, &comp, 4);
image.data = stbi_load_gif_from_memory(fileData, dataSize, delays, &image.width, &image.height, &framesCount, &comp, 4);
image.mipmaps = 1; image.mipmaps = 1;
image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8; image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
RL_FREE(fileData); RL_FREE(fileData);
RL_FREE(delays); // NOTE: Frames delays are discarded
} }
} }
#else #else
@ -286,6 +284,18 @@ Image LoadImageAnim(const char *fileName, int *frames)
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)
{
int *delays = NULL;
LoadImageAnimDelays(fileName, frames, &delays);
RL_FREE(delays);
}
// Load image from memory buffer, fileType refers to extension: i.e. ".png" // Load image from memory buffer, fileType refers to extension: i.e. ".png"
Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, int dataSize) Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, int dataSize)
{ {