[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27469] trunk/blender/source/blender: added method to change algorithm used in channel matte node.

Robert Holcomb bob_holcomb at hotmail.com
Sat Mar 13 15:47:26 CET 2010


Revision: 27469
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27469
Author:   scourage
Date:     2010-03-13 15:47:26 +0100 (Sat, 13 Mar 2010)

Log Message:
-----------
added method to change algorithm used in channel matte node.  Limit a channel by another channel or limit by max of remaining channels.  

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_channelMatte.c

Modified: trunk/blender/source/blender/editors/space_node/drawnode.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/drawnode.c	2010-03-13 11:22:39 UTC (rev 27468)
+++ trunk/blender/source/blender/editors/space_node/drawnode.c	2010-03-13 14:47:26 UTC (rev 27469)
@@ -853,13 +853,24 @@
 {	
 	uiLayout *col, *row;
 
+   uiItemL(layout, "Color Space:", 0);
 	row= uiLayoutRow(layout, 0);
 	uiItemR(row, NULL, 0, ptr, "color_space", UI_ITEM_R_EXPAND);
 
-	row= uiLayoutRow(layout, 0);
+   col=uiLayoutColumn(layout, 0);  
+   uiItemL(col, "Key Channel:", 0);
+	row= uiLayoutRow(col, 0);
 	uiItemR(row, NULL, 0, ptr, "channel", UI_ITEM_R_EXPAND);
 
-	col =uiLayoutColumn(layout, 1);
+	col =uiLayoutColumn(layout, 0);
+
+   uiItemR(col, NULL, 0, ptr, "algorithm", 0);
+   if(RNA_enum_get(ptr, "algorithm")==0) {
+      uiItemL(col, "Limiting Channel:", 0);
+      row=uiLayoutRow(col,0);
+      uiItemR(row, NULL, 0, ptr, "limit_channel", UI_ITEM_R_EXPAND);
+   }
+   
 	uiItemR(col, NULL, 0, ptr, "high", UI_ITEM_R_SLIDER);
 	uiItemR(col, NULL, 0, ptr, "low", UI_ITEM_R_SLIDER);
 }

Modified: trunk/blender/source/blender/makesdna/DNA_node_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_node_types.h	2010-03-13 11:22:39 UTC (rev 27468)
+++ trunk/blender/source/blender/makesdna/DNA_node_types.h	2010-03-13 14:47:26 UTC (rev 27469)
@@ -250,6 +250,7 @@
 	float t1,t2,t3;
 	float fsize,fstrength,falpha;
 	float key[4];
+   short algorithm, channel;
 } NodeChroma;
 
 typedef struct NodeTwoXYs {

Modified: trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2010-03-13 11:22:39 UTC (rev 27468)
+++ trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2010-03-13 14:47:26 UTC (rev 27469)
@@ -1425,6 +1425,11 @@
 		{CMP_NODE_CHANNEL_MATTE_CS_YUV, "YUV", 0, "YUV",   "YUV Color Space"},
 		{CMP_NODE_CHANNEL_MATTE_CS_YCC, "YCC", 0, "YCbCr", "YCbCr Color Space"},
 		{0, NULL, 0, NULL, NULL}};
