~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/nodes/composite/nodes/node_composite_idMask.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

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