aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2018-06-03 21:05:01 +0200
committerRay <raysan5@gmail.com>2018-06-03 21:05:01 +0200
commit0e6458cfee398e572340db461ef6beb85253a4c5 (patch)
treed93f00f5e1e9d2faa9f3596e2ef3eb590abcf937 /src
parent61a1c59472e71a4c4f63afe8cd79582973b9150b (diff)
downloadraylib-0e6458cfee398e572340db461ef6beb85253a4c5.tar.gz
raylib-0e6458cfee398e572340db461ef6beb85253a4c5.zip
Added ImageRotate*() functions
Diffstat (limited to 'src')
-rw-r--r--src/raylib.h2
-rw-r--r--src/textures.c56
2 files changed, 56 insertions, 2 deletions
diff --git a/src/raylib.h b/src/raylib.h
index a3fa1311..86ad5408 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -925,6 +925,8 @@ RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fon
RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, Font font, const char *text, float fontSize, float spacing, Color color); // Draw text (custom sprite font) within an image (destination)
RLAPI void ImageFlipVertical(Image *image); // Flip image vertically
RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally
+RLAPI void ImageRotateCW(Image *image); // Rotate image clockwise 90deg
+RLAPI void ImageRotateCCW(Image *image); // Rotate image counter-clockwise 90deg
RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint
RLAPI void ImageColorInvert(Image *image); // Modify image color: invert
RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale
diff --git a/src/textures.c b/src/textures.c
index 3a62ac14..0b9f907e 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -1539,7 +1539,7 @@ void ImageDrawTextEx(Image *dst, Vector2 position, Font font, const char *text,
void ImageFlipVertical(Image *image)
{
Color *srcPixels = GetImageData(*image);
- Color *dstPixels = (Color *)malloc(sizeof(Color)*image->width*image->height);
+ Color *dstPixels = (Color *)malloc(image->width*image->height*sizeof(Color));
for (int y = 0; y < image->height; y++)
{
@@ -1563,7 +1563,7 @@ void ImageFlipVertical(Image *image)
void ImageFlipHorizontal(Image *image)
{
Color *srcPixels = GetImageData(*image);
- Color *dstPixels = (Color *)malloc(sizeof(Color)*image->width*image->height);
+ Color *dstPixels = (Color *)malloc(image->width*image->height*sizeof(Color));
for (int y = 0; y < image->height; y++)
{
@@ -1583,6 +1583,58 @@ void ImageFlipHorizontal(Image *image)
image->data = processed.data;
}
+// Rotate image clockwise 90deg
+void ImageRotateCW(Image *image)
+{
+ Color *srcPixels = GetImageData(*image);
+ Color *rotPixels = (Color *)malloc(image->width*image->height*sizeof(Color));
+
+ for (int y = 0; y < image->height; y++)
+ {
+ for (int x = 0; x < image->width; x++)
+ {
+ rotPixels[x*image->height + (image->height - y - 1)] = srcPixels[y*image->width + x];
+ }
+ }
+
+ Image processed = LoadImageEx(rotPixels, image->height, image->width);
+ ImageFormat(&processed, image->format);
+ UnloadImage(*image);
+
+ free(srcPixels);
+ free(rotPixels);
+
+ image->data = processed.data;
+ image->width = processed.width;
+ image->height = processed.height;
+}
+
+// Rotate image counter-clockwise 90deg
+void ImageRotateCCW(Image *image)
+{
+ Color *srcPixels = GetImageData(*image);
+ Color *rotPixels = (Color *)malloc(image->width*image->height*sizeof(Color));
+
+ for (int y = 0; y < image->height; y++)
+ {
+ for (int x = 0; x < image->width; x++)
+ {
+ rotPixels[x*image->height + y] = srcPixels[y*image->width + (image->width - x - 1)];
+ }
+ }
+
+ Image processed = LoadImageEx(rotPixels, image->height, image->width);
+ ImageFormat(&processed, image->format);
+ UnloadImage(*image);
+
+ free(srcPixels);
+ free(rotPixels);
+
+ image->data = processed.data;
+ image->width = processed.width;
+ image->height = processed.height;
+}
+
// Modify image color: tint
void ImageColorTint(Image *image, Color color)
{