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