doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / nodes / intern / CMP_nodes / CMP_idMask.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
33 /* **************** ID Mask  ******************** */
34
35 static bNodeSocketType cmp_node_idmask_in[]= {
36         {       SOCK_VALUE, 1, "ID value",                      0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
37         {       -1, 0, ""       }
38 };
39 static bNodeSocketType cmp_node_idmask_out[]= {
40         {       SOCK_VALUE, 0, "Alpha",                 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
41         {       -1, 0, ""       }
42 };
43
44 /* stackbuf should be zeroed */
45 static void do_idmask(CompBuf *stackbuf, CompBuf *cbuf, float idnr)
46 {
47         float *rect;
48         int x;
49         char *abuf= MEM_mapallocN(cbuf->x*cbuf->y, "anti ali buf");
50         
51         rect= cbuf->rect;
52         for(x= cbuf->x*cbuf->y - 1; x>=0; x--)
53                 if(rect[x]==idnr)
54                         abuf[x]= 255;
55         
56         antialias_tagbuf(cbuf->x, cbuf->y, abuf);
57         
58         rect= stackbuf->rect;
59         for(x= cbuf->x*cbuf->y - 1; x>=0; x--)
60                 if(abuf[x]>1)
61                         rect[x]= (1.0f/255.0f)*(float)abuf[x];
62         
63         MEM_freeN(abuf);
64 }
65
66 /* full sample version */
67 static void do_idmask_fsa(CompBuf *stackbuf, CompBuf *cbuf, float idnr)
68 {
69         float *rect, *rs;
70         int x;
71         
72         rect= cbuf->rect;
73         rs= stackbuf->rect;
74         for(x= cbuf->x*cbuf->y - 1; x>=0; x--)
75                 if(rect[x]==idnr)
76                         rs[x]= 1.0f;
77         
78 }
79
80
81 static void node_composit_exec_idmask(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
82 {
83         RenderData *rd= data;
84         
85         if(out[0]->hasoutput==0)
86                 return;
87         
88         if(in[0]->data) {
89                 CompBuf *cbuf= in[0]->data;
90                 CompBuf *stackbuf;
91                 
92                 if(cbuf->type!=CB_VAL)
93                         return;
94                 
95                 stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */;
96                 
97                 if(rd->scemode & R_FULL_SAMPLE)
98                         do_idmask_fsa(stackbuf, cbuf, (float)node->custom1);
99                 else
100                         do_idmask(stackbuf, cbuf, (float)node->custom1);
101                 
102                 out[0]->data= stackbuf;
103         }
104 }
105
106
107 void register_node_type_cmp_idmask(ListBase *lb)
108 {
109         static bNodeType ntype;
110
111         node_type_base(&ntype, CMP_NODE_ID_MASK, "ID Mask", NODE_CLASS_CONVERTOR, NODE_OPTIONS,
112                 cmp_node_idmask_in, cmp_node_idmask_out);
113         node_type_size(&ntype, 140, 100, 320);
114         node_type_exec(&ntype, node_composit_exec_idmask);
115
116         nodeRegisterType(lb, &ntype);
117 }
118
119
120