33
33
#include "node_composite_util.h"
35
35
/* ******************* Color Key ********************************************************** */
36
static bNodeSocketTemplate cmp_node_color_in[]={
37
{SOCK_RGBA,1,"Image", 1.0f, 1.0f, 1.0f, 1.0f},
38
{SOCK_RGBA,1,"Key Color", 1.0f, 1.0f, 1.0f, 1.0f},
42
static bNodeSocketTemplate cmp_node_color_out[]={
43
{SOCK_RGBA,0,"Image"},
44
{SOCK_FLOAT,0,"Matte"},
48
static void do_color_key(bNode *node, float *out, float *in)
58
/* do hue last because it needs to wrap, and does some more checks */
60
/* sat */ (fabsf(in[1]-c->key[1]) < c->t2) &&
61
/* val */ (fabsf(in[2]-c->key[2]) < c->t3) &&
63
/* multiply by 2 because it wraps on both sides of the hue,
64
* otherwise 0.5 would key all hue's */
66
/* hue */ ((h_wrap= 2.0f * fabsf(in[0]-c->key[0])) < c->t1 || (2.0f - h_wrap) < c->t1)
68
out[3]=0.0; /*make transparent*/
71
else { /*pixel is outside key color */
72
out[3]=in[3]; /* make pixel just as transparent as it was before */
76
static void node_composit_exec_color_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
82
if (in[0]->hasinput==0) return;
83
if (in[0]->data==NULL) return;
84
if (out[0]->hasoutput==0 && out[1]->hasoutput==0) return;
86
cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
88
colorbuf= dupalloc_compbuf(cbuf);
92
/*convert rgbbuf to hsv*/
93
composit1_pixel_processor(node, colorbuf, cbuf, in[0]->vec, do_rgba_to_hsva, CB_RGBA);
95
/*convert key to hsv*/
96
do_rgba_to_hsva(node, c->key, in[1]->vec);
99
/*per pixel color key*/
100
composit1_pixel_processor(node, colorbuf, colorbuf, in[0]->vec, do_color_key, CB_RGBA);
103
composit1_pixel_processor(node, colorbuf, colorbuf, in[0]->vec, do_hsva_to_rgba, CB_RGBA);
105
out[0]->data= colorbuf;
106
if (out[1]->hasoutput)
107
out[1]->data= valbuf_from_rgbabuf(colorbuf, CHAN_A);
109
generate_preview(data, node, colorbuf);
111
if (cbuf!=in[0]->data)
115
static void node_composit_init_color_matte(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
36
static bNodeSocketTemplate cmp_node_color_in[] = {
37
{SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f},
38
{SOCK_RGBA, 1, N_("Key Color"), 1.0f, 1.0f, 1.0f, 1.0f},
42
static bNodeSocketTemplate cmp_node_color_out[] = {
43
{SOCK_RGBA, 0, N_("Image")},
44
{SOCK_FLOAT, 0, N_("Matte")},
48
static void node_composit_init_color_matte(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
117
50
NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node color");