2
* $Id: CMP_channelMatte.c,v 1.4 2007/04/04 13:58:09 jesterking Exp $
4
* ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
20
* The Original Code is Copyright (C) 2006 Blender Foundation.
21
* All rights reserved.
23
* The Original Code is: all of this file.
25
* Contributor(s): none yet.
27
* ***** END GPL LICENSE BLOCK *****
30
#include "../CMP_util.h"
33
/* ******************* Channel Matte Node ********************************* */
34
static bNodeSocketType cmp_node_channel_matte_in[]={
35
{SOCK_RGBA,1,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
39
static bNodeSocketType cmp_node_channel_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},
45
static void do_normalized_rgba_to_ycca2(bNode *node, float *out, float *in)
47
/*normalize to the range 0.0 to 1.0) */
48
rgb_to_ycc(in[0],in[1],in[2], &out[0], &out[1], &out[2]);
49
out[0]=(out[0])/255.0;
50
out[1]=(out[1])/255.0;
51
out[2]=(out[2])/255.0;
55
static void do_normalized_ycca_to_rgba2(bNode *node, float *out, float *in)
57
/*un-normalize the normalize from above */
61
ycc_to_rgb(in[0],in[1],in[2], &out[0], &out[1], &out[2]);
66
static void do_channel_matte(bNode *node, float *out, float *in)
68
NodeChroma *c=(NodeChroma *)node->storage;
71
/* Alpha=G-MAX(R, B) */
77
alpha=in[0]-MAX2(in[1],in[2]);
82
alpha=in[1]-MAX2(in[0],in[2]);
87
alpha=in[2]-MAX2(in[0],in[1]);
94
/*flip because 0.0 is transparent, not 1.0*/
99
alpha=in[3]; /*whatever it was prior */
101
else if(alpha<c->t2){
105
alpha=(alpha-c->t2)/(c->t1-c->t2);
109
/* don't make something that was more transparent less transparent */
119
static void node_composit_exec_channel_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
124
if(in[0]->hasinput==0) return;
125
if(in[0]->data==NULL) return;
126
if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return;
128
cbuf=typecheck_compbuf(in[0]->data, CB_RGBA);
130
outbuf=dupalloc_compbuf(cbuf);
132
/*convert to colorspace*/
133
switch(node->custom1) {
137
composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_hsva, CB_RGBA);
140
composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_yuva, CB_RGBA);
143
composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_normalized_rgba_to_ycca2, CB_RGBA);
149
/*use the selected channel information to do the key */
150
composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_channel_matte, CB_RGBA);
152
/*convert back to RGB colorspace in place*/
153
switch(node->custom1) {
157
composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_hsva_to_rgba, CB_RGBA);
160
composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_yuva_to_rgba, CB_RGBA);
163
composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_normalized_ycca_to_rgba2, CB_RGBA);
169
generate_preview(node, outbuf);
171
if(out[1]->hasoutput)
172
out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A);
174
if(cbuf!=in[0]->data)
179
static void node_composit_init_channel_matte(bNode *node)
181
NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma");
188
node->custom1= 1; /* RGB channel */
189
node->custom2= 2; /* Green Channel */
192
bNodeType cmp_node_channel_matte={
193
/* *next,*prev */ NULL, NULL,
194
/* type code */ CMP_NODE_CHANNEL_MATTE,
195
/* name */ "Channel Key",
196
/* width+range */ 200, 80, 250,
197
/* class+opts */ NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS,
198
/* input sock */ cmp_node_channel_matte_in,
199
/* output sock */ cmp_node_channel_matte_out,
200
/* storage */ "NodeChroma",
201
/* execfunc */ node_composit_exec_channel_matte,
203
/* initfunc */ node_composit_init_channel_matte,
204
/* freestoragefunc */ node_free_standard_storage,
205
/* copystoragefunc */ node_copy_standard_storage,