summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2020-06-15 12:05:03 +0200
committerraysan5 <[email protected]>2020-06-15 12:05:03 +0200
commit32c0a7a135658443d646821ac93ed72c26bb14c2 (patch)
tree791f00250279f7b8af2f0c4dc5c6fbacf0fd73f2 /src
parentbfa654403069307f1d828f86fe798893b4e869a3 (diff)
downloadraylib-32c0a7a135658443d646821ac93ed72c26bb14c2.tar.gz
raylib-32c0a7a135658443d646821ac93ed72c26bb14c2.zip
Small code optimization
Diffstat (limited to 'src')
-rw-r--r--src/textures.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/src/textures.c b/src/textures.c
index eccddfa6..033c9578 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -818,8 +818,7 @@ void ImageCrop(Image *image, Rectangle crop)
if (image->format >= COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image manipulation not supported for compressed formats");
else
{
- int dataSize = GetPixelDataSize(image->width, image->height, image->format);
- int bytesPerPixel = dataSize/(image->width*image->height);
+ int bytesPerPixel = GetPixelDataSize(1, 1, image->format);
unsigned char *croppedData = (unsigned char *)RL_MALLOC(crop.width*crop.height*bytesPerPixel);
@@ -1431,9 +1430,7 @@ void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offsetX, i
if (newWidth < srcRec.width) srcRec.width = newWidth;
if (newHeight < srcRec.height) srcRec.height = newHeight;
- int dataSize = GetPixelDataSize(image->width, image->height, image->format);
- int bytesPerPixel = dataSize/(image->width*image->height);
-
+ int bytesPerPixel = GetPixelDataSize(1, 1, image->format);
unsigned char *resizedData = (unsigned char *)RL_CALLOC(newWidth*newHeight*bytesPerPixel, 1);
// TODO: Fill resizedData with fill color (must be formatted to image->format)
@@ -1645,10 +1642,8 @@ void ImageFlipVertical(Image *image)
if (image->format >= COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image manipulation not supported for compressed formats");
else
{
- int dataSize = GetPixelDataSize(image->width, image->height, image->format);
- int bytesPerPixel = dataSize/(image->width*image->height);
-
- unsigned char *flippedData = (unsigned char *)RL_MALLOC(dataSize);
+ int bytesPerPixel = GetPixelDataSize(1, 1, image->format);
+ unsigned char *flippedData = (unsigned char *)RL_MALLOC(image->width*image->height*bytesPerPixel);
for (int i = (image->height - 1), offsetSize = 0; i >= 0; i--)
{
@@ -1671,10 +1666,8 @@ void ImageFlipHorizontal(Image *image)
if (image->format >= COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image manipulation not supported for compressed formats");
else
{
- int dataSize = GetPixelDataSize(image->width, image->height, image->format);
- int bytesPerPixel = dataSize/(image->width*image->height);
-
- unsigned char *flippedData = (unsigned char *)RL_MALLOC(dataSize);
+ int bytesPerPixel = GetPixelDataSize(1, 1, image->format);
+ unsigned char *flippedData = (unsigned char *)RL_MALLOC(image->width*image->height*bytesPerPixel);
for (int y = 0; y < image->height; y++)
{
@@ -1718,10 +1711,8 @@ void ImageRotateCW(Image *image)
if (image->format >= COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image manipulation not supported for compressed formats");
else
{
- int dataSize = GetPixelDataSize(image->width, image->height, image->format);
- int bytesPerPixel = dataSize/(image->width*image->height);
-
- unsigned char *rotatedData = (unsigned char *)RL_MALLOC(dataSize);
+ int bytesPerPixel = GetPixelDataSize(1, 1, image->format);
+ unsigned char *rotatedData = (unsigned char *)RL_MALLOC(image->width*image->height*bytesPerPixel);
for (int y = 0; y < image->height; y++)
{
@@ -1752,10 +1743,8 @@ void ImageRotateCCW(Image *image)
if (image->format >= COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image manipulation not supported for compressed formats");
else
{
- int dataSize = GetPixelDataSize(image->width, image->height, image->format);
- int bytesPerPixel = dataSize/(image->width*image->height);
-
- unsigned char *rotatedData = (unsigned char *)RL_MALLOC(dataSize);
+ int bytesPerPixel = GetPixelDataSize(1, 1, image->format);
+ unsigned char *rotatedData = (unsigned char *)RL_MALLOC(image->width*image->height*bytesPerPixel);
for (int y = 0; y < image->height; y++)
{