~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/nodes/intern/CMP_nodes/CMP_idMask.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * $Id: CMP_idMask.c,v 1.4 2007/04/04 13:58:10 jesterking Exp $
 
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
/* **************** 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
static void node_composit_exec_idmask(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 
67
{
 
68
        if(out[0]->hasoutput==0)
 
69
                return;
 
70
        
 
71
        if(in[0]->data) {
 
72
                CompBuf *cbuf= in[0]->data;
 
73
                CompBuf *stackbuf;
 
74
                
 
75
                if(cbuf->type!=CB_VAL)
 
76
                        return;
 
77
                
 
78
                stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */;
 
79
                
 
80
                do_idmask(stackbuf, cbuf, (float)node->custom1);
 
81
                
 
82
                out[0]->data= stackbuf;
 
83
        }
 
84
}
 
85
 
 
86
 
 
87
bNodeType cmp_node_idmask= {
 
88
        /* *next,*prev */       NULL, NULL,
 
89
        /* type code   */       CMP_NODE_ID_MASK,
 
90
        /* name        */       "ID Mask",
 
91
        /* width+range */       140, 100, 320,
 
92
        /* class+opts  */       NODE_CLASS_CONVERTOR, NODE_OPTIONS,
 
93
        /* input sock  */       cmp_node_idmask_in,
 
94
        /* output sock */       cmp_node_idmask_out,
 
95
        /* storage     */       "",
 
96
        /* execfunc    */       node_composit_exec_idmask,
 
97
        /* butfunc     */       NULL,
 
98
        /* initfunc    */       NULL,
 
99
        /* freestoragefunc    */        NULL,
 
100
        /* copystoragefunc    */        NULL,
 
101
        /* id          */       NULL
 
102
};
 
103
 
 
104