+
+	static EnumPropertyItem algorithm_items[] = {
+		{0, "SINGLE", 0, "Single", "Limit by single channel"},
+		{1, "MAX", 0, "Max", "Limit by max of other channels "},
+		{0, NULL, 0, NULL, NULL}};
 	
 	prop = RNA_def_property(srna, "color_space", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_sdna(prop, NULL, "custom1");
@@ -1432,15 +1437,27 @@
 	RNA_def_property_ui_text(prop, "Color Space", "");
 	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 	
-	
 	prop= RNA_def_property(srna, "channel", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_sdna(prop, NULL, "custom2");
 	RNA_def_property_enum_items(prop, prop_tri_channel_items);
 	RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Node_channel_itemf");
 	RNA_def_property_ui_text(prop, "Channel", "Channel used to determine matte");
 	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
-	
+
 	RNA_def_struct_sdna_from(srna, "NodeChroma", "storage");
+
+	prop = RNA_def_property(srna, "algorithm", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "algorithm");
+	RNA_def_property_enum_items(prop, algorithm_items);
+	RNA_def_property_ui_text(prop, "Algorithm", "Algorithm to use to limit channel");
+	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
+
+	prop = RNA_def_property(srna, "limit_channel", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "channel");
+   RNA_def_property_enum_items(prop, prop_tri_channel_items);
+   RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Node_channel_itemf");
+	RNA_def_property_ui_text(prop, "Limit Channel", "Limit by this channels value");
+	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 	
 	prop = RNA_def_property(srna, "high", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_float_sdna(prop, NULL, "t1");

Modified: trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_channelMatte.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_channelMatte.c	2010-03-13 11:22:39 UTC (rev 27468)
+++ trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_channelMatte.c	2010-03-13 14:47:26 UTC (rev 27469)
@@ -66,31 +66,37 @@
 static void do_channel_matte(bNode *node, float *out, float *in)
 {
 	NodeChroma *c=(NodeChroma *)node->storage;
-	float alpha=0.0;
+	float alpha=0.0;	
+
+	switch(c->algorithm) {
+      case 0: { /* Alpha=key_channel-limit channel */
+         int key_channel=node->custom2-1;
+         int limit_channel=c->channel-1;
+         alpha=in[key_channel]-in[limit_channel];
+         break;
+      }
+      case 1: {  	/* Alpha=G-MAX(R, B) */
+         switch(node->custom2) {
+            case 1: {
+		            alpha=in[0]-MAX2(in[1],in[2]);
+		            break;
+	         }
+            case 2: {
+		            alpha=in[1]-MAX2(in[0],in[2]);
+		            break;
+	         }
+            case 3: {
+		            alpha=in[2]-MAX2(in[0],in[1]);
+		            break;
+	         }
+            default:
+	            break;
+         }
+      }
+      default:
+         break;
+   }
 	
-	/* Alpha=G-MAX(R, B) */
-	
-	switch(node->custom2)
-	{
-	case 1:
-		{
-			alpha=in[0]-MAX2(in[1],in[2]);
-			break;
-		}
-	case 2:
-		{
-			alpha=in[1]-MAX2(in[0],in[2]);
-			break;
-		}
-	case 3:
-		{
-			alpha=in[2]-MAX2(in[0],in[1]);
-			break;
-		}
-	default:
-		break;
-	}
-	
 	/*flip because 0.0 is transparent, not 1.0*/
 	alpha=1-alpha;
 	
@@ -120,6 +126,7 @@
 {
 	CompBuf *cbuf;
 	CompBuf *outbuf;
+   NodeChroma *c=(NodeChroma *)node->storage;
 	
 	if(in[0]->hasinput==0)  return;
 	if(in[0]->data==NULL) return;
@@ -131,24 +138,24 @@
 	
 	/*convert to colorspace*/
 	switch(node->custom1) {
-	case CMP_NODE_CHANNEL_MATTE_CS_RGB:
-		break;
-	case CMP_NODE_CHANNEL_MATTE_CS_HSV: /*HSV*/
-		composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_hsva, CB_RGBA);
-		break;
-	case CMP_NODE_CHANNEL_MATTE_CS_YUV: /*YUV*/
-		composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_yuva, CB_RGBA);
-		break;
-	case CMP_NODE_CHANNEL_MATTE_CS_YCC: /*YCC*/
-		composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_normalized_rgba_to_ycca2, CB_RGBA);
-		break;
-	default:
-		break;
+	   case CMP_NODE_CHANNEL_MATTE_CS_RGB:
+		   break;
+	   case CMP_NODE_CHANNEL_MATTE_CS_HSV: /*HSV*/
+		   composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_hsva, CB_RGBA);
+		   break;
+	   case CMP_NODE_CHANNEL_MATTE_CS_YUV: /*YUV*/
+		   composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_yuva, CB_RGBA);
+		   break;
+	   case CMP_NODE_CHANNEL_MATTE_CS_YCC: /*YCC*/
+		   composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_normalized_rgba_to_ycca2, CB_RGBA);
+		   break;
+	   default:
+		   break;
 	}
 
 	/*use the selected channel information to do the key */
 	composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_channel_matte, CB_RGBA);
-
+   
 	/*convert back to RGB colorspace in place*/
 	switch(node->custom1) {
 	case CMP_NODE_CHANNEL_MATTE_CS_RGB: /*RGB*/
@@ -185,6 +192,8 @@
    c->t3= 0.0f;
    c->fsize= 0.0f;
    c->fstrength= 0.0f;
+   c->algorithm=1; /*max channel limiting */
+   c->channel=1; /* limit by red */
    node->custom1= 1; /* RGB channel */
    node->custom2= 2; /* Green Channel */
 }





More information about the Bf-blender-cvs mailing list