summaryrefslogtreecommitdiffhomepage
path: root/src/rtextures.c
diff options
context:
space:
mode:
authorRay <[email protected]>2023-12-28 23:16:57 +0100
committerRay <[email protected]>2023-12-28 23:16:57 +0100
commitdde738a2fd3f2c657af1693b0f314df361b4c04f (patch)
treed3b320a38682fd108f9b01b55323ddbf5b72b428 /src/rtextures.c
parent7ea6adb29eaf39e18c6faa4d7d6d9bd8a9d60910 (diff)
parentfd5e1e6afb69ef190e74ac780ec3718d36e2d7d1 (diff)
downloadraylib-dde738a2fd3f2c657af1693b0f314df361b4c04f.tar.gz
raylib-dde738a2fd3f2c657af1693b0f314df361b4c04f.zip
Merge branch 'master' of https://github.com/raysan5/raylib
Diffstat (limited to 'src/rtextures.c')
-rw-r--r--src/rtextures.c53
1 files changed, 46 insertions, 7 deletions
diff --git a/src/rtextures.c b/src/rtextures.c
index a16fb386..e9fb95cb 100644
--- a/src/rtextures.c
+++ b/src/rtextures.c
@@ -438,6 +438,45 @@ 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 LoadImageAnimFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int *frames)
+{
+ Image image = { 0 };
+ int frameCount = 0;
+
+#if defined(SUPPORT_FILEFORMAT_GIF)
+ if ((strcmp(fileType, ".gif") == 0) || (strcmp(fileType, ".GIF") == 0))
+ {
+ if (fileData != NULL)
+ {
+ int comp = 0;
+ int *delays = NULL;
+ image.data = stbi_load_gif_from_memory(fileData, dataSize, &delays, &image.width, &image.height, &frameCount, &comp, 4);
+
+ image.mipmaps = 1;
+ image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
+
+ RL_FREE(fileData);
+ RL_FREE(delays); // NOTE: Frames delays are discarded
+ }
+ }
+#else
+ if (false) { }
+#endif
+ else
+ {
+ image = LoadImageFromMemory(fileType,fileData,dataSize);
+ frameCount = 1;
+ }
+
+ *frames = frameCount;
+ return image;
+}
+
// Load image from memory buffer, fileType refers to extension: i.e. ".png"
// WARNING: File extension must be provided in lower-case
Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, int dataSize)
@@ -2108,14 +2147,14 @@ void ImageKernelConvolution(Image *image, float* kernel, int kernelSize){
{
startRange = -kernelWidth/2;
endRange = kernelWidth/2;
- } else
+ } else
{
startRange = -kernelWidth/2;
endRange = kernelWidth/2+1;
}
- for(int x = 0; x < image->height; x++)
+ for(int x = 0; x < image->height; x++)
{
- for(int y = 0; y < image->width; y++)
+ for(int y = 0; y < image->width; y++)
{
for(int xk = startRange; xk < endRange; xk++)
@@ -2193,14 +2232,14 @@ void ImageKernelConvolution(Image *image, float* kernel, int kernelSize){
}
}
- for (int i = 0; i < (image->width) * (image->height); i++)
+ for (int i = 0; i < (image->width) * (image->height); i++)
{
float alpha = (float)imageCopy2[i].w;
pixels[i].r = (unsigned char)((imageCopy2[i].x)*255.0f);
pixels[i].g = (unsigned char)((imageCopy2[i].y)*255.0f);
pixels[i].b = (unsigned char)((imageCopy2[i].z)*255.0f);
pixels[i].a = (unsigned char)((alpha)*255.0f);
- // printf("pixels[%d] = %d", i, pixels[i].r);
+ // printf("pixels[%d] = %d", i, pixels[i].r);
}
@@ -3778,7 +3817,7 @@ TextureCubemap LoadTextureCubemap(Image image, int layout)
if ((image.height/6) == image.width) { layout = CUBEMAP_LAYOUT_LINE_VERTICAL; cubemap.width = image.height/6; }
else if ((image.width/3) == (image.height/4)) { layout = CUBEMAP_LAYOUT_CROSS_THREE_BY_FOUR; cubemap.width = image.width/3; }
}
- }
+ }
else
{
if (layout == CUBEMAP_LAYOUT_LINE_VERTICAL) cubemap.width = image.height/6;
@@ -3797,7 +3836,7 @@ TextureCubemap LoadTextureCubemap(Image image, int layout)
Image faces = { 0 }; // Vertical column image
Rectangle faceRecs[6] = { 0 }; // Face source rectangles
-
+
for (int i = 0; i < 6; i++) faceRecs[i] = (Rectangle){ 0, 0, (float)size, (float)size };
if (layout == CUBEMAP_LAYOUT_LINE_VERTICAL)