summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2020-06-07 11:53:13 +0200
committerraysan5 <[email protected]>2020-06-07 11:53:13 +0200
commit776e4a37ef0266374e5232a63377c411af81ec67 (patch)
tree98897ef09de21ae6ea70205830673523e2202add
parent79e2fbe0c605defd94ea8109f11c10b998a97971 (diff)
downloadraylib-776e4a37ef0266374e5232a63377c411af81ec67.tar.gz
raylib-776e4a37ef0266374e5232a63377c411af81ec67.zip
REDESIGNED: ImageRotateCCW(), optimized #1218
-rw-r--r--src/textures.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/textures.c b/src/textures.c
index 34c23885..fe4ac217 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -1686,30 +1686,32 @@ void ImageRotateCCW(Image *image)
// Security check to avoid program crash
if ((image->data == NULL) || (image->width == 0) || (image->height == 0)) return;
- Color *srcPixels = GetImageData(*image);
- Color *rotPixels = (Color *)RL_MALLOC(image->width*image->height*sizeof(Color));
-
- for (int y = 0; y < image->height; y++)
+ if (image->mipmaps > 1) TRACELOG(LOG_WARNING, "Image manipulation only applied to base mipmap level");
+ if (image->format >= COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image manipulation not supported for compressed formats");
+ else
{
- for (int x = 0; x < image->width; x++)
+ int dataSize = GetPixelDataSize(image->width, image->height, image->format);
+ int bytesPerPixel = dataSize/(image->width*image->height);
+
+ unsigned char *rotatedData = (unsigned char *)RL_MALLOC(dataSize);
+
+ for (int y = 0; y < image->height; y++)
{
- rotPixels[x*image->height + y] = srcPixels[y*image->width + (image->width - x - 1)];
+ for (int x = 0; x < image->width; x++)
+ {
+ //memcpy(rotatedData + (x*image->height + y))*bytesPerPixel, ((unsigned char *)image->data) + (y*image->width + (image->width - x - 1))*bytesPerPixel, bytesPerPixel);
+ for (int i = 0; i < bytesPerPixel; i++) rotatedData[(x*image->height + y)*bytesPerPixel + i] = ((unsigned char *)image->data)[(y*image->width + (image->width - x - 1))*bytesPerPixel + i];
+ }
}
+
+ RL_FREE(image->data);
+ image->data = rotatedData;
+ int width = image->width;
+ int height = image-> height;
+
+ image->width = height;
+ image->height = width;
}
-
- int format = image->format;
- int width = image->width;
- int height = image-> height;
- RL_FREE(image->data);
-
- image->data = rotPixels;
- image->width = height;
- image->height = width;
- image->format = UNCOMPRESSED_R8G8B8A8;
-
- ImageFormat(image, format);
-
- RL_FREE(srcPixels);
}
// Modify image color: tint