added method to change algorithm used in channel matte node. Limit a channel by...
authorRobert Holcomb <bob_holcomb@hotmail.com>
Sat, 13 Mar 2010 14:47:26 +0000 (14:47 +0000)
committerRobert Holcomb <bob_holcomb@hotmail.com>
Sat, 13 Mar 2010 14:47:26 +0000 (14:47 +0000)
source/blender/editors/space_node/drawnode.c
source/blender/makesdna/DNA_node_types.h
source/blender/makesrna/intern/rna_nodetree.c
source/blender/nodes/intern/CMP_nodes/CMP_channelMatte.c

index 16bf52d..9f7b01b 100644 (file)
@@ -853,13 +853,24 @@ static void node_composit_buts_channel_matte(uiLayout *layout, bContext *C, Poin
 {      
        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);
 }
index c178176..c587b21 100644 (file)
@@ -250,6 +250,7 @@ typedef struct NodeChroma {
        float t1,t2,t3;
        float fsize,fstrength,falpha;
        float key[4];
+   short algorithm, channel;
 } NodeChroma;
 
 typedef struct NodeTwoXYs {
index c8b78b3..ba805bd 100644 (file)
@@ -1425,6 +1425,11 @@ static void def_cmp_channel_matte(StructRNA *srna)
                {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 @@ static void def_cmp_channel_matte(StructRNA *srna)
        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");
index cda6cf0..72990ed 100644 (file)
@@ -66,30 +66,36 @@ static void do_normalized_ycca_to_rgba2(bNode *node, float *out, float *in)
 static void do_channel_matte(bNode *node, float *out, float *in)
 {
        NodeChroma *c=(NodeChroma *)node->storage;
-       float alpha=0.0;
-       
-       /* 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;
-       }
+       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;
+   }
        
        /*flip because 0.0 is transparent, not 1.0*/
        alpha=1-alpha;
@@ -120,6 +126,7 @@ static void node_composit_exec_channel_matte(void *data, bNode *node, bNodeStack
 {
        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 @@ static void node_composit_exec_channel_matte(void *data, bNode *node, bNodeStack
        
        /*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 @@ static void node_composit_init_channel_matte(bNode *node)
    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 */
 }