removed 3D view listener for changing the background image frame.
[blender-staging.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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 *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 **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                 
65                 buf1= typecheck_compbuf(in[0]->data, CB_RGBA);
66                 buf2= typecheck_compbuf(in[1]->data, CB_RGBA);
67                 
68                 BKE_image_user_calc_frame(node->storage, rd->cfra, 0);
69                 
70                 /* always returns for viewer image, but we check nevertheless */
71                 ibuf= BKE_image_get_ibuf(ima, node->storage);
72                 if(ibuf==NULL) {
73                         printf("node_composit_exec_viewer error\n");
74                         return;
75                 }
76                 
77                 /* free all in ibuf */
78                 imb_freerectImBuf(ibuf);
79                 imb_freerectfloatImBuf(ibuf);
80                 IMB_freezbuffloatImBuf(ibuf);
81                 
82                 /* make ibuf, and connect to ima */
83                 ibuf->x= buf1->x;
84                 ibuf->y= buf1->y;
85                 imb_addrectfloatImBuf(ibuf);
86                 
87                 ima->ok= IMA_OK_LOADED;
88
89                 /* output buf */
90                 cbuf= alloc_compbuf(buf1->x, buf1->y, CB_RGBA, 0);      /* no alloc*/
91                 cbuf->rect= ibuf->rect_float;
92                 
93                 /* mask buf */
94                 mask= alloc_compbuf(buf1->x, buf1->y, CB_VAL, 1);
95                 
96                 
97                 /* Check which offset mode is selected and limit offset if needed */
98                 if(node->custom2 == 0) {
99                         offset = buf1->x / 100.0f * node->custom1;
100                         CLAMP(offset, 0, buf1->x);
101                 }
102                 else {
103                         offset = buf1->y / 100.0f * node->custom1;
104                         CLAMP(offset, 0, buf1->y);
105                 }
106                 
107                 if(node->custom2 == 0) {
108                         for(y=0; y<buf1->y; y++) {
109                                 float *fac= mask->rect + y*buf1->x;
110                                 for(x=offset; x>0; x--, fac++)
111                                         *fac= 1.0f;
112                         }
113                 }
114                 else {
115                         for(y=0; y<offset; y++) {
116                                 float *fac= mask->rect + y*buf1->x;
117                                 for(x=buf1->x; x>0; x--, fac++)
118                                         *fac= 1.0f;
119                         }
120                 }
121                 
122                 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);
123                 
124                 generate_preview(data, node, cbuf);
125                 free_compbuf(cbuf);
126                 free_compbuf(mask);
127                 
128                 if(in[0]->data != buf1) 
129                         free_compbuf(buf1);
130                 if(in[1]->data != buf2) 
131                         free_compbuf(buf2);
132         }
133 }
134
135 static void node_composit_init_splitviewer(bNode* node)
136 {
137    ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user");
138    node->storage= iuser;
139    iuser->sfra= 1;
140    iuser->fie_ima= 2;
141    iuser->ok= 1;
142    node->custom1= 50;   /* default 50% split */
143 }
144
145 bNodeType cmp_node_splitviewer= {
146         /* *next,*prev */       NULL, NULL,
147         /* type code   */       CMP_NODE_SPLITVIEWER,
148         /* name        */       "SplitViewer",
149         /* width+range */       140, 100, 320,
150         /* class+opts  */       NODE_CLASS_OUTPUT, NODE_PREVIEW|NODE_OPTIONS,
151         /* input sock  */       cmp_node_splitviewer_in,
152         /* output sock */       NULL,
153         /* storage     */       "ImageUser",
154         /* execfunc    */       node_composit_exec_splitviewer,
155         /* butfunc     */       NULL,
156         /* initfunc    */       node_composit_init_splitviewer,
157         /* freestoragefunc    */        node_free_standard_storage,
158         /* copystoragefunc    */        node_copy_standard_storage,
159         /* id          */       NULL
160 };
161
162
163
164