2
* ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18
* The Original Code is Copyright (C) 2006 Blender Foundation.
19
* All rights reserved.
21
* The Original Code is: all of this file.
23
* Contributor(s): Bob Holcomb
25
* ***** END GPL LICENSE BLOCK *****
28
/** \file blender/nodes/composite/nodes/node_composite_channelMatte.c
33
#include "node_composite_util.h"
36
/* ******************* Channel Matte Node ********************************* */
37
static bNodeSocketTemplate cmp_node_channel_matte_in[]={
38
{SOCK_RGBA,1,"Image", 1.0f, 1.0f, 1.0f, 1.0f},
42
static bNodeSocketTemplate cmp_node_channel_matte_out[]={
43
{SOCK_RGBA,0,"Image"},
44
{SOCK_FLOAT,0,"Matte"},
48
static void do_normalized_rgba_to_ycca2(bNode *UNUSED(node), float *out, float *in)
50
/*normalize to the range 0.0 to 1.0) */
51
rgb_to_ycc(in[0],in[1],in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601);
52
out[0]=(out[0])/255.0f;
53
out[1]=(out[1])/255.0f;
54
out[2]=(out[2])/255.0f;
58
static void do_normalized_ycca_to_rgba2(bNode *UNUSED(node), float *out, float *in)
60
/*un-normalize the normalize from above */
64
ycc_to_rgb(in[0],in[1],in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601);
69
static void do_channel_matte(bNode *node, float *out, float *in)
71
NodeChroma *c=(NodeChroma *)node->storage;
74
switch(c->algorithm) {
75
case 0: { /* Alpha=key_channel-limit channel */
76
int key_channel=node->custom2-1;
77
int limit_channel=c->channel-1;
78
alpha=in[key_channel]-in[limit_channel];
81
case 1: { /* Alpha=G-MAX(R, B) */
82
switch(node->custom2) {
84
alpha=in[0]-MAX2(in[1],in[2]);
88
alpha=in[1]-MAX2(in[0],in[2]);
92
alpha=in[2]-MAX2(in[0],in[1]);
104
/*flip because 0.0 is transparent, not 1.0*/
109
alpha=in[3]; /*whatever it was prior */
111
else if (alpha<c->t2) {
115
alpha=(alpha-c->t2)/(c->t1-c->t2);
119
/* don't make something that was more transparent less transparent */
128
static void node_composit_exec_channel_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
133
if (in[0]->hasinput==0) return;
134
if (in[0]->data==NULL) return;
135
if (out[0]->hasoutput==0 && out[1]->hasoutput==0) return;
137
cbuf=typecheck_compbuf(in[0]->data, CB_RGBA);
139
outbuf=dupalloc_compbuf(cbuf);
141
/*convert to colorspace*/
142
switch(node->custom1) {
143
case CMP_NODE_CHANNEL_MATTE_CS_RGB:
145
case CMP_NODE_CHANNEL_MATTE_CS_HSV: /*HSV*/
146
composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_hsva, CB_RGBA);
148
case CMP_NODE_CHANNEL_MATTE_CS_YUV: /*YUV*/
149
composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_yuva, CB_RGBA);
151
case CMP_NODE_CHANNEL_MATTE_CS_YCC: /*YCC*/
152
composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_normalized_rgba_to_ycca2, CB_RGBA);
158
/*use the selected channel information to do the key */
159
composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_channel_matte, CB_RGBA);
161
/*convert back to RGB colorspace in place*/
162
switch(node->custom1) {
163
case CMP_NODE_CHANNEL_MATTE_CS_RGB: /*RGB*/
165
case CMP_NODE_CHANNEL_MATTE_CS_HSV: /*HSV*/
166
composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_hsva_to_rgba, CB_RGBA);
168
case CMP_NODE_CHANNEL_MATTE_CS_YUV: /*YUV*/
169
composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_yuva_to_rgba, CB_RGBA);
171
case CMP_NODE_CHANNEL_MATTE_CS_YCC: /*YCC*/
172
composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_normalized_ycca_to_rgba2, CB_RGBA);
178
generate_preview(data, node, outbuf);
180
if (out[1]->hasoutput)
181
out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A);
183
if (cbuf!=in[0]->data)
188
static void node_composit_init_channel_matte(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
190
NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma");
197
c->algorithm=1; /*max channel limiting */
198
c->channel=1; /* limit by red */
199
node->custom1= 1; /* RGB channel */
200
node->custom2= 2; /* Green Channel */
203
void register_node_type_cmp_channel_matte(bNodeTreeType *ttype)
205
static bNodeType ntype;
207
node_type_base(ttype, &ntype, CMP_NODE_CHANNEL_MATTE, "Channel Key", NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS);
208
node_type_socket_templates(&ntype, cmp_node_channel_matte_in, cmp_node_channel_matte_out);
209
node_type_size(&ntype, 200, 80, 250);
210
node_type_init(&ntype, node_composit_init_channel_matte);
211
node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage);
212
node_type_exec(&ntype, node_composit_exec_channel_matte);
214
nodeRegisterType(ttype, &ntype);