diff options
author | Robert Holcomb <bob_holcomb@hotmail.com> | 2010-03-12 21:47:35 +0300 |
---|---|---|
committer | Robert Holcomb <bob_holcomb@hotmail.com> | 2010-03-12 21:47:35 +0300 |
commit | 85066b5e05c0a770db357b67682431f357c05ad4 (patch) | |
tree | aeda4d3f4d2bc901df170afa1170d47bfa3d5d29 /source/blender/nodes/intern/CMP_nodes | |
parent | 0249d26ca790b9b5a44c83313b0d2afb42931f3f (diff) |
updated despill node to incorperate changes from Xavier Thomas's patch #18012
Diffstat (limited to 'source/blender/nodes/intern/CMP_nodes')
-rw-r--r-- | source/blender/nodes/intern/CMP_nodes/CMP_colorSpill.c | 180 |
1 files changed, 150 insertions, 30 deletions
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, |