removed 3D view listener for changing the background image frame.
[blender-staging.git] / source / blender / nodes / intern / CMP_nodes / CMP_viewer.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
33 /* **************** VIEWER ******************** */
34 static bNodeSocketType cmp_node_viewer_in[]= {
35         {       SOCK_RGBA, 1, "Image",          0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
36         {       SOCK_VALUE, 1, "Alpha",         1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
37         {       SOCK_VALUE, 1, "Z",                     1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
38         {       -1, 0, ""       }
39 };
40
41
42 static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
43 {
44         /* image assigned to output */
45         /* stack order input sockets: col, alpha, z */
46         
47         if(node->id && (node->flag & NODE_DO_OUTPUT)) { /* only one works on out */
48                 RenderData *rd= data;
49                 Image *ima= (Image *)node->id;
50                 ImBuf *ibuf;
51                 CompBuf *cbuf, *tbuf;
52                 int rectx, recty;
53                 
54                 BKE_image_user_calc_frame(node->storage, rd->cfra, 0);
55
56                 /* always returns for viewer image, but we check nevertheless */
57                 ibuf= BKE_image_get_ibuf(ima, node->storage);
58                 if(ibuf==NULL) {
59                         printf("node_composit_exec_viewer error\n");
60                         return;
61                 }
62                 
63                 /* free all in ibuf */
64                 imb_freerectImBuf(ibuf);
65                 imb_freerectfloatImBuf(ibuf);
66                 IMB_freezbuffloatImBuf(ibuf);
67                 
68                 /* get size */
69                 tbuf= in[0]->data?in[0]->data:(in[1]->data?in[1]->data:in[2]->data);
70                 if(tbuf==NULL) {
71                         rectx= 320; recty= 256;
72                 }
73                 else {
74                         rectx= tbuf->x;
75                         recty= tbuf->y;
76                 }
77                 
78                 /* make ibuf, and connect to ima */
79                 ibuf->x= rectx;
80                 ibuf->y= recty;
81                 imb_addrectfloatImBuf(ibuf);
82                 
83                 ima->ok= IMA_OK_LOADED;
84
85                 /* now we combine the input with ibuf */
86                 cbuf= alloc_compbuf(rectx, recty, CB_RGBA, 0);  /* no alloc*/
87                 cbuf->rect= ibuf->rect_float;
88                 
89                 /* when no alpha, we can simply copy */
90                 if(in[1]->data==NULL) {
91                         composit1_pixel_processor(node, cbuf, in[0]->data, in[0]->vec, do_copy_rgba, CB_RGBA);
92                 }
93                 else
94                         composit2_pixel_processor(node, cbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_copy_a_rgba, CB_RGBA, CB_VAL);
95                 
96                 /* zbuf option */
97                 if(in[2]->data) {
98                         CompBuf *zbuf= alloc_compbuf(rectx, recty, CB_VAL, 1);
99                         ibuf->zbuf_float= zbuf->rect;
100                         ibuf->mall |= IB_zbuffloat;
101                         
102                         composit1_pixel_processor(node, zbuf, in[2]->data, in[2]->vec, do_copy_value, CB_VAL);
103                         
104                         /* free compbuf, but not the rect */
105                         zbuf->malloc= 0;
106                         free_compbuf(zbuf);
107                 }
108
109                 generate_preview(data, node, cbuf);
110                 free_compbuf(cbuf);
111
112         }
113         else if(in[0]->data) {
114                 generate_preview(data, node, in[0]->data);
115         }
116 }
117
118 static void node_composit_init_viewer(bNode* node)
119 {
120    ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user");
121    node->storage= iuser;
122    iuser->sfra= 1;
123    iuser->fie_ima= 2;
124    iuser->ok= 1;
125 }
126
127 bNodeType cmp_node_viewer= {
128         /* *next,*prev */       NULL, NULL,
129         /* type code   */       CMP_NODE_VIEWER,
130         /* name        */       "Viewer",
131         /* width+range */       80, 60, 200,
132         /* class+opts  */       NODE_CLASS_OUTPUT, NODE_PREVIEW,
133         /* input sock  */       cmp_node_viewer_in,
134         /* output sock */       NULL,
135         /* storage     */       "ImageUser",
136         /* execfunc    */       node_composit_exec_viewer,
137         /* butfunc     */       NULL,
138         /* initfunc    */       node_composit_init_viewer,
139         /* freestoragefunc    */        node_free_standard_storage,
140         /* copystoragefunc    */        node_copy_standard_storage,
141         /* id          */       NULL
142         
143 };
144