Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/nodes/composite/nodes/node_composite_distanceMatte.c')
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_distanceMatte.c161
1 files changed, 112 insertions, 49 deletions
diff --git a/source/blender/nodes/composite/nodes/node_composite_distanceMatte.c b/source/blender/nodes/composite/nodes/node_composite_distanceMatte.c
index 7aaaa7ed9b4..74e058292d3 100644
--- a/source/blender/nodes/composite/nodes/node_composite_distanceMatte.c
+++ b/source/blender/nodes/composite/nodes/node_composite_distanceMatte.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): 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"
@@ -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;
}