Browse Source

REVIEWED: `ImageRotate()` formatting

Ray 2 years ago
parent
commit
5ef50ae139
1 changed files with 15 additions and 15 deletions
  1. 15 15
      src/rtextures.c

+ 15 - 15
src/rtextures.c

@@ -2128,27 +2128,27 @@ void ImageRotate(Image *image, int degrees)
     if (image->format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image manipulation not supported for compressed formats");
     if (image->format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image manipulation not supported for compressed formats");
     else
     else
     {
     {
-        float rad = degrees * PI / 180.0f;
+        float rad = degrees*PI/180.0f;
         float sinRadius = sin(rad);
         float sinRadius = sin(rad);
         float cosRadius = cos(rad);
         float cosRadius = cos(rad);
 
 
-        int width = abs(image->width * cosRadius) + abs(image->height * sinRadius);
-        int height = abs(image->height * cosRadius) + abs(image->width * sinRadius);
+        int width = fabsf(image->width*cosRadius) + fabsf(image->height*sinRadius);
+        int height = fabsf(image->height*cosRadius) + fabsf(image->width*sinRadius);
 
 
         int bytesPerPixel = GetPixelDataSize(1, 1, image->format);
         int bytesPerPixel = GetPixelDataSize(1, 1, image->format);
-        unsigned char *rotatedData = (unsigned char *)RL_CALLOC(width * height, bytesPerPixel);
+        unsigned char *rotatedData = (unsigned char *)RL_CALLOC(width*height, bytesPerPixel);
 
 
         for (int y = 0; y < height; y++)
         for (int y = 0; y < height; y++)
         {
         {
             for (int x = 0; x < width; x++)
             for (int x = 0; x < width; x++)
             {
             {
-                float oldX = ((x - width / 2.0f) * cosRadius + (y - height / 2.0f) * sinRadius) + image->width / 2.0f;
-                float oldY = ((y - height / 2.0f) * cosRadius - (x - width / 2.0f) * sinRadius) + image->height / 2.0f;
+                float oldX = ((x - width/2.0f)*cosRadius + (y - height/2.0f)*sinRadius) + image->width/2.0f;
+                float oldY = ((y - height/2.0f)*cosRadius - (x - width/2.0f)*sinRadius) + image->height/2.0f;
 
 
-                if (oldX >= 0 && oldX < image->width && oldY >= 0 && oldY < image->height)
+                if ((oldX >= 0) && (oldX < image->width) && (oldY >= 0) && (oldY < image->height))
                 {
                 {
-                    int x1 = (int)floor(oldX);
-                    int y1 = (int)floor(oldY);
+                    int x1 = (int)floorf(oldX);
+                    int y1 = (int)floorf(oldY);
                     int x2 = MIN(x1 + 1, image->width - 1);
                     int x2 = MIN(x1 + 1, image->width - 1);
                     int y2 = MIN(y1 + 1, image->height - 1);
                     int y2 = MIN(y1 + 1, image->height - 1);
 
 
@@ -2157,14 +2157,14 @@ void ImageRotate(Image *image, int degrees)
 
 
                     for (int i = 0; i < bytesPerPixel; i++)
                     for (int i = 0; i < bytesPerPixel; i++)
                     {
                     {
-                        float f1 = ((unsigned char *)image->data)[(y1 * image->width + x1) * bytesPerPixel + i];
-                        float f2 = ((unsigned char *)image->data)[(y1 * image->width + x2) * bytesPerPixel + i];
-                        float f3 = ((unsigned char *)image->data)[(y2 * image->width + x1) * bytesPerPixel + i];
-                        float f4 = ((unsigned char *)image->data)[(y2 * image->width + x2) * bytesPerPixel + i];
+                        float f1 = ((unsigned char *)image->data)[(y1*image->width + x1)*bytesPerPixel + i];
+                        float f2 = ((unsigned char *)image->data)[(y1*image->width + x2)*bytesPerPixel + i];
+                        float f3 = ((unsigned char *)image->data)[(y2*image->width + x1)*bytesPerPixel + i];
+                        float f4 = ((unsigned char *)image->data)[(y2*image->width + x2)*bytesPerPixel + i];
 
 
-                        float val = f1 * (1 - px) * (1 - py) + f2 * px * (1 - py) + f3 * (1 - px) * py + f4 * px * py;
+                        float val = f1*(1 - px)*(1 - py) + f2*px*(1 - py) + f3*(1 - px)*py + f4*px*py;
 
 
-                        rotatedData[(y * width + x) * bytesPerPixel + i] = (unsigned char)val;
+                        rotatedData[(y*width + x)*bytesPerPixel + i] = (unsigned char)val;
                     }
                     }
                 }
                 }
             }
             }