From 85066b5e05c0a770db357b67682431f357c05ad4 Mon Sep 17 00:00:00 2001 From: Robert Holcomb Date: Fri, 12 Mar 2010 18:47:35 +0000 Subject: updated despill node to incorperate changes from Xavier Thomas's patch #18012 --- source/blender/editors/space_node/drawnode.c | 22 ++- source/blender/makesdna/DNA_node_types.h | 8 +- source/blender/makesrna/intern/rna_nodetree.c | 62 ++++++- .../nodes/intern/CMP_nodes/CMP_colorSpill.c | 180 +++++++++++++++++---- 4 files changed, 230 insertions(+), 42 deletions(-) diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index a110e7a5c4b..16bf52db80f 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -803,10 +803,26 @@ static void node_composit_buts_color_spill(uiLayout *layout, bContext *C, Pointe { uiLayout *row, *col; - col =uiLayoutColumn(layout, 0); - uiItemR(col, NULL, 0, ptr, "factor", 0); - row= uiLayoutRow(col, 0); + uiItemL(layout, "Despill Channel:", 0); + row =uiLayoutRow(layout,0); uiItemR(row, NULL, 0, ptr, "channel", UI_ITEM_R_EXPAND); + + 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, "ratio", UI_ITEM_R_SLIDER); + uiItemR(col, NULL, 0, ptr, "unspill", 0); + if (RNA_enum_get(ptr, "unspill")== 1) { + uiItemR(col, NULL, 0, ptr, "unspill_red", UI_ITEM_R_SLIDER); + uiItemR(col, NULL, 0, ptr, "unspill_green", UI_ITEM_R_SLIDER); + uiItemR(col, NULL, 0, ptr, "unspill_blue", UI_ITEM_R_SLIDER); + } } static void node_composit_buts_chroma_matte(uiLayout *layout, bContext *C, PointerRNA *ptr) diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 4dd089949e9..c178176048a 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -22,7 +22,7 @@ * * The Original Code is: all of this file. * - * Contributor(s): none yet. + * Contributor(s): Bob Holcomb, Xavier Thomas * * ***** END GPL LICENSE BLOCK ***** */ @@ -312,6 +312,12 @@ typedef struct NodeColorBalance { float gain[3]; } NodeColorBalance; +typedef struct NodeColorspill { + short limchan, unspill; + float limscale; + float uspillr, uspillg, uspillb; +}NodeColorspill; + /* TEX_output */ typedef struct TexNodeOutput { char name[32]; diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index d8c5c796fa3..c8b78b38b9a 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributor(s): Blender Foundation (2008), Nathan Letwory, Robin Allen + * Contributor(s): Blender Foundation (2008), Nathan Letwory, Robin Allen, Bob Holcomb * * ***** END GPL LICENSE BLOCK ***** */ @@ -1287,12 +1287,23 @@ static void def_cmp_distance_matte(StructRNA *srna) static void def_cmp_color_spill(StructRNA *srna) { PropertyRNA *prop; - + static EnumPropertyItem channel_items[] = { {1, "R", 0, "R", "Red Spill Suppression"}, {2, "G", 0, "G", "Green Spill Suppression"}, {3, "B", 0, "B", "Blue Spill Suppression"}, {0, NULL, 0, NULL, NULL}}; + + static EnumPropertyItem limit_channel_items[] = { + {1, "R", 0, "R", "Limit by Red"}, + {2, "G", 0, "G", "Limit by Green"}, + {3, "B", 0, "B", "Limit by Blue"}, + {0, NULL, 0, NULL, NULL}}; + + static EnumPropertyItem algorithm_items[] = { + {0, "SIMPLE", 0, "Simple", "Simple Limit Algorithm"}, + {1, "AVERAGE", 0, "Average", "Average Limit Algorithm"}, + {0, NULL, 0, NULL, NULL}}; prop = RNA_def_property(srna, "channel", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "custom1"); @@ -1300,12 +1311,47 @@ static void def_cmp_color_spill(StructRNA *srna) RNA_def_property_ui_text(prop, "Channel", ""); 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, "factor", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "t1"); - RNA_def_property_range(prop, 0.0f, 0.5f); - RNA_def_property_ui_text(prop, "Amount", "How much the selected channel is affected by"); + prop = RNA_def_property(srna, "algorithm", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "custom2"); + RNA_def_property_enum_items(prop, algorithm_items); + RNA_def_property_ui_text(prop, "Algorithm", ""); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + + RNA_def_struct_sdna_from(srna, "NodeColorspill", "storage"); + + prop = RNA_def_property(srna, "limit_channel", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "limchan"); + RNA_def_property_enum_items(prop, limit_channel_items); + RNA_def_property_ui_text(prop, "Limit Channel", ""); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "ratio", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "limscale"); + RNA_def_property_range(prop, 0.5f, 1.5f); + RNA_def_property_ui_text(prop, "Ratio", "Scale limit by value"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "unspill", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "unspill", 0); + RNA_def_property_ui_text(prop, "Unspill", "Compensate all channels (diffenrently) by hand"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "unspill_red", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "uspillr"); + RNA_def_property_range(prop, 0.0f, 1.5f); + RNA_def_property_ui_text(prop, "R", "Red spillmap scale"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "unspill_green", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "uspillg"); + RNA_def_property_range(prop, 0.0f, 1.5f); + RNA_def_property_ui_text(prop, "G", "Green spillmap scale"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "unspill_blue", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "uspillb"); + RNA_def_property_range(prop, 0.0f, 1.5f); + RNA_def_property_ui_text(prop, "B", "Blue spillmap scale"); RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_colorSpill.c b/source/blender/nodes/intern/CMP_nodes/CMP_colorSpill.c index 5fcbcd0b854..23a5b719e5b 100644 --- a/source/blender/nodes/intern/CMP_nodes/CMP_colorSpill.c +++ b/source/blender/nodes/intern/CMP_nodes/CMP_colorSpill.c @@ -22,7 +22,7 @@ * * The Original Code is: all of this file. * - * Contributor(s): none yet. + * Contributor(s): Bob Holcomb, Xavier Thomas * * ***** END GPL LICENSE BLOCK ***** */ @@ -30,6 +30,7 @@ #include "../CMP_util.h" +#define avg(a,b) ((a+b)/2) /* ******************* Color Spill Supression ********************************* */ static bNodeSocketType cmp_node_color_spill_in[]={ @@ -42,33 +43,93 @@ static bNodeSocketType cmp_node_color_spill_out[]={ {-1,0,""} }; -static void do_reduce_red(bNode *node, float* out, float *in) +static void do_simple_spillmap_red(bNode *node, float* out, float *in) { - NodeChroma *c; - c=node->storage; - - if(in[0] > in[1] && in[0] > in[2]) { - out[0]=((in[1]+in[2])/2)*(1-c->t1); + NodeColorspill *ncs; + ncs=node->storage; + out[0]=in[0]-( ncs->limscale * in[ncs->limchan] ); +} + +static void do_simple_spillmap_green(bNode *node, float* out, float *in) +{ + NodeColorspill *ncs; + ncs=node->storage; + out[0]=in[1]-( ncs->limscale * in[ncs->limchan] ); +} + +static void do_simple_spillmap_blue(bNode *node, float* out, float *in) +{ + NodeColorspill *ncs; + ncs=node->storage; + out[0]=in[2]-( ncs->limscale * in[ncs->limchan] ); +} + +static void do_average_spillmap_red(bNode *node, float* out, float *in) +{ + NodeColorspill *ncs; + ncs=node->storage; + out[0]=in[0]-(ncs->limscale * avg(in[1], in[2]) ); +} + +static void do_average_spillmap_green(bNode *node, float* out, float *in) +{ + NodeColorspill *ncs; + ncs=node->storage; + out[0]=in[1]-(ncs->limscale * avg(in[0], in[2]) ); +} + +static void do_average_spillmap_blue(bNode *node, float* out, float *in) +{ + NodeColorspill *ncs; + ncs=node->storage; + out[0]=in[2]-(ncs->limscale * avg(in[0], in[1]) ); +} + +static void do_apply_spillmap_red(bNode *node, float* out, float *in, float *map) +{ + NodeColorspill *ncs; + ncs=node->storage; + if(map[0]>0) { + out[0]=in[0]-(ncs->uspillr*map[0]); + out[1]=in[1]+(ncs->uspillg*map[0]); + out[2]=in[2]+(ncs->uspillb*map[0]); + } + else { + out[0]=in[0]; + out[1]=in[1]; + out[2]=in[2]; } } -static void do_reduce_green(bNode *node, float* out, float *in) +static void do_apply_spillmap_green(bNode *node, float* out, float *in, float *map) { - NodeChroma *c; - c=node->storage; - - if(in[1] > in[0] && in[1] > in[2]) { - out[1]=((in[0]+in[2])/2)*(1-c->t1); + NodeColorspill *ncs; + ncs=node->storage; + if(map[0]>0) { + out[0]=in[0]+(ncs->uspillr*map[0]); + out[1]=in[1]-(ncs->uspillg*map[0]); + out[2]=in[2]+(ncs->uspillb*map[0]); + } + else { + out[0]=in[0]; + out[1]=in[1]; + out[2]=in[2]; } } -static void do_reduce_blue(bNode *node, float* out, float *in) +static void do_apply_spillmap_blue(bNode *node, float* out, float *in, float *map) { - NodeChroma *c; - c=node->storage; - - if(in[2] > in[1] && in[2] > in[1]) { - out[2]=((in[1]+in[0])/2)*(1-c->t1); + NodeColorspill *ncs; + ncs=node->storage; + if(map[0]>0) { + out[0]=in[0]+(ncs->uspillr*map[0]); + out[1]=in[1]+(ncs->uspillg*map[0]); + out[2]=in[2]-(ncs->uspillb*map[0]); + } + else { + out[0]=in[0]; + out[1]=in[1]; + out[2]=in[2]; } } @@ -79,28 +140,86 @@ static void node_composit_exec_color_spill(void *data, bNode *node, bNodeStack * discussions from vfxtalk.com.*/ CompBuf *cbuf; CompBuf *rgbbuf; + CompBuf *spillmap; + NodeColorspill *ncs; + ncs=node->storage; if(out[0]->hasoutput==0 || in[0]->hasinput==0) return; if(in[0]->data==NULL) return; cbuf=typecheck_compbuf(in[0]->data, CB_RGBA); + spillmap=alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); rgbbuf=dupalloc_compbuf(cbuf); switch(node->custom1) { case 1: /*red spill*/ { - composit1_pixel_processor(node, rgbbuf, cbuf, in[1]->vec, do_reduce_red, CB_RGBA); + switch(node->custom2) + { + case 0: /* simple limit */ + { + composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_red, CB_RGBA); + break; + } + case 1: /* average limit */ + { + composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_red, CB_RGBA); + break; + } + } + if(ncs->unspill==0) { + ncs->uspillr=1.0f; + ncs->uspillg=0.0f; + ncs->uspillb=0.0f; + } + composit2_pixel_processor(node, rgbbuf, cbuf, in[0]->vec, spillmap, NULL, do_apply_spillmap_red, CB_RGBA, CB_VAL); break; } case 2: /*green spill*/ { - composit1_pixel_processor(node, rgbbuf, cbuf, in[1]->vec, do_reduce_green, CB_RGBA); + switch(node->custom2) + { + case 0: /* simple limit */ + { + composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_green, CB_RGBA); + break; + } + case 1: /* average limit */ + { + composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_green, CB_RGBA); + break; + } + } + if(ncs->unspill==0) { + ncs->uspillr=0.0f; + ncs->uspillg=1.0f; + ncs->uspillb=0.0f; + } + composit2_pixel_processor(node, rgbbuf, cbuf, in[0]->vec, spillmap, NULL, do_apply_spillmap_green, CB_RGBA, CB_VAL); break; } case 3: /*blue spill*/ { - composit1_pixel_processor(node, rgbbuf, cbuf, in[1]->vec, do_reduce_blue, CB_RGBA); + switch(node->custom2) + { + case 0: /* simple limit */ + { + composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_blue, CB_RGBA); + break; + } + case 1: /* average limit */ + { + composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_blue, CB_RGBA); + break; + } + } + if(ncs->unspill==0) { + ncs->uspillr=0.0f; + ncs->uspillg=0.0f; + ncs->uspillb=1.0f; + } + composit2_pixel_processor(node, rgbbuf, cbuf, in[0]->vec, spillmap, NULL, do_apply_spillmap_blue, CB_RGBA, CB_VAL); break; } default: @@ -111,18 +230,19 @@ static void node_composit_exec_color_spill(void *data, bNode *node, bNodeStack * if(cbuf!=in[0]->data) free_compbuf(cbuf); + + free_compbuf(spillmap); } static void node_composit_init_color_spill(bNode *node) { - NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma"); - node->storage=c; - c->t1= 0.0f; - c->t2= 0.0f; - c->t3= 0.0f; - c->fsize= 0.0f; - c->fstrength= 0.0f; + NodeColorspill *ncs= MEM_callocN(sizeof(NodeColorspill), "node colorspill"); + node->storage=ncs; node->custom1= 2; /* green channel */ + node->custom2= 0; /* simple limit algo*/ + ncs->limchan= 0; /* limit by red */ + ncs->limscale= 1.0f; /* limit scaling factor */ + ncs->unspill=0; /* do not use unspill */ } bNodeType cmp_node_color_spill={ @@ -133,7 +253,7 @@ bNodeType cmp_node_color_spill={ /* class+opts */ NODE_CLASS_MATTE, NODE_OPTIONS, /* input sock */ cmp_node_color_spill_in, /* output sock */ cmp_node_color_spill_out, - /* storage */ "NodeChroma", + /* storage */ "NodeColorspill", /* execfunc */ node_composit_exec_color_spill, /* butfunc */ NULL, /* initfunc */ node_composit_init_color_spill, -- cgit v1.2.3