doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / nodes / intern / CMP_nodes / CMP_rotate.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2006 Blender Foundation.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include "../CMP_util.h"
31
32 /* **************** Rotate  ******************** */
33
34 static bNodeSocketType cmp_node_rotate_in[]= {
35         {       SOCK_RGBA, 1, "Image",                  0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
36         {       SOCK_VALUE, 1, "Degr",                  0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f},
37         {       -1, 0, ""       }
38 };
39 static bNodeSocketType cmp_node_rotate_out[]= {
40         {       SOCK_RGBA, 0, "Image",                  0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
41         {       -1, 0, ""       }
42 };
43
44 /* only supports RGBA nodes now */
45 static void node_composit_exec_rotate(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
46 {
47         
48         if(out[0]->hasoutput==0)
49                 return;
50         
51         if(in[0]->data) {
52                 CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
53                 CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* note, this returns zero'd image */
54                 float rad, u, v, s, c, centx, centy, miny, maxy, minx, maxx;
55                 int x, y, yo, xo;
56           ImBuf *ibuf, *obuf;
57         
58                 rad= (M_PI*in[1]->vec[0])/180.0f;
59                 
60                 s= sin(rad);
61                 c= cos(rad);
62                 centx= cbuf->x/2;
63                 centy= cbuf->y/2;
64                 
65                 minx= -centx;
66                 maxx= -centx + (float)cbuf->x;
67                 miny= -centy;
68                 maxy= -centy + (float)cbuf->y;
69                 
70
71           ibuf=IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
72           obuf=IMB_allocImBuf(stackbuf->x, stackbuf->y, 32, 0);
73
74           if(ibuf && obuf){
75                  ibuf->rect_float=cbuf->rect;
76                  obuf->rect_float=stackbuf->rect;
77
78                    for(y=miny; y<maxy; y++) {
79                            yo= y+(int)centy;
80                       
81                         for(x=minx; x<maxx;x++) {
82                            u=c*x + y*s + centx;
83                            v=-s*x + c*y + centy;
84                            xo= x+(int)centx;
85
86                            switch(node->custom1) {
87                                   case 0:
88                                          neareast_interpolation(ibuf, obuf, u, v, xo, yo);
89                                          break ;
90                                   case 1:
91                                          bilinear_interpolation(ibuf, obuf, u, v, xo, yo);
92                                          break;
93                                   case 2:
94                                          bicubic_interpolation(ibuf, obuf, u, v, xo, yo);
95                            }
96                
97                         }
98                         }
99         
100                  /* rotate offset vector too, but why negative rad, ehh?? Has to be replaced with [3][3] matrix once (ton) */
101                    s= sin(-rad);
102                    c= cos(-rad);
103                    centx= (float)cbuf->xof; centy= (float)cbuf->yof;
104                    stackbuf->xof= (int)( c*centx + s*centy);
105                    stackbuf->yof= (int)(-s*centx + c*centy);
106
107                         IMB_freeImBuf(ibuf);
108                         IMB_freeImBuf(obuf);
109                 }
110                 
111                 /* pass on output and free */
112                 out[0]->data= stackbuf;
113                 if(cbuf!=in[0]->data)
114                         free_compbuf(cbuf);
115         }
116 }
117
118 static void node_composit_init_rotate(bNode *node)
119 {
120    node->custom1= 1; /* Bilinear Filter*/
121 }
122
123 void register_node_type_cmp_rotate(ListBase *lb)
124 {
125         static bNodeType ntype;
126
127         node_type_base(&ntype, CMP_NODE_ROTATE, "Rotate", NODE_CLASS_DISTORT, NODE_OPTIONS,
128                 cmp_node_rotate_in, cmp_node_rotate_out);
129         node_type_size(&ntype, 140, 100, 320);
130         node_type_init(&ntype, node_composit_init_rotate);
131         node_type_exec(&ntype, node_composit_exec_rotate);
132
133         nodeRegisterType(lb, &ntype);
134 }
135