Blender V2.61 - r43446

rotate.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  * rotate.c
00027  *
00028  */
00029 
00035 #include "BLI_blenlib.h"
00036 #include "BLI_utildefines.h"
00037 
00038 
00039 #include "MEM_guardedalloc.h"
00040 
00041 #include "imbuf.h"
00042 #include "IMB_imbuf_types.h"
00043 #include "IMB_imbuf.h"
00044 
00045 #include "IMB_allocimbuf.h"
00046 
00047 void IMB_flipy(struct ImBuf * ibuf)
00048 {
00049     int x, y;
00050 
00051     if (ibuf == NULL) return;
00052 
00053     if (ibuf->rect) {
00054         unsigned int *top, *bottom, *line;
00055 
00056         x = ibuf->x;
00057         y = ibuf->y;
00058 
00059         top = ibuf->rect;
00060         bottom = top + ((y-1) * x);
00061         line= MEM_mallocN(x*sizeof(int), "linebuf");
00062     
00063         y >>= 1;
00064 
00065         for(;y>0;y--) {
00066             memcpy(line, top, x*sizeof(int));
00067             memcpy(top, bottom, x*sizeof(int));
00068             memcpy(bottom, line, x*sizeof(int));
00069             bottom -= x;
00070             top+= x;
00071         }
00072 
00073         MEM_freeN(line);
00074     }
00075 
00076     if (ibuf->rect_float) {
00077         float *topf=NULL, *bottomf=NULL, *linef=NULL;
00078 
00079         x = ibuf->x;
00080         y = ibuf->y;
00081 
00082         topf= ibuf->rect_float;
00083         bottomf = topf + 4*((y-1) * x);
00084         linef= MEM_mallocN(4*x*sizeof(float), "linebuff");
00085 
00086         y >>= 1;
00087 
00088         for(;y>0;y--) {
00089             memcpy(linef, topf, 4*x*sizeof(float));
00090             memcpy(topf, bottomf, 4*x*sizeof(float));
00091             memcpy(bottomf, linef, 4*x*sizeof(float));
00092             bottomf -= 4*x;
00093             topf+= 4*x;
00094         }
00095 
00096         MEM_freeN(linef);
00097     }
00098 }
00099 
00100 void IMB_flipx(struct ImBuf * ibuf)
00101 {
00102     int x, y, xr, xl, yi;
00103     float px_f[4];
00104     
00105     if (ibuf == NULL) return;
00106 
00107     x = ibuf->x;
00108     y = ibuf->y;
00109 
00110     if (ibuf->rect) {
00111         for(yi=y-1;yi>=0;yi--) {
00112             for(xr=x-1, xl=0; xr>=xl; xr--, xl++) {
00113                 SWAP(unsigned int, ibuf->rect[(x*yi)+xr], ibuf->rect[(x*yi)+xl]);
00114             }
00115         }
00116     }
00117     
00118     if (ibuf->rect_float) {
00119         for(yi=y-1;yi>=0;yi--) {
00120             for(xr=x-1, xl=0; xr>=xl; xr--, xl++) {
00121                 memcpy(&px_f, &ibuf->rect_float[((x*yi)+xr)*4], 4*sizeof(float));
00122                 memcpy(&ibuf->rect_float[((x*yi)+xr)*4], &ibuf->rect_float[((x*yi)+xl)*4], 4*sizeof(float));
00123                 memcpy(&ibuf->rect_float[((x*yi)+xl)*4], &px_f, 4*sizeof(float));
00124             }
00125         }
00126     }
00127 }