style cleanup: follow style guide for formatting of if/for/while loops, and else...
[blender.git] / source / blender / nodes / composite / nodes / node_composite_composite.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2006 Blender Foundation.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/nodes/composite/nodes/node_composite_composite.c
29  *  \ingroup cmpnodes
30  */
31
32
33 #include "node_composite_util.h"
34
35
36
37 /* **************** COMPOSITE ******************** */
38 static bNodeSocketTemplate cmp_node_composite_in[]= {
39         {       SOCK_RGBA, 1, "Image",          0.0f, 0.0f, 0.0f, 1.0f},
40         {       SOCK_FLOAT, 1, "Alpha",         1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
41         {       SOCK_FLOAT, 1, "Z",                     1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
42         {       -1, 0, ""       }
43 };
44
45 /* applies to render pipeline */
46 static void node_composit_exec_composite(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
47 {
48         /* image assigned to output */
49         /* stack order input sockets: col, alpha, z */
50         
51         if (node->flag & NODE_DO_OUTPUT) {      /* only one works on out */
52                 Scene *scene= (Scene *)node->id;
53                 RenderData *rd= data;
54                 
55                 if (scene && (rd->scemode & R_DOCOMP)) {
56                         Render *re= RE_GetRender(scene->id.name);
57                         RenderResult *rr= RE_AcquireResultWrite(re); 
58                         if (rr) {
59                                 CompBuf *outbuf, *zbuf=NULL;
60                                 
61                                 if (rr->rectf) 
62                                         MEM_freeN(rr->rectf);
63                                 outbuf= alloc_compbuf(rr->rectx, rr->recty, CB_RGBA, 1);
64                                 
65                                 if (in[1]->data==NULL)
66                                         composit1_pixel_processor(node, outbuf, in[0]->data, in[0]->vec, do_copy_rgba, CB_RGBA);
67                                 else
68                                         composit2_pixel_processor(node, outbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_copy_a_rgba, CB_RGBA, CB_VAL);
69                                 
70                                 if (in[2]->data) {
71                                         if (rr->rectz) 
72                                                 MEM_freeN(rr->rectz);
73                                         zbuf= alloc_compbuf(rr->rectx, rr->recty, CB_VAL, 1);
74                                         composit1_pixel_processor(node, zbuf, in[2]->data, in[2]->vec, do_copy_value, CB_VAL);
75                                         rr->rectz= zbuf->rect;
76                                         zbuf->malloc= 0;
77                                         free_compbuf(zbuf);
78                                 }
79                                 generate_preview(data, node, outbuf);
80                                 
81                                 /* we give outbuf to rr... */
82                                 rr->rectf= outbuf->rect;
83                                 outbuf->malloc= 0;
84                                 free_compbuf(outbuf);
85
86                                 /* signal for imageviewer to refresh (it converts to byte rects...) */
87                                 BKE_image_signal(BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"), NULL, IMA_SIGNAL_FREE);
88
89                                 RE_ReleaseResult(re);
90                                 return;
91                         }
92                         else
93                                 RE_ReleaseResult(re);
94                 }
95         }
96         if (in[0]->data)
97                 generate_preview(data, node, in[0]->data);
98 }
99
100 void register_node_type_cmp_composite(bNodeTreeType *ttype)
101 {
102         static bNodeType ntype;
103
104         node_type_base(ttype, &ntype, CMP_NODE_COMPOSITE, "Composite", NODE_CLASS_OUTPUT, NODE_PREVIEW);
105         node_type_socket_templates(&ntype, cmp_node_composite_in, NULL);
106         node_type_size(&ntype, 80, 60, 200);
107         node_type_exec(&ntype, node_composit_exec_composite);
108         /* Do not allow muting for this node. */
109         node_type_internal_connect(&ntype, NULL);
110
111         nodeRegisterType(ttype, &ntype);
112 }