doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / nodes / intern / CMP_nodes / CMP_splitViewer.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 /* **************** SPLIT VIEWER ******************** */
33 static bNodeSocketType cmp_node_splitviewer_in[]= {
34         {       SOCK_RGBA, 1, "Image",          0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
35         {       SOCK_RGBA, 1, "Image",          0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
36         {       -1, 0, ""       }
37 };
38
39 static void do_copy_split_rgba(bNode *UNUSED(node), float *out, float *in1, float *in2, float *fac)
40 {
41         if(*fac==0.0f) {
42                 QUATCOPY(out, in1);
43         }
44         else {
45                 QUATCOPY(out, in2);
46         }
47 }
48
49 static void node_composit_exec_splitviewer(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
50 {
51         /* image assigned to output */
52         /* stack order input sockets: image image */
53         
54         if(in[0]->data==NULL || in[1]->data==NULL)
55                 return;
56         
57         if(node->id && (node->flag & NODE_DO_OUTPUT)) { /* only one works on out */
58                 Image *ima= (Image *)node->id;
59                 RenderData *rd= data;
60                 ImBuf *ibuf;
61                 CompBuf *cbuf, *buf1, *buf2, *mask;
62                 int x, y;
63                 float offset;
64                 void *lock;
65                 
66                 buf1= typecheck_compbuf(in[0]->data, CB_RGBA);
67                 buf2= typecheck_compbuf(in[1]->data, CB_RGBA);
68                 
69                 BKE_image_user_calc_frame(node->storage, rd->cfra, 0);
70                 
71                 /* always returns for viewer image, but we check nevertheless */
72                 ibuf= BKE_image_acquire_ibuf(ima, node->storage, &lock);
73                 if(ibuf==NULL) {
74                         printf("node_composit_exec_viewer error\n");
75                         BKE_image_release_ibuf(ima, lock);
76                         return;
77                 }
78                 
79                 /* free all in ibuf */
80                 imb_freerectImBuf(ibuf);
81                 imb_freerectfloatImBuf(ibuf);
82                 IMB_freezbuffloatImBuf(ibuf);
83                 
84                 /* make ibuf, and connect to ima */
85                 ibuf->x= buf1->x;
86                 ibuf->y= buf1->y;
87                 imb_addrectfloatImBuf(ibuf);
88                 
89                 ima->ok= IMA_OK_LOADED;
90
91                 /* output buf */
92                 cbuf= alloc_compbuf(buf1->x, buf1->y, CB_RGBA, 0);      /* no alloc*/
93                 cbuf->rect= ibuf->rect_float;
94                 
95                 /* mask buf */
96                 mask= alloc_compbuf(buf1->x, buf1->y, CB_VAL, 1);
97                 
98                 
99                 /* Check which offset mode is selected and limit offset if needed */
100                 if(node->custom2 == 0) {
101                         offset = buf1->x / 100.0f * node->custom1;
102                         CLAMP(offset, 0, buf1->x);
103                 }
104                 else {
105                         offset = buf1->y / 100.0f * node->custom1;
106                         CLAMP(offset, 0, buf1->y);
107                 }
108                 
109                 if(node->custom2 == 0) {
110                         for(y=0; y<buf1->y; y++) {
111                                 float *fac= mask->rect + y*buf1->x;
112                                 for(x=offset; x>0; x--, fac++)
113                                         *fac= 1.0f;
114                         }
115                 }
116                 else {
117                         for(y=0; y<offset; y++) {
118                                 float *fac= mask->rect + y*buf1->x;
119                                 for(x=buf1->x; x>0; x--, fac++)
120                                         *fac= 1.0f;
121                         }
122                 }
123                 
124                 composit3_pixel_processor(node, cbuf, buf1, in[0]->vec, buf2, in[1]->vec, mask, NULL, do_copy_split_rgba, CB_RGBA, CB_RGBA, CB_VAL);
125                 
126                 BKE_image_release_ibuf(ima, lock);
127                 
128                 generate_preview(data, node, cbuf);
129                 free_compbuf(cbuf);
130                 free_compbuf(mask);
131                 
132                 if(in[0]->data != buf1) 
133                         free_compbuf(buf1);
134                 if(in[1]->data != buf2) 
135                         free_compbuf(buf2);
136         }
137 }
138
139 static void node_composit_init_splitviewer(bNode* node)
140 {
141    ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user");
142    node->storage= iuser;
143    iuser->sfra= 1;
144    iuser->fie_ima= 2;
145    iuser->ok= 1;
146    node->custom1= 50;   /* default 50% split */
147 }
148
149 void register_node_type_cmp_splitviewer(ListBase *lb)
150 {
151         static bNodeType ntype;
152
153         node_type_base(&ntype, CMP_NODE_SPLITVIEWER, "SplitViewer", NODE_CLASS_OUTPUT, NODE_PREVIEW|NODE_OPTIONS,
154                 cmp_node_splitviewer_in, NULL);
155         node_type_size(&ntype, 140, 100, 320);
156         node_type_init(&ntype, node_composit_init_splitviewer);
157         node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage);
158         node_type_exec(&ntype, node_composit_exec_splitviewer);
159
160         nodeRegisterType(lb, &ntype);
161 }
162
163
164
165
166