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:
authorRobert Holcomb <bob_holcomb@hotmail.com>2012-04-30 00:07:29 +0400
committerRobert Holcomb <bob_holcomb@hotmail.com>2012-04-30 00:07:29 +0400
commit502e594abb270f08c5525cdddc12dc1890b69988 (patch)
treec825457e4f5cfbaa21a619a8a242ec7fc375983f /source/blender/nodes
parentf7ec94cbc6c7dc761f127c50081b3383a58a1c2e (diff)
Fixed UI bug in distance, chroma, and difference nodes that caused the threshold to be limited by the falloff value. These should be independent. Cleaned up how falloff works in keying nodes.
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_chromaMatte.c100
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_diffMatte.c109
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_distanceMatte.c173
3 files changed, 222 insertions, 160 deletions
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 (alpha<in[3]) {
@@ -130,11 +129,8 @@ static void do_chroma_key(bNode *node, float *out, float *in)
out[3]=in[3];
}
}
- else { /*pixel is outside key color */
- out[0]=in[0];
- out[1]=in[1];
- out[2]=in[2];
- out[3]=in[3]; /* make pixel just as transparent as it was before */
+ else { /* make pixel just as transparent as it was before */
+ out[3]=in[3];
}
}
@@ -143,32 +139,32 @@ static void node_composit_exec_chroma_matte(void *data, bNode *node, bNodeStack
CompBuf *cbuf;
CompBuf *chromabuf;
NodeChroma *c;
-
+
if (in[0]->hasinput==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;
}