doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / imbuf / intern / rotate.c
1 /*
2  *
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * The Original Code is: all of this file.
23  *
24  * Contributor(s): none yet.
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  * rotate.c
28  *
29  * $Id$
30  */
31
32 #include "BLI_blenlib.h"
33 #include "BLI_utildefines.h"
34
35
36 #include "MEM_guardedalloc.h"
37
38 #include "imbuf.h"
39 #include "IMB_imbuf_types.h"
40 #include "IMB_imbuf.h"
41
42 #include "IMB_allocimbuf.h"
43
44 void IMB_flipy(struct ImBuf * ibuf)
45 {
46         int x, y;
47
48         if (ibuf == NULL) return;
49
50         if (ibuf->rect) {
51                 unsigned int *top, *bottom, *line;
52
53                 x = ibuf->x;
54                 y = ibuf->y;
55
56                 top = ibuf->rect;
57                 bottom = top + ((y-1) * x);
58                 line= MEM_mallocN(x*sizeof(int), "linebuf");
59         
60                 y >>= 1;
61
62                 for(;y>0;y--) {
63                         memcpy(line, top, x*sizeof(int));
64                         memcpy(top, bottom, x*sizeof(int));
65                         memcpy(bottom, line, x*sizeof(int));
66                         bottom -= x;
67                         top+= x;
68                 }
69
70                 MEM_freeN(line);
71         }
72
73         if (ibuf->rect_float) {
74                 float *topf=NULL, *bottomf=NULL, *linef=NULL;
75
76                 x = ibuf->x;
77                 y = ibuf->y;
78
79                 topf= ibuf->rect_float;
80                 bottomf = topf + 4*((y-1) * x);
81                 linef= MEM_mallocN(4*x*sizeof(float), "linebuff");
82
83                 y >>= 1;
84
85                 for(;y>0;y--) {
86                         memcpy(linef, topf, 4*x*sizeof(float));
87                         memcpy(topf, bottomf, 4*x*sizeof(float));
88                         memcpy(bottomf, linef, 4*x*sizeof(float));
89                         bottomf -= 4*x;
90                         topf+= 4*x;
91                 }
92
93                 MEM_freeN(linef);
94         }
95 }
96
97 void IMB_flipx(struct ImBuf * ibuf)
98 {
99         short x, y, xr, xl, yi;
100         float px_f[4];
101         
102         if (ibuf == NULL) return;
103
104         x = ibuf->x;
105         y = ibuf->y;
106
107         if (ibuf->rect) {
108                 for(yi=y-1;yi>=0;yi--) {
109                         for(xr=x-1, xl=0; xr>=xl; xr--, xl++) {
110                                 SWAP(unsigned int, ibuf->rect[(x*yi)+xr], ibuf->rect[(x*yi)+xl]);
111                         }
112                 }
113         }
114         
115         if (ibuf->rect_float) {
116                 for(yi=y-1;yi>=0;yi--) {
117                         for(xr=x-1, xl=0; xr>=xl; xr--, xl++) {
118                                 memcpy(&px_f, &ibuf->rect_float[((x*yi)+xr)*4], 4*sizeof(float));
119                                 memcpy(&ibuf->rect_float[((x*yi)+xr)*4], &ibuf->rect_float[((x*yi)+xl)*4], 4*sizeof(float));
120                                 memcpy(&ibuf->rect_float[((x*yi)+xl)*4], &px_f, 4*sizeof(float));
121                         }
122                 }
123         }
124 }