summaryrefslogtreecommitdiffhomepage
path: root/src/textures.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/textures.c')
-rw-r--r--src/textures.c181
1 files changed, 93 insertions, 88 deletions
diff --git a/src/textures.c b/src/textures.c
index 7059fabb..eb743026 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -112,9 +112,14 @@
defined(SUPPORT_FILEFORMAT_GIF) || \
defined(SUPPORT_FILEFORMAT_PIC) || \
defined(SUPPORT_FILEFORMAT_HDR))
+
+ #define STBI_MALLOC RL_MALLOC
+ #define STBI_FREE RL_FREE
+ #define STBI_REALLOC(p,newsz) realloc(p,newsz)
+
#define STB_IMAGE_IMPLEMENTATION
- #include "external/stb_image.h" // Required for: stbi_load_from_file()
- // NOTE: Used to read image data (multiple formats support)
+ #include "external/stb_image.h" // Required for: stbi_load_from_file()
+ // NOTE: Used to read image data (multiple formats support)
#endif
#if defined(SUPPORT_IMAGE_EXPORT)
@@ -305,7 +310,7 @@ Image LoadImageEx(Color *pixels, int width, int height)
int k = 0;
- image.data = (unsigned char *)malloc(image.width*image.height*4*sizeof(unsigned char));
+ image.data = (unsigned char *)RL_MALLOC(image.width*image.height*4*sizeof(unsigned char));
for (int i = 0; i < image.width*image.height*4; i += 4)
{
@@ -353,7 +358,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int
unsigned int size = GetPixelDataSize(width, height, format);
- image.data = malloc(size); // Allocate required memory in bytes
+ image.data = RL_MALLOC(size); // Allocate required memory in bytes
// NOTE: fread() returns num read elements instead of bytes,
// to get bytes we need to read (1 byte size, elements) instead of (x byte size, 1 element)
@@ -364,7 +369,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int
{
TraceLog(LOG_WARNING, "[%s] RAW image data can not be read, wrong requested format or size", fileName);
- free(image.data);
+ RL_FREE(image.data);
}
else
{
@@ -425,7 +430,7 @@ RenderTexture2D LoadRenderTexture(int width, int height)
// Unload image from CPU memory (RAM)
void UnloadImage(Image image)
{
- free(image.data);
+ RL_FREE(image.data);
}
// Unload texture from GPU memory (VRAM)
@@ -448,7 +453,7 @@ void UnloadRenderTexture(RenderTexture2D target)
// Get pixel data from image in the form of Color struct array
Color *GetImageData(Image image)
{
- Color *pixels = (Color *)malloc(image.width*image.height*sizeof(Color));
+ Color *pixels = (Color *)RL_MALLOC(image.width*image.height*sizeof(Color));
if (image.format >= COMPRESSED_DXT1_RGB) TraceLog(LOG_WARNING, "Pixel data retrieval not supported for compressed image formats");
else
@@ -563,7 +568,7 @@ Color *GetImageData(Image image)
// Get pixel data from image as Vector4 array (float normalized)
Vector4 *GetImageDataNormalized(Image image)
{
- Vector4 *pixels = (Vector4 *)malloc(image.width*image.height*sizeof(Vector4));
+ Vector4 *pixels = (Vector4 *)RL_MALLOC(image.width*image.height*sizeof(Vector4));
if (image.format >= COMPRESSED_DXT1_RGB) TraceLog(LOG_WARNING, "Pixel data retrieval not supported for compressed image formats");
else
@@ -797,7 +802,7 @@ void ExportImage(Image image, const char *fileName)
fclose(rawFile);
}
- free(imgData);
+ RL_FREE(imgData);
#endif
if (success != 0) TraceLog(LOG_INFO, "Image exported successfully: %s", fileName);
@@ -863,7 +868,7 @@ Image ImageCopy(Image image)
if (height < 1) height = 1;
}
- newImage.data = malloc(size);
+ newImage.data = RL_MALLOC(size);
if (newImage.data != NULL)
{
@@ -896,7 +901,7 @@ void ImageToPOT(Image *image, Color fillColor)
Color *pixelsPOT = NULL;
// Generate POT array from NPOT data
- pixelsPOT = (Color *)malloc(potWidth*potHeight*sizeof(Color));
+ pixelsPOT = (Color *)RL_MALLOC(potWidth*potHeight*sizeof(Color));
for (int j = 0; j < potHeight; j++)
{
@@ -909,15 +914,15 @@ void ImageToPOT(Image *image, Color fillColor)
TraceLog(LOG_WARNING, "Image converted to POT: (%ix%i) -> (%ix%i)", image->width, image->height, potWidth, potHeight);
- free(pixels); // Free pixels data
- free(image->data); // Free old image data
+ RL_FREE(pixels); // Free pixels data
+ RL_FREE(image->data); // Free old image data
int format = image->format; // Store image data format to reconvert later
// NOTE: Image size changes, new width and height
*image = LoadImageEx(pixelsPOT, potWidth, potHeight);
- free(pixelsPOT); // Free POT pixels data
+ RL_FREE(pixelsPOT); // Free POT pixels data
ImageFormat(image, format); // Reconvert image to previous format
}
@@ -932,7 +937,7 @@ void ImageFormat(Image *image, int newFormat)
{
Vector4 *pixels = GetImageDataNormalized(*image); // Supports 8 to 32 bit per channel
- free(image->data); // WARNING! We loose mipmaps data --> Regenerated at the end...
+ RL_FREE(image->data); // WARNING! We loose mipmaps data --> Regenerated at the end...
image->data = NULL;
image->format = newFormat;
@@ -942,7 +947,7 @@ void ImageFormat(Image *image, int newFormat)
{
case UNCOMPRESSED_GRAYSCALE:
{
- image->data = (unsigned char *)malloc(image->width*image->height*sizeof(unsigned char));
+ image->data = (unsigned char *)RL_MALLOC(image->width*image->height*sizeof(unsigned char));
for (int i = 0; i < image->width*image->height; i++)
{
@@ -952,7 +957,7 @@ void ImageFormat(Image *image, int newFormat)
} break;
case UNCOMPRESSED_GRAY_ALPHA:
{
- image->data = (unsigned char *)malloc(image->width*image->height*2*sizeof(unsigned char));
+ image->data = (unsigned char *)RL_MALLOC(image->width*image->height*2*sizeof(unsigned char));
for (int i = 0; i < image->width*image->height*2; i += 2, k++)
{
@@ -963,7 +968,7 @@ void ImageFormat(Image *image, int newFormat)
} break;
case UNCOMPRESSED_R5G6B5:
{
- image->data = (unsigned short *)malloc(image->width*image->height*sizeof(unsigned short));
+ image->data = (unsigned short *)RL_MALLOC(image->width*image->height*sizeof(unsigned short));
unsigned char r = 0;
unsigned char g = 0;
@@ -981,7 +986,7 @@ void ImageFormat(Image *image, int newFormat)
} break;
case UNCOMPRESSED_R8G8B8:
{
- image->data = (unsigned char *)malloc(image->width*image->height*3*sizeof(unsigned char));
+ image->data = (unsigned char *)RL_MALLOC(image->width*image->height*3*sizeof(unsigned char));
for (int i = 0, k = 0; i < image->width*image->height*3; i += 3, k++)
{
@@ -994,7 +999,7 @@ void ImageFormat(Image *image, int newFormat)
{
#define ALPHA_THRESHOLD 50
- image->data = (unsigned short *)malloc(image->width*image->height*sizeof(unsigned short));
+ image->data = (unsigned short *)RL_MALLOC(image->width*image->height*sizeof(unsigned short));
unsigned char r = 0;
unsigned char g = 0;
@@ -1014,7 +1019,7 @@ void ImageFormat(Image *image, int newFormat)
} break;
case UNCOMPRESSED_R4G4B4A4:
{
- image->data = (unsigned short *)malloc(image->width*image->height*sizeof(unsigned short));
+ image->data = (unsigned short *)RL_MALLOC(image->width*image->height*sizeof(unsigned short));
unsigned char r = 0;
unsigned char g = 0;
@@ -1034,7 +1039,7 @@ void ImageFormat(Image *image, int newFormat)
} break;
case UNCOMPRESSED_R8G8B8A8:
{
- image->data = (unsigned char *)malloc(image->width*image->height*4*sizeof(unsigned char));
+ image->data = (unsigned char *)RL_MALLOC(image->width*image->height*4*sizeof(unsigned char));
for (int i = 0, k = 0; i < image->width*image->height*4; i += 4, k++)
{
@@ -1048,7 +1053,7 @@ void ImageFormat(Image *image, int newFormat)
{
// WARNING: Image is converted to GRAYSCALE eqeuivalent 32bit
- image->data = (float *)malloc(image->width*image->height*sizeof(float));
+ image->data = (float *)RL_MALLOC(image->width*image->height*sizeof(float));
for (int i = 0; i < image->width*image->height; i++)
{
@@ -1057,7 +1062,7 @@ void ImageFormat(Image *image, int newFormat)
} break;
case UNCOMPRESSED_R32G32B32:
{
- image->data = (float *)malloc(image->width*image->height*3*sizeof(float));
+ image->data = (float *)RL_MALLOC(image->width*image->height*3*sizeof(float));
for (int i = 0, k = 0; i < image->width*image->height*3; i += 3, k++)
{
@@ -1068,7 +1073,7 @@ void ImageFormat(Image *image, int newFormat)
} break;
case UNCOMPRESSED_R32G32B32A32:
{
- image->data = (float *)malloc(image->width*image->height*4*sizeof(float));
+ image->data = (float *)RL_MALLOC(image->width*image->height*4*sizeof(float));
for (int i = 0, k = 0; i < image->width*image->height*4; i += 4, k++)
{
@@ -1081,7 +1086,7 @@ void ImageFormat(Image *image, int newFormat)
default: break;
}
- free(pixels);
+ RL_FREE(pixels);
pixels = NULL;
// In case original image had mipmaps, generate mipmaps for formated image
@@ -1286,7 +1291,7 @@ void ImageCrop(Image *image, Rectangle crop)
{
// Start the cropping process
Color *pixels = GetImageData(*image); // Get data as Color pixels array
- Color *cropPixels = (Color *)malloc((int)crop.width*(int)crop.height*sizeof(Color));
+ Color *cropPixels = (Color *)RL_MALLOC((int)crop.width*(int)crop.height*sizeof(Color));
for (int j = (int)crop.y; j < (int)(crop.y + crop.height); j++)
{
@@ -1296,7 +1301,7 @@ void ImageCrop(Image *image, Rectangle crop)
}
}
- free(pixels);
+ RL_FREE(pixels);
int format = image->format;
@@ -1304,7 +1309,7 @@ void ImageCrop(Image *image, Rectangle crop)
*image = LoadImageEx(cropPixels, (int)crop.width, (int)crop.height);
- free(cropPixels);
+ RL_FREE(cropPixels);
// Reformat 32bit RGBA image to original format
ImageFormat(image, format);
@@ -1341,7 +1346,7 @@ void ImageAlphaCrop(Image *image, float threshold)
Rectangle crop = { xMin, yMin, (xMax + 1) - xMin, (yMax + 1) - yMin };
- free(pixels);
+ RL_FREE(pixels);
// Check for not empty image brefore cropping
if (!((xMax < xMin) || (yMax < yMin))) ImageCrop(image, crop);
@@ -1355,7 +1360,7 @@ void ImageResize(Image *image, int newWidth, int newHeight)
{
// Get data as Color pixels array to work with it
Color *pixels = GetImageData(*image);
- Color *output = (Color *)malloc(newWidth*newHeight*sizeof(Color));
+ Color *output = (Color *)RL_MALLOC(newWidth*newHeight*sizeof(Color));
// NOTE: Color data is casted to (unsigned char *), there shouldn't been any problem...
stbir_resize_uint8((unsigned char *)pixels, image->width, image->height, 0, (unsigned char *)output, newWidth, newHeight, 0, 4);
@@ -1367,15 +1372,15 @@ void ImageResize(Image *image, int newWidth, int newHeight)
*image = LoadImageEx(output, newWidth, newHeight);
ImageFormat(image, format); // Reformat 32bit RGBA image to original format
- free(output);
- free(pixels);
+ RL_FREE(output);
+ RL_FREE(pixels);
}
// Resize and image to new size using Nearest-Neighbor scaling algorithm
void ImageResizeNN(Image *image,int newWidth,int newHeight)
{
Color *pixels = GetImageData(*image);
- Color *output = (Color *)malloc(newWidth*newHeight*sizeof(Color));
+ Color *output = (Color *)RL_MALLOC(newWidth*newHeight*sizeof(Color));
// EDIT: added +1 to account for an early rounding problem
int xRatio = (int)((image->width << 16)/newWidth) + 1;
@@ -1400,8 +1405,8 @@ void ImageResizeNN(Image *image,int newWidth,int newHeight)
*image = LoadImageEx(output, newWidth, newHeight);
ImageFormat(image, format); // Reformat 32bit RGBA image to original format
- free(output);
- free(pixels);
+ RL_FREE(output);
+ RL_FREE(pixels);
}
// Resize canvas and fill with color
@@ -1555,7 +1560,7 @@ void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp)
{
Color *pixels = GetImageData(*image);
- free(image->data); // free old image data
+ RL_FREE(image->data); // free old image data
if ((image->format != UNCOMPRESSED_R8G8B8) && (image->format != UNCOMPRESSED_R8G8B8A8))
{
@@ -1573,7 +1578,7 @@ void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp)
}
// NOTE: We will store the dithered data as unsigned short (16bpp)
- image->data = (unsigned short *)malloc(image->width*image->height*sizeof(unsigned short));
+ image->data = (unsigned short *)RL_MALLOC(image->width*image->height*sizeof(unsigned short));
Color oldPixel = WHITE;
Color newPixel = WHITE;
@@ -1641,7 +1646,7 @@ void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp)
}
}
- free(pixels);
+ RL_FREE(pixels);
}
}
@@ -1652,7 +1657,7 @@ Color *ImageExtractPalette(Image image, int maxPaletteSize, int *extractCount)
#define COLOR_EQUAL(col1, col2) ((col1.r == col2.r)&&(col1.g == col2.g)&&(col1.b == col2.b)&&(col1.a == col2.a))
Color *pixels = GetImageData(image);
- Color *palette = (Color *)malloc(maxPaletteSize*sizeof(Color));
+ Color *palette = (Color *)RL_MALLOC(maxPaletteSize*sizeof(Color));
int palCount = 0;
for (int i = 0; i < maxPaletteSize; i++) palette[i] = BLANK; // Set all colors to BLANK
@@ -1689,7 +1694,7 @@ Color *ImageExtractPalette(Image image, int maxPaletteSize, int *extractCount)
}
}
- free(pixels);
+ RL_FREE(pixels);
*extractCount = palCount;
@@ -1799,8 +1804,8 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec)
*dst = LoadImageEx(dstPixels, (int)dst->width, (int)dst->height);
ImageFormat(dst, dst->format);
- free(srcPixels);
- free(dstPixels);
+ RL_FREE(srcPixels);
+ RL_FREE(dstPixels);
}
// Create an image from text (default font)
@@ -1933,7 +1938,7 @@ void ImageDrawTextEx(Image *dst, Vector2 position, Font font, const char *text,
void ImageFlipVertical(Image *image)
{
Color *srcPixels = GetImageData(*image);
- Color *dstPixels = (Color *)malloc(image->width*image->height*sizeof(Color));
+ Color *dstPixels = (Color *)RL_MALLOC(image->width*image->height*sizeof(Color));
for (int y = 0; y < image->height; y++)
{
@@ -1947,8 +1952,8 @@ void ImageFlipVertical(Image *image)
ImageFormat(&processed, image->format);
UnloadImage(*image);
- free(srcPixels);
- free(dstPixels);
+ RL_FREE(srcPixels);
+ RL_FREE(dstPixels);
image->data = processed.data;
}
@@ -1957,7 +1962,7 @@ void ImageFlipVertical(Image *image)
void ImageFlipHorizontal(Image *image)
{
Color *srcPixels = GetImageData(*image);
- Color *dstPixels = (Color *)malloc(image->width*image->height*sizeof(Color));
+ Color *dstPixels = (Color *)RL_MALLOC(image->width*image->height*sizeof(Color));
for (int y = 0; y < image->height; y++)
{
@@ -1971,8 +1976,8 @@ void ImageFlipHorizontal(Image *image)
ImageFormat(&processed, image->format);
UnloadImage(*image);
- free(srcPixels);
- free(dstPixels);
+ RL_FREE(srcPixels);
+ RL_FREE(dstPixels);
image->data = processed.data;
}
@@ -1981,7 +1986,7 @@ void ImageFlipHorizontal(Image *image)
void ImageRotateCW(Image *image)
{
Color *srcPixels = GetImageData(*image);
- Color *rotPixels = (Color *)malloc(image->width*image->height*sizeof(Color));
+ Color *rotPixels = (Color *)RL_MALLOC(image->width*image->height*sizeof(Color));
for (int y = 0; y < image->height; y++)
{
@@ -1995,8 +2000,8 @@ void ImageRotateCW(Image *image)
ImageFormat(&processed, image->format);
UnloadImage(*image);
- free(srcPixels);
- free(rotPixels);
+ RL_FREE(srcPixels);
+ RL_FREE(rotPixels);
image->data = processed.data;
image->width = processed.width;
@@ -2007,7 +2012,7 @@ void ImageRotateCW(Image *image)
void ImageRotateCCW(Image *image)
{
Color *srcPixels = GetImageData(*image);
- Color *rotPixels = (Color *)malloc(image->width*image->height*sizeof(Color));
+ Color *rotPixels = (Color *)RL_MALLOC(image->width*image->height*sizeof(Color));
for (int y = 0; y < image->height; y++)
{
@@ -2021,8 +2026,8 @@ void ImageRotateCCW(Image *image)
ImageFormat(&processed, image->format);
UnloadImage(*image);
- free(srcPixels);
- free(rotPixels);
+ RL_FREE(srcPixels);
+ RL_FREE(rotPixels);
image->data = processed.data;
image->width = processed.width;
@@ -2059,7 +2064,7 @@ void ImageColorTint(Image *image, Color color)
Image processed = LoadImageEx(pixels, image->width, image->height);
ImageFormat(&processed, image->format);
UnloadImage(*image);
- free(pixels);
+ RL_FREE(pixels);
image->data = processed.data;
}
@@ -2082,7 +2087,7 @@ void ImageColorInvert(Image *image)
Image processed = LoadImageEx(pixels, image->width, image->height);
ImageFormat(&processed, image->format);
UnloadImage(*image);
- free(pixels);
+ RL_FREE(pixels);
image->data = processed.data;
}
@@ -2142,7 +2147,7 @@ void ImageColorContrast(Image *image, float contrast)
Image processed = LoadImageEx(pixels, image->width, image->height);
ImageFormat(&processed, image->format);
UnloadImage(*image);
- free(pixels);
+ RL_FREE(pixels);
image->data = processed.data;
}
@@ -2182,7 +2187,7 @@ void ImageColorBrightness(Image *image, int brightness)
Image processed = LoadImageEx(pixels, image->width, image->height);
ImageFormat(&processed, image->format);
UnloadImage(*image);
- free(pixels);
+ RL_FREE(pixels);
image->data = processed.data;
}
@@ -2212,7 +2217,7 @@ void ImageColorReplace(Image *image, Color color, Color replace)
Image processed = LoadImageEx(pixels, image->width, image->height);
ImageFormat(&processed, image->format);
UnloadImage(*image);
- free(pixels);
+ RL_FREE(pixels);
image->data = processed.data;
}
@@ -2221,13 +2226,13 @@ void ImageColorReplace(Image *image, Color color, Color replace)
// Generate image: plain color
Image GenImageColor(int width, int height, Color color)
{
- Color *pixels = (Color *)calloc(width*height, sizeof(Color));
+ Color *pixels = (Color *)RL_CALLOC(width*height, sizeof(Color));
for (int i = 0; i < width*height; i++) pixels[i] = color;
Image image = LoadImageEx(pixels, width, height);
- free(pixels);
+ RL_FREE(pixels);
return image;
}
@@ -2236,7 +2241,7 @@ Image GenImageColor(int width, int height, Color color)
// Generate image: vertical gradient
Image GenImageGradientV(int width, int height, Color top, Color bottom)
{
- Color *pixels = (Color *)malloc(width*height*sizeof(Color));
+ Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));
for (int j = 0; j < height; j++)
{
@@ -2251,7 +2256,7 @@ Image GenImageGradientV(int width, int height, Color top, Color bottom)
}
Image image = LoadImageEx(pixels, width, height);
- free(pixels);
+ RL_FREE(pixels);
return image;
}
@@ -2259,7 +2264,7 @@ Image GenImageGradientV(int width, int height, Color top, Color bottom)
// Generate image: horizontal gradient
Image GenImageGradientH(int width, int height, Color left, Color right)
{
- Color *pixels = (Color *)malloc(width*height*sizeof(Color));
+ Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));
for (int i = 0; i < width; i++)
{
@@ -2274,7 +2279,7 @@ Image GenImageGradientH(int width, int height, Color left, Color right)
}
Image image = LoadImageEx(pixels, width, height);
- free(pixels);
+ RL_FREE(pixels);
return image;
}
@@ -2282,7 +2287,7 @@ Image GenImageGradientH(int width, int height, Color left, Color right)
// Generate image: radial gradient
Image GenImageGradientRadial(int width, int height, float density, Color inner, Color outer)
{
- Color *pixels = (Color *)malloc(width*height*sizeof(Color));
+ Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));
float radius = (width < height)? (float)width/2.0f : (float)height/2.0f;
float centerX = (float)width/2.0f;
@@ -2306,7 +2311,7 @@ Image GenImageGradientRadial(int width, int height, float density, Color inner,
}
Image image = LoadImageEx(pixels, width, height);
- free(pixels);
+ RL_FREE(pixels);
return image;
}
@@ -2314,7 +2319,7 @@ Image GenImageGradientRadial(int width, int height, float density, Color inner,
// Generate image: checked
Image GenImageChecked(int width, int height, int checksX, int checksY, Color col1, Color col2)
{
- Color *pixels = (Color *)malloc(width*height*sizeof(Color));
+ Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));
for (int y = 0; y < height; y++)
{
@@ -2326,7 +2331,7 @@ Image GenImageChecked(int width, int height, int checksX, int checksY, Color col
}
Image image = LoadImageEx(pixels, width, height);
- free(pixels);
+ RL_FREE(pixels);
return image;
}
@@ -2334,7 +2339,7 @@ Image GenImageChecked(int width, int height, int checksX, int checksY, Color col
// Generate image: white noise
Image GenImageWhiteNoise(int width, int height, float factor)
{
- Color *pixels = (Color *)malloc(width*height*sizeof(Color));
+ Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));
for (int i = 0; i < width*height; i++)
{
@@ -2343,7 +2348,7 @@ Image GenImageWhiteNoise(int width, int height, float factor)
}
Image image = LoadImageEx(pixels, width, height);
- free(pixels);
+ RL_FREE(pixels);
return image;
}
@@ -2351,7 +2356,7 @@ Image GenImageWhiteNoise(int width, int height, float factor)
// Generate image: perlin noise
Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float scale)
{
- Color *pixels = (Color *)malloc(width*height*sizeof(Color));
+ Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));
for (int y = 0; y < height; y++)
{
@@ -2374,7 +2379,7 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float
}
Image image = LoadImageEx(pixels, width, height);
- free(pixels);
+ RL_FREE(pixels);
return image;
}
@@ -2382,13 +2387,13 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float
// Generate image: cellular algorithm. Bigger tileSize means bigger cells
Image GenImageCellular(int width, int height, int tileSize)
{
- Color *pixels = (Color *)malloc(width*height*sizeof(Color));
+ Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));
int seedsPerRow = width/tileSize;
int seedsPerCol = height/tileSize;
int seedsCount = seedsPerRow * seedsPerCol;
- Vector2 *seeds = (Vector2 *)malloc(seedsCount*sizeof(Vector2));
+ Vector2 *seeds = (Vector2 *)RL_MALLOC(seedsCount*sizeof(Vector2));
for (int i = 0; i < seedsCount; i++)
{
@@ -2431,10 +2436,10 @@ Image GenImageCellular(int width, int height, int tileSize)
}
}
- free(seeds);
+ RL_FREE(seeds);
Image image = LoadImageEx(pixels, width, height);
- free(pixels);
+ RL_FREE(pixels);
return image;
}
@@ -2921,7 +2926,7 @@ static Image LoadDDS(const char *fileName)
{
if (ddsHeader.ddspf.flags == 0x40) // no alpha channel
{
- image.data = (unsigned short *)malloc(image.width*image.height*sizeof(unsigned short));
+ image.data = (unsigned short *)RL_MALLOC(image.width*image.height*sizeof(unsigned short));
fread(image.data, image.width*image.height*sizeof(unsigned short), 1, ddsFile);
image.format = UNCOMPRESSED_R5G6B5;
@@ -2930,7 +2935,7 @@ static Image LoadDDS(const char *fileName)
{
if (ddsHeader.ddspf.aBitMask == 0x8000) // 1bit alpha
{
- image.data = (unsigned short *)malloc(image.width*image.height*sizeof(unsigned short));
+ image.data = (unsigned short *)RL_MALLOC(image.width*image.height*sizeof(unsigned short));
fread(image.data, image.width*image.height*sizeof(unsigned short), 1, ddsFile);
unsigned char alpha = 0;
@@ -2947,7 +2952,7 @@ static Image LoadDDS(const char *fileName)
}
else if (ddsHeader.ddspf.aBitMask == 0xf000) // 4bit alpha
{
- image.data = (unsigned short *)malloc(image.width*image.height*sizeof(unsigned short));
+ image.data = (unsigned short *)RL_MALLOC(image.width*image.height*sizeof(unsigned short));
fread(image.data, image.width*image.height*sizeof(unsigned short), 1, ddsFile);
unsigned char alpha = 0;
@@ -2967,14 +2972,14 @@ static Image LoadDDS(const char *fileName)
if (ddsHeader.ddspf.flags == 0x40 && ddsHeader.ddspf.rgbBitCount == 24) // DDS_RGB, no compressed
{
// NOTE: not sure if this case exists...
- image.data = (unsigned char *)malloc(image.width*image.height*3*sizeof(unsigned char));
+ image.data = (unsigned char *)RL_MALLOC(image.width*image.height*3*sizeof(unsigned char));
fread(image.data, image.width*image.height*3, 1, ddsFile);
image.format = UNCOMPRESSED_R8G8B8;
}
else if (ddsHeader.ddspf.flags == 0x41 && ddsHeader.ddspf.rgbBitCount == 32) // DDS_RGBA, no compressed
{
- image.data = (unsigned char *)malloc(image.width*image.height*4*sizeof(unsigned char));
+ image.data = (unsigned char *)RL_MALLOC(image.width*image.height*4*sizeof(unsigned char));
fread(image.data, image.width*image.height*4, 1, ddsFile);
unsigned char blue = 0;
@@ -3001,7 +3006,7 @@ static Image LoadDDS(const char *fileName)
TraceLog(LOG_DEBUG, "Pitch or linear size: %i", ddsHeader.pitchOrLinearSize);
- image.data = (unsigned char *)malloc(size*sizeof(unsigned char));
+ image.data = (unsigned char *)RL_MALLOC(size*sizeof(unsigned char));
fread(image.data, size, 1, ddsFile);
@@ -3098,7 +3103,7 @@ static Image LoadPKM(const char *fileName)
int size = image.width*image.height*bpp/8; // Total data size in bytes
- image.data = (unsigned char *)malloc(size*sizeof(unsigned char));
+ image.data = (unsigned char *)RL_MALLOC(size*sizeof(unsigned char));
fread(image.data, size, 1, pkmFile);
@@ -3192,7 +3197,7 @@ static Image LoadKTX(const char *fileName)
int dataSize;
fread(&dataSize, sizeof(unsigned int), 1, ktxFile);
- image.data = (unsigned char *)malloc(dataSize*sizeof(unsigned char));
+ image.data = (unsigned char *)RL_MALLOC(dataSize*sizeof(unsigned char));
fread(image.data, dataSize, 1, ktxFile);
@@ -3441,7 +3446,7 @@ static Image LoadPVR(const char *fileName)
}
int dataSize = image.width*image.height*bpp/8; // Total data size in bytes
- image.data = (unsigned char *)malloc(dataSize*sizeof(unsigned char));
+ image.data = (unsigned char *)RL_MALLOC(dataSize*sizeof(unsigned char));
// Read data from file
fread(image.data, dataSize, 1, pvrFile);
@@ -3518,7 +3523,7 @@ static Image LoadASTC(const char *fileName)
{
int dataSize = image.width*image.height*bpp/8; // Data size in bytes
- image.data = (unsigned char *)malloc(dataSize*sizeof(unsigned char));
+ image.data = (unsigned char *)RL_MALLOC(dataSize*sizeof(unsigned char));
fread(image.data, dataSize, 1, astcFile);
if (bpp == 8) image.format = COMPRESSED_ASTC_4x4_RGBA;