diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index c1af8d3016a..bd17c821567 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -1635,9 +1635,14 @@ static void node_composit_buts_diff_matte(uiLayout *layout, bContext *UNUSED(C), static void node_composit_buts_distance_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col, *row; col = uiLayoutColumn(layout, 1); + + uiItemL(layout, "Color Space:", ICON_NONE); + row= uiLayoutRow(layout, 0); + uiItemR(row, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE); } diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index a101bcaec12..58fd936819b 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -328,6 +328,39 @@ static void rna_Matte_t2_set(PointerRNA *ptr, float value) chroma->t2 = value; } +static void rna_distance_matte_t1_set(PointerRNA *ptr, float value) +{ + bNode *node = (bNode*)ptr->data; + NodeChroma *chroma = node->storage; + + chroma->t1 = value; +} + +static void rna_distance_matte_t2_set(PointerRNA *ptr, float value) +{ + bNode *node = (bNode*)ptr->data; + NodeChroma *chroma = node->storage; + + chroma->t2 = value; +} + +static void rna_difference_matte_t1_set(PointerRNA *ptr, float value) +{ + bNode *node = (bNode*)ptr->data; + NodeChroma *chroma = node->storage; + + chroma->t1 = value; +} + +static void rna_difference_matte_t2_set(PointerRNA *ptr, float value) +{ + bNode *node = (bNode*)ptr->data; + NodeChroma *chroma = node->storage; + + chroma->t2 = value; +} + + static void rna_Node_scene_set(PointerRNA *ptr, PointerRNA value) { bNode *node = (bNode*)ptr->data; @@ -1891,14 +1924,14 @@ static void def_cmp_diff_matte(StructRNA *srna) prop = RNA_def_property(srna, "tolerance", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "t1"); - RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t1_set", NULL); + RNA_def_property_float_funcs(prop, NULL, "rna_difference_matte_t1_set", NULL); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Tolerance", "Color distances below this threshold are keyed"); RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "t2"); - RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t2_set", NULL); + RNA_def_property_float_funcs(prop, NULL, "rna_difference_matte_t2_set", NULL); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Falloff", "Color distances below this additional threshold are partially keyed"); RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); @@ -1933,18 +1966,30 @@ static void def_cmp_distance_matte(StructRNA *srna) { PropertyRNA *prop; - RNA_def_struct_sdna_from(srna, "NodeChroma", "storage"); + static EnumPropertyItem color_space_items[] = { + {1, "RGB", 0, "RGB", "RGB color space"}, + {2, "YCC", 0, "YCC", "YCbCr Suppression"}, + {0, NULL, 0, NULL, NULL}}; + + RNA_def_struct_sdna_from(srna, "NodeChroma", "storage"); + + prop = RNA_def_property(srna, "channel", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "channel"); + RNA_def_property_enum_items(prop, color_space_items); + RNA_def_property_ui_text(prop, "Channel", ""); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + prop = RNA_def_property(srna, "tolerance", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "t1"); - RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t1_set", NULL); + RNA_def_property_float_funcs(prop, NULL, "rna_distance_matte_t1_set", NULL); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Tolerance", "Color distances below this threshold are keyed"); RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "t2"); - RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t2_set", NULL); + RNA_def_property_float_funcs(prop, NULL, "rna_distance_matte_t2_set", NULL); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Falloff", "Color distances below this additional threshold are partially keyed"); RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); @@ -2071,7 +2116,7 @@ static void def_cmp_chroma_matte(StructRNA *srna) prop = RNA_def_property(srna, "gain", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "fstrength"); RNA_def_property_range(prop, 0.0f, 1.0f); - RNA_def_property_ui_text(prop, "Gain", "Alpha gain"); + RNA_def_property_ui_text(prop, "Falloff", "Alpha falloff"); RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "shadow_adjust", PROP_FLOAT, PROP_NONE); diff --git a/source/blender/nodes/composite/nodes/node_composite_chromaMatte.c b/source/blender/nodes/composite/nodes/node_composite_chromaMatte.c index 8684f67a54e..f366642149a 100644 --- a/source/blender/nodes/composite/nodes/node_composite_chromaMatte.c +++ b/source/blender/nodes/composite/nodes/node_composite_chromaMatte.c @@ -1,33 +1,33 @@ /* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ +* ***** BEGIN GPL LICENSE BLOCK ***** +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +* The Original Code is Copyright (C) 2006 Blender Foundation. +* All rights reserved. +* +* The Original Code is: all of this file. +* +* Contributor(s): none yet. +* +* ***** END GPL LICENSE BLOCK ***** +*/ /** \file blender/nodes/composite/nodes/node_composite_chromaMatte.c - * \ingroup cmpnodes - */ +* \ingroup cmpnodes +*/ #include "node_composite_util.h" @@ -59,9 +59,9 @@ static void do_rgba_to_ycca_normalized(bNode *UNUSED(node), float *out, float *i out[1]=(out[1]*2.0f)-1.0f; out[2]=(out[2]*2.0f)-1.0f; -// out[0]=((out[0])-16)/255.0; -// out[1]=((out[1])-128)/255.0; -// out[2]=((out[2])-128)/255.0; + // out[0]=((out[0])-16)/255.0; + // out[1]=((out[1])-128)/255.0; + // out[2]=((out[2])-128)/255.0; out[3]=in[3]; } @@ -77,8 +77,8 @@ static void do_ycca_to_rgba_normalized(bNode *UNUSED(node), float *out, float *i in[2]=(in[2]*255.0f); // in[0]=(in[0]*255.0)+16; -// in[1]=(in[1]*255.0)+128; -// in[2]=(in[2]*255.0)+128; + // in[1]=(in[1]*255.0)+128; + // in[2]=(in[2]*255.0)+128; ycc_to_rgb(in[0], in[1], in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601); out[3]=in[3]; } @@ -94,7 +94,7 @@ static void do_chroma_key(bNode *node, float *out, float *in) /* Algorithm from book "Video Demistified," does not include the spill reduction part */ - /* find theta, the angle that the color space should be rotated based on key*/ + /* find theta, the angle that the color space should be rotated based on key chroma values*/ theta=atan2(c->key[2], c->key[1]); /*rotate the cb and cr into x/z space */ @@ -107,13 +107,9 @@ static void do_chroma_key(bNode *node, float *out, float *in) /* if kfg is <0 then the pixel is outside of the key color */ kfg= x-(fabsf(z)/tanf(angle/2.0f)); - out[0]=in[0]; - out[1]=in[1]; - out[2]=in[2]; + copy_v3_v3(out, in); if (kfg>0.0f) { /* found a pixel that is within key color */ - alpha=(1.0f-kfg)*(c->fstrength); - beta=atan2(z, x); angle2=c->t2; /* t2 is radians. */ @@ -121,6 +117,9 @@ static void do_chroma_key(bNode *node, float *out, float *in) if (fabsf(beta) < (angle2/2.0f)) { alpha=0.0; } + else { + alpha=1.0f-(kfg/c->fstrength); + } /* don't make something that was more transparent less transparent */ if (alphahasinput==0) return; if (in[0]->data==NULL) return; if (out[0]->hasoutput==0 && out[1]->hasoutput==0) return; - + cbuf= typecheck_compbuf(in[0]->data, CB_RGBA); - + chromabuf= dupalloc_compbuf(cbuf); - + c=node->storage; - + /*convert rgbbuf to normalized chroma space*/ composit1_pixel_processor(node, chromabuf, cbuf, in[0]->vec, do_rgba_to_ycca_normalized, CB_RGBA); /*convert key to normalized chroma color space */ do_rgba_to_ycca_normalized(node, c->key, in[1]->vec); - + /*per pixel chroma key*/ composit1_pixel_processor(node, chromabuf, chromabuf, in[0]->vec, do_chroma_key, CB_RGBA); - + /*convert back*/ composit1_pixel_processor(node, chromabuf, chromabuf, in[0]->vec, do_ycca_to_rgba_normalized, CB_RGBA); - + out[0]->data= chromabuf; if (out[1]->hasoutput) out[1]->data= valbuf_from_rgbabuf(chromabuf, CHAN_A); - + generate_preview(data, node, chromabuf); if (cbuf!=in[0]->data) diff --git a/source/blender/nodes/composite/nodes/node_composite_diffMatte.c b/source/blender/nodes/composite/nodes/node_composite_diffMatte.c index a827f094477..5dea0e1c067 100644 --- a/source/blender/nodes/composite/nodes/node_composite_diffMatte.c +++ b/source/blender/nodes/composite/nodes/node_composite_diffMatte.c @@ -1,87 +1,90 @@ /* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Bob Holcomb - * - * ***** END GPL LICENSE BLOCK ***** - */ +* ***** BEGIN GPL LICENSE BLOCK ***** +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +* The Original Code is Copyright (C) 2006 Blender Foundation. +* All rights reserved. +* +* The Original Code is: all of this file. +* +* Contributor(s): Bob Holcomb +* +* ***** END GPL LICENSE BLOCK ***** +*/ /** \file blender/nodes/composite/nodes/node_composite_diffMatte.c - * \ingroup cmpnodes - */ +* \ingroup cmpnodes +*/ #include "node_composite_util.h" /* ******************* channel Difference Matte ********************************* */ static bNodeSocketTemplate cmp_node_diff_matte_in[]={ - {SOCK_RGBA, 1, "Image 1", 1.0f, 1.0f, 1.0f, 1.0f}, - {SOCK_RGBA, 1, "Image 2", 1.0f, 1.0f, 1.0f, 1.0f}, - {-1, 0, ""} + {SOCK_RGBA,1,"Image 1", 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_RGBA,1,"Image 2", 1.0f, 1.0f, 1.0f, 1.0f}, + {-1,0,""} }; static bNodeSocketTemplate cmp_node_diff_matte_out[]={ - {SOCK_RGBA, 0, "Image"}, - {SOCK_FLOAT, 0, "Matte"}, - {-1, 0, ""} + {SOCK_RGBA,0,"Image"}, + {SOCK_FLOAT,0,"Matte"}, + {-1,0,""} }; static void do_diff_matte(bNode *node, float *outColor, float *inColor1, float *inColor2) { NodeChroma *c= (NodeChroma *)node->storage; float tolerence=c->t1; - float falloff=c->t2; + float fper=c->t2; + /* get falloff amount over tolerence size */ + float falloff=(1.0f-fper) * tolerence; float difference; float alpha; + float maxInputAlpha; + /* average together the distances */ difference= fabs(inColor2[0]-inColor1[0]) + - fabs(inColor2[1]-inColor1[1]) + - fabs(inColor2[2]-inColor1[2]); - - /*average together the distances*/ + fabs(inColor2[1]-inColor1[1]) + + fabs(inColor2[2]-inColor1[2]); difference=difference/3.0f; copy_v3_v3(outColor, inColor1); - /*make 100% transparent*/ - if (difference < tolerence) { - outColor[3]=0.0; - } - /*in the falloff region, make partially transparent */ - else if (difference < falloff+tolerence) { - difference=difference-tolerence; - alpha=difference/falloff; - /*only change if more transparent than before */ - if (alpha < inColor1[3]) { + if (difference <= tolerence) { + if(difference<=falloff) { + alpha=0.0f; + } + else{ + /* alpha as percent (distance / tolerance), each modified by falloff amount (in pixels)*/ + alpha=(difference-falloff)/(tolerence-falloff); + } + + /*only change if more transparent than either image */ + maxInputAlpha=maxf(inColor1[3], inColor2[3]); + if (alpha < maxInputAlpha) { + /*clamp*/ + if(alpha<0.0f) alpha=0.0f; + if(alpha>1.0f) alpha=1.0f; outColor[3]=alpha; } else { /* leave as before */ - outColor[3]=inColor1[3]; + outColor[3]=maxInputAlpha; } } - else { - /*foreground object*/ - outColor[3]= inColor1[3]; - } } static void node_composit_exec_diff_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) diff --git a/source/blender/nodes/composite/nodes/node_composite_distanceMatte.c b/source/blender/nodes/composite/nodes/node_composite_distanceMatte.c index 8ea8b64a26e..74e058292d3 100644 --- a/source/blender/nodes/composite/nodes/node_composite_distanceMatte.c +++ b/source/blender/nodes/composite/nodes/node_composite_distanceMatte.c @@ -1,48 +1,48 @@ /* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Bob Holcomb - * - * ***** END GPL LICENSE BLOCK ***** - */ +* ***** BEGIN GPL LICENSE BLOCK ***** +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +* The Original Code is Copyright (C) 2006 Blender Foundation. +* All rights reserved. +* +* The Original Code is: all of this file. +* +* Contributor(s): Bob Holcomb +* +* ***** END GPL LICENSE BLOCK ***** +*/ /** \file blender/nodes/composite/nodes/node_composite_distanceMatte.c - * \ingroup cmpnodes - */ +* \ingroup cmpnodes +*/ #include "node_composite_util.h" /* ******************* channel Distance Matte ********************************* */ static bNodeSocketTemplate cmp_node_distance_matte_in[]={ - {SOCK_RGBA, 1, "Image", 1.0f, 1.0f, 1.0f, 1.0f}, - {SOCK_RGBA, 1, "Key Color", 1.0f, 1.0f, 1.0f, 1.0f}, - {-1, 0, ""} + {SOCK_RGBA,1,"Image", 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_RGBA,1,"Key Color", 1.0f, 1.0f, 1.0f, 1.0f}, + {-1,0,""} }; static bNodeSocketTemplate cmp_node_distance_matte_out[]={ - {SOCK_RGBA, 0, "Image"}, - {SOCK_FLOAT, 0, "Matte"}, - {-1, 0, ""} + {SOCK_RGBA,0,"Image"}, + {SOCK_FLOAT,0,"Matte"}, + {-1,0,""} }; /* note, keyvals is passed on from caller as stack array */ @@ -51,34 +51,88 @@ static void do_distance_matte(bNode *node, float *out, float *in) { NodeChroma *c= (NodeChroma *)node->storage; float tolerence=c->t1; - float falloff=c->t2; + float fper=c->t2; + /* get falloff amount over tolerence size */ + float falloff=(1.0f-fper) * tolerence; float distance; float alpha; distance=sqrt((c->key[0]-in[0])*(c->key[0]-in[0]) + - (c->key[1]-in[1])*(c->key[1]-in[1]) + - (c->key[2]-in[2])*(c->key[2]-in[2])); + (c->key[1]-in[1])*(c->key[1]-in[1]) + + (c->key[2]-in[2])*(c->key[2]-in[2])); copy_v3_v3(out, in); - /*make 100% transparent */ - if (distance < tolerence) { - out[3]=0.0; - } - /*in the falloff region, make partially transparent */ - else if (distance < falloff+tolerence) { - distance=distance-tolerence; - alpha=distance/falloff; + if (distance <= tolerence) { + if(distance<=falloff) { + alpha=0.0f; + } + else{ + /* alpha as percent (distance / tolerance), each modified by falloff amount (in pixels)*/ + alpha=(distance-falloff)/(tolerence-falloff); + } + /*only change if more transparent than before */ if (alpha < in[3]) { + /*clamp*/ + if(alpha<0.0f) alpha=0.0f; + if(alpha>1.0f) alpha=1.0f; out[3]=alpha; } else { /* leave as before */ out[3]=in[3]; } } - else { - out[3]=in[3]; +} + +static void do_chroma_distance_matte(bNode *node, float *out, float *in) +{ + NodeChroma *c= (NodeChroma *)node->storage; + float tolerence=c->t1; + float fper=c->t2; + /* get falloff amount over tolerence size */ + float falloff=(1.0f-fper) * tolerence; + float y_key, cb_key, cr_key; + float y_pix, cb_pix, cr_pix; + float distance; + float alpha; + + /*convert key to chroma colorspace */ + rgb_to_ycc(c->key[0], c->key[1], c->key[2], &y_key, &cb_key, &cr_key, BLI_YCC_JFIF_0_255); + /* normalize the values */ + cb_key=cb_key/255.0f; + cr_key=cr_key/255.0f; + + /*convert pixel to chroma colorspace */ + rgb_to_ycc(in[0], in[1], in[2], &y_pix, &cb_pix, &cr_pix, BLI_YCC_JFIF_0_255); + /*normalize the values */ + cb_pix=cb_pix/255.0f; + cr_pix=cr_pix/255.0f; + + distance=sqrt((cb_key-cb_pix)*(cb_key-cb_pix) + + (cr_key-cr_pix)*(cr_key-cr_pix)); + + copy_v3_v3(out, in); + + if (distance <= tolerence) { + if(distance<=falloff) { + alpha=0.0f; + } + else{ + /* alpha as percent (distance / tolerance), each modified by falloff amount (in pixels)*/ + alpha=(distance-falloff)/(tolerence-falloff); + } + + /*only change if more transparent than before */ + if (alpha < in[3]) { + /*clamp*/ + if(alpha<0.0f) alpha=0.0f; + if(alpha>1.0f) alpha=1.0f; + out[3]=alpha; + } + else { /* leave as before */ + out[3]=in[3]; + } } } @@ -91,26 +145,34 @@ static void node_composit_exec_distance_matte(void *data, bNode *node, bNodeStac CompBuf *workbuf; CompBuf *inbuf; NodeChroma *c; - + /*is anything connected?*/ if (out[0]->hasoutput==0 && out[1]->hasoutput==0) return; /*must have an image imput*/ if (in[0]->data==NULL) return; - + inbuf=typecheck_compbuf(in[0]->data, CB_RGBA); - + c=node->storage; workbuf=dupalloc_compbuf(inbuf); - + /*use the input color*/ c->key[0]= in[1]->vec[0]; c->key[1]= in[1]->vec[1]; c->key[2]= in[1]->vec[2]; - - /* note, processor gets a keyvals array passed on as buffer constant */ - composit1_pixel_processor(node, workbuf, workbuf, in[0]->vec, do_distance_matte, CB_RGBA); - - + + /* work in RGB color space */ + if(c->channel==1) { + /* note, processor gets a keyvals array passed on as buffer constant */ + composit1_pixel_processor(node, workbuf, workbuf, in[0]->vec, do_distance_matte, CB_RGBA); + } + /* work in YCbCr color space */ + else { + composit1_pixel_processor(node, workbuf, workbuf, in[0]->vec, do_chroma_distance_matte, CB_RGBA); + } + + + out[0]->data=workbuf; if (out[1]->hasoutput) out[1]->data=valbuf_from_rgbabuf(workbuf, CHAN_A); @@ -124,6 +186,7 @@ static void node_composit_init_distance_matte(bNodeTree *UNUSED(ntree), bNode* n { NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma"); node->storage= c; + c->channel=1; c->t1= 0.1f; c->t2= 0.1f; }