diff -Naurb blender2.42/source/blender/blenkernel/BKE_node.h blender-work/source/blender/blenkernel/BKE_node.h --- blender2.42/source/blender/blenkernel/BKE_node.h 2006-07-03 05:49:12.000000000 -0400 +++ blender-work/source/blender/blenkernel/BKE_node.h 2006-07-19 10:12:46.000000000 -0400 @@ -1,34 +1,34 @@ /** - * $Id: BKE_node.h,v 1.15 2006/07/03 09:49:12 ton Exp $ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. The Blender - * Foundation also sells licenses for use in proprietary software under - * the Blender License. See http://www.blender.org/BL/ for information - * about this. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ +* $Id: BKE_node.h,v 1.15 2006/07/03 09:49:12 ton Exp $ +* +* ***** BEGIN GPL LICENSE BLOCK ***** +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. The Blender +* Foundation also sells licenses for use in proprietary software under +* the Blender License. See http://www.blender.org/BL/ for information +* about this. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +* The Original Code is Copyright (C) 2005 Blender Foundation. +* All rights reserved. +* +* The Original Code is: all of this file. +* +* Contributor(s): none yet. +* +* ***** END GPL LICENSE BLOCK ***** +*/ #ifndef BKE_NODE_H #define BKE_NODE_H @@ -88,6 +88,7 @@ #define NODE_CLASS_GROUP 6 #define NODE_CLASS_FILE 7 #define NODE_CLASS_CONVERTOR 8 +#define NODE_CLASS_MATTE 9 /* ************** GENERIC API, TREES *************** */ @@ -192,7 +193,7 @@ int ntreeShaderGetTexco(struct bNodeTree *ntree, int osa); void nodeShaderSynchronizeID(struct bNode *node, int copyto); - /* switch material render loop */ +/* switch material render loop */ void set_node_shader_lamp_loop(void (*lamp_loop_func)(struct ShadeInput *, struct ShadeResult *)); /* ************** COMPOSITE NODES *************** */ @@ -224,6 +225,15 @@ #define CMP_NODE_TEXTURE 224 #define CMP_NODE_TRANSLATE 225 #define CMP_NODE_ZCOMBINE 226 +#define CMP_NODE_SEPYCCA 227 +#define CMP_NODE_SEPYUVA 228 +#define CMP_NODE_YUV_MATTE 229 +#define CMP_NODE_DIFF_MATTE 230 +#define CMP_NODE_CHROMA_MATTE 231 +#define CMP_NODE_COLOR_SPILL 232 +#define CMP_NODE_COMBRGBA 233 +#define CMP_NODE_DILATE_ERODE 234 + /* filter types */ diff -Naurb blender2.42/source/blender/blenkernel/intern/node.c blender-work/source/blender/blenkernel/intern/node.c --- blender2.42/source/blender/blenkernel/intern/node.c 2006-07-09 07:54:41.000000000 -0400 +++ blender-work/source/blender/blenkernel/intern/node.c 2006-07-19 10:10:48.000000000 -0400 @@ -1,31 +1,31 @@ /** - * $Id: node.c,v 1.40 2006/07/09 11:54:41 ton Exp $ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ +* $Id: node.c,v 1.40 2006/07/09 11:54:41 ton Exp $ +* +* ***** BEGIN GPL LICENSE BLOCK ***** +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +* The Original Code is Copyright (C) 2005 Blender Foundation. +* All rights reserved. +* +* The Original Code is: all of this file. +* +* Contributor(s): none yet. +* +* ***** END GPL LICENSE BLOCK ***** +*/ #include #include @@ -233,7 +233,7 @@ /* input sock */ NULL, /* output sock */ NULL, /* storage */ "", - /* execfunc */ NULL, + /* execfunc */ NULL }; @@ -795,6 +795,35 @@ node->storage= nhs; nhs->hue= 0.5f; nhs->sat= 1.0f; + nhs->val= 1.0f; + } + else if(type==CMP_NODE_YUV_MATTE){ + NodeChroma *c=MEM_callocN(sizeof(NodeChroma), "node chroma"); + node->storage=c; + c->rt=0.01f; + c->bt=0.01f; + c->gt=0.01f; + } + else if(type==CMP_NODE_DIFF_MATTE){ + NodeChroma *c=MEM_callocN(sizeof(NodeChroma), "node chroma"); + node->storage=c; + c->rt=0.01f; + c->bt=0.01f; + c->gt=0.01f; + } + else if(type==CMP_NODE_CHROMA_MATTE){ + NodeChroma *c=MEM_callocN(sizeof(NodeChroma), "node chroma"); + node->storage=c; + c->rt=0.00f; + c->bt=0.00f; + c->gt=0.00f; + } + else if(type==CMP_NODE_COLOR_SPILL){ + NodeChroma *c=MEM_callocN(sizeof(NodeChroma), "node chroma"); + node->storage=c; + c->rt=0.00f; + c->bt=0.00f; + c->gt=0.00f; } } @@ -1278,7 +1307,7 @@ } /* use flags are not persistant yet, groups might need different tagging, so we do it each time - when we need to get this info */ +when we need to get this info */ void ntreeSocketUseFlags(bNodeTree *ntree) { bNode *node; @@ -1321,7 +1350,7 @@ } } } -// printf("node sort %s level %d\n", node->name, level); + // printf("node sort %s level %d\n", node->name, level); **nsort= node; (*nsort)++; @@ -1449,7 +1478,7 @@ if(node->preview==NULL) { node->preview= MEM_callocN(sizeof(bNodePreview), "node preview"); -// printf("added preview %s\n", node->name); + // printf("added preview %s\n", node->name); } /* node previews can get added with variable size this way */ @@ -1509,8 +1538,8 @@ } /* hack warning! this function is only used for shader previews, and - since it gets called multiple times per pixel for Ztransp we only - add the color once. Preview gets cleared before it starts render though */ +since it gets called multiple times per pixel for Ztransp we only +add the color once. Preview gets cleared before it starts render though */ void nodeAddToPreview(bNode *node, float *col, int x, int y) { bNodePreview *preview= node->preview; @@ -1606,7 +1635,7 @@ /* recursively called for groups */ /* we set all trees on own local indices, but put a total counter - in the groups, so each instance of a group has own stack */ +in the groups, so each instance of a group has own stack */ static int ntree_begin_exec_tree(bNodeTree *ntree) { bNode *node; diff -Naurb blender2.42/source/blender/blenkernel/intern/node_composite.c blender-work/source/blender/blenkernel/intern/node_composite.c --- blender2.42/source/blender/blenkernel/intern/node_composite.c 2006-07-03 11:25:11.000000000 -0400 +++ blender-work/source/blender/blenkernel/intern/node_composite.c 2006-07-21 17:05:31.000000000 -0400 @@ -1,31 +1,31 @@ /** - * $Id: node_composite.c,v 1.51 2006/07/03 15:25:11 ton Exp $ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ +* $Id: node_composite.c,v 1.51 2006/07/03 15:25:11 ton Exp $ +* +* ***** BEGIN GPL LICENSE BLOCK ***** +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +* The Original Code is Copyright (C) 2006 Blender Foundation. +* All rights reserved. +* +* The Original Code is: all of this file. +* +* Contributor(s): none yet. +* +* ***** END GPL LICENSE BLOCK ***** +*/ #include #include @@ -473,7 +473,7 @@ /* ******************************************************** */ /* SocketType syntax: - socket type, max connections (0 is no limit), name, 4 values for default, 2 values for range */ +socket type, max connections (0 is no limit), name, 4 values for default, 2 values for range */ /* Verification rule: If name changes, a saved socket and its links will be removed! Type changes are OK */ @@ -926,12 +926,12 @@ { SOCK_VALUE, 0, "Z", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, { SOCK_VECTOR, 0, "Normal", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, { SOCK_VECTOR, 0, "Speed", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, -// { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, -// { SOCK_RGBA, 0, "Diffuse", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, -// { SOCK_RGBA, 0, "Specular", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, -// { SOCK_RGBA, 0, "Shadow", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, -// { SOCK_RGBA, 0, "AO", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, -// { SOCK_RGBA, 0, "Ray", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + // { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + // { SOCK_RGBA, 0, "Diffuse", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + // { SOCK_RGBA, 0, "Specular", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + // { SOCK_RGBA, 0, "Shadow", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + // { SOCK_RGBA, 0, "AO", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + // { SOCK_RGBA, 0, "Ray", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, { -1, 0, "" } }; @@ -1393,7 +1393,7 @@ { NodeHueSat *nhs= node->storage; - if(*fac!=0.0f && (nhs->hue!=0.5f || nhs->sat!=1.0)) { + if(*fac!=0.0f && (nhs->hue!=0.5f || nhs->sat!=1.0 || nhs->val!=1.0)) { float col[3], hsv[3], mfac= 1.0f - *fac; rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2); @@ -1401,6 +1401,8 @@ if(hsv[0]>1.0) hsv[0]-=1.0; else if(hsv[0]<0.0) hsv[0]+= 1.0; hsv[1]*= nhs->sat; if(hsv[1]>1.0) hsv[1]= 1.0; else if(hsv[1]<0.0) hsv[1]= 0.0; + hsv[2]*= nhs->val; + if(hsv[2]>1.0) hsv[2]= 1.0; else if(hsv[2]<0.0) hsv[2]= 0.0; hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2); out[0]= mfac*in[0] + *fac*col[0]; @@ -1436,7 +1438,7 @@ static bNodeType cmp_node_hue_sat= { /* type code */ CMP_NODE_HUE_SAT, - /* name */ "Hue Saturation", + /* name */ "Hue Saturation Value", /* width+range */ 150, 80, 250, /* class+opts */ NODE_CLASS_OP_COLOR, NODE_OPTIONS, /* input sock */ cmp_node_hue_sat_in, @@ -1849,6 +1851,72 @@ }; +/* **************** COMBINE RGBA ******************** */ +static bNodeSocketType cmp_node_combrgba_in[]= { + { SOCK_VALUE, 1, "R", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_VALUE, 1, "G", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_VALUE, 1, "B", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_VALUE, 1, "A", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; +static bNodeSocketType cmp_node_combrgba_out[]= { + { SOCK_RGBA, 0, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; + +static void do_combrgba(bNode *node, float *out, float *in1, float *in2, float *in3, float *in4) +{ + out[0] = in1[0]; + out[1] = in2[0]; + out[2] = in3[0]; + out[3] = in4[0]; +} + +static void node_composit_exec_combrgba(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +{ + /* stack order out: 1 rgba channels */ + /* stack order in: 4 value channels */ + + /* input no image? then only color operation */ + if((in[0]->data==NULL) && (in[1]->data==NULL) && (in[2]->data==NULL) && (in[3]->data==NULL)) { + out[0]->vec[0] = in[0]->vec[0]; + out[0]->vec[1] = in[1]->vec[0]; + out[0]->vec[2] = in[2]->vec[0]; + out[0]->vec[3] = in[3]->vec[0]; + } + else { + /* make output size of first available input image */ + CompBuf *cbuf; + CompBuf *stackbuf; + + if (in[0]->data) cbuf = in[0]->data; + else if (in[1]->data) cbuf = in[1]->data; + else if (in[2]->data) cbuf = in[2]->data; + else if (in[3]->data) cbuf = in[3]->data; + + stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); // allocs + + composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, + in[2]->data, in[2]->vec, in[3]->data, in[3]->vec, + do_combrgba, CB_VAL, CB_VAL, CB_VAL, CB_VAL); + + out[0]->data= stackbuf; + } +} + +static bNodeType cmp_node_combrgba= { + /* type code */ CMP_NODE_COMBRGBA, + /* name */ "Combine RGBA", + /* width+range */ 80, 40, 140, + /* class+opts */ NODE_CLASS_CONVERTOR, NODE_OPTIONS, + /* input sock */ cmp_node_combrgba_in, + /* output sock */ cmp_node_combrgba_out, + /* storage */ "", + /* execfunc */ node_composit_exec_combrgba + +}; + + /* **************** SEPARATE HSVA ******************** */ static bNodeSocketType cmp_node_sephsva_in[]= { { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, @@ -1925,6 +1993,162 @@ }; + +/* **************** SEPARATE YUVA ******************** */ +static bNodeSocketType cmp_node_sepyuva_in[]= { + { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; +static bNodeSocketType cmp_node_sepyuva_out[]= { + { SOCK_VALUE, 0, "Y", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_VALUE, 0, "U", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_VALUE, 0, "V", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_VALUE, 0, "A", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; + +static void do_sepyuva(bNode *node, float *out, float *in) +{ + float y, u, v; + + rgb_to_yuv(in[0], in[1], in[2], &y, &u, &v); + + out[0]= y; + out[1]= u; + out[2]= v; + out[3]= in[3]; +} + +static void node_composit_exec_sepyuva(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +{ + /* stack order out: bw channels */ + /* stack order in: col */ + + /* input no image? then only color operation */ + if(in[0]->data==NULL) { + float y, u, v; + + rgb_to_yuv(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &u, &v); + + out[0]->vec[0] = y; + out[1]->vec[0] = u; + out[2]->vec[0] = v; + out[3]->vec[0] = in[0]->vec[3]; + } + else if ((out[0]->hasoutput) || (out[1]->hasoutput) || (out[2]->hasoutput) || (out[3]->hasoutput)) { + /* make output size of input image */ + CompBuf *cbuf= in[0]->data; + + CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); // allocs + + /* convert the RGB stackbuf to an HSV representation */ + composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_sepyuva, CB_RGBA); + + /* separate each of those channels */ + if(out[0]->hasoutput) + out[0]->data= valbuf_from_rgbabuf(stackbuf, CHAN_R); + if(out[1]->hasoutput) + out[1]->data= valbuf_from_rgbabuf(stackbuf, CHAN_G); + if(out[2]->hasoutput) + out[2]->data= valbuf_from_rgbabuf(stackbuf, CHAN_B); + if(out[3]->hasoutput) + out[3]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A); + + free_compbuf(stackbuf); + } +} + +static bNodeType cmp_node_sepyuva= { + /* type code */ CMP_NODE_SEPYUVA, + /* name */ "Separate YUVA", + /* width+range */ 80, 40, 140, + /* class+opts */ NODE_CLASS_CONVERTOR, 0, + /* input sock */ cmp_node_sepyuva_in, + /* output sock */ cmp_node_sepyuva_out, + /* storage */ "", + /* execfunc */ node_composit_exec_sepyuva + +}; + +/* **************** SEPARATE YCCA ******************** */ +static bNodeSocketType cmp_node_sepycca_in[]= { + { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; +static bNodeSocketType cmp_node_sepycca_out[]= { + { SOCK_VALUE, 0, "Y", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_VALUE, 0, "Cb", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_VALUE, 0, "Cr", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_VALUE, 0, "A", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; + +static void do_sepycca(bNode *node, float *out, float *in) +{ + float y, cb, cr; + + rgb_to_ycc(in[0], in[1], in[2], &y, &cb, &cr); + + //divided by 255 to normalize for viewing in + out[0]= y/255.0; + out[1]= cb/255.0; + out[2]= cr/255.0; + out[3]= in[3]; +} + +static void node_composit_exec_sepycca(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +{ + /* stack order out: bw channels */ + /* stack order in: col */ + + /* input no image? then only color operation */ + if(in[0]->data==NULL) { + float y, cb, cr; + + rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr); + + //divided by 255 to normalize for viewing in + out[0]->vec[0] = y/255.0; + out[1]->vec[0] = cb/255.0; + out[2]->vec[0] = cr/255.0; + out[3]->vec[0] = in[0]->vec[3]; + } + else if ((out[0]->hasoutput) || (out[1]->hasoutput) || (out[2]->hasoutput) || (out[3]->hasoutput)) { + /* make output size of input image */ + CompBuf *cbuf= in[0]->data; + + CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); // allocs + + /* convert the RGB stackbuf to an HSV representation */ + composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_sepycca, CB_RGBA); + + /* separate each of those channels */ + if(out[0]->hasoutput) + out[0]->data= valbuf_from_rgbabuf(stackbuf, CHAN_R); + if(out[1]->hasoutput) + out[1]->data= valbuf_from_rgbabuf(stackbuf, CHAN_G); + if(out[2]->hasoutput) + out[2]->data= valbuf_from_rgbabuf(stackbuf, CHAN_B); + if(out[3]->hasoutput) + out[3]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A); + + free_compbuf(stackbuf); + } +} + +static bNodeType cmp_node_sepycca= { + /* type code */ CMP_NODE_SEPYCCA, + /* name */ "Separate YCbCrA", + /* width+range */ 80, 40, 140, + /* class+opts */ NODE_CLASS_CONVERTOR, 0, + /* input sock */ cmp_node_sepycca_in, + /* output sock */ cmp_node_sepycca_out, + /* storage */ "", + /* execfunc */ node_composit_exec_sepycca + +}; + + /* **************** SET ALPHA ******************** */ static bNodeSocketType cmp_node_setalpha_in[]= { { SOCK_RGBA, 1, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, @@ -2378,7 +2602,7 @@ maintabs[i]= make_bloomtab(i+1); /* vars to store before we go */ -// refd= ref->rect; + // refd= ref->rect; src= img->rect; radxf= (float)radx; @@ -2387,8 +2611,8 @@ for (y = 0; y < imgy; y++) { for (x = 0; x < imgx ; x++, src+=4) {//, refd++) { -// int refradx= (int)(refd[0]*radxf); -// int refrady= (int)(refd[0]*radyf); + // int refradx= (int)(refd[0]*radxf); + // int refrady= (int)(refd[0]*radyf); int refradx= (int)(radxf*0.3f*src[3]*(src[0]+src[1]+src[2])); int refrady= (int)(radyf*0.3f*src[3]*(src[0]+src[1]+src[2])); @@ -2542,7 +2766,7 @@ float fi= (float)i/radxf; float dist= sqrt(fj*fj + fi*fi); -// *dgauss= hexagon_filter(fi, fj); + // *dgauss= hexagon_filter(fi, fj); *dgauss= RE_filter_value(nbd->filtertype, 2.0f*dist - 1.0f); val+= *dgauss; @@ -2884,6 +3108,646 @@ /* execfunc */ node_composit_exec_translate }; +/* ******************* YUV Difference Matte ********************************* */ +static bNodeSocketType cmp_node_YUV_matte_in[]={ + {SOCK_RGBA,1,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_RGBA,1,"Key", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {-1,0,""}, +}; + +static bNodeSocketType cmp_node_YUV_matte_out[]={ + {SOCK_RGBA,0,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_VALUE,0,"Matte",0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {-1,0,""} +}; + +static void node_composit_exec_YUV_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +{ + int i,max; + + float distance, tolerance, alpha,edgesmoothness, edgeslope; + float yuvkey[3]; + NodeChroma *c; + CompBuf *yuvbuf; + CompBuf *rgbbuf; + CompBuf *matte; + CompBuf *cbuf; + + if(out[0]->hasoutput==0 || in[0]->hasinput==0) return; + if(in[0]->data==NULL) return; + + cbuf=in[0]->data; + + //is it an RGBA image or a value + if(cbuf->type==CB_RGBA) + { + c=node->storage; + tolerance=c->rt; + edgesmoothness=c->gt; + edgeslope=c->bt; + yuvbuf=alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA,1); + rgbbuf=dupalloc_compbuf(cbuf); + matte=alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA,1); + + //convert RGB to YUV + max=cbuf->x*cbuf->y*4; + for(i=0;irect[i+0],cbuf->rect[i+1],cbuf->rect[i+2],&yuvbuf->rect[i+0], &yuvbuf->rect[i+1], &yuvbuf->rect[i+2]); + yuvbuf->rect[3]=cbuf->rect[3]; + } + + //convert key to YUV + rgb_to_yuv(in[1]->vec[0], in[1]->vec[1], in[1]->vec[2], &yuvkey[0], &yuvkey[1], &yuvkey[2]); + + for(i=0;irect[i+3]<1.0) + { + //make transparent + //premultiplied + rgbbuf->rect[i+3]=cbuf->rect[i+3]; + //matte + matte->rect[i+0]=cbuf->rect[i+3]; + matte->rect[i+1]=cbuf->rect[i+3]; + matte->rect[i+2]=cbuf->rect[i+3]; + matte->rect[i+3]=1.0; + continue; + + } + distance=sqrt((yuvkey[0]-yuvbuf->rect[i+0])*(yuvkey[0]-yuvbuf->rect[i+0])+ + (yuvkey[1]-yuvbuf->rect[i+1])*(yuvkey[1]-yuvbuf->rect[i+1])+ + (yuvkey[2]-yuvbuf->rect[i+2])*(yuvkey[2]-yuvbuf->rect[i+2])); + + if(distance1.0) alpha=1.0; + if (alpha<0.0) alpha=0.0; + //premultiplied + rgbbuf->rect[i+3]=alpha; + //matte + matte->rect[i+0]=alpha; + matte->rect[i+1]=alpha; + matte->rect[i+2]=alpha; + matte->rect[i+3]=1.0; + } + else + { + //premultipled + rgbbuf->rect[i+3]=1.0; + //matte + matte->rect[i+0]=1.0; + matte->rect[i+1]=1.0; + matte->rect[i+2]=1.0; + matte->rect[i+3]=1.0; + } + } + + //free the yuv image + free_compbuf(yuvbuf); + + out[0]->data=rgbbuf; + out[1]->data=matte; + + generate_preview(node, rgbbuf); + } + else + { + return; + } +} + +static bNodeType cmp_node_YUV_matte={ + /* type code */ CMP_NODE_YUV_MATTE, + /* name */ "YUV Difference Matte", + /* width+range */ 200, 80, 250, + /* class+opts */ NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS, + /* input sock */ cmp_node_YUV_matte_in, + /* output sock */ cmp_node_YUV_matte_out, + /* storage */ "NodeChroma", + /* execfunc */ node_composit_exec_YUV_matte +}; + + +/* ******************* RGB Difference Matte ********************************* */ +static bNodeSocketType cmp_node_diff_matte_in[]={ + {SOCK_RGBA,1,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_RGBA,1,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {-1,0,""} +}; + +static bNodeSocketType cmp_node_diff_matte_out[]={ + {SOCK_RGBA,0,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_VALUE,0,"Matte",0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {-1,0,""} +}; + +static void node_composit_exec_diff_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +{ + int i,max; + int use_val=0; + + CompBuf *rgbbuf; + CompBuf *matte; + CompBuf *cbuf1, *cbuf2; + NodeChroma *c; + float distance, tolerance, alpha,edgesmoothness,edgeslope; + + //is anything connected? + if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return; + //must have an image imput + if(in[0]->data==NULL) return; + //using an image or a color? + if(in[1]->data==NULL) use_val=1; + + if(use_val==0) + { + cbuf1=in[0]->data; + cbuf2=in[1]->data; + //same size? + if(cbuf1->x!=cbuf2->x || cbuf1->y!=cbuf2->y) return; + + c=node->storage; + tolerance=c->rt; + edgesmoothness=c->gt; + edgeslope=c->bt; + rgbbuf=dupalloc_compbuf(cbuf1); + matte=alloc_compbuf(cbuf1->x, cbuf1->y,CB_RGBA,1); + + //find min/max tolerances + tolerance=c->rt; + max=cbuf1->x*cbuf1->y*4; + + for(i=0;irect[i+3]<1.0) + { + //make transparent + //premultiplied + rgbbuf->rect[i+3]=cbuf1->rect[i+3]; + //matte + matte->rect[i+0]=cbuf1->rect[i+3]; + matte->rect[i+1]=cbuf1->rect[i+3]; + matte->rect[i+2]=cbuf1->rect[i+3]; + matte->rect[i+3]=1.0; + continue; + } + + //new way (distance in 3 space between colors) + distance=sqrt((cbuf2->rect[i+0]-cbuf1->rect[i+0])*(cbuf2->rect[i+0]-cbuf1->rect[i+0])+ + (cbuf2->rect[i+1]-cbuf1->rect[i+1])*(cbuf2->rect[i+1]-cbuf1->rect[i+1])+ + (cbuf2->rect[i+2]-cbuf1->rect[i+2])*(cbuf2->rect[i+2]-cbuf1->rect[i+2])); + if(distance<=tolerance) + { + //make transparent + alpha=((distance/tolerance)-(1-edgesmoothness))*(edgeslope); + + //clamp + if (alpha>1.0) alpha=1.0; + if (alpha<0.0) alpha=0.0; + //premultiplied + rgbbuf->rect[i+3]=alpha; + //matte + matte->rect[i+0]=alpha; + matte->rect[i+1]=alpha; + matte->rect[i+2]=alpha; + matte->rect[i+3]=1.0; + } + else + { + //premultipled + rgbbuf->rect[i+3]=1.0; + //matte + matte->rect[i+0]=1.0; + matte->rect[i+1]=1.0; + matte->rect[i+2]=1.0; + matte->rect[i+3]=1.0; + } + } + } + //use the input color + else + { + cbuf1=in[0]->data; + c=node->storage; + + rgbbuf=dupalloc_compbuf(cbuf1); + matte=alloc_compbuf(cbuf1->x, cbuf1->y,CB_RGBA,1); + tolerance=c->rt; + edgesmoothness=c->gt; + edgeslope=c->bt; + + max=cbuf1->x*cbuf1->y*4; + + for(i=0;irect[i+3]<1.0) + { + //make transparent + //premultiplied + rgbbuf->rect[i+3]=cbuf1->rect[i+3]; + //matte + matte->rect[i+0]=cbuf1->rect[i+3]; + matte->rect[i+1]=cbuf1->rect[i+3]; + matte->rect[i+2]=cbuf1->rect[i+3]; + matte->rect[i+3]=1.0; + continue; + } + + distance=sqrt((in[1]->vec[0]-cbuf1->rect[i+0])*(in[1]->vec[0]-cbuf1->rect[i+0])+ + (in[1]->vec[1]-cbuf1->rect[i+1])*(in[1]->vec[1]-cbuf1->rect[i+1])+ + (in[1]->vec[2]-cbuf1->rect[i+2])*(in[1]->vec[2]-cbuf1->rect[i+2])); + if(distance1.0) alpha=1.0; + if (alpha<0.0) alpha=0.0; + //premultiplied + rgbbuf->rect[i+3]=alpha; + //matte + matte->rect[i+0]=alpha; + matte->rect[i+1]=alpha; + matte->rect[i+2]=alpha; + matte->rect[i+3]=1.0; + } + else + { + //foreground object + //premultipled + rgbbuf->rect[i+3]=1.0; + //matte + matte->rect[i+0]=1.0; + matte->rect[i+1]=1.0; + matte->rect[i+2]=1.0; + matte->rect[i+3]=1.0; + } + } + } + out[0]->data=rgbbuf; + out[1]->data=matte; + generate_preview(node, rgbbuf); +} + +static bNodeType cmp_node_diff_matte={ + /* type code */ CMP_NODE_DIFF_MATTE, + /* name */ "RGB Difference Matte", + /* width+range */ 200, 80, 250, + /* class+opts */ NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS, + /* input sock */ cmp_node_diff_matte_in, + /* output sock */ cmp_node_diff_matte_out, + /* storage */ "NodeChroma", + /* execfunc */ node_composit_exec_diff_matte +}; + +/* ******************* Chroma Matte ********************************* */ +static bNodeSocketType cmp_node_chroma_matte_in[]={ + {SOCK_RGBA,1,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_RGBA,1,"Key", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {-1,0,""} +}; + +static bNodeSocketType cmp_node_chroma_matte_out[]={ + {SOCK_RGBA,0,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_VALUE,0,"Matte",0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {-1,0,""} +}; + + +static void node_composit_exec_chroma_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +{ + int i,max; + + float distance, tolerance, alpha,edgesmoothness,edgeslope; + float ycckey[3]; + CompBuf *cbuf; + NodeChroma *c; + CompBuf *yccbuf; + CompBuf *rgbbuf; + CompBuf *matte; + + if(out[0]->hasoutput==0 || in[0]->hasinput==0) return; + if(in[0]->data==NULL) return; + + cbuf=in[0]->data; + + //is it an RGBA image or a value + if(cbuf->type==CB_RGBA) + { + c=node->storage; + tolerance=c->rt; + edgesmoothness=c->gt; + edgeslope=c->bt; + yccbuf=alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA,1); + rgbbuf=dupalloc_compbuf(cbuf); + matte=alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA,1); + + //convert RGB to YCC + max=cbuf->x*cbuf->y*4; + for(i=0;irect[i+0],cbuf->rect[i+1],cbuf->rect[i+2],&yccbuf->rect[i+0], &yccbuf->rect[i+1], &yccbuf->rect[i+2]); + yccbuf->rect[3]=cbuf->rect[3]; + } + + //convert key to YCC + rgb_to_ycc(in[1]->vec[0], in[1]->vec[1], in[1]->vec[2], &ycckey[0], &ycckey[1], &ycckey[2]); + + for(i=0;irect[i+3]<1.0) + { + //make transparent + //premultiplied + rgbbuf->rect[i+3]=cbuf->rect[i+3]; + //matte + matte->rect[i+0]=cbuf->rect[i+3]; + matte->rect[i+1]=cbuf->rect[i+3]; + matte->rect[i+2]=cbuf->rect[i+3]; + matte->rect[i+3]=1.0; + continue; + } + distance=sqrt((ycckey[0]-yccbuf->rect[i+0])*(ycckey[0]-yccbuf->rect[i+0])+ + (ycckey[1]-yccbuf->rect[i+1])*(ycckey[1]-yccbuf->rect[i+1])+ + (ycckey[2]-yccbuf->rect[i+2])*(ycckey[2]-yccbuf->rect[i+2])); + if(distance<=tolerance) + { + //make transparent + alpha=((distance/tolerance)-(1-edgesmoothness))*(edgeslope); + + //clamp + if (alpha>1.0) alpha=1.0; + if (alpha<0.0) alpha=0.0; + //premultiplied + rgbbuf->rect[i+3]=alpha; + //matte + matte->rect[i+0]=alpha; + matte->rect[i+1]=alpha; + matte->rect[i+2]=alpha; + matte->rect[i+3]=1.0; + + } + else //the pixel is not masked + { + //premultipled + rgbbuf->rect[i+3]=1.0; + //matte + matte->rect[i+0]=1.0; + matte->rect[i+1]=1.0; + matte->rect[i+2]=1.0; + matte->rect[i+3]=1.0; + } + } + + //free the ycc image + free_compbuf(yccbuf); + + out[0]->data=rgbbuf; + out[1]->data=matte; + + generate_preview(node, rgbbuf); + } + else + { + return; + } +} + +static bNodeType cmp_node_chroma_matte={ + /* type code */ CMP_NODE_CHROMA_MATTE, + /* name */ "Chroma Difference Matte", + /* width+range */ 200, 80, 250, + /* class+opts */ NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS, + /* input sock */ cmp_node_chroma_matte_in, + /* output sock */ cmp_node_chroma_matte_out, + /* storage */ "NodeChroma", + /* execfunc */ node_composit_exec_chroma_matte +}; + + +/* ******************* Color Spill Supression ********************************* */ +static bNodeSocketType cmp_node_color_spill_in[]={ + {SOCK_RGBA,1,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {-1,0,""} +}; + +static bNodeSocketType cmp_node_color_spill_out[]={ + {SOCK_RGBA,0,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {-1,0,""} +}; + + +static void node_composit_exec_color_spill(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +{ + int i,max; + float tolerance; + CompBuf *cbuf; + CompBuf *rgbbuf; + NodeChroma *c; + + if(out[0]->hasoutput==0 || in[0]->hasinput==0) return; + if(in[0]->data==NULL) return; + + cbuf=in[0]->data; + c=node->storage; + tolerance=c->rt; + + //is it an RGBA image + if(cbuf->type==CB_RGBA) + { + rgbbuf=dupalloc_compbuf(cbuf); + max=cbuf->x*cbuf->y*4; + + switch(node->custom1) + { + case 1: //red spill + { + for(i=0;irect[i+0]>cbuf->rect[i+2]) + { + rgbbuf->rect[i+0]=rgbbuf->rect[i+2]-(tolerance*rgbbuf->rect[i+2]); + } + } + break; + } + case 2: //green spill + { + for(i=0;irect[i+1]>cbuf->rect[i+2]) + { + rgbbuf->rect[i+1]=rgbbuf->rect[i+2]-(tolerance*rgbbuf->rect[i+2]); + } + } + break; + } + case 3: //blue spill + { + for(i=0;irect[i+2]>cbuf->rect[i+1]) + { + rgbbuf->rect[i+2]=rgbbuf->rect[i+1]-(tolerance*rgbbuf->rect[i+1]); + } + } + break; + } + default: + break; + } + + out[0]->data=rgbbuf; + } + else + { + return; + } +} + +static bNodeType cmp_node_color_spill={ + /* type code */ CMP_NODE_COLOR_SPILL, + /* name */ "Color Spill", + /* width+range */ 140, 80, 140, + /* class+opts */ NODE_CLASS_MATTE, NODE_OPTIONS, + /* input sock */ cmp_node_color_spill_in, + /* output sock */ cmp_node_color_spill_out, + /* storage */ "NodeChroma", + /* execfunc */ node_composit_exec_color_spill +}; + +/* **************** Dilate/Erode ******************** */ + +static bNodeSocketType cmp_node_dilateerode_in[]= { + { SOCK_VALUE, 1, "Mask", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; +static bNodeSocketType cmp_node_dilateerode_out[]= { + { SOCK_VALUE, 0, "Mask", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; + +static void morpho_dilate(CompBuf *cbuf) +{ + int x, y; + float *p, *rectf = cbuf->rect; + + for (y=0; y < cbuf->y; y++) { + for (x=0; x < cbuf->x-1; x++) { + p = rectf + cbuf->x*y + x; + *p = MAX2(*p, *(p + 1)); + } + } + + for (y=0; y < cbuf->y; y++) { + for (x=cbuf->x-1; x >= 1; x--) { + p = rectf + cbuf->x*y + x; + *p = MAX2(*p, *(p - 1)); + } + } + + for (x=0; x < cbuf->x; x++) { + for (y=0; y < cbuf->y-1; y++) { + p = rectf + cbuf->x*y + x; + *p = MAX2(*p, *(p + cbuf->x)); + } + } + + for (x=0; x < cbuf->x; x++) { + for (y=cbuf->y-1; y >= 1; y--) { + p = rectf + cbuf->x*y + x; + *p = MAX2(*p, *(p - cbuf->x)); + } + } +} + +static void morpho_erode(CompBuf *cbuf) +{ + int x, y; + float *p, *rectf = cbuf->rect; + + for (y=0; y < cbuf->y; y++) { + for (x=0; x < cbuf->x-1; x++) { + p = rectf + cbuf->x*y + x; + *p = MIN2(*p, *(p + 1)); + } + } + + for (y=0; y < cbuf->y; y++) { + for (x=cbuf->x-1; x >= 1; x--) { + p = rectf + cbuf->x*y + x; + *p = MIN2(*p, *(p - 1)); + } + } + + for (x=0; x < cbuf->x; x++) { + for (y=0; y < cbuf->y-1; y++) { + p = rectf + cbuf->x*y + x; + *p = MIN2(*p, *(p + cbuf->x)); + } + } + + for (x=0; x < cbuf->x; x++) { + for (y=cbuf->y-1; y >= 1; y--) { + p = rectf + cbuf->x*y + x; + *p = MIN2(*p, *(p - cbuf->x)); + } + } + +} + +static void node_composit_exec_dilateerode(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +{ + /* stack order in: mask */ + /* stack order out: mask */ + if(out[0]->hasoutput==0) + return; + + /* input no image? then only color operation */ + if(in[0]->data==NULL) { + out[0]->vec[0] = out[0]->vec[1] = out[0]->vec[2] = 0.0f; + out[0]->vec[3] = 0.0f; + } + else { + /* make output size of input image */ + CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_VAL); + CompBuf *stackbuf= dupalloc_compbuf(cbuf); + short i; + + if (node->custom2 > 0) { // positive, dilate + for (i = 0; i < node->custom2; i++) + morpho_dilate(stackbuf); + } else if (node->custom2 < 0) { // negative, erode + for (i = 0; i > node->custom2; i--) + morpho_erode(stackbuf); + } + + out[0]->data= stackbuf; + } +} + +static bNodeType cmp_node_dilateerode= { + /* type code */ CMP_NODE_DILATE_ERODE, + /* name */ "Dilate/Erode", + /* width+range */ 130, 100, 320, + /* class+opts */ NODE_CLASS_MATTE, NODE_OPTIONS, + /* input sock */ cmp_node_dilateerode_in, + /* output sock */ cmp_node_dilateerode_out, + /* storage */ "", + /* execfunc */ node_composit_exec_dilateerode +}; + + /* ****************** types array for all shaders ****************** */ @@ -2911,10 +3775,18 @@ &cmp_node_rgbtobw, &cmp_node_seprgba, &cmp_node_sephsva, + &cmp_node_sepyuva, &cmp_node_setalpha, &cmp_node_texture, &cmp_node_translate, &cmp_node_zcombine, + &cmp_node_YUV_matte, + &cmp_node_diff_matte, + &cmp_node_chroma_matte, + &cmp_node_color_spill, + &cmp_node_sepycca, + &cmp_node_combrgba, + &cmp_node_dilateerode, NULL }; diff -Naurb blender2.42/source/blender/blenlib/BLI_arithb.h blender-work/source/blender/blenlib/BLI_arithb.h --- blender2.42/source/blender/blenlib/BLI_arithb.h 2006-06-03 13:21:45.000000000 -0400 +++ blender-work/source/blender/blenlib/BLI_arithb.h 2006-07-17 21:12:44.000000000 -0400 @@ -666,7 +666,13 @@ void hex_to_rgb(char *hexcol, float *r, float *g, float *b); - void +void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv); +void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb); + +void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb); +void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr); + +void rgb_to_hsv( float r, float g, float b, float *lh, float *ls, float *lv diff -Naurb blender2.42/source/blender/blenlib/intern/arithb.c blender-work/source/blender/blenlib/intern/arithb.c --- blender2.42/source/blender/blenlib/intern/arithb.c 2006-07-05 00:03:40.000000000 -0400 +++ blender-work/source/blender/blenlib/intern/arithb.c 2006-07-18 13:10:55.000000000 -0400 @@ -2639,6 +2639,61 @@ } } +void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv) +{ + float y, u, v; + y= 0.299*r + 0.587*g + 0.114*b; + u=-0.147*r - 0.289*g + 0.436*b; + v= 0.615*r - 0.515*g - 0.100*b; + + *ly=y; + *lu=u; + *lv=v; +} + +void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb) +{ + float r, g, b; + r=y+1.140*v; + g=y-0.394*u - 0.581*v; + b=y+2.032*u; + + *lr=r; + *lg=g; + *lb=b; +} + +void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr) +{ + float sr,sg, sb; + float y, cr, cb; + + sr=255.0*r; + sg=255.0*g; + sb=255.0*b; + + //y-16, cb-128, cr-128 + y=(0.257*sr)+(0.504*sg)+(0.098*sb)+16.0; + cb=(-0.148*sr)-(0.291*sg)+(0.439*sb)+128.0; + cr=(0.439*sr)-(0.368*sg)-(0.071*sb)+128.0; + + *ly=y; + *lcb=cb; + *lcr=cr; +} + +void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb) +{ + float r,g,b; + + r=1.164*(y-16)+1.596*(cr-128); + g=1.164*(y-16)-0.813*(cr-128)-0.392*(cb-128); + b=1.164*(y-16)+2.017*(cb-128); + + *lr=r/255.0; + *lg=g/255.0; + *lb=b/255.0; +} void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv) { float h, s, v; diff -Naurb blender2.42/source/blender/makesdna/DNA_node_types.h blender-work/source/blender/makesdna/DNA_node_types.h --- blender2.42/source/blender/makesdna/DNA_node_types.h 2006-06-17 09:04:09.000000000 -0400 +++ blender-work/source/blender/makesdna/DNA_node_types.h 2006-07-19 00:50:40.000000000 -0400 @@ -90,11 +90,10 @@ /* only used now for groups... */ #define SOCK_IN_USE 4 -# -# typedef struct bNodePreview { float *rect; short xsize, ysize; + int pad; } bNodePreview; @@ -193,8 +192,12 @@ } NodeBlurData; typedef struct NodeHueSat { - float hue, sat; + float hue, sat,val; } NodeHueSat; +typedef struct NodeChroma { + float rt, gt, bt; +} NodeChroma; + #endif diff -Naurb blender2.42/source/blender/src/drawnode.c blender-work/source/blender/src/drawnode.c --- blender2.42/source/blender/src/drawnode.c 2006-07-03 05:49:12.000000000 -0400 +++ blender-work/source/blender/src/drawnode.c 2006-07-21 14:50:19.000000000 -0400 @@ -975,16 +975,114 @@ NodeHueSat *nhs= node->storage; uiBlockBeginAlign(block); - uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Hue ", - butr->xmin, butr->ymin+19.0f, butr->xmax-butr->xmin, 19, + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Hue: ", + butr->xmin, butr->ymin+40.0f, butr->xmax-butr->xmin, 20, &nhs->hue, 0.0f, 1.0f, 100, 0, ""); - uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Sat ", - butr->xmin, butr->ymin, butr->xmax-butr->xmin, 19, + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Sat: ", + butr->xmin, butr->ymin+20.0f, butr->xmax-butr->xmin, 20, &nhs->sat, 0.0f, 2.0f, 100, 0, ""); + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Val: ", + butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20, + &nhs->val, 0.0f, 2.0f, 100, 0, ""); + } + return 60; +} + +static int node_composit_buts_YUV_matte(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr) +{ + if(block) + { + NodeChroma *c= node->storage; + uiBlockBeginAlign(block); + + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Tolerance ", + butr->xmin, butr->ymin+38, butr->xmax-butr->xmin, 19, + &c->rt, 0.0f, 1.0f, 100, 0, ""); + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Falloff Size", + butr->xmin, butr->ymin+19, butr->xmax-butr->xmin, 19, + &c->gt, 0.0001f, 1.0f, 100, 0, ""); + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Falloff Strength", + butr->xmin, butr->ymin, butr->xmax-butr->xmin, 19, + &c->bt, 0.0001f, 1.0f, 100, 0, ""); + } + return 57; +} + +static int node_composit_buts_diff_matte(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr) +{ + if(block) + { + NodeChroma *c= node->storage; + uiBlockBeginAlign(block); + + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Tolerance ", + butr->xmin, butr->ymin+38, butr->xmax-butr->xmin, 19, + &c->rt, 0.0f, 1.0f, 100, 0, ""); + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Falloff Size ", + butr->xmin, butr->ymin+19, butr->xmax-butr->xmin, 19, + &c->gt, 0.0001f, 1.0f, 100, 0, ""); + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Falloff Strenght ", + butr->xmin, butr->ymin, butr->xmax-butr->xmin, 19, + &c->bt, 0.0001f, 1.0f, 100, 0, ""); + } + return 57; +} + +static int node_composit_buts_chroma_matte(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr) +{ + if(block) + { + NodeChroma *c= node->storage; + uiBlockBeginAlign(block); + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Tolerance ", + butr->xmin, butr->ymin+38, butr->xmax-butr->xmin, 19, + &c->rt, 0.0f, 255.0f, 100, 0, ""); + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Falloff Size ", + butr->xmin, butr->ymin+19, butr->xmax-butr->xmin, 19, + &c->gt, 0.0001f, 1.0f, 100, 0, ""); + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Falloff Strength ", + butr->xmin, butr->ymin, butr->xmax-butr->xmin, 19, + &c->bt, 0.0001f, 1.0f, 100, 0, ""); + } + return 57; +} + +static int node_composit_buts_color_spill(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr) +{ + if(block) + { + short dx= (butr->xmax-butr->xmin)/3; + + NodeChroma *c=node->storage; + uiBlockBeginAlign(block); + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Enhancement ", + butr->xmin, butr->ymin+19.0, butr->xmax-butr->xmin, 19, + &c->rt, 0.0f, 0.5f, 100, 0, ""); + uiDefButS(block, ROW,B_DIFF,"R", + butr->xmin,butr->ymin,dx,19, + &node->custom1,1,1, 0, 0, "Red Spill Suppression"); + uiDefButS(block, ROW,B_DIFF,"G", + butr->xmin+dx,butr->ymin,dx,19, + &node->custom1,1,2, 0, 0, "Green Spill Suppression"); + uiDefButS(block, ROW,B_DIFF,"B", + butr->xmin+2*dx,butr->ymin,dx,19, + &node->custom1,1,3, 0, 0, "Blue Spill Suppression"); + uiBlockEndAlign(block); } return 38; } +static int node_composit_buts_dilateerode(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr) +{ + if(block) { + uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Distance:", + butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20, + &node->custom2, -100, 100, 0, 0, "Distance to grow/shrink (number of iterations)"); + } + return 20; +} + + /* only once called */ static void node_composit_set_butfunc(bNodeType *ntype) @@ -1044,6 +1142,21 @@ case CMP_NODE_TEXTURE: ntype->butfunc= node_buts_texture; break; + case CMP_NODE_YUV_MATTE: + ntype->butfunc=node_composit_buts_YUV_matte; + break; + case CMP_NODE_DIFF_MATTE: + ntype->butfunc=node_composit_buts_diff_matte; + break; + case CMP_NODE_CHROMA_MATTE: + ntype->butfunc=node_composit_buts_chroma_matte; + break; + case CMP_NODE_COLOR_SPILL: + ntype->butfunc=node_composit_buts_color_spill; + break; + case CMP_NODE_DILATE_ERODE: + ntype->butfunc= node_composit_buts_dilateerode; + break; default: ntype->butfunc= NULL; } diff -Naurb blender2.42/source/blender/src/header_node.c blender-work/source/blender/src/header_node.c --- blender2.42/source/blender/src/header_node.c 2006-06-26 07:01:09.000000000 -0400 +++ blender-work/source/blender/src/header_node.c 2006-07-17 13:01:37.000000000 -0400 @@ -368,6 +368,19 @@ return block; } +static uiBlock *node_add_mattemenu(void *arg_unused) +{ + SpaceNode *snode=curarea->spacedata.first; + uiBlock *block; + + block=uiNewBlock(&curarea->uiblocks, "node_add_mattemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin); + uiBlockSetButmFunc(block,do_node_addmenu, NULL); + node_make_addmenu(snode, NODE_CLASS_MATTE, block); + uiBlockSetDirection(block, UI_RIGHT); + uiTextBoundsBlock(block,60); + return block; +} + static uiBlock *node_addmenu(void *arg_unused) { SpaceNode *snode= curarea->spacedata.first; @@ -394,6 +407,7 @@ uiDefIconTextBlockBut(block, node_add_filtermenu, NULL, ICON_RIGHTARROW_THIN, "Filter", 0, yco-=20, 120, 19, ""); uiDefIconTextBlockBut(block, node_add_convertermenu, NULL, ICON_RIGHTARROW_THIN, "Convertor", 0, yco-=20, 120, 19, ""); uiDefIconTextBlockBut(block, node_add_groupmenu, NULL, ICON_RIGHTARROW_THIN, "Group", 0, yco-=20, 120, 19, ""); + uiDefIconTextBlockBut(block, node_add_mattemenu, NULL, ICON_RIGHTARROW_THIN, "Matte", 0, yco-=20, 120,19,""); } else uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); diff -Naurb blender2.42/source/blender/src/toolbox.c blender-work/source/blender/src/toolbox.c --- blender2.42/source/blender/src/toolbox.c 2006-07-12 10:51:30.000000000 -0400 +++ blender-work/source/blender/src/toolbox.c 2006-07-18 15:50:37.000000000 -0400 @@ -1526,6 +1526,7 @@ #define TB_CMP_OP_FILTER 4 #define TB_CMP_CONVERTORS 5 #define TB_CMP_GROUPS 6 +#define TB_CMP_MATTE 7 static TBitem tb_node_addcomp[]= { { 0, "Input", 1, NULL}, @@ -1535,6 +1536,7 @@ { 0, "Filters", 5, NULL}, { 0, "Convertors", 6, NULL}, { 0, "Groups", 7, NULL}, + { 0, "Mattes", 8, NULL}, { -1, "", 0, NULL}}; /* do_node_addmenu() in header_node.c, prototype in BSE_headerbuttons.h */ @@ -1738,6 +1740,7 @@ TBitem *menu7=NULL, *groupmenu= NULL; TBitem *node_add_gen= NULL, *node_add_group= NULL, *node_add_out= NULL, *node_add_in= NULL; TBitem *node_add_op_col= NULL, *node_add_op_filt= NULL, *node_add_op_vec= NULL, *node_add_con= NULL; + TBitem *node_add_matte=NULL; int dx=0; short event, mval[2], tot=0; char *str1=NULL, *str2=NULL, *str3=NULL, *str4=NULL, *str5=NULL, *str6=NULL, *str7=NULL; @@ -1918,6 +1921,7 @@ node_add_op_vec= node_add_sublevel(&menu1[TB_CMP_OP_VECTOR].poin, snode->nodetree, NODE_CLASS_OP_VECTOR); node_add_con= node_add_sublevel(&menu1[TB_CMP_CONVERTORS].poin, snode->nodetree, NODE_CLASS_CONVERTOR); node_add_group= node_add_sublevel(&menu1[TB_CMP_GROUPS].poin, snode->nodetree, NODE_CLASS_GROUP); + node_add_matte= node_add_sublevel(&menu1[TB_CMP_MATTE].poin,snode->nodetree, NODE_CLASS_MATTE); } dx= 96; @@ -2018,6 +2022,7 @@ if(node_add_con) MEM_freeN(node_add_con); if(node_add_gen) MEM_freeN(node_add_gen); if(node_add_group) MEM_freeN(node_add_group); + if(node_add_matte) MEM_freeN(node_add_matte); mywinset(curarea->win); }