[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31358] trunk/blender/source/blender: Fixed bug in normalition of YCbCr color space conversion (from 0..1 to

Robert Holcomb bob_holcomb at hotmail.com
Mon Aug 16 00:08:50 CEST 2010


Revision: 31358
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31358
Author:   scourage
Date:     2010-08-16 00:08:49 +0200 (Mon, 16 Aug 2010)

Log Message:
-----------
Fixed bug in normalition of YCbCr color space conversion (from 0..1 to
-1..1) to fix errors in keying.  Simplified chroma key to not take
despill into consideration (handled elsewhere).  Simplified user
interface for pieces not used.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_chromaMatte.c
    trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_sepcombHSVA.c

Modified: trunk/blender/source/blender/editors/space_node/drawnode.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/drawnode.c	2010-08-15 21:39:48 UTC (rev 31357)
+++ trunk/blender/source/blender/editors/space_node/drawnode.c	2010-08-15 22:08:49 UTC (rev 31358)
@@ -823,9 +823,9 @@
 	uiItemR(col, ptr, "cutoff", 0, NULL, 0);
 	
 	col= uiLayoutColumn(layout, 1);
-	uiItemR(col, ptr, "lift", UI_ITEM_R_SLIDER, NULL, 0);
+   /*uiItemR(col, ptr, "lift", UI_ITEM_R_SLIDER, NULL, 0);  Removed for now */
 	uiItemR(col, ptr, "gain", UI_ITEM_R_SLIDER, NULL, 0);
-	uiItemR(col, ptr, "shadow_adjust", UI_ITEM_R_SLIDER, NULL, 0);
+   /*uiItemR(col, ptr, "shadow_adjust", UI_ITEM_R_SLIDER, NULL, 0);  Removed for now*/
 }
 
 static void node_composit_buts_color_matte(uiLayout *layout, bContext *C, PointerRNA *ptr)

Modified: trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_chromaMatte.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_chromaMatte.c	2010-08-15 21:39:48 UTC (rev 31357)
+++ trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_chromaMatte.c	2010-08-15 22:08:49 UTC (rev 31358)
@@ -44,20 +44,38 @@
 
 static void do_rgba_to_ycca_normalized(bNode *node, float *out, float *in)
 {
-	/*normalize to the range -1.0 to 1.0) */
-	rgb_to_ycc(in[0],in[1],in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601);
-	out[0]=((out[0])-16)/255.0;
-	out[1]=((out[1])-128)/255.0;
-	out[2]=((out[2])-128)/255.0;
+   rgb_to_ycc(in[0],in[1],in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601);
+
+   //normalize to 0..1.0
+   out[0]=out[0]/255.0;
+   out[1]=out[1]/255.0;
+   out[2]=out[2]/255.0;
+
+   //rescale to -1.0..1.0
+   out[0]=(out[0]*2.0)-1.0;
+   out[1]=(out[1]*2.0)-1.0;
+   out[2]=(out[2]*2.0)-1.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];
 }
 
 static void do_ycca_to_rgba_normalized(bNode *node, float *out, float *in)
 {
-	/*un-normalize the normalize from above */
-	in[0]=(in[0]*255.0)+16;
-	in[1]=(in[1]*255.0)+128;
-	in[2]=(in[2]*255.0)+128;
+   /*un-normalize the normalize from above */
+   in[0]=(in[0]+1.0)/2.0;
+   in[1]=(in[1]+1.0)/2.0;
+   in[2]=(in[2]+1.0)/2.0;
+
+   in[0]=(in[0]*255.0);
+   in[1]=(in[1]*255.0);
+   in[2]=(in[2]*255.0);
+
+//	in[0]=(in[0]*255.0)+16;
+//	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];
 }
@@ -65,48 +83,42 @@
 static void do_chroma_key(bNode *node, float *out, float *in)
 {
 	NodeChroma *c;
-	float x, z, alpha;
-	float theta, beta, angle;
-	float kfg, newY, newCb, newCr;
+   float x, z, kx, kz, alpha;
+   float theta, beta, angle, angle2;
+   float kfg, newY, newCb, newCr;
 
 	c=node->storage;
 
-	/* Algorithm from book "Video Demistified" */
+   /* 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*/
-	theta=atan2(c->key[2],c->key[1]);
+   theta=atan2(c->key[2], c->key[1]);
 
 	/*rotate the cb and cr into x/z space */
-	x=in[1]*cos(theta)+in[2]*sin(theta);
-	z=in[2]*cos(theta)-in[1]*sin(theta);
+   x=in[1]*cos(theta)+in[2]*sin(theta);
+   z=in[2]*cos(theta)-in[1]*sin(theta);
 
-	/*if within the acceptance angle */
-	angle=c->t1*M_PI/180.0; /* convert to radians */
+   /*if within the acceptance angle */
+   angle=c->t1*M_PI/180.0; /* convert to radians */
 	
-	/* if kfg is <0 then the pixel is outside of the key color */
-	kfg=x-(fabs(z)/tan(angle/2.0));
+   /* if kfg is <0 then the pixel is outside of the key color */
+   kfg=x-(fabs(z)/tan(angle/2.0));
 
-	if(kfg>0.0) {  /* found a pixel that is within key color */
+   out[0]=in[0];
+   out[1]=in[1];
+   out[2]=in[2];
 
-		newY=in[0]-(1-c->t3)*kfg;
-		newCb=in[1]-kfg*cos((double)theta);
-		newCr=in[2]-kfg*sin((double)theta);
-		alpha=(kfg+c->fsize)*(c->fstrength);
+   if(kfg>0.0) {  /* found a pixel that is within key color */
+      alpha=(1.0-kfg)*(c->fstrength);
 
-		beta=atan2(newCr,newCb);
-		beta=beta*180.0/M_PI; /* convert to degrees for compare*/
+      beta=atan2(z,x);
+      angle2=c->t2*M_PI/180.0;
 
-		/* if beta is within the clippin angle */
-		if(fabs(beta)<(c->t2/2.0)) {
-			newCb=0.0;
-			newCr=0.0;
-			alpha=0.0;
-		}
+      /* if beta is within the cutoff angle */
+      if(fabs(beta)<(angle2/2.0)) {
+         alpha=0.0;
+      }
 
-		out[0]=newY;
-		out[1]=newCb;
-		out[2]=newCr;
-
 		/* don't make something that was more transparent less transparent */
 		if (alpha<in[3]) {
 			out[3]=alpha;

Modified: trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_sepcombHSVA.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_sepcombHSVA.c	2010-08-15 21:39:48 UTC (rev 31357)
+++ trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_sepcombHSVA.c	2010-08-15 22:08:49 UTC (rev 31358)
@@ -64,7 +64,7 @@
 	if(in[0]->data==NULL) {
 		float h, s, v;
 	
-		rgb_to_hsv(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &h, &s, &v);
+      rgb_to_hsv(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &h, &s, &v);
 		
 		out[0]->vec[0] = h;
 		out[1]->vec[0] = s;





More information about the Bf-blender-cvs mailing list