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

« back to all changes in this revision

Viewing changes to source/blender/nodes/intern/CMP_nodes/CMP_lummaMatte.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_lummaMatte.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
/* ******************* Luma Matte Node ********************************* */
 
34
static bNodeSocketType cmp_node_luma_matte_in[]={
 
35
        {SOCK_RGBA,1,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
 
36
        {-1,0,""}
 
37
};
 
38
 
 
39
static bNodeSocketType cmp_node_luma_matte_out[]={
 
40
        {SOCK_RGBA,0,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
 
41
        {SOCK_VALUE,0,"Matte",0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 
42
        {-1,0,""}
 
43
};
 
44
 
 
45
static void do_luma_matte(bNode *node, float *out, float *in)
 
46
{
 
47
        NodeChroma *c=(NodeChroma *)node->storage;
 
48
        float alpha;
 
49
 
 
50
        alpha=0.0;
 
51
 
 
52
        /* test range*/
 
53
        if(in[0]>c->t1) {
 
54
                alpha=1.0;
 
55
        }
 
56
        else if(in[1]<c->t2){
 
57
                alpha=0.0;
 
58
        }
 
59
        else {/*blend */
 
60
                alpha=(in[0]-c->t2)/(c->t1-c->t2);
 
61
        }
 
62
        
 
63
        /* don't make something that was more transparent less transparent */
 
64
        if (alpha<in[3]) {
 
65
                out[3]=alpha;
 
66
        }
 
67
        else {
 
68
                out[3]=in[3];
 
69
        }
 
70
 
 
71
}
 
72
 
 
73
static void node_composit_exec_luma_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 
74
{
 
75
        CompBuf *cbuf;
 
76
        CompBuf *outbuf;
 
77
        
 
78
        if(in[0]->hasinput==0)  return;
 
79
        if(in[0]->data==NULL) return;
 
80
        if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return;
 
81
        
 
82
        cbuf=typecheck_compbuf(in[0]->data, CB_RGBA);
 
83
        
 
84
        outbuf=dupalloc_compbuf(cbuf);
 
85
 
 
86
        composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_yuva, CB_RGBA);
 
87
        composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_luma_matte, CB_RGBA);
 
88
        composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_yuva_to_rgba, CB_RGBA);
 
89
        
 
90
        generate_preview(node, outbuf);
 
91
        out[0]->data=outbuf;
 
92
        if (out[1]->hasoutput)
 
93
                out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A);
 
94
        if(cbuf!=in[0]->data)
 
95
                free_compbuf(cbuf);
 
96
}
 
97
 
 
98
static void node_composit_init_luma_matte(bNode *node)
 
99
{
 
100
   NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma");
 
101
   node->storage=c;
 
102
   c->t1= 0.0f;
 
103
   c->t2= 0.0f;
 
104
};
 
105
 
 
106
bNodeType cmp_node_luma_matte={
 
107
        /* *next,*prev */       NULL, NULL,
 
108
        /* type code   */       CMP_NODE_LUMA_MATTE,
 
109
        /* name        */       "Luminance Key",
 
110
        /* width+range */       200, 80, 250,
 
111
        /* class+opts  */       NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS,
 
112
        /* input sock  */       cmp_node_luma_matte_in,
 
113
        /* output sock */       cmp_node_luma_matte_out,
 
114
        /* storage     */       "NodeChroma",
 
115
        /* execfunc    */       node_composit_exec_luma_matte,
 
116
        /* butfunc     */       NULL,
 
117
        /* initfunc    */       node_composit_init_luma_matte,
 
118
        /* freestoragefunc    */        node_free_standard_storage,
 
119
        /* copystoragefunc    */        node_copy_standard_storage,
 
120
        /* id          */       NULL
 
121
};
 
122