Move allocation of imbuf from array to allocimbuf.
[blender.git] / source / blender / imbuf / intern / rotate.c
index 732c06907df9594408fa9162a3d213603c53a73b..886944f6190153c145a056a972eccd192fbd0c48 100644 (file)
@@ -1,5 +1,4 @@
-/**
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -14,7 +13,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  * All rights reserved.
  * ***** END GPL LICENSE BLOCK *****
  * rotate.c
  *
- * $Id$
  */
 
-#include "BLI_blenlib.h"
-#include  "BKE_utildefines.h"
+/** \file blender/imbuf/intern/rotate.c
+ *  \ingroup imbuf
+ */
+
+#include "BLI_utildefines.h"
+
+#include "MEM_guardedalloc.h"
 
 #include "imbuf.h"
-#include "imbuf_patch.h"
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
 
-#include "IMB_allocimbuf.h"
-
-void IMB_flipy(struct ImBuf * ibuf)
+void IMB_flipy(struct ImBuf *ibuf)
 {
        int x, y;
 
@@ -52,49 +52,49 @@ void IMB_flipy(struct ImBuf * ibuf)
                y = ibuf->y;
 
                top = ibuf->rect;
-               bottom = top + ((y-1) * x);
-               line= MEM_mallocN(x*sizeof(int), "linebuf");
+               bottom = top + ((y - 1) * x);
+               line = MEM_mallocN(x * sizeof(int), "linebuf");
        
                y >>= 1;
 
-               for(;y>0;y--) {
-                       memcpy(line, top, x*sizeof(int));
-                       memcpy(top, bottom, x*sizeof(int));
-                       memcpy(bottom, line, x*sizeof(int));
+               for (; y > 0; y--) {
+                       memcpy(line, top, x * sizeof(int));
+                       memcpy(top, bottom, x * sizeof(int));
+                       memcpy(bottom, line, x * sizeof(int));
                        bottom -= x;
-                       top+= x;
+                       top += x;
                }
 
                MEM_freeN(line);
        }
 
        if (ibuf->rect_float) {
-               float *topf=NULL, *bottomf=NULL, *linef=NULL;
+               float *topf = NULL, *bottomf = NULL, *linef = NULL;
 
                x = ibuf->x;
                y = ibuf->y;
 
-               topf= ibuf->rect_float;
-               bottomf = topf + 4*((y-1) * x);
-               linef= MEM_mallocN(4*x*sizeof(float), "linebuff");
+               topf = ibuf->rect_float;
+               bottomf = topf + 4 * ((y - 1) * x);
+               linef = MEM_mallocN(4 * x * sizeof(float), "linebuff");
 
                y >>= 1;
 
-               for(;y>0;y--) {
-                       memcpy(linef, topf, 4*x*sizeof(float));
-                       memcpy(topf, bottomf, 4*x*sizeof(float));
-                       memcpy(bottomf, linef, 4*x*sizeof(float));
-                       bottomf -= 4*x;
-                       topf+= 4*x;
+               for (; y > 0; y--) {
+                       memcpy(linef, topf, 4 * x * sizeof(float));
+                       memcpy(topf, bottomf, 4 * x * sizeof(float));
+                       memcpy(bottomf, linef, 4 * x * sizeof(float));
+                       bottomf -= 4 * x;
+                       topf += 4 * x;
                }
 
                MEM_freeN(linef);
        }
 }
 
-void IMB_flipx(struct ImBuf * ibuf)
+void IMB_flipx(struct ImBuf *ibuf)
 {
-       short x, y, xr, xl, yi;
+       int x, y, xr, xl, yi;
        float px_f[4];
        
        if (ibuf == NULL) return;
@@ -103,19 +103,19 @@ void IMB_flipx(struct ImBuf * ibuf)
        y = ibuf->y;
 
        if (ibuf->rect) {
-               for(yi=y-1;yi>=0;yi--) {
-                       for(xr=x-1, xl=0; xr>=xl; xr--, xl++) {
-                               SWAP(unsigned int, ibuf->rect[(x*yi)+xr], ibuf->rect[(x*yi)+xl]);
+               for (yi = y - 1; yi >= 0; yi--) {
+                       for (xr = x - 1, xl = 0; xr >= xl; xr--, xl++) {
+                               SWAP(unsigned int, ibuf->rect[(x * yi) + xr], ibuf->rect[(x * yi) + xl]);
                        }
                }
        }
        
        if (ibuf->rect_float) {
-               for(yi=y-1;yi>=0;yi--) {
-                       for(xr=x-1, xl=0; xr>=xl; xr--, xl++) {
-                               memcpy(&px_f, &ibuf->rect_float[((x*yi)+xr)*4], 4*sizeof(float));
-                               memcpy(&ibuf->rect_float[((x*yi)+xr)*4], &ibuf->rect_float[((x*yi)+xl)*4], 4*sizeof(float));
-                               memcpy(&ibuf->rect_float[((x*yi)+xl)*4], &px_f, 4*sizeof(float));
+               for (yi = y - 1; yi >= 0; yi--) {
+                       for (xr = x - 1, xl = 0; xr >= xl; xr--, xl++) {
+                               memcpy(&px_f, &ibuf->rect_float[((x * yi) + xr) * 4], 4 * sizeof(float));
+                               memcpy(&ibuf->rect_float[((x * yi) + xr) * 4], &ibuf->rect_float[((x * yi) + xl) * 4], 4 * sizeof(float));
+                               memcpy(&ibuf->rect_float[((x * yi) + xl) * 4], &px_f, 4 * sizeof(float));
                        }
                }
        }