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