== Sequencer ==
[blender.git] / source / blender / imbuf / intern / rotate.c
1 /**
2  *
3  * ***** BEGIN GPL/BL DUAL 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. The Blender
9  * Foundation also sells licenses for use in proprietary software under
10  * the Blender License.  See http://www.blender.org/BL/ for information
11  * about this.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL/BL DUAL LICENSE BLOCK *****
30  * rotate.c
31  *
32  * $Id$
33  */
34
35 #include "BLI_blenlib.h"
36
37 #include "imbuf.h"
38 #include "imbuf_patch.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         unsigned int px;
101         float px_f[4];
102         
103         if (ibuf == NULL) return;
104
105         x = ibuf->x;
106         y = ibuf->y;
107
108         if (ibuf->rect) {
109                 for(yi=y-1;yi>=0;yi--) {
110                         for(xr=x-1, xl=0; xr>=xl; xr--, xl++) {
111                                 px = ibuf->rect[(x*yi)+xr];
112                                 ibuf->rect[(x*yi)+xr] = ibuf->rect[(x*yi)+xl];
113                                 ibuf->rect[(x*yi)+xl] = px;             
114                         }
115                 }
116         }
117         
118         if (ibuf->rect_float) {
119                 for(yi=y-1;yi>=0;yi--) {
120                         for(xr=x-1, xl=0; xr>=xl; xr--, xl++) {
121                                 memcpy(&px_f, &ibuf->rect_float[((x*yi)+xr)*4], 4*sizeof(float));
122                                 memcpy(&ibuf->rect_float[((x*yi)+xr)*4], &ibuf->rect_float[((x*yi)+xl)*4], 4*sizeof(float));
123                                 memcpy(&ibuf->rect_float[((x*yi)+xl)*4], &px_f, 4*sizeof(float));
124                         }
125                 }
126         }
127 }