diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2011-09-06 01:01:50 +0400 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2011-09-06 01:01:50 +0400 |
commit | 8e0fe8bff72e2dc2926618577eaffdd3417a8304 (patch) | |
tree | 43b933c88cac451518dc68846c1119acacffca4f /source/blender/nodes/intern | |
parent | 6e9ff495eb082aeb49e6a1da23a7827d3fcd0fde (diff) |
Merged the particles-2010 branch with node improvements into trunk.
This branch adds mostly organizational improvements to the node system by renaming the node folders and files. A couple of internal features have been added too.
Detailed information can be found on the wiki page:
http://wiki.blender.org/index.php/User:Phonybone/Particles2010
Diffstat (limited to 'source/blender/nodes/intern')
109 files changed, 1901 insertions, 18596 deletions
diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_alphaOver.c b/source/blender/nodes/intern/CMP_nodes/CMP_alphaOver.c deleted file mode 100644 index 9dcdfaf21e6..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_alphaOver.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_alphaOver.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** ALPHAOVER ******************** */ -static bNodeSocketType cmp_node_alphaover_in[]= { - { SOCK_VALUE, 1, "Fac", 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { 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_alphaover_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_alphaover_premul(bNode *UNUSED(node), float *out, float *src, float *over, float *fac) -{ - - if(over[3]<=0.0f) { - QUATCOPY(out, src); - } - else if(fac[0]==1.0f && over[3]>=1.0f) { - QUATCOPY(out, over); - } - else { - float mul= 1.0f - fac[0]*over[3]; - - out[0]= (mul*src[0]) + fac[0]*over[0]; - out[1]= (mul*src[1]) + fac[0]*over[1]; - out[2]= (mul*src[2]) + fac[0]*over[2]; - out[3]= (mul*src[3]) + fac[0]*over[3]; - } -} - -/* result will be still premul, but the over part is premulled */ -static void do_alphaover_key(bNode *UNUSED(node), float *out, float *src, float *over, float *fac) -{ - - if(over[3]<=0.0f) { - QUATCOPY(out, src); - } - else if(fac[0]==1.0f && over[3]>=1.0f) { - QUATCOPY(out, over); - } - else { - float premul= fac[0]*over[3]; - float mul= 1.0f - premul; - - out[0]= (mul*src[0]) + premul*over[0]; - out[1]= (mul*src[1]) + premul*over[1]; - out[2]= (mul*src[2]) + premul*over[2]; - out[3]= (mul*src[3]) + fac[0]*over[3]; - } -} - -/* result will be still premul, but the over part is premulled */ -static void do_alphaover_mixed(bNode *node, float *out, float *src, float *over, float *fac) -{ - - if(over[3]<=0.0f) { - QUATCOPY(out, src); - } - else if(fac[0]==1.0f && over[3]>=1.0f) { - QUATCOPY(out, over); - } - else { - NodeTwoFloats *ntf= node->storage; - float addfac= 1.0f - ntf->x + over[3]*ntf->x; - float premul= fac[0]*addfac; - float mul= 1.0f - fac[0]*over[3]; - - out[0]= (mul*src[0]) + premul*over[0]; - out[1]= (mul*src[1]) + premul*over[1]; - out[2]= (mul*src[2]) + premul*over[2]; - out[3]= (mul*src[3]) + fac[0]*over[3]; - } -} - - - - -static void node_composit_exec_alphaover(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order in: col col */ - /* stack order out: col */ - if(out[0]->hasoutput==0) - return; - - /* input no image? then only color operation */ - if(in[1]->data==NULL && in[2]->data==NULL) { - do_alphaover_premul(node, out[0]->vec, in[1]->vec, in[2]->vec, in[0]->vec); - } - else { - /* make output size of input image */ - CompBuf *cbuf= in[1]->data?in[1]->data:in[2]->data; - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ - NodeTwoFloats *ntf= node->storage; - - if(ntf->x != 0.0f) - composit3_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, in[0]->data, in[0]->vec, do_alphaover_mixed, CB_RGBA, CB_RGBA, CB_VAL); - else if(node->custom1) - composit3_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, in[0]->data, in[0]->vec, do_alphaover_key, CB_RGBA, CB_RGBA, CB_VAL); - else - composit3_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, in[0]->data, in[0]->vec, do_alphaover_premul, CB_RGBA, CB_RGBA, CB_VAL); - - out[0]->data= stackbuf; - } -} - -static void node_alphaover_init(bNode* node) -{ - node->storage= MEM_callocN(sizeof(NodeTwoFloats), "NodeTwoFloats"); -} - -void register_node_type_cmp_alphaover(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_ALPHAOVER, "AlphaOver", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - cmp_node_alphaover_in, cmp_node_alphaover_out); - node_type_size(&ntype, 80, 40, 120); - node_type_init(&ntype, node_alphaover_init); - node_type_storage(&ntype, "NodeTwoFloats", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_alphaover); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_bilateralblur.c b/source/blender/nodes/intern/CMP_nodes/CMP_bilateralblur.c deleted file mode 100644 index c106b437e17..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_bilateralblur.c +++ /dev/null @@ -1,271 +0,0 @@ -/* - * - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Vilem Novak - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_bilateralblur.c - * \ingroup cmpnodes - */ - -#include "../CMP_util.h" - -/* **************** BILATERALBLUR ******************** */ -static bNodeSocketType cmp_node_bilateralblur_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, "Determinator", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType cmp_node_bilateralblur_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -#define INIT_C3\ - mean0 = 1; mean1[0] = src[0];mean1[1] = src[1];mean1[2] = src[2];mean1[3] = src[3]; - -/* finds color distances */ -#define COLOR_DISTANCE_C3(c1, c2)\ - ((c1[0] - c2[0])*(c1[0] - c2[0]) + \ - (c1[1] - c2[1])*(c1[1] - c2[1]) + \ - (c1[2] - c2[2])*(c1[2] - c2[2]) + \ - (c1[3] - c2[3])*(c1[3] - c2[3])) - -/* this is the main kernel function for comparing color distances - and adding them weighted to the final color */ -#define KERNEL_ELEMENT_C3(k)\ - temp_color = src + deltas[k];\ - ref_color = ref + deltas[k];\ - w = weight_tab[k] + COLOR_DISTANCE_C3(ref, ref_color )*i2sigma_color;\ - w = 1./(w*w + 1); \ - mean0 += w;\ - mean1[0] += temp_color[0]*w; \ - mean1[1] += temp_color[1]*w; \ - mean1[2] += temp_color[2]*w; \ - mean1[3] += temp_color[3]*w; - -/* write blurred values to image */ -#define UPDATE_OUTPUT_C3\ - mean0 = 1./mean0;\ - dest[x*pix + 0] = mean1[0]*mean0; \ - dest[x*pix + 1] = mean1[1]*mean0; \ - dest[x*pix + 2] = mean1[2]*mean0; \ - dest[x*pix + 3] = mean1[3]*mean0; - -/* initializes deltas for fast access to neighbour pixels */ -#define INIT_3X3_DELTAS( deltas, step, nch ) \ - ((deltas)[0] = (nch), (deltas)[1] = -(step) + (nch), \ - (deltas)[2] = -(step), (deltas)[3] = -(step) - (nch), \ - (deltas)[4] = -(nch), (deltas)[5] = (step) - (nch), \ - (deltas)[6] = (step), (deltas)[7] = (step) + (nch)); - - -/* code of this node was heavily inspired by the smooth function of opencv library. -The main change is an optional image input */ -static void node_composit_exec_bilateralblur(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - NodeBilateralBlurData *nbbd= node->storage; - CompBuf *new, *source, *img= in[0]->data , *refimg= in[1]->data; - double mean0, w, i2sigma_color, i2sigma_space; - double mean1[4]; - double weight_tab[8]; - float *src, *dest, *ref, *temp_color, *ref_color; - float sigma_color, sigma_space; - int imgx, imgy, x, y, pix, i, step; - int deltas[8]; - short found_determinator= 0; - - if(img == NULL || out[0]->hasoutput == 0) - return; - - if(img->type != CB_RGBA) { - img= typecheck_compbuf(in[0]->data, CB_RGBA); - } - - imgx= img->x; - imgy= img->y; - pix= img->type; - step= pix * imgx; - - if(refimg) { - if(refimg->x == imgx && refimg->y == imgy) { - if(ELEM3(refimg->type, CB_VAL, CB_VEC2, CB_VEC3)) { - refimg= typecheck_compbuf(in[1]->data, CB_RGBA); - found_determinator= 1; - } - } - } - else { - refimg= img; - } - - /* allocs */ - source= dupalloc_compbuf(img); - new= alloc_compbuf(imgx, imgy, pix, 1); - - /* accept image offsets from other nodes */ - new->xof= img->xof; - new->yof= img->yof; - - /* bilateral code properties */ - sigma_color= nbbd->sigma_color; - sigma_space= nbbd->sigma_space; - - i2sigma_color= 1. / (sigma_color * sigma_color); - i2sigma_space= 1. / (sigma_space * sigma_space); - - INIT_3X3_DELTAS(deltas, step, pix); - - weight_tab[0] = weight_tab[2] = weight_tab[4] = weight_tab[6] = i2sigma_space; - weight_tab[1] = weight_tab[3] = weight_tab[5] = weight_tab[7] = i2sigma_space * 2; - - /* iterations */ - for(i= 0; i < nbbd->iter; i++) { - src= source->rect; - ref= refimg->rect; - dest= new->rect; - /*goes through image, there are more loops for 1st/last line and all other lines*/ - /*kernel element accumulates surrounding colors, which are then written with the update_output function*/ - for(x= 0; x < imgx; x++, src+= pix, ref+= pix) { - INIT_C3; - - KERNEL_ELEMENT_C3(6); - - if(x > 0) { - KERNEL_ELEMENT_C3(5); - KERNEL_ELEMENT_C3(4); - } - - if(x < imgx - 1) { - KERNEL_ELEMENT_C3(7); - KERNEL_ELEMENT_C3(0); - } - - UPDATE_OUTPUT_C3; - } - - dest+= step; - - for(y= 1; y < imgy - 1; y++, dest+= step, src+= pix, ref+= pix) { - x= 0; - - INIT_C3; - - KERNEL_ELEMENT_C3(0); - KERNEL_ELEMENT_C3(1); - KERNEL_ELEMENT_C3(2); - KERNEL_ELEMENT_C3(6); - KERNEL_ELEMENT_C3(7); - - UPDATE_OUTPUT_C3; - - src+= pix; - ref+= pix; - - for(x= 1; x < imgx - 1; x++, src+= pix, ref+= pix) { - INIT_C3; - - KERNEL_ELEMENT_C3(0); - KERNEL_ELEMENT_C3(1); - KERNEL_ELEMENT_C3(2); - KERNEL_ELEMENT_C3(3); - KERNEL_ELEMENT_C3(4); - KERNEL_ELEMENT_C3(5); - KERNEL_ELEMENT_C3(6); - KERNEL_ELEMENT_C3(7); - - UPDATE_OUTPUT_C3; - } - - INIT_C3; - - KERNEL_ELEMENT_C3(2); - KERNEL_ELEMENT_C3(3); - KERNEL_ELEMENT_C3(4); - KERNEL_ELEMENT_C3(5); - KERNEL_ELEMENT_C3(6); - - UPDATE_OUTPUT_C3; - } - - for(x= 0; x < imgx; x++, src+= pix, ref+= pix) { - INIT_C3; - - KERNEL_ELEMENT_C3(2); - - if(x > 0) { - KERNEL_ELEMENT_C3(3); - KERNEL_ELEMENT_C3(4); - } - if(x < imgx - 1) { - KERNEL_ELEMENT_C3(1); - KERNEL_ELEMENT_C3(0); - } - - UPDATE_OUTPUT_C3; - } - - if(node->exec & NODE_BREAK) break; - - SWAP(CompBuf, *source, *new); - } - - if(img != in[0]->data) - free_compbuf(img); - - if(found_determinator == 1) { - if(refimg != in[1]->data) - free_compbuf(refimg); - } - - out[0]->data= source; - - free_compbuf(new); -} - -static void node_composit_init_bilateralblur(bNode* node) -{ - NodeBilateralBlurData *nbbd= MEM_callocN(sizeof(NodeBilateralBlurData), "node bilateral blur data"); - node->storage= nbbd; - nbbd->sigma_color= 0.3; - nbbd->sigma_space= 5.0; -} - -void register_node_type_cmp_bilateralblur(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_BILATERALBLUR, "Bilateral Blur", NODE_CLASS_OP_FILTER, NODE_OPTIONS, - cmp_node_bilateralblur_in, cmp_node_bilateralblur_out); - node_type_size(&ntype, 150, 120, 200); - node_type_init(&ntype, node_composit_init_bilateralblur); - node_type_storage(&ntype, "NodeBilateralBlurData", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_bilateralblur); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_blur.c b/source/blender/nodes/intern/CMP_nodes/CMP_blur.c deleted file mode 100644 index 718578a921b..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_blur.c +++ /dev/null @@ -1,736 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Campbell Barton, Alfredo de Greef, David Millan Escriva, - * Juho Vepsäläinen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_blur.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** BLUR ******************** */ -static bNodeSocketType cmp_node_blur_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Size", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_blur_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static float *make_gausstab(int filtertype, int rad) -{ - float *gausstab, sum, val; - int i, n; - - n = 2 * rad + 1; - - gausstab = (float *) MEM_mallocN(n * sizeof(float), "gauss"); - - sum = 0.0f; - for (i = -rad; i <= rad; i++) { - val= RE_filter_value(filtertype, (float)i/(float)rad); - sum += val; - gausstab[i+rad] = val; - } - - sum= 1.0f/sum; - for(i=0; i<n; i++) - gausstab[i]*= sum; - - return gausstab; -} - -static float *make_bloomtab(int rad) -{ - float *bloomtab, val; - int i, n; - - n = 2 * rad + 1; - - bloomtab = (float *) MEM_mallocN(n * sizeof(float), "bloom"); - - for (i = -rad; i <= rad; i++) { - val = pow(1.0 - fabs((float)i)/((float)rad), 4.0); - bloomtab[i+rad] = val; - } - - return bloomtab; -} - -/* both input images of same type, either 4 or 1 channel */ -static void blur_single_image(bNode *node, CompBuf *new, CompBuf *img, float scale) -{ - NodeBlurData *nbd= node->storage; - CompBuf *work; - register float sum, val; - float rval, gval, bval, aval; - float *gausstab, *gausstabcent; - int rad, imgx= img->x, imgy= img->y; - int x, y, pix= img->type; - int i, bigstep; - float *src, *dest; - - /* helper image */ - work= alloc_compbuf(imgx, imgy, img->type, 1); /* allocs */ - - /* horizontal */ - if(nbd->sizex == 0) { - memcpy(work->rect, img->rect, sizeof(float) * img->type * imgx * imgy); - } - else { - rad = scale*(float)nbd->sizex; - if(rad>imgx/2) - rad= imgx/2; - else if(rad<1) - rad= 1; - - gausstab= make_gausstab(nbd->filtertype, rad); - gausstabcent= gausstab+rad; - - for (y = 0; y < imgy; y++) { - float *srcd= img->rect + pix*(y*img->x); - - dest = work->rect + pix*(y * img->x); - - for (x = 0; x < imgx ; x++) { - int minr= x-rad<0?-x:-rad; - int maxr= x+rad>imgx?imgx-x:rad; - - src= srcd + pix*(x+minr); - - sum= gval = rval= bval= aval= 0.0f; - for (i= minr; i < maxr; i++) { - val= gausstabcent[i]; - sum+= val; - rval += val * (*src++); - if(pix==4) { - gval += val * (*src++); - bval += val * (*src++); - aval += val * (*src++); - } - } - sum= 1.0f/sum; - *dest++ = rval*sum; - if(pix==4) { - *dest++ = gval*sum; - *dest++ = bval*sum; - *dest++ = aval*sum; - } - } - if(node->exec & NODE_BREAK) - break; - } - - /* vertical */ - MEM_freeN(gausstab); - } - - if(nbd->sizey == 0) { - memcpy(new->rect, work->rect, sizeof(float) * img->type * imgx * imgy); - } - else { - rad = scale*(float)nbd->sizey; - if(rad>imgy/2) - rad= imgy/2; - else if(rad<1) - rad= 1; - - gausstab= make_gausstab(nbd->filtertype, rad); - gausstabcent= gausstab+rad; - - bigstep = pix*imgx; - for (x = 0; x < imgx; x++) { - float *srcd= work->rect + pix*x; - - dest = new->rect + pix*x; - - for (y = 0; y < imgy ; y++) { - int minr= y-rad<0?-y:-rad; - int maxr= y+rad>imgy?imgy-y:rad; - - src= srcd + bigstep*(y+minr); - - sum= gval = rval= bval= aval= 0.0f; - for (i= minr; i < maxr; i++) { - val= gausstabcent[i]; - sum+= val; - rval += val * src[0]; - if(pix==4) { - gval += val * src[1]; - bval += val * src[2]; - aval += val * src[3]; - } - src += bigstep; - } - sum= 1.0f/sum; - dest[0] = rval*sum; - if(pix==4) { - dest[1] = gval*sum; - dest[2] = bval*sum; - dest[3] = aval*sum; - } - dest+= bigstep; - } - if(node->exec & NODE_BREAK) - break; - } - MEM_freeN(gausstab); - } - - free_compbuf(work); -} - -/* reference has to be mapped 0-1, and equal in size */ -static void bloom_with_reference(CompBuf *new, CompBuf *img, CompBuf *UNUSED(ref), float UNUSED(fac), NodeBlurData *nbd) -{ - CompBuf *wbuf; - register float val; - float radxf, radyf; - float **maintabs; - float *gausstabx, *gausstabcenty; - float *gausstaby, *gausstabcentx; - int radx, rady, imgx= img->x, imgy= img->y; - int x, y; - int i, j; - float *src, *dest, *wb; - - wbuf= alloc_compbuf(imgx, imgy, CB_VAL, 1); - - /* horizontal */ - radx = (float)nbd->sizex; - if(radx>imgx/2) - radx= imgx/2; - else if(radx<1) - radx= 1; - - /* vertical */ - rady = (float)nbd->sizey; - if(rady>imgy/2) - rady= imgy/2; - else if(rady<1) - rady= 1; - - x= MAX2(radx, rady); - maintabs= MEM_mallocN(x*sizeof(void *), "gauss array"); - for(i= 0; i<x; i++) - maintabs[i]= make_bloomtab(i+1); - - /* vars to store before we go */ -// refd= ref->rect; - src= img->rect; - - radxf= (float)radx; - radyf= (float)rady; - - 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)(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])); - - if(refradx>radx) refradx= radx; - else if(refradx<1) refradx= 1; - if(refrady>rady) refrady= rady; - else if(refrady<1) refrady= 1; - - if(refradx==1 && refrady==1) { - wb= wbuf->rect + ( y*imgx + x); - dest= new->rect + 4*( y*imgx + x); - wb[0]+= 1.0f; - dest[0] += src[0]; - dest[1] += src[1]; - dest[2] += src[2]; - dest[3] += src[3]; - } - else { - int minxr= x-refradx<0?-x:-refradx; - int maxxr= x+refradx>imgx?imgx-x:refradx; - int minyr= y-refrady<0?-y:-refrady; - int maxyr= y+refrady>imgy?imgy-y:refrady; - - float *destd= new->rect + 4*( (y + minyr)*imgx + x + minxr); - float *wbufd= wbuf->rect + ( (y + minyr)*imgx + x + minxr); - - gausstabx= maintabs[refradx-1]; - gausstabcentx= gausstabx+refradx; - gausstaby= maintabs[refrady-1]; - gausstabcenty= gausstaby+refrady; - - for (i= minyr; i < maxyr; i++, destd+= 4*imgx, wbufd+= imgx) { - dest= destd; - wb= wbufd; - for (j= minxr; j < maxxr; j++, dest+=4, wb++) { - - val= gausstabcenty[i]*gausstabcentx[j]; - wb[0]+= val; - dest[0] += val * src[0]; - dest[1] += val * src[1]; - dest[2] += val * src[2]; - dest[3] += val * src[3]; - } - } - } - } - } - - x= imgx*imgy; - dest= new->rect; - wb= wbuf->rect; - while(x--) { - val= 1.0f/wb[0]; - dest[0]*= val; - dest[1]*= val; - dest[2]*= val; - dest[3]*= val; - wb++; - dest+= 4; - } - - free_compbuf(wbuf); - - x= MAX2(radx, rady); - for(i= 0; i<x; i++) - MEM_freeN(maintabs[i]); - MEM_freeN(maintabs); - -} - -#if 0 -static float hexagon_filter(float fi, float fj) -{ - fi= fabs(fi); - fj= fabs(fj); - - if(fj>0.33f) { - fj= (fj-0.33f)/0.66f; - if(fi+fj>1.0f) - return 0.0f; - else - return 1.0f; - } - else return 1.0f; -} -#endif - -/* uses full filter, no horizontal/vertical optimize possible */ -/* both images same type, either 1 or 4 channels */ -static void bokeh_single_image(bNode *node, CompBuf *new, CompBuf *img, float fac) -{ - NodeBlurData *nbd= node->storage; - register float val; - float radxf, radyf; - float *gausstab, *dgauss; - int radx, rady, imgx= img->x, imgy= img->y; - int x, y, pix= img->type; - int i, j, n; - float *src= NULL, *dest, *srcd= NULL; - - /* horizontal */ - radxf = fac*(float)nbd->sizex; - if(radxf>imgx/2.0f) - radxf= imgx/2.0f; - else if(radxf<1.0f) - radxf= 1.0f; - - /* vertical */ - radyf = fac*(float)nbd->sizey; - if(radyf>imgy/2.0f) - radyf= imgy/2.0f; - else if(radyf<1.0f) - radyf= 1.0f; - - radx= ceil(radxf); - rady= ceil(radyf); - - n = (2*radx+1)*(2*rady+1); - - /* create a full filter image */ - gausstab= MEM_mallocN(sizeof(float)*n, "filter tab"); - dgauss= gausstab; - val= 0.0f; - for(j=-rady; j<=rady; j++) { - for(i=-radx; i<=radx; i++, dgauss++) { - float fj= (float)j/radyf; - float fi= (float)i/radxf; - float dist= sqrt(fj*fj + fi*fi); - - //*dgauss= hexagon_filter(fi, fj); - *dgauss= RE_filter_value(nbd->filtertype, dist); - - val+= *dgauss; - } - } - - if(val!=0.0f) { - val= 1.0f/val; - for(j= n -1; j>=0; j--) - gausstab[j]*= val; - } - else gausstab[4]= 1.0f; - - for (y = -rady+1; y < imgy+rady-1; y++) { - - if(y<=0) srcd= img->rect; - else if(y<imgy) srcd+= pix*imgx; - else srcd= img->rect + pix*(imgy-1)*imgx; - - for (x = -radx+1; x < imgx+radx-1 ; x++) { - int minxr= x-radx<0?-x:-radx; - int maxxr= x+radx>=imgx?imgx-x-1:radx; - int minyr= y-rady<0?-y:-rady; - int maxyr= y+rady>imgy-1?imgy-y-1:rady; - - float *destd= new->rect + pix*( (y + minyr)*imgx + x + minxr); - float *dgausd= gausstab + (minyr+rady)*(2*radx+1) + minxr+radx; - - if(x<=0) src= srcd; - else if(x<imgx) src+= pix; - else src= srcd + pix*(imgx-1); - - for (i= minyr; i <=maxyr; i++, destd+= pix*imgx, dgausd+= 2*radx + 1) { - dest= destd; - dgauss= dgausd; - for (j= minxr; j <=maxxr; j++, dest+=pix, dgauss++) { - val= *dgauss; - if(val!=0.0f) { - dest[0] += val * src[0]; - if(pix>1) { - dest[1] += val * src[1]; - dest[2] += val * src[2]; - dest[3] += val * src[3]; - } - } - } - } - } - if(node->exec & NODE_BREAK) - break; - } - - MEM_freeN(gausstab); -} - - -/* reference has to be mapped 0-1, and equal in size */ -static void blur_with_reference(bNode *node, CompBuf *new, CompBuf *img, CompBuf *ref) -{ - NodeBlurData *nbd= node->storage; - CompBuf *blurbuf, *ref_use; - register float sum, val; - float rval, gval, bval, aval, radxf, radyf; - float **maintabs; - float *gausstabx, *gausstabcenty; - float *gausstaby, *gausstabcentx; - int radx, rady, imgx= img->x, imgy= img->y; - int x, y, pix= img->type; - int i, j; - float *src, *dest, *refd, *blurd; - - if(ref->x!=img->x && ref->y!=img->y) - return; - - ref_use= typecheck_compbuf(ref, CB_VAL); - - /* trick is; we blur the reference image... but only works with clipped values*/ - blurbuf= alloc_compbuf(imgx, imgy, CB_VAL, 1); - blurd= blurbuf->rect; - refd= ref_use->rect; - for(x= imgx*imgy; x>0; x--, refd++, blurd++) { - if(refd[0]<0.0f) blurd[0]= 0.0f; - else if(refd[0]>1.0f) blurd[0]= 1.0f; - else blurd[0]= refd[0]; - } - - blur_single_image(node, blurbuf, blurbuf, 1.0f); - - /* horizontal */ - radx = (float)nbd->sizex; - if(radx>imgx/2) - radx= imgx/2; - else if(radx<1) - radx= 1; - - /* vertical */ - rady = (float)nbd->sizey; - if(rady>imgy/2) - rady= imgy/2; - else if(rady<1) - rady= 1; - - x= MAX2(radx, rady); - maintabs= MEM_mallocN(x*sizeof(void *), "gauss array"); - for(i= 0; i<x; i++) - maintabs[i]= make_gausstab(nbd->filtertype, i+1); - - refd= blurbuf->rect; - dest= new->rect; - radxf= (float)radx; - radyf= (float)rady; - - for (y = 0; y < imgy; y++) { - for (x = 0; x < imgx ; x++, dest+=pix, refd++) { - int refradx= (int)(refd[0]*radxf); - int refrady= (int)(refd[0]*radyf); - - if(refradx>radx) refradx= radx; - else if(refradx<1) refradx= 1; - if(refrady>rady) refrady= rady; - else if(refrady<1) refrady= 1; - - if(refradx==1 && refrady==1) { - src= img->rect + pix*( y*imgx + x); - if(pix==1) - dest[0]= src[0]; - else - QUATCOPY(dest, src); - } - else { - int minxr= x-refradx<0?-x:-refradx; - int maxxr= x+refradx>imgx?imgx-x:refradx; - int minyr= y-refrady<0?-y:-refrady; - int maxyr= y+refrady>imgy?imgy-y:refrady; - - float *srcd= img->rect + pix*( (y + minyr)*imgx + x + minxr); - - gausstabx= maintabs[refradx-1]; - gausstabcentx= gausstabx+refradx; - gausstaby= maintabs[refrady-1]; - gausstabcenty= gausstaby+refrady; - - sum= gval = rval= bval= aval= 0.0f; - - for (i= minyr; i < maxyr; i++, srcd+= pix*imgx) { - src= srcd; - for (j= minxr; j < maxxr; j++, src+=pix) { - - val= gausstabcenty[i]*gausstabcentx[j]; - sum+= val; - rval += val * src[0]; - if(pix>1) { - gval += val * src[1]; - bval += val * src[2]; - aval += val * src[3]; - } - } - } - sum= 1.0f/sum; - dest[0] = rval*sum; - if(pix>1) { - dest[1] = gval*sum; - dest[2] = bval*sum; - dest[3] = aval*sum; - } - } - } - if(node->exec & NODE_BREAK) - break; - } - - free_compbuf(blurbuf); - - x= MAX2(radx, rady); - for(i= 0; i<x; i++) - MEM_freeN(maintabs[i]); - MEM_freeN(maintabs); - - if(ref_use!=ref) - free_compbuf(ref_use); -} - -static void node_composit_exec_blur(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf *new, *img= in[0]->data; - NodeBlurData *nbd= node->storage; - - if(img==NULL) return; - - /* store image in size that is needed for absolute/relative conversions on ui level */ - nbd->image_in_width= img->x; - nbd->image_in_height= img->y; - - if(out[0]->hasoutput==0) return; - - if(nbd->relative) { - if (nbd->aspect==CMP_NODE_BLUR_ASPECT_NONE) { - nbd->sizex= (int)(nbd->percentx*0.01f*nbd->image_in_width); - nbd->sizey= (int)(nbd->percenty*0.01f*nbd->image_in_height); - } - else if (nbd->aspect==CMP_NODE_BLUR_ASPECT_Y) { - nbd->sizex= (int)(nbd->percentx*0.01f*nbd->image_in_width); - nbd->sizey= (int)(nbd->percenty*0.01f*nbd->image_in_width); - } - else if (nbd->aspect==CMP_NODE_BLUR_ASPECT_X) { - nbd->sizex= (int)(nbd->percentx*0.01f*nbd->image_in_height); - nbd->sizey= (int)(nbd->percenty*0.01f*nbd->image_in_height); - } - } - - if (nbd->sizex==0 && nbd->sizey==0) { - new= pass_on_compbuf(img); - out[0]->data= new; - } - else if (nbd->filtertype == R_FILTER_FAST_GAUSS) { - CompBuf *new, *img = in[0]->data; - // TODO: can this be mapped with reference, too? - const float sx = ((float)nbd->sizex*in[1]->vec[0])/2.0f, sy = ((float)nbd->sizey*in[1]->vec[0])/2.0f; - int c; - - if ((img==NULL) || (out[0]->hasoutput==0)) return; - - if (img->type == CB_VEC2) - new = typecheck_compbuf(img, CB_VAL); - else if (img->type == CB_VEC3) - new = typecheck_compbuf(img, CB_RGBA); - else - new = dupalloc_compbuf(img); - - if ((sx == sy) && (sx > 0.f)) { - for (c=0; c<new->type; ++c) - IIR_gauss(new, sx, c, 3); - } - else { - if (sx > 0.f) { - for (c=0; c<new->type; ++c) - IIR_gauss(new, sx, c, 1); - } - if (sy > 0.f) { - for (c=0; c<new->type; ++c) - IIR_gauss(new, sy, c, 2); - } - } - out[0]->data = new; - - } else { - /* All non fast gauss blur methods */ - if(img->type==CB_VEC2 || img->type==CB_VEC3) { - img= typecheck_compbuf(in[0]->data, CB_RGBA); - } - - /* if fac input, we do it different */ - if(in[1]->data) { - CompBuf *gammabuf; - - /* make output size of input image */ - new= alloc_compbuf(img->x, img->y, img->type, 1); /* allocs */ - - /* accept image offsets from other nodes */ - new->xof = img->xof; - new->yof = img->yof; - - if(nbd->gamma) { - gammabuf= dupalloc_compbuf(img); - gamma_correct_compbuf(gammabuf, 0); - } - else gammabuf= img; - - blur_with_reference(node, new, gammabuf, in[1]->data); - - if(nbd->gamma) { - gamma_correct_compbuf(new, 1); - free_compbuf(gammabuf); - } - if(node->exec & NODE_BREAK) { - free_compbuf(new); - new= NULL; - } - out[0]->data= new; - } - else { - - if(in[1]->vec[0]<=0.001f) { /* time node inputs can be a tiny value */ - new= pass_on_compbuf(img); - } - else { - CompBuf *gammabuf; - - /* make output size of input image */ - new= alloc_compbuf(img->x, img->y, img->type, 1); /* allocs */ - - /* accept image offsets from other nodes */ - new->xof = img->xof; - new->yof = img->yof; - - if(nbd->gamma) { - gammabuf= dupalloc_compbuf(img); - gamma_correct_compbuf(gammabuf, 0); - } - else gammabuf= img; - - if(nbd->bokeh) - bokeh_single_image(node, new, gammabuf, in[1]->vec[0]); - else if(1) - blur_single_image(node, new, gammabuf, in[1]->vec[0]); - else /* bloom experimental... */ - bloom_with_reference(new, gammabuf, NULL, in[1]->vec[0], nbd); - - if(nbd->gamma) { - gamma_correct_compbuf(new, 1); - free_compbuf(gammabuf); - } - if(node->exec & NODE_BREAK) { - free_compbuf(new); - new= NULL; - } - } - out[0]->data= new; - } - if(img!=in[0]->data) - free_compbuf(img); - } - - generate_preview(data, node, out[0]->data); -} - -static void node_composit_init_blur(bNode* node) -{ - node->storage= MEM_callocN(sizeof(NodeBlurData), "node blur data"); -} - -void register_node_type_cmp_blur(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_BLUR, "Blur", NODE_CLASS_OP_FILTER, NODE_PREVIEW|NODE_OPTIONS, - cmp_node_blur_in, cmp_node_blur_out); - node_type_size(&ntype, 120, 80, 200); - node_type_init(&ntype, node_composit_init_blur); - node_type_storage(&ntype, "NodeBlurData", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_blur); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_brightness.c b/source/blender/nodes/intern/CMP_nodes/CMP_brightness.c deleted file mode 100644 index 50a8d05b03d..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_brightness.c +++ /dev/null @@ -1,110 +0,0 @@ -/* -* $Id$ -* -* ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - -*/ - -/** \file blender/nodes/intern/CMP_nodes/CMP_brightness.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** Brigh and contrsast ******************** */ - -static bNodeSocketType cmp_node_brightcontrast_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Bright", 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f}, - { SOCK_VALUE, 1, "Contrast", 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_brightcontrast_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_brightnesscontrast(bNode *UNUSED(node), float *out, float *in, float *in_brightness, float *in_contrast) -{ - float i; - int c; - float a, b, v; - float brightness = (*in_brightness) / 100.0f; - float contrast = *in_contrast; - float delta = contrast / 200.0f; - a = 1.0f - delta * 2.0f; - /* - * The algorithm is by Werner D. Streidt - * (http://visca.com/ffactory/archives/5-99/msg00021.html) - * Extracted of OpenCV demhist.c - */ - if( contrast > 0 ) -{ - a = 1.0f / a; - b = a * (brightness - delta); - } - else - { - delta *= -1; - b = a * (brightness + delta); - } - - for(c=0; c<3; c++){ - i = in[c]; - v = a*i + b; - out[c] = v; - } -} - -static void node_composit_exec_brightcontrast(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - if(out[0]->hasoutput==0) - return; - - if(in[0]->data) { - CompBuf *stackbuf, *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA); - stackbuf= dupalloc_compbuf(cbuf); - composit3_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, do_brightnesscontrast, CB_RGBA, CB_VAL, CB_VAL); - out[0]->data = stackbuf; - if(cbuf != in[0]->data) - free_compbuf(cbuf); - } -} - -void register_node_type_cmp_brightcontrast(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_BRIGHTCONTRAST, "Bright/Contrast", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - cmp_node_brightcontrast_in, cmp_node_brightcontrast_out); - node_type_size(&ntype, 140, 100, 320); - node_type_exec(&ntype, node_composit_exec_brightcontrast); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_channelMatte.c b/source/blender/nodes/intern/CMP_nodes/CMP_channelMatte.c deleted file mode 100644 index e395716f36d..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_channelMatte.c +++ /dev/null @@ -1,217 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Bob Holcomb - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_channelMatte.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* ******************* Channel Matte Node ********************************* */ -static bNodeSocketType cmp_node_channel_matte_in[]={ - {SOCK_RGBA,1,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - {-1,0,""} -}; - -static bNodeSocketType cmp_node_channel_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 do_normalized_rgba_to_ycca2(bNode *UNUSED(node), float *out, float *in) -{ - /*normalize to the range 0.0 to 1.0) */ - rgb_to_ycc(in[0],in[1],in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601); - out[0]=(out[0])/255.0; - out[1]=(out[1])/255.0; - out[2]=(out[2])/255.0; - out[3]=in[3]; -} - -static void do_normalized_ycca_to_rgba2(bNode *UNUSED(node), float *out, float *in) -{ - /*un-normalize the normalize from above */ - in[0]=in[0]*255.0; - in[1]=in[1]*255.0; - in[2]=in[2]*255.0; - ycc_to_rgb(in[0],in[1],in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601); - out[3]=in[3]; -} - - -static void do_channel_matte(bNode *node, float *out, float *in) -{ - NodeChroma *c=(NodeChroma *)node->storage; - 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; - } - break; - } - default: - break; - } - - /*flip because 0.0 is transparent, not 1.0*/ - alpha=1-alpha; - - /* test range*/ - if(alpha>c->t1) { - alpha=in[3]; /*whatever it was prior */ - } - else if(alpha<c->t2){ - alpha=0.0; - } - else {/*blend */ - alpha=(alpha-c->t2)/(c->t1-c->t2); - } - - - /* don't make something that was more transparent less transparent */ - if (alpha<in[3]) { - out[3]=alpha; - } - else { - out[3]=in[3]; - } -} - -static void node_composit_exec_channel_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf *cbuf; - CompBuf *outbuf; - - if(in[0]->hasinput==0) return; - if(in[0]->data==NULL) return; - if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return; - - cbuf=typecheck_compbuf(in[0]->data, CB_RGBA); - - outbuf=dupalloc_compbuf(cbuf); - - /*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; - } - - /*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*/ - break; - case CMP_NODE_CHANNEL_MATTE_CS_HSV: /*HSV*/ - composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_hsva_to_rgba, CB_RGBA); - break; - case CMP_NODE_CHANNEL_MATTE_CS_YUV: /*YUV*/ - composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_yuva_to_rgba, CB_RGBA); - break; - case CMP_NODE_CHANNEL_MATTE_CS_YCC: /*YCC*/ - composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_normalized_ycca_to_rgba2, CB_RGBA); - break; - default: - break; - } - - generate_preview(data, node, outbuf); - out[0]->data=outbuf; - if(out[1]->hasoutput) - out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A); - - if(cbuf!=in[0]->data) - free_compbuf(cbuf); - -} - -static void node_composit_init_channel_matte(bNode *node) -{ - NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma"); - node->storage=c; - c->t1= 1.0f; - c->t2= 0.0f; - 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 */ -} - -void register_node_type_cmp_channel_matte(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_CHANNEL_MATTE, "Channel Key", NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS, - cmp_node_channel_matte_in, cmp_node_channel_matte_out); - node_type_size(&ntype, 200, 80, 250); - node_type_init(&ntype, node_composit_init_channel_matte); - node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_channel_matte); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_chromaMatte.c b/source/blender/nodes/intern/CMP_nodes/CMP_chromaMatte.c deleted file mode 100644 index 03230f2e212..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_chromaMatte.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_chromaMatte.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* ******************* Chroma Key ********************************************************** */ -static bNodeSocketType cmp_node_chroma_in[]={ - {SOCK_RGBA,1,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - {SOCK_RGBA,1,"Key Color", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - {-1,0,""} -}; - -static bNodeSocketType cmp_node_chroma_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 do_rgba_to_ycca_normalized(bNode *UNUSED(node), float *out, float *in) -{ - rgb_to_ycc(in[0],in[1],in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601); - - //normalize to 0..1.0 - out[0]=out[0]/255.0; - out[1]=out[1]/255.0; - out[2]=out[2]/255.0; - - //rescale to -1.0..1.0 - out[0]=(out[0]*2.0)-1.0; - out[1]=(out[1]*2.0)-1.0; - out[2]=(out[2]*2.0)-1.0; - -// out[0]=((out[0])-16)/255.0; -// out[1]=((out[1])-128)/255.0; -// out[2]=((out[2])-128)/255.0; - out[3]=in[3]; -} - -static void do_ycca_to_rgba_normalized(bNode *UNUSED(node), float *out, float *in) -{ - /*un-normalize the normalize from above */ - in[0]=(in[0]+1.0)/2.0; - in[1]=(in[1]+1.0)/2.0; - in[2]=(in[2]+1.0)/2.0; - - in[0]=(in[0]*255.0); - in[1]=(in[1]*255.0); - in[2]=(in[2]*255.0); - - // in[0]=(in[0]*255.0)+16; -// in[1]=(in[1]*255.0)+128; -// in[2]=(in[2]*255.0)+128; - ycc_to_rgb(in[0],in[1],in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601); - out[3]=in[3]; -} - -static void do_chroma_key(bNode *node, float *out, float *in) -{ - NodeChroma *c; - float x, z, alpha; - float theta, beta, angle, angle2; - float kfg; - - c=node->storage; - - /* Algorithm from book "Video Demistified," does not include the spill reduction part */ - - /* find theta, the angle that the color space should be rotated based on key*/ - theta=atan2(c->key[2], c->key[1]); - - /*rotate the cb and cr into x/z space */ - x=in[1]*cos(theta)+in[2]*sin(theta); - z=in[2]*cos(theta)-in[1]*sin(theta); - - /*if within the acceptance angle */ - angle=c->t1*M_PI/180.0; /* convert to radians */ - - /* if kfg is <0 then the pixel is outside of the key color */ - kfg=x-(fabs(z)/tan(angle/2.0)); - - out[0]=in[0]; - out[1]=in[1]; - out[2]=in[2]; - - if(kfg>0.0) { /* found a pixel that is within key color */ - alpha=(1.0-kfg)*(c->fstrength); - - beta=atan2(z,x); - angle2=c->t2*M_PI/180.0; - - /* if beta is within the cutoff angle */ - if(fabs(beta)<(angle2/2.0)) { - alpha=0.0; - } - - /* don't make something that was more transparent less transparent */ - if (alpha<in[3]) { - out[3]=alpha; - } - else { - out[3]=in[3]; - } - } - else { /*pixel is outside key color */ - out[0]=in[0]; - out[1]=in[1]; - out[2]=in[2]; - out[3]=in[3]; /* make pixel just as transparent as it was before */ - } -} - -static void node_composit_exec_chroma_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf *cbuf; - CompBuf *chromabuf; - NodeChroma *c; - - if(in[0]->hasinput==0) return; - if(in[0]->data==NULL) return; - if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return; - - cbuf= typecheck_compbuf(in[0]->data, CB_RGBA); - - chromabuf= dupalloc_compbuf(cbuf); - - c=node->storage; - - /*convert rgbbuf to normalized chroma space*/ - composit1_pixel_processor(node, chromabuf, cbuf, in[0]->vec, do_rgba_to_ycca_normalized, CB_RGBA); - /*convert key to normalized chroma color space */ - do_rgba_to_ycca_normalized(node, c->key, in[1]->vec); - - /*per pixel chroma key*/ - composit1_pixel_processor(node, chromabuf, chromabuf, in[0]->vec, do_chroma_key, CB_RGBA); - - /*convert back*/ - composit1_pixel_processor(node, chromabuf, chromabuf, in[0]->vec, do_ycca_to_rgba_normalized, CB_RGBA); - - out[0]->data= chromabuf; - if(out[1]->hasoutput) - out[1]->data= valbuf_from_rgbabuf(chromabuf, CHAN_A); - - generate_preview(data, node, chromabuf); - - if(cbuf!=in[0]->data) - free_compbuf(cbuf); -} - - -static void node_composit_init_chroma_matte(bNode *node) -{ - NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma"); - node->storage= c; - c->t1= 30.0f; - c->t2= 10.0f; - c->t3= 0.0f; - c->fsize= 0.0f; - c->fstrength= 1.0f; -} - -void register_node_type_cmp_chroma_matte(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_CHROMA_MATTE, "Chroma Key", NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS, - cmp_node_chroma_in, cmp_node_chroma_out); - node_type_size(&ntype, 200, 80, 300); - node_type_init(&ntype, node_composit_init_chroma_matte); - node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_chroma_matte); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_colorMatte.c b/source/blender/nodes/intern/CMP_nodes/CMP_colorMatte.c deleted file mode 100644 index 55d77a902b9..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_colorMatte.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Bob Holcomb - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_colorMatte.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* ******************* Color Key ********************************************************** */ -static bNodeSocketType cmp_node_color_in[]={ - {SOCK_RGBA,1,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - {SOCK_RGBA,1,"Key Color", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - {-1,0,""} -}; - -static bNodeSocketType cmp_node_color_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 do_color_key(bNode *node, float *out, float *in) -{ - float h_wrap; - NodeChroma *c; - c=node->storage; - - - VECCOPY(out, in); - - if( - /* do hue last because it needs to wrap, and does some more checks */ - - /* sat */ (fabs(in[1]-c->key[1]) < c->t2) && - /* val */ (fabs(in[2]-c->key[2]) < c->t3) && - - /* multiply by 2 because it wraps on both sides of the hue, - * otherwise 0.5 would key all hue's */ - - /* hue */ ((h_wrap= 2.0f * fabs(in[0]-c->key[0])) < c->t1 || (2.0f - h_wrap) < c->t1) - ) { - out[3]=0.0; /*make transparent*/ - } - - else { /*pixel is outside key color */ - out[3]=in[3]; /* make pixel just as transparent as it was before */ - } -} - -static void node_composit_exec_color_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf *cbuf; - CompBuf *colorbuf; - NodeChroma *c; - - if(in[0]->hasinput==0) return; - if(in[0]->data==NULL) return; - if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return; - - cbuf= typecheck_compbuf(in[0]->data, CB_RGBA); - - colorbuf= dupalloc_compbuf(cbuf); - - c=node->storage; - - /*convert rgbbuf to hsv*/ - composit1_pixel_processor(node, colorbuf, cbuf, in[0]->vec, do_rgba_to_hsva, CB_RGBA); - - /*convert key to hsv*/ - do_rgba_to_hsva(node, c->key, in[1]->vec); - - - /*per pixel color key*/ - composit1_pixel_processor(node, colorbuf, colorbuf, in[0]->vec, do_color_key, CB_RGBA); - - /*convert back*/ - composit1_pixel_processor(node, colorbuf, colorbuf, in[0]->vec, do_hsva_to_rgba, CB_RGBA); - - out[0]->data= colorbuf; - if(out[1]->hasoutput) - out[1]->data= valbuf_from_rgbabuf(colorbuf, CHAN_A); - - generate_preview(data, node, colorbuf); - - if(cbuf!=in[0]->data) - free_compbuf(cbuf); -} - -static void node_composit_init_color_matte(bNode *node) -{ - NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node color"); - node->storage= c; - c->t1= 0.01f; - c->t2= 0.1f; - c->t3= 0.1f; - c->fsize= 0.0f; - c->fstrength= 1.0f; -} - -void register_node_type_cmp_color_matte(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_COLOR_MATTE, "Color Key", NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS, - cmp_node_color_in, cmp_node_color_out); - node_type_size(&ntype, 200, 80, 300); - node_type_init(&ntype, node_composit_init_color_matte); - node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_color_matte); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_colorSpill.c b/source/blender/nodes/intern/CMP_nodes/CMP_colorSpill.c deleted file mode 100644 index 905d97709c3..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_colorSpill.c +++ /dev/null @@ -1,341 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Bob Holcomb, Xavier Thomas - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_colorSpill.c - * \ingroup cmpnodes - */ - - - -#include "../CMP_util.h" - -#define avg(a,b) ((a+b)/2) - -/* ******************* 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}, - {SOCK_VALUE, 1, "Fac", 1.0f, 0.0f, 0.0f, 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 do_simple_spillmap_red(bNode *node, float* out, float *in) -{ - NodeColorspill *ncs; - ncs=node->storage; - out[0]=in[0]-( ncs->limscale * in[ncs->limchan] ); -} - -static void do_simple_spillmap_red_fac(bNode *node, float* out, float *in, float *fac) -{ - NodeColorspill *ncs; - ncs=node->storage; - - out[0] = *fac * (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_green_fac(bNode *node, float* out, float *in, float *fac) -{ - NodeColorspill *ncs; - ncs=node->storage; - - out[0] = *fac * (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_simple_spillmap_blue_fac(bNode *node, float* out, float *in, float *fac) -{ - NodeColorspill *ncs; - ncs=node->storage; - - out[0] = *fac * (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_red_fac(bNode *node, float* out, float *in, float *fac) -{ - NodeColorspill *ncs; - ncs=node->storage; - - out[0] = *fac * (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_green_fac(bNode *node, float* out, float *in, float *fac) -{ - NodeColorspill *ncs; - ncs=node->storage; - - out[0] = *fac * (in[0]-(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_average_spillmap_blue_fac(bNode *node, float* out, float *in, float *fac) -{ - NodeColorspill *ncs; - ncs=node->storage; - - out[0] = *fac * (in[0]-(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_apply_spillmap_green(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_apply_spillmap_blue(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 node_composit_exec_color_spill(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* Originally based on the information from the book "The Art and Science of Digital Composition" and - * discussions from vfxtalk.com .*/ - CompBuf *cbuf; - CompBuf *mask; - CompBuf *rgbbuf; - CompBuf *spillmap; - NodeColorspill *ncs; - ncs=node->storage; - - /* early out for missing connections */ - if(out[0]->hasoutput==0 ) return; - if(in[0]->hasinput==0) return; - if(in[0]->data==NULL) return; - - cbuf=typecheck_compbuf(in[0]->data, CB_RGBA); - mask=typecheck_compbuf(in[1]->data, CB_VAL); - spillmap=alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); - rgbbuf=dupalloc_compbuf(cbuf); - - switch(node->custom1) - { - case 1: /*red spill*/ - { - switch(node->custom2) - { - case 0: /* simple limit */ - { - if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) { - composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_red, CB_RGBA); - } else { - composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_simple_spillmap_red_fac, CB_RGBA, CB_VAL); - } - break; - } - case 1: /* average limit */ - { - if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) { - composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_red, CB_RGBA); - } else { - composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_average_spillmap_red_fac, CB_RGBA, CB_VAL); - } - 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*/ - { - switch(node->custom2) - { - case 0: /* simple limit */ - { - if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) { - composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_green, CB_RGBA); - } else { - composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_simple_spillmap_green_fac, CB_RGBA, CB_VAL); - } - break; - } - case 1: /* average limit */ - { - if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) { - composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_green, CB_RGBA); - } else { - composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_average_spillmap_green_fac, CB_RGBA, CB_VAL); - } - 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*/ - { - switch(node->custom2) - { - case 0: /* simple limit */ - { - if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) { - composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_blue, CB_RGBA); - } else { - composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_simple_spillmap_blue_fac, CB_RGBA, CB_VAL); - } - break; - } - case 1: /* average limit */ - { - if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) { - composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_blue, CB_RGBA); - } else { - composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_average_spillmap_blue_fac, CB_RGBA, CB_VAL); - } - 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: - break; - } - - out[0]->data=rgbbuf; - - if(cbuf!=in[0]->data) - free_compbuf(cbuf); - - free_compbuf(spillmap); -} - -static void node_composit_init_color_spill(bNode *node) -{ - 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 */ -} - -void register_node_type_cmp_color_spill(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_COLOR_SPILL, "Color Spill", NODE_CLASS_MATTE, NODE_OPTIONS, - cmp_node_color_spill_in, cmp_node_color_spill_out); - node_type_size(&ntype, 140, 80, 200); - node_type_init(&ntype, node_composit_init_color_spill); - node_type_storage(&ntype, "NodeColorspill", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_color_spill); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_colorbalance.c b/source/blender/nodes/intern/CMP_nodes/CMP_colorbalance.c deleted file mode 100644 index 4074ea2fa29..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_colorbalance.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - * - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Matt Ebb. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_colorbalance.c - * \ingroup cmpnodes - */ - - - -#include "../CMP_util.h" - - -/* ******************* Color Balance ********************************* */ -static bNodeSocketType cmp_node_colorbalance_in[]={ - {SOCK_VALUE, 1, "Fac", 1.0f, 0.0f, 0.0f, 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_colorbalance_out[]={ - {SOCK_RGBA,0,"Image", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, - {-1,0,""} -}; - -/* this function implements ASC-CDL according to the spec at http://www.asctech.org/ - Slope - S = in * slope - Offset - O = S + offset - = (in * slope) + offset - Power - out = Clamp(O) ^ power - = Clamp((in * slope) + offset) ^ power - */ -DO_INLINE float colorbalance_cdl(float in, float offset, float power, float slope) -{ - float x = in * slope + offset; - - /* prevent NaN */ - CLAMP(x, 0.0, 1.0); - - return powf(x, power); -} - -/* note: lift_lgg is just 2-lift, gamma_inv is 1.0/gamma */ -DO_INLINE float colorbalance_lgg(float in, float lift_lgg, float gamma_inv, float gain) -{ - /* 1:1 match with the sequencer with linear/srgb conversions, the conversion isnt pretty - * but best keep it this way, sice testing for durian shows a similar calculation - * without lin/srgb conversions gives bad results (over-saturated shadows) with colors - * slightly below 1.0. some correction can be done but it ends up looking bad for shadows or lighter tones - campbell */ - float x= (((linearrgb_to_srgb(in) - 1.0f) * lift_lgg) + 1.0f) * gain; - - /* prevent NaN */ - if (x < 0.f) x = 0.f; - - return powf(srgb_to_linearrgb(x), gamma_inv); -} - -static void do_colorbalance_cdl(bNode *node, float* out, float *in) -{ - NodeColorBalance *n= (NodeColorBalance *)node->storage; - - out[0] = colorbalance_cdl(in[0], n->lift[0], n->gamma[0], n->gain[0]); - out[1] = colorbalance_cdl(in[1], n->lift[1], n->gamma[1], n->gain[1]); - out[2] = colorbalance_cdl(in[2], n->lift[2], n->gamma[2], n->gain[2]); - out[3] = in[3]; -} - -static void do_colorbalance_cdl_fac(bNode *node, float* out, float *in, float *fac) -{ - NodeColorBalance *n= (NodeColorBalance *)node->storage; - const float mfac= 1.0f - *fac; - - out[0] = mfac*in[0] + *fac * colorbalance_cdl(in[0], n->lift[0], n->gamma[0], n->gain[0]); - out[1] = mfac*in[1] + *fac * colorbalance_cdl(in[1], n->lift[1], n->gamma[1], n->gain[1]); - out[2] = mfac*in[2] + *fac * colorbalance_cdl(in[2], n->lift[2], n->gamma[2], n->gain[2]); - out[3] = in[3]; -} - -static void do_colorbalance_lgg(bNode *node, float* out, float *in) -{ - NodeColorBalance *n= (NodeColorBalance *)node->storage; - - out[0] = colorbalance_lgg(in[0], n->lift_lgg[0], n->gamma_inv[0], n->gain[0]); - out[1] = colorbalance_lgg(in[1], n->lift_lgg[1], n->gamma_inv[1], n->gain[1]); - out[2] = colorbalance_lgg(in[2], n->lift_lgg[2], n->gamma_inv[2], n->gain[2]); - out[3] = in[3]; -} - -static void do_colorbalance_lgg_fac(bNode *node, float* out, float *in, float *fac) -{ - NodeColorBalance *n= (NodeColorBalance *)node->storage; - const float mfac= 1.0f - *fac; - - out[0] = mfac*in[0] + *fac * colorbalance_lgg(in[0], n->lift_lgg[0], n->gamma_inv[0], n->gain[0]); - out[1] = mfac*in[1] + *fac * colorbalance_lgg(in[1], n->lift_lgg[1], n->gamma_inv[1], n->gain[1]); - out[2] = mfac*in[2] + *fac * colorbalance_lgg(in[2], n->lift_lgg[2], n->gamma_inv[2], n->gain[2]); - out[3] = in[3]; -} - -static void node_composit_exec_colorbalance(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf *cbuf= in[1]->data; - CompBuf *stackbuf; - - /* stack order input: fac, image */ - /* stack order output: image */ - if(out[0]->hasoutput==0) return; - - if(in[0]->vec[0] == 0.f && in[0]->data == NULL) { - out[0]->data = pass_on_compbuf(cbuf); - return; - } - - { - NodeColorBalance *n= (NodeColorBalance *)node->storage; - int c; - - for (c = 0; c < 3; c++) { - n->lift_lgg[c] = 2.0f - n->lift[c]; - n->gamma_inv[c] = (n->gamma[c] != 0.0f) ? 1.0f/n->gamma[c] : 1000000.0f; - } - } - - if (cbuf) { - stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* create output based on image input */ - - if (node->custom1 == 0) { - /* lift gamma gain */ - if ((in[0]->data==NULL) && (in[0]->vec[0] >= 1.f)) { - composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_colorbalance_lgg, CB_RGBA); - } - else { - composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_colorbalance_lgg_fac, CB_RGBA, CB_VAL); - } - } else { - /* offset/power/slope : ASC-CDL */ - if ((in[0]->data==NULL) && (in[0]->vec[0] >= 1.f)) { - composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_colorbalance_cdl, CB_RGBA); - } - else { - composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_colorbalance_cdl_fac, CB_RGBA, CB_VAL); - } - - } - - out[0]->data=stackbuf; - } -} - -static void node_composit_init_colorbalance(bNode *node) -{ - NodeColorBalance *n= node->storage= MEM_callocN(sizeof(NodeColorBalance), "node colorbalance"); - - n->lift[0] = n->lift[1] = n->lift[2] = 1.0f; - n->gamma[0] = n->gamma[1] = n->gamma[2] = 1.0f; - n->gain[0] = n->gain[1] = n->gain[2] = 1.0f; -} - -void register_node_type_cmp_colorbalance(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_COLORBALANCE, "Color Balance", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - cmp_node_colorbalance_in, cmp_node_colorbalance_out); - node_type_size(&ntype, 400, 200, 400); - node_type_init(&ntype, node_composit_init_colorbalance); - node_type_storage(&ntype, "NodeColorBalance", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_colorbalance); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_composite.c b/source/blender/nodes/intern/CMP_nodes/CMP_composite.c deleted file mode 100644 index fb68f56ae64..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_composite.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_composite.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - - -/* **************** COMPOSITE ******************** */ -static bNodeSocketType cmp_node_composite_in[]= { - { SOCK_RGBA, 1, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Z", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -/* applies to render pipeline */ -static void node_composit_exec_composite(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out)) -{ - /* image assigned to output */ - /* stack order input sockets: col, alpha, z */ - - if(node->flag & NODE_DO_OUTPUT) { /* only one works on out */ - Scene *scene= (Scene *)node->id; - RenderData *rd= data; - - if(scene && (rd->scemode & R_DOCOMP)) { - Render *re= RE_GetRender(scene->id.name); - RenderResult *rr= RE_AcquireResultWrite(re); - if(rr) { - CompBuf *outbuf, *zbuf=NULL; - - if(rr->rectf) - MEM_freeN(rr->rectf); - outbuf= alloc_compbuf(rr->rectx, rr->recty, CB_RGBA, 1); - - if(in[1]->data==NULL) - composit1_pixel_processor(node, outbuf, in[0]->data, in[0]->vec, do_copy_rgba, CB_RGBA); - else - composit2_pixel_processor(node, outbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_copy_a_rgba, CB_RGBA, CB_VAL); - - if(in[2]->data) { - if(rr->rectz) - MEM_freeN(rr->rectz); - zbuf= alloc_compbuf(rr->rectx, rr->recty, CB_VAL, 1); - composit1_pixel_processor(node, zbuf, in[2]->data, in[2]->vec, do_copy_value, CB_VAL); - rr->rectz= zbuf->rect; - zbuf->malloc= 0; - free_compbuf(zbuf); - } - generate_preview(data, node, outbuf); - - /* we give outbuf to rr... */ - rr->rectf= outbuf->rect; - outbuf->malloc= 0; - free_compbuf(outbuf); - - /* signal for imageviewer to refresh (it converts to byte rects...) */ - BKE_image_signal(BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"), NULL, IMA_SIGNAL_FREE); - - RE_ReleaseResult(re); - return; - } - else - RE_ReleaseResult(re); - } - } - if(in[0]->data) - generate_preview(data, node, in[0]->data); -} - -void register_node_type_cmp_composite(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_COMPOSITE, "Composite", NODE_CLASS_OUTPUT, NODE_PREVIEW, - cmp_node_composite_in, NULL); - node_type_size(&ntype, 80, 60, 200); - node_type_exec(&ntype, node_composit_exec_composite); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_crop.c b/source/blender/nodes/intern/CMP_nodes/CMP_crop.c deleted file mode 100644 index 0331217f0cb..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_crop.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Juho Vepsäläinen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_crop.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** Crop ******************** */ - -static bNodeSocketType cmp_node_crop_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_crop_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_composit_exec_crop(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - if(in[0]->data) { - NodeTwoXYs *ntxy= node->storage; - CompBuf *cbuf= in[0]->data; - CompBuf *stackbuf; - int x, y; - float *srcfp, *outfp; - rcti outputrect; - - if(node->custom2) { - ntxy->x1= cbuf->x* ntxy->fac_x1; - ntxy->x2= cbuf->x* ntxy->fac_x2; - ntxy->y1= cbuf->y* ntxy->fac_y1; - ntxy->y2= cbuf->y* ntxy->fac_y2; - } - - /* check input image size */ - if(cbuf->x <= ntxy->x1 + 1) - ntxy->x1= cbuf->x - 1; - - if(cbuf->y <= ntxy->y1 + 1) - ntxy->y1= cbuf->y - 1; - - if(cbuf->x <= ntxy->x2 + 1) - ntxy->x2= cbuf->x - 1; - - if(cbuf->y <= ntxy->y2 + 1) - ntxy->y2= cbuf->y - 1; - - /* figure out the minimums and maximums */ - outputrect.xmax=MAX2(ntxy->x1, ntxy->x2) + 1; - outputrect.xmin=MIN2(ntxy->x1, ntxy->x2); - outputrect.ymax=MAX2(ntxy->y1, ntxy->y2) + 1; - outputrect.ymin=MIN2(ntxy->y1, ntxy->y2); - - if(node->custom1) { - /* this option crops the image size too */ - stackbuf= get_cropped_compbuf(&outputrect, cbuf->rect, cbuf->x, cbuf->y, cbuf->type); - } - else { - /* this option won't crop the size of the image as well */ - /* allocate memory for the output image */ - stackbuf = alloc_compbuf(cbuf->x, cbuf->y, cbuf->type, 1); - - /* select the cropped part of the image and set it to the output */ - for(y=outputrect.ymin; y<outputrect.ymax; y++){ - srcfp= cbuf->rect + (y * cbuf->x + outputrect.xmin) * cbuf->type; - outfp= stackbuf->rect + (y * stackbuf->x + outputrect.xmin) * stackbuf->type; - for(x=outputrect.xmin; x<outputrect.xmax; x++, outfp+= stackbuf->type, srcfp+= cbuf->type) - memcpy(outfp, srcfp, sizeof(float)*stackbuf->type); - } - } - - out[0]->data= stackbuf; - } -} - -static void node_composit_init_crop(bNode* node) -{ - NodeTwoXYs *nxy= MEM_callocN(sizeof(NodeTwoXYs), "node xy data"); - node->storage= nxy; - nxy->x1= 0; - nxy->x2= 0; - nxy->y1= 0; - nxy->y2= 0; -} - -void register_node_type_cmp_crop(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_CROP, "Crop", NODE_CLASS_DISTORT, NODE_OPTIONS, - cmp_node_crop_in, cmp_node_crop_out); - node_type_size(&ntype, 140, 100, 320); - node_type_init(&ntype, node_composit_init_crop); - node_type_storage(&ntype, "NodeTwoXYs", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_crop); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_curves.c b/source/blender/nodes/intern/CMP_nodes/CMP_curves.c deleted file mode 100644 index 921c5e21fea..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_curves.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Björn C. Schaefer - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_curves.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** CURVE Time ******************** */ - -/* custom1 = sfra, custom2 = efra */ -static bNodeSocketType cmp_node_time_out[]= { - { SOCK_VALUE, 0, "Fac", 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_composit_exec_curves_time(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out) -{ - RenderData *rd= data; - /* stack order output: fac */ - float fac= 0.0f; - - if(node->custom1 < node->custom2) - fac= (rd->cfra - node->custom1)/(float)(node->custom2-node->custom1); - - fac= curvemapping_evaluateF(node->storage, 0, fac); - out[0]->vec[0]= CLAMPIS(fac, 0.0f, 1.0f); -} - - -static void node_composit_init_curves_time(bNode* node) -{ - node->custom1= 1; - node->custom2= 250; - node->storage= curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); -} - -void register_node_type_cmp_curve_time(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_TIME, "Time", NODE_CLASS_INPUT, NODE_OPTIONS, - NULL, cmp_node_time_out); - node_type_size(&ntype, 140, 100, 320); - node_type_init(&ntype, node_composit_init_curves_time); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - node_type_exec(&ntype, node_composit_exec_curves_time); - - nodeRegisterType(lb, &ntype); -} - - - - -/* **************** CURVE VEC ******************** */ -static bNodeSocketType cmp_node_curve_vec_in[]= { - { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType cmp_node_curve_vec_out[]= { - { SOCK_VECTOR, 0, "Vector", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_composit_exec_curve_vec(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order input: vec */ - /* stack order output: vec */ - - curvemapping_evaluate_premulRGBF(node->storage, out[0]->vec, in[0]->vec); -} - -static void node_composit_init_curve_vec(bNode* node) -{ - node->storage= curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f); -} - -void register_node_type_cmp_curve_vec(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_CURVE_VEC, "Vector Curves", NODE_CLASS_OP_VECTOR, NODE_OPTIONS, - cmp_node_curve_vec_in, cmp_node_curve_vec_out); - node_type_size(&ntype, 200, 140, 320); - node_type_init(&ntype, node_composit_init_curve_vec); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - node_type_exec(&ntype, node_composit_exec_curve_vec); - - nodeRegisterType(lb, &ntype); -} - - -/* **************** CURVE RGB ******************** */ -static bNodeSocketType cmp_node_curve_rgb_in[]= { - { SOCK_VALUE, 1, "Fac", 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { SOCK_RGBA, 1, "Image", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { SOCK_RGBA, 1, "Black Level", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { SOCK_RGBA, 1, "White Level", 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType cmp_node_curve_rgb_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_curves(bNode *node, float *out, float *in) -{ - curvemapping_evaluate_premulRGBF(node->storage, out, in); - out[3]= in[3]; -} - -static void do_curves_fac(bNode *node, float *out, float *in, float *fac) -{ - - if(*fac>=1.0) - curvemapping_evaluate_premulRGBF(node->storage, out, in); - else if(*fac<=0.0) { - VECCOPY(out, in); - } - else { - float col[4], mfac= 1.0f-*fac; - curvemapping_evaluate_premulRGBF(node->storage, col, in); - out[0]= mfac*in[0] + *fac*col[0]; - out[1]= mfac*in[1] + *fac*col[1]; - out[2]= mfac*in[2] + *fac*col[2]; - } - out[3]= in[3]; -} - -static void node_composit_exec_curve_rgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order input: fac, image, black level, white level */ - /* stack order output: image */ - - if(out[0]->hasoutput==0) - return; - - /* input no image? then only color operation */ - if(in[1]->data==NULL) { - curvemapping_evaluateRGBF(node->storage, out[0]->vec, in[1]->vec); - } - else { - /* make output size of input image */ - CompBuf *cbuf= in[1]->data; - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ - - curvemapping_set_black_white(node->storage, in[2]->vec, in[3]->vec); - - if(in[0]->vec[0] == 1.0) - composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_curves, CB_RGBA); - else - composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_curves_fac, CB_RGBA, CB_VAL); - - out[0]->data= stackbuf; - } - -} - -static void node_composit_init_curve_rgb(bNode* node) -{ - node->storage= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f); -} - -void register_node_type_cmp_curve_rgb(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - cmp_node_curve_rgb_in, cmp_node_curve_rgb_out); - node_type_size(&ntype, 200, 140, 320); - node_type_init(&ntype, node_composit_init_curve_rgb); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - node_type_exec(&ntype, node_composit_exec_curve_rgb); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_defocus.c b/source/blender/nodes/intern/CMP_nodes/CMP_defocus.c deleted file mode 100644 index f249e2cff6c..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_defocus.c +++ /dev/null @@ -1,892 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_defocus.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* ************ qdn: Defocus node ****************** */ -static bNodeSocketType cmp_node_defocus_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Z", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_defocus_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - - -// line coefs for point sampling & scancon. data. -typedef struct BokehCoeffs { - float x0, y0, dx, dy; - float ls_x, ls_y; - float min_x, min_y, max_x, max_y; -} BokehCoeffs; - -// returns array of BokehCoeffs -// returns length of array in 'len_bkh', -// radius squared of inscribed disk in 'inradsq', needed in getWeight() test, -// BKH[8] is the data returned for the bokeh shape & bkh_b[4] is it's 2d bound -static void makeBokeh(char bktype, char ro, int* len_bkh, float* inradsq, BokehCoeffs BKH[8], float bkh_b[4]) -{ - float x0, x1, y0, y1, dx, dy, iDxy; - float w = MAX2(1e-5f, ro)*M_PI/180.f; // never reported stangely enough, but a zero offset causes missing center line... - float wi = (360.f/bktype)*M_PI/180.f; - int i, ov, nv; - - // bktype must be at least 3 & <= 8 - bktype = (bktype<3) ? 3 : ((bktype>8) ? 8 : bktype); - *len_bkh = bktype; - *inradsq = -1.f; - - for (i=0; i<(*len_bkh); i++) { - x0 = cos(w); - y0 = sin(w); - w += wi; - x1 = cos(w); - y1 = sin(w); - if ((*inradsq)<0.f) { - // radius squared of inscribed disk - float idx=(x0+x1)*0.5f, idy=(y0+y1)*0.5f; - *inradsq = idx*idx + idy*idy; - } - BKH[i].x0 = x0; - BKH[i].y0 = y0; - dx = x1-x0, dy = y1-y0; - iDxy = 1.f / sqrt(dx*dx + dy*dy); - dx *= iDxy; - dy *= iDxy; - BKH[i].dx = dx; - BKH[i].dy = dy; - } - - // precalc scanconversion data - // bokeh bound, not transformed, for scanconvert - bkh_b[0] = bkh_b[2] = 1e10f; // xmin/ymin - bkh_b[1] = bkh_b[3] = -1e10f; // xmax/ymax - ov = (*len_bkh) - 1; - for (nv=0; nv<(*len_bkh); nv++) { - bkh_b[0] = MIN2(bkh_b[0], BKH[nv].x0); // xmin - bkh_b[1] = MAX2(bkh_b[1], BKH[nv].x0); // xmax - bkh_b[2] = MIN2(bkh_b[2], BKH[nv].y0); // ymin - bkh_b[3] = MAX2(bkh_b[3], BKH[nv].y0); // ymax - BKH[nv].min_x = MIN2(BKH[ov].x0, BKH[nv].x0); - BKH[nv].max_x = MAX2(BKH[ov].x0, BKH[nv].x0); - BKH[nv].min_y = MIN2(BKH[ov].y0, BKH[nv].y0); - BKH[nv].max_y = MAX2(BKH[ov].y0, BKH[nv].y0); - dy = BKH[nv].y0 - BKH[ov].y0; - BKH[nv].ls_x = (BKH[nv].x0 - BKH[ov].x0) / ((dy==0.f) ? 1.f : dy); - BKH[nv].ls_y = (BKH[nv].ls_x==0.f) ? 1.f : (1.f/BKH[nv].ls_x); - ov = nv; - } -} - -// test if u/v inside shape & returns weight value -static float getWeight(BokehCoeffs* BKH, int len_bkh, float u, float v, float rad, float inradsq) -{ - BokehCoeffs* bc = BKH; - float cdist, irad = (rad==0.f) ? 1.f : (1.f/rad); - u *= irad; - v *= irad; - - // early out test1: if point outside outer unit disk, it cannot be inside shape - cdist = u*u + v*v; - if (cdist>1.f) return 0.f; - - // early out test2: if point inside or on inner disk, point must be inside shape - if (cdist<=inradsq) return 1.f; - - while (len_bkh--) { - if ((bc->dy*(u - bc->x0) - bc->dx*(v - bc->y0)) > 0.f) return 0.f; - bc++; - } - return 1.f; -} - -// QMC.seq. for sampling, A.Keller, EMS -static float RI_vdC(unsigned int bits, unsigned int r) -{ - bits = ( bits << 16) | ( bits >> 16); - bits = ((bits & 0x00ff00ff) << 8) | ((bits & 0xff00ff00) >> 8); - bits = ((bits & 0x0f0f0f0f) << 4) | ((bits & 0xf0f0f0f0) >> 4); - bits = ((bits & 0x33333333) << 2) | ((bits & 0xcccccccc) >> 2); - bits = ((bits & 0x55555555) << 1) | ((bits & 0xaaaaaaaa) >> 1); - bits ^= r; - return (float)((double)bits / 4294967296.0); -} - -// single channel IIR gaussian filtering -// much faster than anything else, constant time independent of width -// should extend to multichannel and make this a node, could be useful -static void IIR_gauss_single(CompBuf* buf, float sigma) -{ - double q, q2, sc, cf[4], tsM[9], tsu[3], tsv[3]; - float *X, *Y, *W; - int i, x, y, sz; - - // single channel only for now - if (buf->type != CB_VAL) return; - - // <0.5 not valid, though can have a possibly useful sort of sharpening effect - if (sigma < 0.5) return; - - // see "Recursive Gabor Filtering" by Young/VanVliet - // all factors here in double.prec. Required, because for single.prec it seems to blow up if sigma > ~200 - if (sigma >= 3.556) - q = 0.9804*(sigma - 3.556) + 2.5091; - else // sigma >= 0.5 - q = (0.0561*sigma + 0.5784)*sigma - 0.2568; - q2 = q*q; - sc = (1.1668 + q)*(3.203729649 + (2.21566 + q)*q); - // no gabor filtering here, so no complex multiplies, just the regular coefs. - // all negated here, so as not to have to recalc Triggs/Sdika matrix - cf[1] = q*(5.788961737 + (6.76492 + 3.0*q)*q)/ sc; - cf[2] = -q2*(3.38246 + 3.0*q)/sc; - // 0 & 3 unchanged - cf[3] = q2*q/sc; - cf[0] = 1.0 - cf[1] - cf[2] - cf[3]; - - // Triggs/Sdika border corrections, - // it seems to work, not entirely sure if it is actually totally correct, - // Besides J.M.Geusebroek's anigauss.c (see http://www.science.uva.nl/~mark), - // found one other implementation by Cristoph Lampert, - // but neither seem to be quite the same, result seems to be ok sofar anyway. - // Extra scale factor here to not have to do it in filter, - // though maybe this had something to with the precision errors - sc = cf[0]/((1.0 + cf[1] - cf[2] + cf[3])*(1.0 - cf[1] - cf[2] - cf[3])*(1.0 + cf[2] + (cf[1] - cf[3])*cf[3])); - tsM[0] = sc*(-cf[3]*cf[1] + 1.0 - cf[3]*cf[3] - cf[2]); - tsM[1] = sc*((cf[3] + cf[1])*(cf[2] + cf[3]*cf[1])); - tsM[2] = sc*(cf[3]*(cf[1] + cf[3]*cf[2])); - tsM[3] = sc*(cf[1] + cf[3]*cf[2]); - tsM[4] = sc*(-(cf[2] - 1.0)*(cf[2] + cf[3]*cf[1])); - tsM[5] = sc*(-(cf[3]*cf[1] + cf[3]*cf[3] + cf[2] - 1.0)*cf[3]); - tsM[6] = sc*(cf[3]*cf[1] + cf[2] + cf[1]*cf[1] - cf[2]*cf[2]); - tsM[7] = sc*(cf[1]*cf[2] + cf[3]*cf[2]*cf[2] - cf[1]*cf[3]*cf[3] - cf[3]*cf[3]*cf[3] - cf[3]*cf[2] + cf[3]); - tsM[8] = sc*(cf[3]*(cf[1] + cf[3]*cf[2])); - -#define YVV(L)\ -{\ - W[0] = cf[0]*X[0] + cf[1]*X[0] + cf[2]*X[0] + cf[3]*X[0];\ - W[1] = cf[0]*X[1] + cf[1]*W[0] + cf[2]*X[0] + cf[3]*X[0];\ - W[2] = cf[0]*X[2] + cf[1]*W[1] + cf[2]*W[0] + cf[3]*X[0];\ - for (i=3; i<L; i++)\ - W[i] = cf[0]*X[i] + cf[1]*W[i-1] + cf[2]*W[i-2] + cf[3]*W[i-3];\ - tsu[0] = W[L-1] - X[L-1];\ - tsu[1] = W[L-2] - X[L-1];\ - tsu[2] = W[L-3] - X[L-1];\ - tsv[0] = tsM[0]*tsu[0] + tsM[1]*tsu[1] + tsM[2]*tsu[2] + X[L-1];\ - tsv[1] = tsM[3]*tsu[0] + tsM[4]*tsu[1] + tsM[5]*tsu[2] + X[L-1];\ - tsv[2] = tsM[6]*tsu[0] + tsM[7]*tsu[1] + tsM[8]*tsu[2] + X[L-1];\ - Y[L-1] = cf[0]*W[L-1] + cf[1]*tsv[0] + cf[2]*tsv[1] + cf[3]*tsv[2];\ - Y[L-2] = cf[0]*W[L-2] + cf[1]*Y[L-1] + cf[2]*tsv[0] + cf[3]*tsv[1];\ - Y[L-3] = cf[0]*W[L-3] + cf[1]*Y[L-2] + cf[2]*Y[L-1] + cf[3]*tsv[0];\ - for (i=L-4; i>=0; i--)\ - Y[i] = cf[0]*W[i] + cf[1]*Y[i+1] + cf[2]*Y[i+2] + cf[3]*Y[i+3];\ -} - - // intermediate buffers - sz = MAX2(buf->x, buf->y); - Y = MEM_callocN(sz*sizeof(float), "IIR_gauss Y buf"); - W = MEM_callocN(sz*sizeof(float), "IIR_gauss W buf"); - // H - for (y=0; y<buf->y; y++) { - X = &buf->rect[y*buf->x]; - YVV(buf->x); - memcpy(X, Y, sizeof(float)*buf->x); - } - // V - X = MEM_callocN(buf->y*sizeof(float), "IIR_gauss X buf"); - for (x=0; x<buf->x; x++) { - for (y=0; y<buf->y; y++) - X[y] = buf->rect[x + y*buf->x]; - YVV(buf->y); - for (y=0; y<buf->y; y++) - buf->rect[x + y*buf->x] = Y[y]; - } - MEM_freeN(X); - - MEM_freeN(W); - MEM_freeN(Y); -#undef YVV -} - -static void defocus_blur(bNode *node, CompBuf *new, CompBuf *img, CompBuf *zbuf, float inpval, int no_zbuf) -{ - NodeDefocus *nqd = node->storage; - CompBuf *wts; // weights buffer - CompBuf *crad; // CoC radius buffer - BokehCoeffs BKH[8]; // bokeh shape data, here never > 8 pts. - float bkh_b[4] = {0}; // shape 2D bound - float cam_fdist=1, cam_invfdist=1, cam_lens=35; - float dof_sp, maxfgc, bk_hn_theta=0, inradsq=0; - int y, len_bkh=0, ydone=0; - float aspect, aperture; - int minsz; - //float bcrad, nmaxc, scf; - - // get some required params from the current scene camera - // (ton) this is wrong, needs fixed - Scene *scene= (Scene*)node->id; - Object* camob = (scene)? scene->camera: NULL; - if (camob && camob->type==OB_CAMERA) { - Camera* cam = (Camera*)camob->data; - cam_lens = cam->lens; - cam_fdist = dof_camera(camob); - if (cam_fdist==0.0) cam_fdist = 1e10f; /* if the dof is 0.0 then set it be be far away */ - cam_invfdist = 1.f/cam_fdist; - } - - // guess work here.. best match with raytraced result - minsz = MIN2(img->x, img->y); - dof_sp = (float)minsz / (16.f / cam_lens); // <- == aspect * MIN2(img->x, img->y) / tan(0.5f * fov); - - // aperture - aspect = (img->x > img->y) ? (img->y / (float)img->x) : (img->x / (float)img->y); - aperture = 0.5f*(cam_lens / (aspect*32.f)) / nqd->fstop; - - // if not disk, make bokeh coefficients and other needed data - if (nqd->bktype!=0) { - makeBokeh(nqd->bktype, nqd->rotation, &len_bkh, &inradsq, BKH, bkh_b); - bk_hn_theta = 0.5 * nqd->bktype * sin(2.0 * M_PI / nqd->bktype); // weight factor - } - - // accumulated weights - wts = alloc_compbuf(img->x, img->y, CB_VAL, 1); - // CoC radius buffer - crad = alloc_compbuf(img->x, img->y, CB_VAL, 1); - - // if 'no_zbuf' flag set (which is always set if input is not an image), - // values are instead interpreted directly as blur radius values - if (no_zbuf) { - // to prevent *reaaallly* big radius values and impossible calculation times, - // limit the maximum to half the image width or height, whichever is smaller - float maxr = 0.5f*(float)MIN2(img->x, img->y); - unsigned int p; - - for (p=0; p<(unsigned int)(img->x*img->y); p++) { - crad->rect[p] = zbuf ? (zbuf->rect[p]*nqd->scale) : inpval; - // bug #5921, limit minimum - crad->rect[p] = MAX2(1e-5f, crad->rect[p]); - crad->rect[p] = MIN2(crad->rect[p], maxr); - // if maxblur!=0, limit maximum - if (nqd->maxblur != 0.f) crad->rect[p] = MIN2(crad->rect[p], nqd->maxblur); - } - } - else { - float wt; - - // actual zbuffer. - // separate foreground from background CoC's - // then blur background and blend in again with foreground, - // improves the 'blurred foreground overlapping in-focus midground' sharp boundary problem. - // wts buffer here used for blendmask - maxfgc = 0.f; // maximum foreground CoC radius - for (y=0; y<img->y; y++) { - unsigned int p = y * img->x; - int x; - for (x=0; x<img->x; x++) { - unsigned int px = p + x; - float iZ = (zbuf->rect[px]==0.f) ? 0.f : (1.f/zbuf->rect[px]); - crad->rect[px] = 0.5f*(aperture*(dof_sp*(cam_invfdist - iZ) - 1.f)); - if (crad->rect[px] <= 0.f) { - wts->rect[px] = 1.f; - crad->rect[px] = -crad->rect[px]; - if (crad->rect[px] > maxfgc) maxfgc = crad->rect[px]; - } - else crad->rect[px] = wts->rect[px] = 0; - } - } - - // fast blur... - // bug #6656 part 1, probably when previous node_composite.c was split into separate files, it was not properly updated - // to include recent cvs commits (well, at least not defocus node), so this part was missing... - wt = aperture*128.f; - IIR_gauss_single(crad, wt); - IIR_gauss_single(wts, wt); - - // bug #6656 part 2a, although foreground blur is not based anymore on closest object, - // the rescaling op below was still based on that anyway, and unlike the comment in below code, - // the difference is therefore not always that small at all... - // so for now commented out, not sure if this is going to cause other future problems, lets just wait and see... - /* - // find new maximum to scale it back to original - // (could skip this, not strictly necessary, in general, difference is quite small, but just in case...) - nmaxc = 0; - for (p=0; p<(img->x*img->y); p++) - if (crad->rect[p] > nmaxc) nmaxc = crad->rect[p]; - // rescale factor - scf = (nmaxc==0.f) ? 1.f: (maxfgc / nmaxc); - */ - - // and blend... - for (y=0; y<img->y; y++) { - unsigned int p = y*img->x; - int x; - - for (x=0; x<img->x; x++) { - unsigned px = p + x; - if (zbuf->rect[px]!=0.f) { - float iZ = (zbuf->rect[px]==0.f) ? 0.f : (1.f/zbuf->rect[px]); - - // bug #6656 part 2b, do not rescale - /* - bcrad = 0.5f*fabs(aperture*(dof_sp*(cam_invfdist - iZ) - 1.f)); - // scale crad back to original maximum and blend - crad->rect[px] = bcrad + wts->rect[px]*(scf*crad->rect[px] - bcrad); - */ - crad->rect[px] = 0.5f*fabs(aperture*(dof_sp*(cam_invfdist - iZ) - 1.f)); - - // 'bug' #6615, limit minimum radius to 1 pixel, not really a solution, but somewhat mitigates the problem - crad->rect[px] = MAX2(crad->rect[px], 0.5f); - // if maxblur!=0, limit maximum - if (nqd->maxblur != 0.f) crad->rect[px] = MIN2(crad->rect[px], nqd->maxblur); - } - else crad->rect[px] = 0.f; - // clear weights for next part - wts->rect[px] = 0.f; - } - // esc set by main calling process - if(node->exec & NODE_BREAK) - break; - } - } - - //------------------------------------------------------------------ - // main loop -#ifndef __APPLE__ /* can crash on Mac, see bug #22856, disabled for now */ -#ifdef __INTEL_COMPILER /* icc doesn't like the compound statement -- internal error: 0_1506 */ - #pragma omp parallel for private(y) if(!nqd->preview) schedule(guided) -#else - #pragma omp parallel for private(y) if(!nqd->preview && img->y*img->x > 16384) schedule(guided) -#endif -#endif - for (y=0; y<img->y; y++) { - unsigned int p, p4, zp, cp, cp4; - float *ctcol, u, v, ct_crad, cR2=0; - int x, sx, sy; - - // some sort of visual feedback would be nice, or at least this text in the renderwin header - // but for now just print some info in the console every 8 scanlines. - #pragma omp critical - { - if (((ydone & 7)==0) || (ydone==(img->y-1))) { - if(G.background==0) { - printf("\rdefocus: Processing Line %d of %d ... ", ydone+1, img->y); - fflush(stdout); - } - } - - ydone++; - } - - // esc set by main calling process. don't break because openmp doesn't - // allow it, just continue and do nothing - if(node->exec & NODE_BREAK) - continue; - - zp = y * img->x; - for (x=0; x<img->x; x++) { - cp = zp + x; - cp4 = cp * img->type; - - // Circle of Confusion radius for current pixel - cR2 = ct_crad = crad->rect[cp]; - // skip if zero (border render) - if (ct_crad==0.f) { - // related to bug #5921, forgot output image when skipping 0 radius values - new->rect[cp4] = img->rect[cp4]; - if (new->type != CB_VAL) { - new->rect[cp4+1] = img->rect[cp4+1]; - new->rect[cp4+2] = img->rect[cp4+2]; - new->rect[cp4+3] = img->rect[cp4+3]; - } - continue; - } - cR2 *= cR2; - - // pixel color - ctcol = &img->rect[cp4]; - - if (!nqd->preview) { - int xs, xe, ys, ye; - float lwt, wtcol[4] = {0}, aacol[4] = {0}; - float wt; - - // shape weight - if (nqd->bktype==0) // disk - wt = 1.f/((float)M_PI*cR2); - else - wt = 1.f/(cR2*bk_hn_theta); - - // weighted color - wtcol[0] = wt*ctcol[0]; - if (new->type != CB_VAL) { - wtcol[1] = wt*ctcol[1]; - wtcol[2] = wt*ctcol[2]; - wtcol[3] = wt*ctcol[3]; - } - - // macro for background blur overlap test - // unfortunately, since this is done per pixel, - // it has a very significant negative impact on processing time... - // (eg. aa disk blur without test: 112 sec, vs with test: 176 sec...) - // iff center blur radius > threshold - // and if overlap pixel in focus, do nothing, else add color/weigbt - // (threshold constant is dependant on amount of blur) - #define TESTBG1(c, w) {\ - if (ct_crad > nqd->bthresh) {\ - if (crad->rect[p] > nqd->bthresh) {\ - new->rect[p] += c[0];\ - wts->rect[p] += w;\ - }\ - }\ - else {\ - new->rect[p] += c[0];\ - wts->rect[p] += w;\ - }\ - } - #define TESTBG4(c, w) {\ - if (ct_crad > nqd->bthresh) {\ - if (crad->rect[p] > nqd->bthresh) {\ - new->rect[p4] += c[0];\ - new->rect[p4+1] += c[1];\ - new->rect[p4+2] += c[2];\ - new->rect[p4+3] += c[3];\ - wts->rect[p] += w;\ - }\ - }\ - else {\ - new->rect[p4] += c[0];\ - new->rect[p4+1] += c[1];\ - new->rect[p4+2] += c[2];\ - new->rect[p4+3] += c[3];\ - wts->rect[p] += w;\ - }\ - } - if (nqd->bktype == 0) { - // Disk - int _x, i, j, di; - float Dj, T; - // AA pixel - #define AAPIX(a, b) {\ - int _ny = b;\ - if ((_ny >= 0) && (_ny < new->y)) {\ - int _nx = a;\ - if ((_nx >=0) && (_nx < new->x)) {\ - p = _ny*new->x + _nx;\ - if (new->type==CB_VAL) {\ - TESTBG1(aacol, lwt);\ - }\ - else {\ - p4 = p * new->type;\ - TESTBG4(aacol, lwt);\ - }\ - }\ - }\ - } - // circle scanline - #define CSCAN(a, b) {\ - int _ny = y + b;\ - if ((_ny >= 0) && (_ny < new->y)) {\ - xs = x - a + 1;\ - if (xs < 0) xs = 0;\ - xe = x + a;\ - if (xe > new->x) xe = new->x;\ - p = _ny*new->x + xs;\ - if (new->type==CB_VAL) {\ - for (_x=xs; _x<xe; _x++, p++) TESTBG1(wtcol, wt);\ - }\ - else {\ - p4 = p * new->type;\ - for (_x=xs; _x<xe; _x++, p++, p4+=new->type) TESTBG4(wtcol, wt);\ - }\ - }\ - } - i = ceil(ct_crad); - j = 0; - T = 0; - while (i > j) { - Dj = sqrt(cR2 - j*j); - Dj -= floor(Dj); - di = 0; - if (Dj > T) { i--; di = 1; } - T = Dj; - aacol[0] = wtcol[0]*Dj; - if (new->type != CB_VAL) { - aacol[1] = wtcol[1]*Dj; - aacol[2] = wtcol[2]*Dj; - aacol[3] = wtcol[3]*Dj; - } - lwt = wt*Dj; - if (i!=j) { - // outer pixels - AAPIX(x+j, y+i); - AAPIX(x+j, y-i); - if (j) { - AAPIX(x-j, y+i); // BL - AAPIX(x-j, y-i); // TL - } - if (di) { // only when i changed, interior of outer section - CSCAN(j, i); // bottom - CSCAN(j, -i); // top - } - } - // lower mid section - AAPIX(x+i, y+j); - if (i) AAPIX(x-i, y+j); - CSCAN(i, j); - // upper mid section - if (j) { - AAPIX(x+i, y-j); - if (i) AAPIX(x-i, y-j); - CSCAN(i, -j); - } - j++; - } - #undef CSCAN - #undef AAPIX - } - else { - // n-agonal - int ov, nv; - float mind, maxd, lwt; - ys = MAX2((int)floor(bkh_b[2]*ct_crad + y), 0); - ye = MIN2((int)ceil(bkh_b[3]*ct_crad + y), new->y - 1); - for (sy=ys; sy<=ye; sy++) { - float fxs = 1e10f, fxe = -1e10f; - float yf = (sy - y)/ct_crad; - int found = 0; - ov = len_bkh - 1; - mind = maxd = 0; - for (nv=0; nv<len_bkh; nv++) { - if ((BKH[nv].max_y >= yf) && (BKH[nv].min_y <= yf)) { - float tx = BKH[ov].x0 + BKH[nv].ls_x*(yf - BKH[ov].y0); - if (tx < fxs) { fxs = tx; mind = BKH[nv].ls_x; } - if (tx > fxe) { fxe = tx; maxd = BKH[nv].ls_x; } - if (++found == 2) break; - } - ov = nv; - } - if (found) { - fxs = fxs*ct_crad + x; - fxe = fxe*ct_crad + x; - xs = (int)floor(fxs), xe = (int)ceil(fxe); - // AA hack for first and last x pixel, near vertical edges only - if (fabs(mind) <= 1.f) { - if ((xs >= 0) && (xs < new->x)) { - lwt = 1.f-(fxs - xs); - aacol[0] = wtcol[0]*lwt; - p = xs + sy*new->x; - if (new->type==CB_VAL) { - lwt *= wt; - TESTBG1(aacol, lwt); - } - else { - p4 = p * new->type; - aacol[1] = wtcol[1]*lwt; - aacol[2] = wtcol[2]*lwt; - aacol[3] = wtcol[3]*lwt; - lwt *= wt; - TESTBG4(aacol, lwt); - } - } - } - if (fabs(maxd) <= 1.f) { - if ((xe >= 0) && (xe < new->x)) { - lwt = 1.f-(xe - fxe); - aacol[0] = wtcol[0]*lwt; - p = xe + sy*new->x; - if (new->type==CB_VAL) { - lwt *= wt; - TESTBG1(aacol, lwt); - } - else { - p4 = p * new->type; - aacol[1] = wtcol[1]*lwt; - aacol[2] = wtcol[2]*lwt; - aacol[3] = wtcol[3]*lwt; - lwt *= wt; - TESTBG4(aacol, lwt); - } - } - } - xs = MAX2(xs+1, 0); - xe = MIN2(xe, new->x); - // remaining interior scanline - p = sy*new->x + xs; - if (new->type==CB_VAL) { - for (sx=xs; sx<xe; sx++, p++) TESTBG1(wtcol, wt); - } - else { - p4 = p * new->type; - for (sx=xs; sx<xe; sx++, p++, p4+=new->type) TESTBG4(wtcol, wt); - } - } - } - - // now traverse in opposite direction, y scanlines, - // but this time only draw the near horizontal edges, - // applying same AA hack as above - xs = MAX2((int)floor(bkh_b[0]*ct_crad + x), 0); - xe = MIN2((int)ceil(bkh_b[1]*ct_crad + x), img->x - 1); - for (sx=xs; sx<=xe; sx++) { - float xf = (sx - x)/ct_crad; - float fys = 1e10f, fye = -1e10f; - int found = 0; - ov = len_bkh - 1; - mind = maxd = 0; - for (nv=0; nv<len_bkh; nv++) { - if ((BKH[nv].max_x >= xf) && (BKH[nv].min_x <= xf)) { - float ty = BKH[ov].y0 + BKH[nv].ls_y*(xf - BKH[ov].x0); - if (ty < fys) { fys = ty; mind = BKH[nv].ls_y; } - if (ty > fye) { fye = ty; maxd = BKH[nv].ls_y; } - if (++found == 2) break; - } - ov = nv; - } - if (found) { - fys = fys*ct_crad + y; - fye = fye*ct_crad + y; - // near horizontal edges only, line slope <= 1 - if (fabs(mind) <= 1.f) { - int iys = (int)floor(fys); - if ((iys >= 0) && (iys < new->y)) { - lwt = 1.f - (fys - iys); - aacol[0] = wtcol[0]*lwt; - p = sx + iys*new->x; - if (new->type==CB_VAL) { - lwt *= wt; - TESTBG1(aacol, lwt); - } - else { - p4 = p * new->type; - aacol[1] = wtcol[1]*lwt; - aacol[2] = wtcol[2]*lwt; - aacol[3] = wtcol[3]*lwt; - lwt *= wt; - TESTBG4(aacol, lwt); - } - } - } - if (fabs(maxd) <= 1.f) { - int iye = ceil(fye); - if ((iye >= 0) && (iye < new->y)) { - lwt = 1.f - (iye - fye); - aacol[0] = wtcol[0]*lwt; - p = sx + iye*new->x; - if (new->type==CB_VAL) { - lwt *= wt; - TESTBG1(aacol, lwt); - } - else { - p4 = p * new->type; - aacol[1] = wtcol[1]*lwt; - aacol[2] = wtcol[2]*lwt; - aacol[3] = wtcol[3]*lwt; - lwt *= wt; - TESTBG4(aacol, lwt); - } - } - } - } - } - - } - #undef TESTBG4 - #undef TESTBG1 - - } - else { - // sampled, simple rejection sampling here, good enough - unsigned int maxsam, s, ui = BLI_rand()*BLI_rand(); - float wcor, cpr = BLI_frand(), lwt; - if (no_zbuf) - maxsam = nqd->samples; // no zbuffer input, use sample value directly - else { - // depth adaptive sampling hack, the more out of focus, the more samples taken, 16 minimum. - maxsam = (int)(0.5f + nqd->samples*(1.f-(float)exp(-fabs(zbuf->rect[cp] - cam_fdist)))); - if (maxsam < 16) maxsam = 16; - } - wcor = 1.f/(float)maxsam; - for (s=0; s<maxsam; ++s) { - u = ct_crad*(2.f*RI_vdC(s, ui) - 1.f); - v = ct_crad*(2.f*(s + cpr)/(float)maxsam - 1.f); - sx = (int)(x + u + 0.5f), sy = (int)(y + v + 0.5f); - if ((sx<0) || (sx >= new->x) || (sy<0) || (sy >= new->y)) continue; - p = sx + sy*new->x; - p4 = p * new->type; - if (nqd->bktype==0) // Disk - lwt = ((u*u + v*v)<=cR2) ? wcor : 0.f; - else // AA not needed here - lwt = wcor * getWeight(BKH, len_bkh, u, v, ct_crad, inradsq); - // prevent background bleeding onto in-focus pixels, user-option - if (ct_crad > nqd->bthresh) { // if center blur > threshold - if (crad->rect[p] > nqd->bthresh) { // if overlap pixel in focus, do nothing, else add color/weigbt - new->rect[p4] += ctcol[0] * lwt; - if (new->type != CB_VAL) { - new->rect[p4+1] += ctcol[1] * lwt; - new->rect[p4+2] += ctcol[2] * lwt; - new->rect[p4+3] += ctcol[3] * lwt; - } - wts->rect[p] += lwt; - } - } - else { - new->rect[p4] += ctcol[0] * lwt; - if (new->type != CB_VAL) { - new->rect[p4+1] += ctcol[1] * lwt; - new->rect[p4+2] += ctcol[2] * lwt; - new->rect[p4+3] += ctcol[3] * lwt; - } - wts->rect[p] += lwt; - } - } - } - - } - } - - // finally, normalize - for (y=0; y<new->y; y++) { - unsigned int p = y * new->x; - unsigned int p4 = p * new->type; - int x; - - for (x=0; x<new->x; x++) { - float dv = (wts->rect[p]==0.f) ? 1.f : (1.f/wts->rect[p]); - new->rect[p4] *= dv; - if (new->type!=CB_VAL) { - new->rect[p4+1] *= dv; - new->rect[p4+2] *= dv; - new->rect[p4+3] *= dv; - } - p++; - p4 += new->type; - } - } - - free_compbuf(crad); - free_compbuf(wts); - - printf("Done\n"); -} - - -static void node_composit_exec_defocus(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf *new, *old, *zbuf_use = NULL, *img = in[0]->data, *zbuf = in[1]->data; - NodeDefocus *nqd = node->storage; - int no_zbuf = nqd->no_zbuf; - - if ((img==NULL) || (out[0]->hasoutput==0)) return; - - // if image not valid type or fstop==infinite (128), nothing to do, pass in to out - if (((img->type!=CB_RGBA) && (img->type!=CB_VAL)) || ((no_zbuf==0) && (nqd->fstop==128.f))) { - out[0]->data = pass_on_compbuf(img); - return; - } - - if (zbuf!=NULL) { - // Zbuf input, check to make sure, single channel, same size - // doesn't have to be actual zbuffer, but must be value type - if ((zbuf->x != img->x) || (zbuf->y != img->y)) { - // could do a scale here instead... - printf("Z input must be same size as image !\n"); - return; - } - zbuf_use = typecheck_compbuf(zbuf, CB_VAL); - } - else no_zbuf = 1; // no zbuffer input - - // ok, process - old = img; - if (nqd->gamco) { - // gamma correct, blender func is simplified, fixed value & RGBA only, - // should make user param. also depremul and premul afterwards, gamma - // correction can't work with premul alpha - old = dupalloc_compbuf(img); - premul_compbuf(old, 1); - gamma_correct_compbuf(old, 0); - premul_compbuf(old, 0); - } - - new = alloc_compbuf(old->x, old->y, old->type, 1); - defocus_blur(node, new, old, zbuf_use, in[1]->vec[0]*nqd->scale, no_zbuf); - - if (nqd->gamco) { - premul_compbuf(new, 1); - gamma_correct_compbuf(new, 1); - premul_compbuf(new, 0); - free_compbuf(old); - } - if(node->exec & NODE_BREAK) { - free_compbuf(new); - new= NULL; - } - out[0]->data = new; - if (zbuf_use && (zbuf_use != zbuf)) free_compbuf(zbuf_use); -} - -static void node_composit_init_defocus(bNode* node) -{ - /* qdn: defocus node */ - NodeDefocus *nbd = MEM_callocN(sizeof(NodeDefocus), "node defocus data"); - nbd->bktype = 0; - nbd->rotation = 0.f; - nbd->preview = 1; - nbd->gamco = 0; - nbd->samples = 16; - nbd->fstop = 128.f; - nbd->maxblur = 0; - nbd->bthresh = 1.f; - nbd->scale = 1.f; - nbd->no_zbuf = 1; - node->storage = nbd; -} - -void register_node_type_cmp_defocus(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_DEFOCUS, "Defocus", NODE_CLASS_OP_FILTER, NODE_OPTIONS, - cmp_node_defocus_in, cmp_node_defocus_out); - node_type_size(&ntype, 150, 120, 200); - node_type_init(&ntype, node_composit_init_defocus); - node_type_storage(&ntype, "NodeDefocus", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_defocus); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_diffMatte.c b/source/blender/nodes/intern/CMP_nodes/CMP_diffMatte.c deleted file mode 100644 index 296053298da..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_diffMatte.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Bob Holcomb - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_diffMatte.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* ******************* channel Difference Matte ********************************* */ -static bNodeSocketType cmp_node_diff_matte_in[]={ - {SOCK_RGBA,1,"Image 1", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - {SOCK_RGBA,1,"Image 2", 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 do_diff_matte(bNode *node, float *outColor, float *inColor1, float *inColor2) -{ - NodeChroma *c= (NodeChroma *)node->storage; - float tolerence=c->t1; - float falloff=c->t2; - float difference; - float alpha; - - difference= fabs(inColor2[0]-inColor1[0])+ - fabs(inColor2[1]-inColor1[1])+ - fabs(inColor2[2]-inColor1[2]); - - /*average together the distances*/ - difference=difference/3.0; - - VECCOPY(outColor, inColor1); - - /*make 100% transparent*/ - if(difference < tolerence) { - outColor[3]=0.0; - } - /*in the falloff region, make partially transparent */ - else if(difference < falloff+tolerence) { - difference=difference-tolerence; - alpha=difference/falloff; - /*only change if more transparent than before */ - if(alpha < inColor1[3]) { - outColor[3]=alpha; - } - else { /* leave as before */ - outColor[3]=inColor1[3]; - } - } - else { - /*foreground object*/ - outColor[3]= inColor1[3]; - } -} - -static void node_composit_exec_diff_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf *outbuf=0; - CompBuf *imbuf1=0; - CompBuf *imbuf2=0; - NodeChroma *c; - - /*is anything connected?*/ - if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return; - - /*must have an image imput*/ - if(in[0]->data==NULL) return; - - - imbuf1=typecheck_compbuf(in[0]->data, CB_RGBA); - - /* if there's an image, use that, if not use the color */ - if(in[1]->data) { - imbuf2=typecheck_compbuf(in[1]->data, CB_RGBA); - } - - c=node->storage; - outbuf=dupalloc_compbuf(imbuf1); - - /* note, processor gets a keyvals array passed on as buffer constant */ - composit2_pixel_processor(node, outbuf, imbuf1, in[0]->vec, imbuf2, in[1]->vec, do_diff_matte, CB_RGBA, CB_RGBA); - - out[0]->data=outbuf; - if(out[1]->hasoutput) - out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A); - generate_preview(data, node, outbuf); - - if(imbuf1!=in[0]->data) - free_compbuf(imbuf1); - - if(imbuf2!=in[1]->data) - free_compbuf(imbuf2); -} - -static void node_composit_init_diff_matte(bNode *node) -{ - NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma"); - node->storage= c; - c->t1= 0.1f; - c->t2= 0.1f; -} - -void register_node_type_cmp_diff_matte(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_DIFF_MATTE, "Difference Key", NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS, - cmp_node_diff_matte_in, cmp_node_diff_matte_out); - node_type_size(&ntype, 200, 80, 250); - node_type_init(&ntype, node_composit_init_diff_matte); - node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_diff_matte); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_dilate.c b/source/blender/nodes/intern/CMP_nodes/CMP_dilate.c deleted file mode 100644 index f5d16ff0ab8..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_dilate.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_dilate.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** 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 *UNUSED(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); - } - - if(cbuf!=in[0]->data) - free_compbuf(cbuf); - - out[0]->data= stackbuf; - } -} - -void register_node_type_cmp_dilateerode(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_DILATEERODE, "Dilate/Erode", NODE_CLASS_OP_FILTER, NODE_OPTIONS, - cmp_node_dilateerode_in, cmp_node_dilateerode_out); - node_type_size(&ntype, 130, 100, 320); - node_type_exec(&ntype, node_composit_exec_dilateerode); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_directionalblur.c b/source/blender/nodes/intern/CMP_nodes/CMP_directionalblur.c deleted file mode 100644 index 2a8bbcc9ad5..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_directionalblur.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Alfredo de Greef (eeshlo) - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_directionalblur.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -static bNodeSocketType cmp_node_dblur_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.f, 0.f, 1.f}, - { -1, 0, "" } -}; - -static bNodeSocketType cmp_node_dblur_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static CompBuf *dblur(bNode *node, CompBuf *img, int iterations, int wrap, - float center_x, float center_y, float dist, float angle, float spin, float zoom) -{ - if ((dist != 0.f) || (spin != 0.f) || (zoom != 0.f)) { - void (*getpix)(CompBuf*, float, float, float*) = wrap ? qd_getPixelLerpWrap : qd_getPixelLerp; - const float a= angle * (float)M_PI / 180.f; - const float itsc= 1.f / pow(2.f, (float)iterations); - float D; - float center_x_pix, center_y_pix; - float tx, ty; - float sc, rot; - CompBuf *tmp; - int i, j; - - tmp= dupalloc_compbuf(img); - - D= dist * sqrtf(img->x * img->x + img->y * img->y); - center_x_pix= center_x * img->x; - center_y_pix= center_y * img->y; - - tx= itsc * D * cos(a); - ty= -itsc * D * sin(a); - sc= itsc * zoom; - rot= itsc * spin * (float)M_PI / 180.f; - - /* blur the image */ - for(i= 0; i < iterations; ++i) { - const float cs= cos(rot), ss= sin(rot); - const float isc= 1.f / (1.f + sc); - unsigned int x, y; - float col[4]= {0,0,0,0}; - - for(y= 0; y < img->y; ++y) { - const float v= isc * (y - center_y_pix) + ty; - - for(x= 0; x < img->x; ++x) { - const float u= isc * (x - center_x_pix) + tx; - unsigned int p= (x + y * img->x) * img->type; - - getpix(tmp, cs * u + ss * v + center_x_pix, cs * v - ss * u + center_y_pix, col); - - /* mix img and transformed tmp */ - for(j= 0; j < 4; ++j) - img->rect[p + j]= AVG2(img->rect[p + j], col[j]); - } - } - - /* copy img to tmp */ - if(i != (iterations - 1)) - memcpy(tmp->rect, img->rect, sizeof(float) * img->x * img->y * img->type); - - /* double transformations */ - tx *= 2.f, ty *= 2.f; - sc *= 2.f, rot *= 2.f; - - if(node->exec & NODE_BREAK) break; - } - - free_compbuf(tmp); - } - - return img; -} - -static void node_composit_exec_dblur(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - NodeDBlurData *ndbd= node->storage; - CompBuf *new, *img= in[0]->data; - - if((img == NULL) || (out[0]->hasoutput == 0)) return; - - if (img->type != CB_RGBA) - new = typecheck_compbuf(img, CB_RGBA); - else - new = dupalloc_compbuf(img); - - out[0]->data= dblur(node, new, ndbd->iter, ndbd->wrap, ndbd->center_x, ndbd->center_y, ndbd->distance, ndbd->angle, ndbd->spin, ndbd->zoom); -} - -static void node_composit_init_dblur(bNode* node) -{ - NodeDBlurData *ndbd= MEM_callocN(sizeof(NodeDBlurData), "node dblur data"); - node->storage= ndbd; - ndbd->center_x= 0.5; - ndbd->center_y= 0.5; -} - -void register_node_type_cmp_dblur(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_DBLUR, "Directional Blur", NODE_CLASS_OP_FILTER, NODE_OPTIONS, - cmp_node_dblur_in, cmp_node_dblur_out); - node_type_size(&ntype, 150, 120, 200); - node_type_init(&ntype, node_composit_init_dblur); - node_type_storage(&ntype, "NodeDBlurData", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_dblur); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_displace.c b/source/blender/nodes/intern/CMP_nodes/CMP_displace.c deleted file mode 100644 index 9139edf8560..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_displace.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_displace.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** Displace ******************** */ - -static bNodeSocketType cmp_node_displace_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 1, "Vector", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "X Scale", 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - { SOCK_VALUE, 1, "Y Scale", 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_displace_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -/* minimum distance (in pixels) a pixel has to be displaced - * in order to take effect */ -#define DISPLACE_EPSILON 0.01 - -static void do_displace(bNode *node, CompBuf *stackbuf, CompBuf *cbuf, CompBuf *vecbuf, float *UNUSED(veccol), CompBuf *xbuf, CompBuf *ybuf, float *xscale, float *yscale) -{ - ImBuf *ibuf; - int x, y; - float p_dx, p_dy; /* main displacement in pixel space */ - float d_dx, d_dy; - float dxt, dyt; - float u, v; - float xs, ys; - float vec[3], vecdx[3], vecdy[3]; - float col[3]; - - ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0); - ibuf->rect_float= cbuf->rect; - - for(y=0; y < stackbuf->y; y++) { - for(x=0; x < stackbuf->x; x++) { - /* calc pixel coordinates */ - qd_getPixel(vecbuf, x-vecbuf->xof, y-vecbuf->yof, vec); - - if (xbuf) - qd_getPixel(xbuf, x-xbuf->xof, y-xbuf->yof, &xs); - else - xs = xscale[0]; - - if (ybuf) - qd_getPixel(ybuf, x-ybuf->xof, y-ybuf->yof, &ys); - else - ys = yscale[0]; - - /* clamp x and y displacement to triple image resolution - - * to prevent hangs from huge values mistakenly plugged in eg. z buffers */ - CLAMP(xs, -stackbuf->x*4, stackbuf->x*4); - CLAMP(ys, -stackbuf->y*4, stackbuf->y*4); - - p_dx = vec[0] * xs; - p_dy = vec[1] * ys; - - /* if no displacement, then just copy this pixel */ - if (fabsf(p_dx) < DISPLACE_EPSILON && fabsf(p_dy) < DISPLACE_EPSILON) { - qd_getPixel(cbuf, x-cbuf->xof, y-cbuf->yof, col); - qd_setPixel(stackbuf, x, y, col); - continue; - } - - /* displaced pixel in uv coords, for image sampling */ - u = (x - cbuf->xof - p_dx + 0.5f) / (float)stackbuf->x; - v = (y - cbuf->yof - p_dy + 0.5f) / (float)stackbuf->y; - - - /* calc derivatives */ - qd_getPixel(vecbuf, x-vecbuf->xof+1, y-vecbuf->yof, vecdx); - qd_getPixel(vecbuf, x-vecbuf->xof, y-vecbuf->yof+1, vecdy); - d_dx = vecdx[0] * xs; - d_dy = vecdy[0] * ys; - - /* clamp derivatives to minimum displacement distance in UV space */ - dxt = p_dx - d_dx; - dyt = p_dy - d_dy; - - dxt = signf(dxt)*maxf(fabsf(dxt), DISPLACE_EPSILON)/(float)stackbuf->x; - dyt = signf(dyt)*maxf(fabsf(dyt), DISPLACE_EPSILON)/(float)stackbuf->y; - - ibuf_sample(ibuf, u, v, dxt, dyt, col); - qd_setPixel(stackbuf, x, y, col); - - if(node->exec & NODE_BREAK) break; - } - - if(node->exec & NODE_BREAK) break; - } - IMB_freeImBuf(ibuf); - - -/* simple method for reference, linear interpolation */ -/* - int x, y; - float dx, dy; - float u, v; - float vec[3]; - float col[3]; - - for(y=0; y < stackbuf->y; y++) { - for(x=0; x < stackbuf->x; x++) { - qd_getPixel(vecbuf, x, y, vec); - - dx = vec[0] * (xscale[0]); - dy = vec[1] * (yscale[0]); - - u = (x - dx + 0.5f) / (float)stackbuf->x; - v = (y - dy + 0.5f) / (float)stackbuf->y; - - qd_getPixelLerp(cbuf, u*cbuf->x - 0.5f, v*cbuf->y - 0.5f, col); - qd_setPixel(stackbuf, x, y, col); - } - } -*/ -} - - -static void node_composit_exec_displace(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - if(out[0]->hasoutput==0) - return; - - if(in[0]->data && in[1]->data) { - CompBuf *cbuf= in[0]->data; - CompBuf *vecbuf= in[1]->data; - CompBuf *xbuf= in[2]->data; - CompBuf *ybuf= in[3]->data; - CompBuf *stackbuf; - - cbuf= typecheck_compbuf(cbuf, CB_RGBA); - vecbuf= typecheck_compbuf(vecbuf, CB_VEC3); - xbuf= typecheck_compbuf(xbuf, CB_VAL); - ybuf= typecheck_compbuf(ybuf, CB_VAL); - - stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ - - do_displace(node, stackbuf, cbuf, vecbuf, in[1]->vec, xbuf, ybuf, in[2]->vec, in[3]->vec); - - out[0]->data= stackbuf; - - - if(cbuf!=in[0]->data) - free_compbuf(cbuf); - if(vecbuf!=in[1]->data) - free_compbuf(vecbuf); - } -} - -void register_node_type_cmp_displace(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_DISPLACE, "Displace", NODE_CLASS_DISTORT, NODE_OPTIONS, - cmp_node_displace_in, cmp_node_displace_out); - node_type_size(&ntype, 140, 100, 320); - node_type_exec(&ntype, node_composit_exec_displace); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_distanceMatte.c b/source/blender/nodes/intern/CMP_nodes/CMP_distanceMatte.c deleted file mode 100644 index 5f7613464c1..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_distanceMatte.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Bob Holcomb - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_distanceMatte.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* ******************* channel Distance Matte ********************************* */ -static bNodeSocketType cmp_node_distance_matte_in[]={ - {SOCK_RGBA,1,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - {SOCK_RGBA,1,"Key Color", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - {-1,0,""} -}; - -static bNodeSocketType cmp_node_distance_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,""} -}; - -/* note, keyvals is passed on from caller as stack array */ -/* might have been nicer as temp struct though... */ -static void do_distance_matte(bNode *node, float *out, float *in) -{ - NodeChroma *c= (NodeChroma *)node->storage; - float tolerence=c->t1; - float falloff=c->t2; - float distance; - float alpha; - - distance=sqrt((c->key[0]-in[0])*(c->key[0]-in[0]) + - (c->key[1]-in[1])*(c->key[1]-in[1]) + - (c->key[2]-in[2])*(c->key[2]-in[2])); - - VECCOPY(out, in); - - /*make 100% transparent */ - if(distance < tolerence) { - out[3]=0.0; - } - /*in the falloff region, make partially transparent */ - else if(distance < falloff+tolerence){ - distance=distance-tolerence; - alpha=distance/falloff; - /*only change if more transparent than before */ - if(alpha < in[3]) { - out[3]=alpha; - } - else { /* leave as before */ - out[3]=in[3]; - } - } - else { - out[3]=in[3]; - } -} - -static void node_composit_exec_distance_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* - Loosely based on the Sequencer chroma key plug-in, but enhanced to work in other color spaces and - uses a different difference function (suggested in forums of vfxtalk.com). - */ - CompBuf *workbuf; - CompBuf *inbuf; - NodeChroma *c; - - /*is anything connected?*/ - if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return; - /*must have an image imput*/ - if(in[0]->data==NULL) return; - - inbuf=typecheck_compbuf(in[0]->data, CB_RGBA); - - c=node->storage; - workbuf=dupalloc_compbuf(inbuf); - - /*use the input color*/ - c->key[0]= in[1]->vec[0]; - c->key[1]= in[1]->vec[1]; - c->key[2]= in[1]->vec[2]; - - /* note, processor gets a keyvals array passed on as buffer constant */ - composit1_pixel_processor(node, workbuf, workbuf, in[0]->vec, do_distance_matte, CB_RGBA); - - - out[0]->data=workbuf; - if(out[1]->hasoutput) - out[1]->data=valbuf_from_rgbabuf(workbuf, CHAN_A); - generate_preview(data, node, workbuf); - - if(inbuf!=in[0]->data) - free_compbuf(inbuf); -} - -static void node_composit_init_distance_matte(bNode *node) -{ - NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma"); - node->storage= c; - c->t1= 0.1f; - c->t2= 0.1f; -} - -void register_node_type_cmp_distance_matte(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_DIST_MATTE, "Distance Key", NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS, - cmp_node_distance_matte_in, cmp_node_distance_matte_out); - node_type_size(&ntype, 200, 80, 250); - node_type_init(&ntype, node_composit_init_distance_matte); - node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_distance_matte); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_filter.c b/source/blender/nodes/intern/CMP_nodes/CMP_filter.c deleted file mode 100644 index 915cb01d2d4..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_filter.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_filter.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** FILTER ******************** */ -static bNodeSocketType cmp_node_filter_in[]= { - { SOCK_VALUE, 1, "Fac", 1.0f, 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_filter_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_filter_edge(CompBuf *out, CompBuf *in, float *filter, float fac) -{ - float *row1, *row2, *row3; - float *fp, f1, f2, mfac= 1.0f-fac; - int rowlen, x, y, c, pix= in->type; - - rowlen= in->x; - - for(y=0; y<in->y; y++) { - /* setup rows */ - if(y==0) row1= in->rect; - else row1= in->rect + pix*(y-1)*rowlen; - - row2= in->rect + y*pix*rowlen; - - if(y==in->y-1) row3= row2; - else row3= row2 + pix*rowlen; - - fp= out->rect + pix*y*rowlen; - - if(pix==CB_RGBA) { - QUATCOPY(fp, row2); - fp+= pix; - - for(x=2; x<rowlen; x++) { - for(c=0; c<3; c++) { - f1= filter[0]*row1[0] + filter[1]*row1[4] + filter[2]*row1[8] + filter[3]*row2[0] + filter[4]*row2[4] + filter[5]*row2[8] + filter[6]*row3[0] + filter[7]*row3[4] + filter[8]*row3[8]; - f2= filter[0]*row1[0] + filter[3]*row1[4] + filter[6]*row1[8] + filter[1]*row2[0] + filter[4]*row2[4] + filter[7]*row2[8] + filter[2]*row3[0] + filter[5]*row3[4] + filter[8]*row3[8]; - fp[0]= mfac*row2[4] + fac*sqrt(f1*f1 + f2*f2); - fp++; row1++; row2++; row3++; - } - fp[0]= row2[4]; - /* no alpha... will clear it completely */ - fp++; row1++; row2++; row3++; - } - QUATCOPY(fp, row2+4); - } - else if(pix==CB_VAL) { - fp+= pix; - for(x=2; x<rowlen; x++) { - f1= filter[0]*row1[0] + filter[1]*row1[1] + filter[2]*row1[2] + filter[3]*row2[0] + filter[4]*row2[1] + filter[5]*row2[2] + filter[6]*row3[0] + filter[7]*row3[1] + filter[8]*row3[2]; - f2= filter[0]*row1[0] + filter[3]*row1[1] + filter[6]*row1[2] + filter[1]*row2[0] + filter[4]*row2[1] + filter[7]*row2[2] + filter[2]*row3[0] + filter[5]*row3[1] + filter[8]*row3[2]; - fp[0]= mfac*row2[1] + fac*sqrt(f1*f1 + f2*f2); - fp++; row1++; row2++; row3++; - } - } - } -} - -static void do_filter3(CompBuf *out, CompBuf *in, float *filter, float fac) -{ - float *row1, *row2, *row3; - float *fp, mfac= 1.0f-fac; - int rowlen, x, y, c; - int pixlen= in->type; - - rowlen= in->x; - - for(y=0; y<in->y; y++) { - /* setup rows */ - if(y==0) row1= in->rect; - else row1= in->rect + pixlen*(y-1)*rowlen; - - row2= in->rect + y*pixlen*rowlen; - - if(y==in->y-1) row3= row2; - else row3= row2 + pixlen*rowlen; - - fp= out->rect + pixlen*(y)*rowlen; - - if(pixlen==1) { - fp[0]= row2[0]; - fp+= 1; - - for(x=2; x<rowlen; x++) { - fp[0]= mfac*row2[1] + fac*(filter[0]*row1[0] + filter[1]*row1[1] + filter[2]*row1[2] + filter[3]*row2[0] + filter[4]*row2[1] + filter[5]*row2[2] + filter[6]*row3[0] + filter[7]*row3[1] + filter[8]*row3[2]); - fp++; row1++; row2++; row3++; - } - fp[0]= row2[1]; - } - else if(pixlen==2) { - fp[0]= row2[0]; - fp[1]= row2[1]; - fp+= 2; - - for(x=2; x<rowlen; x++) { - for(c=0; c<2; c++) { - fp[0]= mfac*row2[2] + fac*(filter[0]*row1[0] + filter[1]*row1[2] + filter[2]*row1[4] + filter[3]*row2[0] + filter[4]*row2[2] + filter[5]*row2[4] + filter[6]*row3[0] + filter[7]*row3[2] + filter[8]*row3[4]); - fp++; row1++; row2++; row3++; - } - } - fp[0]= row2[2]; - fp[1]= row2[3]; - } - else if(pixlen==3) { - VECCOPY(fp, row2); - fp+= 3; - - for(x=2; x<rowlen; x++) { - for(c=0; c<3; c++) { - fp[0]= mfac*row2[3] + fac*(filter[0]*row1[0] + filter[1]*row1[3] + filter[2]*row1[6] + filter[3]*row2[0] + filter[4]*row2[3] + filter[5]*row2[6] + filter[6]*row3[0] + filter[7]*row3[3] + filter[8]*row3[6]); - fp++; row1++; row2++; row3++; - } - } - VECCOPY(fp, row2+3); - } - else { - QUATCOPY(fp, row2); - fp+= 4; - - for(x=2; x<rowlen; x++) { - for(c=0; c<4; c++) { - fp[0]= mfac*row2[4] + fac*(filter[0]*row1[0] + filter[1]*row1[4] + filter[2]*row1[8] + filter[3]*row2[0] + filter[4]*row2[4] + filter[5]*row2[8] + filter[6]*row3[0] + filter[7]*row3[4] + filter[8]*row3[8]); - fp++; row1++; row2++; row3++; - } - } - QUATCOPY(fp, row2+4); - } - } -} - - -static void node_composit_exec_filter(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - static float soft[9]= {1/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 4/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 1/16.0f}; - float sharp[9]= {-1,-1,-1,-1,9,-1,-1,-1,-1}; - float laplace[9]= {-1/8.0f, -1/8.0f, -1/8.0f, -1/8.0f, 1.0f, -1/8.0f, -1/8.0f, -1/8.0f, -1/8.0f}; - float sobel[9]= {1,2,1,0,0,0,-1,-2,-1}; - float prewitt[9]= {1,1,1,0,0,0,-1,-1,-1}; - float kirsch[9]= {5,5,5,-3,-3,-3,-2,-2,-2}; - float shadow[9]= {1,2,1,0,1,0,-1,-2,-1}; - - if(out[0]->hasoutput==0) return; - - /* stack order in: Image */ - /* stack order out: Image */ - - if(in[1]->data) { - /* make output size of first available input image */ - CompBuf *cbuf= in[1]->data; - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, cbuf->type, 1); /* allocs */ - - /* warning note: xof and yof are applied in pixelprocessor, but should be copied otherwise? */ - stackbuf->xof= cbuf->xof; - stackbuf->yof= cbuf->yof; - - switch(node->custom1) { - case CMP_FILT_SOFT: - do_filter3(stackbuf, cbuf, soft, in[0]->vec[0]); - break; - case CMP_FILT_SHARP: - do_filter3(stackbuf, cbuf, sharp, in[0]->vec[0]); - break; - case CMP_FILT_LAPLACE: - do_filter3(stackbuf, cbuf, laplace, in[0]->vec[0]); - break; - case CMP_FILT_SOBEL: - do_filter_edge(stackbuf, cbuf, sobel, in[0]->vec[0]); - break; - case CMP_FILT_PREWITT: - do_filter_edge(stackbuf, cbuf, prewitt, in[0]->vec[0]); - break; - case CMP_FILT_KIRSCH: - do_filter_edge(stackbuf, cbuf, kirsch, in[0]->vec[0]); - break; - case CMP_FILT_SHADOW: - do_filter3(stackbuf, cbuf, shadow, in[0]->vec[0]); - break; - } - - out[0]->data= stackbuf; - - generate_preview(data, node, out[0]->data); - } -} - - -void register_node_type_cmp_filter(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_FILTER, "Filter", NODE_CLASS_OP_FILTER, NODE_PREVIEW|NODE_OPTIONS, - cmp_node_filter_in, cmp_node_filter_out); - node_type_size(&ntype, 80, 40, 120); - node_type_label(&ntype, node_filter_label); - node_type_exec(&ntype, node_composit_exec_filter); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_flip.c b/source/blender/nodes/intern/CMP_nodes/CMP_flip.c deleted file mode 100644 index b5fd7b46e03..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_flip.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_flip.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** Flip ******************** */ -static bNodeSocketType cmp_node_flip_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType cmp_node_flip_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_composit_exec_flip(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - if(in[0]->data) { - CompBuf *cbuf= in[0]->data; - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, cbuf->type, 1); /* note, this returns zero'd image */ - int i, src_pix, src_width, src_height, srcydelt, outydelt, x, y; - float *srcfp, *outfp; - - src_pix= cbuf->type; - src_width= cbuf->x; - src_height= cbuf->y; - srcfp= cbuf->rect; - outfp= stackbuf->rect; - srcydelt= src_width*src_pix; - outydelt= srcydelt; - - if(node->custom1) { /*set up output pointer for y flip*/ - outfp+= (src_height-1)*outydelt; - outydelt= -outydelt; - } - - for(y=0; y<src_height; y++) { - if(node->custom1 == 1) { /* no x flip so just copy line*/ - memcpy(outfp, srcfp, sizeof(float) * src_pix * src_width); - srcfp+=srcydelt; - } - else { - outfp += (src_width-1)*src_pix; - for(x=0; x<src_width; x++) { - for(i=0; i<src_pix; i++) { - outfp[i]= srcfp[i]; - } - outfp -= src_pix; - srcfp += src_pix; - } - outfp += src_pix; - } - outfp += outydelt; - } - - out[0]->data= stackbuf; - - } -} - -void register_node_type_cmp_flip(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_FLIP, "Flip", NODE_CLASS_DISTORT, NODE_OPTIONS, - cmp_node_flip_in, cmp_node_flip_out); - node_type_size(&ntype, 140, 100, 320); - node_type_exec(&ntype, node_composit_exec_flip); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_gamma.c b/source/blender/nodes/intern/CMP_nodes/CMP_gamma.c deleted file mode 100644 index 261257d3b5f..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_gamma.c +++ /dev/null @@ -1,90 +0,0 @@ -/* -* $Id$ -* -* ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - -*/ - -/** \file blender/nodes/intern/CMP_nodes/CMP_gamma.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** Gamma Tools ******************** */ - -static bNodeSocketType cmp_node_gamma_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Gamma", 1.0f, 0.0f, 0.0f, 0.0f, 0.001f, 10.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_gamma_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_gamma(bNode *UNUSED(node), float *out, float *in, float *fac) -{ - int i=0; - for(i=0; i<3; i++) { - /* check for negative to avoid nan's */ - out[i] = (in[i] > 0.0f)? pow(in[i],fac[0]): in[i]; - } - out[3] = in[3]; -} -static void node_composit_exec_gamma(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order in: Fac, Image */ - /* stack order out: Image */ - if(out[0]->hasoutput==0) return; - - /* input no image? then only color operation */ - if(in[0]->data==NULL) { - do_gamma(node, out[0]->vec, in[0]->vec, in[1]->vec); - } - else { - /* make output size of input image */ - CompBuf *cbuf= in[0]->data; - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); // allocs - - composit2_pixel_processor(node, stackbuf, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_gamma, CB_RGBA, CB_VAL); - - out[0]->data= stackbuf; - } -} - -void register_node_type_cmp_gamma(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_GAMMA, "Gamma", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - cmp_node_gamma_in, cmp_node_gamma_out); - node_type_size(&ntype, 140, 100, 320); - node_type_exec(&ntype, node_composit_exec_gamma); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_glare.c b/source/blender/nodes/intern/CMP_nodes/CMP_glare.c deleted file mode 100644 index 2e0822a4511..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_glare.c +++ /dev/null @@ -1,506 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Alfredo de Greef (eeshlo) - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_glare.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -static bNodeSocketType cmp_node_glare_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_glare_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - - -// mix two images, src buffer does not have to be same size, -static void mixImages(CompBuf *dst, CompBuf *src, float mix) -{ - int x, y; - fRGB c1, c2, *dcolp, *scolp; - const float mf = 2.f - 2.f*fabsf(mix - 0.5f); - if ((dst->x == src->x) && (dst->y == src->y)) { - for (y=0; y<dst->y; y++) { - dcolp = (fRGB*)&dst->rect[y*dst->x*dst->type]; - scolp = (fRGB*)&src->rect[y*dst->x*dst->type]; - for (x=0; x<dst->x; x++) { - fRGB_copy(c1, dcolp[x]); - fRGB_copy(c2, scolp[x]); - c1[0] += mix*(c2[0] - c1[0]); - c1[1] += mix*(c2[1] - c1[1]); - c1[2] += mix*(c2[2] - c1[2]); - if (c1[0] < 0.f) c1[0] = 0.f; - if (c1[1] < 0.f) c1[1] = 0.f; - if (c1[2] < 0.f) c1[2] = 0.f; - fRGB_mult(c1, mf); - fRGB_copy(dcolp[x], c1); - } - } - } - else { - float xr = src->x / (float)dst->x; - float yr = src->y / (float)dst->y; - for (y=0; y<dst->y; y++) { - dcolp = (fRGB*)&dst->rect[y*dst->x*dst->type]; - for (x=0; x<dst->x; x++) { - fRGB_copy(c1, dcolp[x]); - qd_getPixelLerp(src, (x + 0.5f)*xr - 0.5f, (y + 0.5f)*yr - 0.5f, c2); - c1[0] += mix*(c2[0] - c1[0]); - c1[1] += mix*(c2[1] - c1[1]); - c1[2] += mix*(c2[2] - c1[2]); - if (c1[0] < 0.f) c1[0] = 0.f; - if (c1[1] < 0.f) c1[1] = 0.f; - if (c1[2] < 0.f) c1[2] = 0.f; - fRGB_mult(c1, mf); - fRGB_copy(dcolp[x], c1); - } - } - } -} - - -// adds src to dst image, must be of same size -static void addImage(CompBuf* dst, CompBuf* src, float scale) -{ - if ((dst->x == src->x) && (dst->y == src->y)) { - int p = dst->x*dst->y*dst->type; - float *dcol = dst->rect, *scol = src->rect; - while (p--) *dcol++ += *scol++ * scale; - } -} - - -// returns possibly downscaled copy of all pixels above threshold -static CompBuf* BTP(CompBuf* src, float threshold, int scaledown) -{ - int x, y; - CompBuf* bsrc = qd_downScaledCopy(src, scaledown); - float* cr = bsrc->rect; - for (y=0; y<bsrc->y; ++y) - for (x=0; x<bsrc->x; ++x, cr+=4) { - if ((0.212671f*cr[0] + 0.71516f*cr[1] + 0.072169f*cr[2]) >= threshold) { - cr[0] -= threshold, cr[1] -= threshold, cr[2] -= threshold; - cr[0] = MAX2(cr[0], 0.f); - cr[1] = MAX2(cr[1], 0.f); - cr[2] = MAX2(cr[2], 0.f); - } - else cr[0] = cr[1] = cr[2] = 0.f; - } - return bsrc; -} - -//-------------------------------------------------------------------------------------------- -// simple 4-point star filter - -static void star4(NodeGlare* ndg, CompBuf* dst, CompBuf* src) -{ - int x, y, i, xm, xp, ym, yp; - float c[4] = {0,0,0,0}, tc[4] = {0,0,0,0}; - CompBuf *tbuf1, *tbuf2, *tsrc; - const float f1 = 1.f - ndg->fade, f2 = (1.f - f1)*0.5f; - //const float t3 = ndg->threshold*3.f; - const float sc = (float)(1 << ndg->quality); - const float isc = 1.f/sc; - - tsrc = BTP(src, ndg->threshold, (int)sc); - - tbuf1 = dupalloc_compbuf(tsrc); - tbuf2 = dupalloc_compbuf(tsrc); - - for (i=0; i<ndg->iter; i++) { - // (x || x-1, y-1) to (x || x+1, y+1) - // F - for (y=0; y<tbuf1->y; y++) { - ym = y - i; - yp = y + i; - for (x=0; x<tbuf1->x; x++) { - xm = x - i; - xp = x + i; - qd_getPixel(tbuf1, x, y, c); - fRGB_mult(c, f1); - qd_getPixel(tbuf1, (ndg->angle ? xm : x), ym, tc); - fRGB_madd(c, tc, f2); - qd_getPixel(tbuf1, (ndg->angle ? xp : x), yp, tc); - fRGB_madd(c, tc, f2); - qd_setPixel(tbuf1, x, y, c); - } - } - // B - for (y=tbuf1->y-1; y>=0; y--) { - ym = y - i; - yp = y + i; - for (x=tbuf1->x-1; x>=0; x--) { - xm = x - i; - xp = x + i; - qd_getPixel(tbuf1, x, y, c); - fRGB_mult(c, f1); - qd_getPixel(tbuf1, (ndg->angle ? xm : x), ym, tc); - fRGB_madd(c, tc, f2); - qd_getPixel(tbuf1, (ndg->angle ? xp : x), yp, tc); - fRGB_madd(c, tc, f2); - qd_setPixel(tbuf1, x, y, c); - } - } - // (x-1, y || y+1) to (x+1, y || y-1) - // F - for (y=0; y<tbuf2->y; y++) { - ym = y - i; - yp = y + i; - for (x=0; x<tbuf2->x; x++) { - xm = x - i; - xp = x + i; - qd_getPixel(tbuf2, x, y, c); - fRGB_mult(c, f1); - qd_getPixel(tbuf2, xm, (ndg->angle ? yp : y), tc); - fRGB_madd(c, tc, f2); - qd_getPixel(tbuf2, xp, (ndg->angle ? ym : y), tc); - fRGB_madd(c, tc, f2); - qd_setPixel(tbuf2, x, y, c); - } - } - // B - for (y=tbuf2->y-1; y>=0; y--) { - ym = y - i; - yp = y + i; - for (x=tbuf2->x-1; x>=0; x--) { - xm = x - i; - xp = x + i; - qd_getPixel(tbuf2, x, y, c); - fRGB_mult(c, f1); - qd_getPixel(tbuf2, xm, (ndg->angle ? yp : y), tc); - fRGB_madd(c, tc, f2); - qd_getPixel(tbuf2, xp, (ndg->angle ? ym : y), tc); - fRGB_madd(c, tc, f2); - qd_setPixel(tbuf2, x, y, c); - } - } - } - - for (y=0; y<tbuf1->y; ++y) - for (x=0; x<tbuf1->x; ++x) { - unsigned int p = (x + y*tbuf1->x)*tbuf1->type; - tbuf1->rect[p] += tbuf2->rect[p]; - tbuf1->rect[p+1] += tbuf2->rect[p+1]; - tbuf1->rect[p+2] += tbuf2->rect[p+2]; - } - - for (y=0; y<dst->y; ++y) { - const float m = 0.5f + 0.5f*ndg->mix; - for (x=0; x<dst->x; ++x) { - unsigned int p = (x + y*dst->x)*dst->type; - qd_getPixelLerp(tbuf1, x*isc, y*isc, tc); - dst->rect[p] = src->rect[p] + m*(tc[0] - src->rect[p]); - dst->rect[p+1] = src->rect[p+1] + m*(tc[1] - src->rect[p+1]); - dst->rect[p+2] = src->rect[p+2] + m*(tc[2] - src->rect[p+2]); - } - } - - free_compbuf(tbuf1); - free_compbuf(tbuf2); - free_compbuf(tsrc); -} - -//-------------------------------------------------------------------------------------------- -// streak filter - -static void streaks(NodeGlare* ndg, CompBuf* dst, CompBuf* src) -{ - CompBuf *bsrc, *tsrc, *tdst, *sbuf; - int x, y, n; - unsigned int nump=0; - fRGB c1, c2, c3, c4; - float a, ang = 360.f/(float)ndg->angle; - - bsrc = BTP(src, ndg->threshold, 1 << ndg->quality); - tsrc = dupalloc_compbuf(bsrc); // sample from buffer - tdst = alloc_compbuf(tsrc->x, tsrc->y, tsrc->type, 1); // sample to buffer - sbuf = alloc_compbuf(tsrc->x, tsrc->y, tsrc->type, 1); // streak sum buffer - - - for (a=0.f; a<360.f; a+=ang) { - const float an = (a + (float)ndg->angle_ofs)*(float)M_PI/180.f; - const float vx = cos((double)an), vy = sin((double)an); - for (n=0; n<ndg->iter; ++n) { - const float p4 = pow(4.0, (double)n); - const float vxp = vx*p4, vyp = vy*p4; - const float wt = pow((double)ndg->fade, (double)p4); - const float cmo = 1.f - pow((double)ndg->colmod, (double)n+1); // colormodulation amount relative to current pass - float* tdstcol = tdst->rect; - for (y=0; y<tsrc->y; ++y) { - for (x=0; x<tsrc->x; ++x, tdstcol+=4) { - // first pass no offset, always same for every pass, exact copy, - // otherwise results in uneven brightness, only need once - if (n==0) qd_getPixel(tsrc, x, y, c1); else c1[0]=c1[1]=c1[2]=0; - qd_getPixelLerp(tsrc, x + vxp, y + vyp, c2); - qd_getPixelLerp(tsrc, x + vxp*2.f, y + vyp*2.f, c3); - qd_getPixelLerp(tsrc, x + vxp*3.f, y + vyp*3.f, c4); - // modulate color to look vaguely similar to a color spectrum - fRGB_rgbmult(c2, 1.f, cmo, cmo); - fRGB_rgbmult(c3, cmo, cmo, 1.f); - fRGB_rgbmult(c4, cmo, 1.f, cmo); - tdstcol[0] = 0.5f*(tdstcol[0] + c1[0] + wt*(c2[0] + wt*(c3[0] + wt*c4[0]))); - tdstcol[1] = 0.5f*(tdstcol[1] + c1[1] + wt*(c2[1] + wt*(c3[1] + wt*c4[1]))); - tdstcol[2] = 0.5f*(tdstcol[2] + c1[2] + wt*(c2[2] + wt*(c3[2] + wt*c4[2]))); - } - } - memcpy(tsrc->rect, tdst->rect, sizeof(float)*tdst->x*tdst->y*tdst->type); - } - - addImage(sbuf, tsrc, 1.f/(float)(6 - ndg->iter)); - memset(tdst->rect, 0, tdst->x*tdst->y*tdst->type*sizeof(float)); - memcpy(tsrc->rect, bsrc->rect, bsrc->x*bsrc->y*bsrc->type*sizeof(float)); - nump++; - } - - mixImages(dst, sbuf, 0.5f + 0.5f*ndg->mix); - - free_compbuf(tsrc); - free_compbuf(tdst); - free_compbuf(sbuf); - free_compbuf(bsrc); -} - - -//-------------------------------------------------------------------------------------------- -// Ghosts (lensflare) - -static float smoothMask(float x, float y) -{ - float t; - x = 2.f*x - 1.f, y = 2.f*y - 1.f; - if ((t = 1.f - sqrtf(x*x + y*y)) <= 0.f) return 0.f; - return t; -} - -static void ghosts(NodeGlare* ndg, CompBuf* dst, CompBuf* src) -{ - // colormodulation and scale factors (cm & scalef) for 16 passes max: 64 - int x, y, n, p, np; - fRGB c, tc, cm[64]; - float sc, isc, u, v, sm, s, t, ofs, scalef[64]; - CompBuf *tbuf1, *tbuf2, *gbuf; - const float cmo = 1.f - ndg->colmod; - const int qt = 1 << ndg->quality; - const float s1 = 4.f/(float)qt, s2 = 2.f*s1; - - gbuf = BTP(src, ndg->threshold, qt); - tbuf1 = dupalloc_compbuf(gbuf); - IIR_gauss(tbuf1, s1, 0, 3); - IIR_gauss(tbuf1, s1, 1, 3); - IIR_gauss(tbuf1, s1, 2, 3); - tbuf2 = dupalloc_compbuf(tbuf1); - IIR_gauss(tbuf2, s2, 0, 3); - IIR_gauss(tbuf2, s2, 1, 3); - IIR_gauss(tbuf2, s2, 2, 3); - - if (ndg->iter & 1) ofs = 0.5f; else ofs = 0.f; - for (x=0; x<(ndg->iter*4); x++) { - y = x & 3; - cm[x][0] = cm[x][1] = cm[x][2] = 1; - if (y==1) fRGB_rgbmult(cm[x], 1.f, cmo, cmo); - if (y==2) fRGB_rgbmult(cm[x], cmo, cmo, 1.f); - if (y==3) fRGB_rgbmult(cm[x], cmo, 1.f, cmo); - scalef[x] = 2.1f*(1.f-(x+ofs)/(float)(ndg->iter*4)); - if (x & 1) scalef[x] = -0.99f/scalef[x]; - } - - sc = 2.13; - isc = -0.97; - for (y=0; y<gbuf->y; y++) { - v = (float)(y+0.5f) / (float)gbuf->y; - for (x=0; x<gbuf->x; x++) { - u = (float)(x+0.5f) / (float)gbuf->x; - s = (u-0.5f)*sc + 0.5f, t = (v-0.5f)*sc + 0.5f; - qd_getPixelLerp(tbuf1, s*gbuf->x, t*gbuf->y, c); - sm = smoothMask(s, t); - fRGB_mult(c, sm); - s = (u-0.5f)*isc + 0.5f, t = (v-0.5f)*isc + 0.5f; - qd_getPixelLerp(tbuf2, s*gbuf->x - 0.5f, t*gbuf->y - 0.5f, tc); - sm = smoothMask(s, t); - fRGB_madd(c, tc, sm); - qd_setPixel(gbuf, x, y, c); - } - } - - memset(tbuf1->rect, 0, tbuf1->x*tbuf1->y*tbuf1->type*sizeof(float)); - for (n=1; n<ndg->iter; n++) { - for (y=0; y<gbuf->y; y++) { - v = (float)(y+0.5f) / (float)gbuf->y; - for (x=0; x<gbuf->x; x++) { - u = (float)(x+0.5f) / (float)gbuf->x; - tc[0] = tc[1] = tc[2] = 0.f; - for (p=0;p<4;p++) { - np = (n<<2) + p; - s = (u-0.5f)*scalef[np] + 0.5f; - t = (v-0.5f)*scalef[np] + 0.5f; - qd_getPixelLerp(gbuf, s*gbuf->x - 0.5f, t*gbuf->y - 0.5f, c); - fRGB_colormult(c, cm[np]); - sm = smoothMask(s, t)*0.25f; - fRGB_madd(tc, c, sm); - } - p = (x + y*tbuf1->x)*tbuf1->type; - tbuf1->rect[p] += tc[0]; - tbuf1->rect[p+1] += tc[1]; - tbuf1->rect[p+2] += tc[2]; - } - } - memcpy(gbuf->rect, tbuf1->rect, tbuf1->x*tbuf1->y*tbuf1->type*sizeof(float)); - } - - free_compbuf(tbuf1); - free_compbuf(tbuf2); - - mixImages(dst, gbuf, 0.5f + 0.5f*ndg->mix); - free_compbuf(gbuf); -} - -//-------------------------------------------------------------------------------------------- -// Fog glow (convolution with kernel of exponential falloff) - -static void fglow(NodeGlare* ndg, CompBuf* dst, CompBuf* src) -{ - int x, y; - float scale, u, v, r, w, d; - fRGB fcol; - CompBuf *tsrc, *ckrn; - unsigned int sz = 1 << ndg->size; - const float cs_r = 1.f, cs_g = 1.f, cs_b = 1.f; - - // temp. src image - tsrc = BTP(src, ndg->threshold, 1 << ndg->quality); - // make the convolution kernel - ckrn = alloc_compbuf(sz, sz, CB_RGBA, 1); - - scale = 0.25f*sqrtf(sz*sz); - - for (y=0; y<sz; ++y) { - v = 2.f*(y / (float)sz) - 1.f; - for (x=0; x<sz; ++x) { - u = 2.f*(x / (float)sz) - 1.f; - r = (u*u + v*v)*scale; - d = -sqrtf(sqrtf(sqrtf(r)))*9.f; - fcol[0] = expf(d*cs_r), fcol[1] = expf(d*cs_g), fcol[2] = expf(d*cs_b); - // linear window good enough here, visual result counts, not scientific analysis - //w = (1.f-fabs(u))*(1.f-fabs(v)); - // actually, Hanning window is ok, cos^2 for some reason is slower - w = (0.5f + 0.5f*cos((double)u*M_PI))*(0.5f + 0.5f*cos((double)v*M_PI)); - fRGB_mult(fcol, w); - qd_setPixel(ckrn, x, y, fcol); - } - } - - convolve(tsrc, tsrc, ckrn); - free_compbuf(ckrn); - mixImages(dst, tsrc, 0.5f + 0.5f*ndg->mix); - free_compbuf(tsrc); -} - -//-------------------------------------------------------------------------------------------- - -static void node_composit_exec_glare(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf *new, *src, *img = in[0]->data; - NodeGlare* ndg = node->storage; - - if ((img == NULL) || (out[0]->hasoutput == 0)) return; - - if (img->type != CB_RGBA) { - new = typecheck_compbuf(img, CB_RGBA); - src = typecheck_compbuf(img, CB_RGBA); - } else { - new = dupalloc_compbuf(img); - src = dupalloc_compbuf(img); - } - - { - int x, y; - for (y=0; y<new->y; ++y) { - fRGB* col = (fRGB*)&new->rect[y*new->x*new->type]; - for (x=0; x<new->x; ++x) { - col[x][0] = MAX2(col[x][0], 0.f); - col[x][1] = MAX2(col[x][1], 0.f); - col[x][2] = MAX2(col[x][2], 0.f); - } - } - } - - switch (ndg->type) { - case 0: - star4(ndg, new, src); - break; - case 1: - fglow(ndg, new, src); - break; - case 3: - ghosts(ndg, new, src); - break; - case 2: - default: - streaks(ndg, new, src); - break; - } - - free_compbuf(src); - out[0]->data = new; -} - -static void node_composit_init_glare(bNode* node) -{ - NodeGlare *ndg = MEM_callocN(sizeof(NodeGlare), "node glare data"); - ndg->quality = 1; - ndg->type = 2; - ndg->iter = 3; - ndg->colmod = 0.25; - ndg->mix = 0; - ndg->threshold = 1; - ndg->angle = 4; - ndg->angle_ofs = 0; - ndg->fade = 0.9; - ndg->size = 8; - node->storage = ndg; -} - -void register_node_type_cmp_glare(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_GLARE, "Glare", NODE_CLASS_OP_FILTER, NODE_OPTIONS, - cmp_node_glare_in, cmp_node_glare_out); - node_type_size(&ntype, 150, 120, 200); - node_type_init(&ntype, node_composit_init_glare); - node_type_storage(&ntype, "NodeGlare", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_glare); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_hueSatVal.c b/source/blender/nodes/intern/CMP_nodes/CMP_hueSatVal.c deleted file mode 100644 index 7b5511c699c..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_hueSatVal.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_hueSatVal.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** Hue Saturation ******************** */ -static bNodeSocketType cmp_node_hue_sat_in[]= { - { SOCK_VALUE, 1, "Fac", 1.0f, 0.0f, 0.0f, 0.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_hue_sat_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_hue_sat_fac(bNode *node, float *out, float *in, float *fac) -{ - NodeHueSat *nhs= node->storage; - - 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); - hsv[0]+= (nhs->hue - 0.5f); - if(hsv[0]>1.0) hsv[0]-=1.0; else if(hsv[0]<0.0) hsv[0]+= 1.0; - hsv[1]*= nhs->sat; - hsv[2]*= nhs->val; - hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2); - - out[0]= mfac*in[0] + *fac*col[0]; - out[1]= mfac*in[1] + *fac*col[1]; - out[2]= mfac*in[2] + *fac*col[2]; - out[3]= in[3]; - } - else { - QUATCOPY(out, in); - } -} - -static void node_composit_exec_hue_sat(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order in: Fac, Image */ - /* stack order out: Image */ - if(out[0]->hasoutput==0) return; - - /* input no image? then only color operation */ - if(in[1]->data==NULL) { - do_hue_sat_fac(node, out[0]->vec, in[1]->vec, in[0]->vec); - } - else { - /* make output size of input image */ - CompBuf *cbuf= dupalloc_compbuf(in[1]->data); - CompBuf *stackbuf=typecheck_compbuf(cbuf,CB_RGBA); - - composit2_pixel_processor(node, stackbuf, stackbuf, in[1]->vec, in[0]->data, in[0]->vec, do_hue_sat_fac, CB_RGBA, CB_VAL); - - out[0]->data= stackbuf; - - /* get rid of intermediary cbuf if it's extra */ - if(stackbuf!=cbuf) - free_compbuf(cbuf); - } -} - -static void node_composit_init_hue_sat(bNode* node) -{ - NodeHueSat *nhs= MEM_callocN(sizeof(NodeHueSat), "node hue sat"); - node->storage= nhs; - nhs->hue= 0.5f; - nhs->sat= 1.0f; - nhs->val= 1.0f; -} - -void register_node_type_cmp_hue_sat(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - cmp_node_hue_sat_in, cmp_node_hue_sat_out); - node_type_size(&ntype, 150, 80, 250); - node_type_init(&ntype, node_composit_init_hue_sat); - node_type_storage(&ntype, "NodeHueSat", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_hue_sat); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_huecorrect.c b/source/blender/nodes/intern/CMP_nodes/CMP_huecorrect.c deleted file mode 100644 index edf6c454285..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_huecorrect.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Matt Ebb - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_huecorrect.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -static bNodeSocketType cmp_node_huecorrect_in[]= { - { SOCK_VALUE, 1, "Fac", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, "Image", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType cmp_node_huecorrect_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_huecorrect(bNode *node, float *out, float *in) -{ - float hsv[3], f; - - rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2); - - /* adjust hue, scaling returned default 0.5 up to 1 */ - f = curvemapping_evaluateF(node->storage, 0, hsv[0]); - hsv[0] += f-0.5f; - - /* adjust saturation, scaling returned default 0.5 up to 1 */ - f = curvemapping_evaluateF(node->storage, 1, hsv[0]); - hsv[1] *= (f * 2.f); - - /* adjust value, scaling returned default 0.5 up to 1 */ - f = curvemapping_evaluateF(node->storage, 2, hsv[0]); - hsv[2] *= (f * 2.f); - - hsv[0] = hsv[0] - floor(hsv[0]); /* mod 1.0 */ - CLAMP(hsv[1], 0.f, 1.f); - - /* convert back to rgb */ - hsv_to_rgb(hsv[0], hsv[1], hsv[2], out, out+1, out+2); - - out[3]= in[3]; -} - -static void do_huecorrect_fac(bNode *node, float *out, float *in, float *fac) -{ - float hsv[3], rgb[3], f; - const float mfac = 1.f-*fac; - - rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2); - - /* adjust hue, scaling returned default 0.5 up to 1 */ - f = curvemapping_evaluateF(node->storage, 0, hsv[0]); - hsv[0] += f-0.5f; - - /* adjust saturation, scaling returned default 0.5 up to 1 */ - f = curvemapping_evaluateF(node->storage, 1, hsv[0]); - hsv[1] *= (f * 2.f); - - /* adjust value, scaling returned default 0.5 up to 1 */ - f = curvemapping_evaluateF(node->storage, 2, hsv[0]); - hsv[2] *= (f * 2.f); - - hsv[0] = hsv[0] - floor(hsv[0]); /* mod 1.0 */ - CLAMP(hsv[1], 0.f, 1.f); - - /* convert back to rgb */ - hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); - - out[0]= mfac*in[0] + *fac*rgb[0]; - out[1]= mfac*in[1] + *fac*rgb[1]; - out[2]= mfac*in[2] + *fac*rgb[2]; - out[3]= in[3]; -} - -static void node_composit_exec_huecorrect(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf *cbuf= in[1]->data; - CompBuf *stackbuf; - - /* stack order input: fac, image, black level, white level */ - /* stack order output: image */ - - if(out[0]->hasoutput==0) - return; - - if(in[0]->vec[0] == 0.f && in[0]->data == NULL) { - out[0]->data = pass_on_compbuf(cbuf); - return; - } - - /* input no image? then only color operation */ - if(in[1]->data==NULL) { - do_huecorrect_fac(node, out[0]->vec, in[1]->vec, in[0]->vec); - } - - if (cbuf) { - stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* make output size of input image */ - - if ((in[0]->data==NULL) && (in[0]->vec[0] >= 1.f)) - composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_huecorrect, CB_RGBA); - else - composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_huecorrect_fac, CB_RGBA, CB_VAL); - - out[0]->data= stackbuf; - } - -} - -static void node_composit_init_huecorrect(bNode* node) -{ - CurveMapping *cumapping = node->storage= curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); - int c; - - cumapping->preset = CURVE_PRESET_MID9; - - for (c=0; c<3; c++) { - CurveMap *cuma = &cumapping->cm[c]; - curvemap_reset(cuma, &cumapping->clipr, cumapping->preset, CURVEMAP_SLOPE_POSITIVE); - } - - /* default to showing Saturation */ - cumapping->cur = 1; -} - -void register_node_type_cmp_huecorrect(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_HUECORRECT, "Hue Correct", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - cmp_node_huecorrect_in, cmp_node_huecorrect_out); - node_type_size(&ntype, 320, 140, 400); - node_type_init(&ntype, node_composit_init_huecorrect); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - node_type_exec(&ntype, node_composit_exec_huecorrect); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_idMask.c b/source/blender/nodes/intern/CMP_nodes/CMP_idMask.c deleted file mode 100644 index 72d0de7d15e..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_idMask.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_idMask.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** ID Mask ******************** */ - -static bNodeSocketType cmp_node_idmask_in[]= { - { SOCK_VALUE, 1, "ID value", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_idmask_out[]= { - { SOCK_VALUE, 0, "Alpha", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -/* stackbuf should be zeroed */ -static void do_idmask(CompBuf *stackbuf, CompBuf *cbuf, float idnr) -{ - float *rect; - int x; - char *abuf= MEM_mapallocN(cbuf->x*cbuf->y, "anti ali buf"); - - rect= cbuf->rect; - for(x= cbuf->x*cbuf->y - 1; x>=0; x--) - if(rect[x]==idnr) - abuf[x]= 255; - - antialias_tagbuf(cbuf->x, cbuf->y, abuf); - - rect= stackbuf->rect; - for(x= cbuf->x*cbuf->y - 1; x>=0; x--) - if(abuf[x]>1) - rect[x]= (1.0f/255.0f)*(float)abuf[x]; - - MEM_freeN(abuf); -} - -/* full sample version */ -static void do_idmask_fsa(CompBuf *stackbuf, CompBuf *cbuf, float idnr) -{ - float *rect, *rs; - int x; - - rect= cbuf->rect; - rs= stackbuf->rect; - for(x= cbuf->x*cbuf->y - 1; x>=0; x--) - if(rect[x]==idnr) - rs[x]= 1.0f; - -} - - -static void node_composit_exec_idmask(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - RenderData *rd= data; - - if(out[0]->hasoutput==0) - return; - - if(in[0]->data) { - CompBuf *cbuf= in[0]->data; - CompBuf *stackbuf; - - if(cbuf->type!=CB_VAL) - return; - - stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */; - - if(rd->scemode & R_FULL_SAMPLE) - do_idmask_fsa(stackbuf, cbuf, (float)node->custom1); - else - do_idmask(stackbuf, cbuf, (float)node->custom1); - - out[0]->data= stackbuf; - } -} - - -void register_node_type_cmp_idmask(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_ID_MASK, "ID Mask", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - cmp_node_idmask_in, cmp_node_idmask_out); - node_type_size(&ntype, 140, 100, 320); - node_type_exec(&ntype, node_composit_exec_idmask); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_image.c b/source/blender/nodes/intern/CMP_nodes/CMP_image.c deleted file mode 100644 index a5f256054cd..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_image.c +++ /dev/null @@ -1,452 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_image.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** IMAGE (and RenderResult, multilayer image) ******************** */ - -static bNodeSocketType cmp_node_rlayers_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { 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, "UV", 1.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, "Reflect", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, "Refract", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, "Indirect", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "IndexOB", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "IndexMA", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "Mist", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, "Emit", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, "Environment",0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - - -/* note: this function is used for multilayer too, to ensure uniform - handling with BKE_image_get_ibuf() */ -static CompBuf *node_composit_get_image(RenderData *rd, Image *ima, ImageUser *iuser) -{ - ImBuf *ibuf; - CompBuf *stackbuf; - int type; - - float *rect; - int alloc= FALSE; - - ibuf= BKE_image_get_ibuf(ima, iuser); - if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL)) { - return NULL; - } - - if (ibuf->rect_float == NULL) { - IMB_float_from_rect(ibuf); - } - - /* now we need a float buffer from the image with matching color management */ - /* XXX weak code, multilayer is excluded from this */ - if(ibuf->channels == 4 && ima->rr==NULL) { - if(rd->color_mgt_flag & R_COLOR_MANAGEMENT) { - if(ibuf->profile != IB_PROFILE_NONE) { - rect= ibuf->rect_float; - } - else { - rect= MEM_mapallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, "node_composit_get_image"); - srgb_to_linearrgb_rgba_rgba_buf(rect, ibuf->rect_float, ibuf->x * ibuf->y); - alloc= TRUE; - } - } - else { - if(ibuf->profile == IB_PROFILE_NONE) { - rect= ibuf->rect_float; - } - else { - rect= MEM_mapallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, "node_composit_get_image"); - linearrgb_to_srgb_rgba_rgba_buf(rect, ibuf->rect_float, ibuf->x * ibuf->y); - alloc= TRUE; - } - } - } - else { - /* non-rgba passes can't use color profiles */ - rect= ibuf->rect_float; - } - /* done coercing into the correct color management */ - - - type= ibuf->channels; - - if(rd->scemode & R_COMP_CROP) { - stackbuf= get_cropped_compbuf(&rd->disprect, rect, ibuf->x, ibuf->y, type); - if(alloc) - MEM_freeN(rect); - } - else { - /* we put imbuf copy on stack, cbuf knows rect is from other ibuf when freed! */ - stackbuf= alloc_compbuf(ibuf->x, ibuf->y, type, FALSE); - stackbuf->rect= rect; - stackbuf->malloc= alloc; - } - - /*code to respect the premul flag of images; I'm - not sure if this is a good idea for multilayer images, - since it never worked before for them. - if (type==CB_RGBA && ima->flag & IMA_DO_PREMUL) { - //premul the image - int i; - float *pixel = stackbuf->rect; - - for (i=0; i<stackbuf->x*stackbuf->y; i++, pixel += 4) { - pixel[0] *= pixel[3]; - pixel[1] *= pixel[3]; - pixel[2] *= pixel[3]; - } - } - */ - return stackbuf; -} - -static CompBuf *node_composit_get_zimage(bNode *node, RenderData *rd) -{ - ImBuf *ibuf= BKE_image_get_ibuf((Image *)node->id, node->storage); - CompBuf *zbuf= NULL; - - if(ibuf && ibuf->zbuf_float) { - if(rd->scemode & R_COMP_CROP) { - zbuf= get_cropped_compbuf(&rd->disprect, ibuf->zbuf_float, ibuf->x, ibuf->y, CB_VAL); - } - else { - zbuf= alloc_compbuf(ibuf->x, ibuf->y, CB_VAL, 0); - zbuf->rect= ibuf->zbuf_float; - } - } - return zbuf; -} - -/* check if layer is available, returns pass buffer */ -static CompBuf *compbuf_multilayer_get(RenderData *rd, RenderLayer *rl, Image *ima, ImageUser *iuser, int passtype) -{ - RenderPass *rpass; - short index; - - for(index=0, rpass= rl->passes.first; rpass; rpass= rpass->next, index++) - if(rpass->passtype==passtype) - break; - - if(rpass) { - CompBuf *cbuf; - - iuser->pass= index; - BKE_image_multilayer_index(ima->rr, iuser); - cbuf= node_composit_get_image(rd, ima, iuser); - - return cbuf; - } - return NULL; -} - -static void outputs_multilayer_get(RenderData *rd, RenderLayer *rl, bNodeStack **out, Image *ima, ImageUser *iuser) -{ - if(out[RRES_OUT_Z]->hasoutput) - out[RRES_OUT_Z]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_Z); - if(out[RRES_OUT_VEC]->hasoutput) - out[RRES_OUT_VEC]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_VECTOR); - if(out[RRES_OUT_NORMAL]->hasoutput) - out[RRES_OUT_NORMAL]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_NORMAL); - if(out[RRES_OUT_UV]->hasoutput) - out[RRES_OUT_UV]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_UV); - - if(out[RRES_OUT_RGBA]->hasoutput) - out[RRES_OUT_RGBA]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_RGBA); - if(out[RRES_OUT_DIFF]->hasoutput) - out[RRES_OUT_DIFF]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_DIFFUSE); - if(out[RRES_OUT_SPEC]->hasoutput) - out[RRES_OUT_SPEC]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_SPEC); - if(out[RRES_OUT_SHADOW]->hasoutput) - out[RRES_OUT_SHADOW]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_SHADOW); - if(out[RRES_OUT_AO]->hasoutput) - out[RRES_OUT_AO]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_AO); - if(out[RRES_OUT_REFLECT]->hasoutput) - out[RRES_OUT_REFLECT]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_REFLECT); - if(out[RRES_OUT_REFRACT]->hasoutput) - out[RRES_OUT_REFRACT]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_REFRACT); - if(out[RRES_OUT_INDIRECT]->hasoutput) - out[RRES_OUT_INDIRECT]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_INDIRECT); - if(out[RRES_OUT_INDEXOB]->hasoutput) - out[RRES_OUT_INDEXOB]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_INDEXOB); - if(out[RRES_OUT_INDEXMA]->hasoutput) - out[RRES_OUT_INDEXMA]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_INDEXMA); - if(out[RRES_OUT_MIST]->hasoutput) - out[RRES_OUT_MIST]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_MIST); - if(out[RRES_OUT_EMIT]->hasoutput) - out[RRES_OUT_EMIT]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_EMIT); - if(out[RRES_OUT_ENV]->hasoutput) - out[RRES_OUT_ENV]->data= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_ENVIRONMENT); -} - - -static void node_composit_exec_image(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out) -{ - - /* image assigned to output */ - /* stack order input sockets: col, alpha */ - if(node->id) { - RenderData *rd= data; - Image *ima= (Image *)node->id; - ImageUser *iuser= (ImageUser *)node->storage; - CompBuf *stackbuf= NULL; - - /* first set the right frame number in iuser */ - BKE_image_user_calc_frame(iuser, rd->cfra, 0); - - /* force a load, we assume iuser index will be set OK anyway */ - if(ima->type==IMA_TYPE_MULTILAYER) - BKE_image_get_ibuf(ima, iuser); - - if(ima->type==IMA_TYPE_MULTILAYER && ima->rr) { - RenderLayer *rl= BLI_findlink(&ima->rr->layers, iuser->layer); - - if(rl) { - out[0]->data= stackbuf= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_COMBINED); - - /* go over all layers */ - outputs_multilayer_get(rd, rl, out, ima, iuser); - } - } - else { - stackbuf= node_composit_get_image(rd, ima, iuser); - - if (stackbuf) { - /*respect image premul option*/ - if (stackbuf->type==CB_RGBA && ima->flag & IMA_DO_PREMUL) { - int i; - float *pixel; - - /*first duplicate stackbuf->rect, since it's just a pointer - to the source imbuf, and we don't want to change that.*/ - stackbuf->rect = MEM_dupallocN(stackbuf->rect); - - /* since stackbuf now has allocated memory, rather than just a pointer, - * mark it as allocated so it can be freed properly */ - stackbuf->malloc=1; - - /*premul the image*/ - pixel = stackbuf->rect; - for (i=0; i<stackbuf->x*stackbuf->y; i++, pixel += 4) { - pixel[0] *= pixel[3]; - pixel[1] *= pixel[3]; - pixel[2] *= pixel[3]; - } - } - - /* put image on stack */ - out[0]->data= stackbuf; - - if(out[2]->hasoutput) - out[2]->data= node_composit_get_zimage(node, rd); - } - } - - /* alpha and preview for both types */ - if(stackbuf) { - if(out[1]->hasoutput) - out[1]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A); - - generate_preview(data, node, stackbuf); - } - } -} - -static void node_composit_init_image(bNode* node) -{ - ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user"); - node->storage= iuser; - iuser->frames= 1; - iuser->sfra= 1; - iuser->fie_ima= 2; - iuser->ok= 1; -} - -void register_node_type_cmp_image(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_IMAGE, "Image", NODE_CLASS_INPUT, NODE_PREVIEW|NODE_OPTIONS, - NULL, cmp_node_rlayers_out); - node_type_size(&ntype, 120, 80, 300); - node_type_init(&ntype, node_composit_init_image); - node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_image); - - nodeRegisterType(lb, &ntype); -} - - -/* **************** RENDER RESULT ******************** */ - -static CompBuf *compbuf_from_pass(RenderData *rd, RenderLayer *rl, int rectx, int recty, int passcode) -{ - float *fp= RE_RenderLayerGetPass(rl, passcode); - if(fp) { - CompBuf *buf; - int buftype= CB_VEC3; - - if(ELEM4(passcode, SCE_PASS_Z, SCE_PASS_INDEXOB, SCE_PASS_MIST, SCE_PASS_INDEXMA)) - buftype= CB_VAL; - else if(passcode==SCE_PASS_VECTOR) - buftype= CB_VEC4; - else if(ELEM(passcode, SCE_PASS_COMBINED, SCE_PASS_RGBA)) - buftype= CB_RGBA; - - if(rd->scemode & R_COMP_CROP) - buf= get_cropped_compbuf(&rd->disprect, fp, rectx, recty, buftype); - else { - buf= alloc_compbuf(rectx, recty, buftype, 0); - buf->rect= fp; - } - return buf; - } - return NULL; -} - -static void node_composit_rlayers_out(RenderData *rd, RenderLayer *rl, bNodeStack **out, int rectx, int recty) -{ - if(out[RRES_OUT_Z]->hasoutput) - out[RRES_OUT_Z]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_Z); - if(out[RRES_OUT_VEC]->hasoutput) - out[RRES_OUT_VEC]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_VECTOR); - if(out[RRES_OUT_NORMAL]->hasoutput) - out[RRES_OUT_NORMAL]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_NORMAL); - if(out[RRES_OUT_UV]->hasoutput) - out[RRES_OUT_UV]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_UV); - - if(out[RRES_OUT_RGBA]->hasoutput) - out[RRES_OUT_RGBA]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_RGBA); - if(out[RRES_OUT_DIFF]->hasoutput) - out[RRES_OUT_DIFF]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_DIFFUSE); - if(out[RRES_OUT_SPEC]->hasoutput) - out[RRES_OUT_SPEC]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_SPEC); - if(out[RRES_OUT_SHADOW]->hasoutput) - out[RRES_OUT_SHADOW]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_SHADOW); - if(out[RRES_OUT_AO]->hasoutput) - out[RRES_OUT_AO]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_AO); - if(out[RRES_OUT_REFLECT]->hasoutput) - out[RRES_OUT_REFLECT]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_REFLECT); - if(out[RRES_OUT_REFRACT]->hasoutput) - out[RRES_OUT_REFRACT]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_REFRACT); - if(out[RRES_OUT_INDIRECT]->hasoutput) - out[RRES_OUT_INDIRECT]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_INDIRECT); - if(out[RRES_OUT_INDEXOB]->hasoutput) - out[RRES_OUT_INDEXOB]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_INDEXOB); - if(out[RRES_OUT_INDEXMA]->hasoutput) - out[RRES_OUT_INDEXMA]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_INDEXMA); - if(out[RRES_OUT_MIST]->hasoutput) - out[RRES_OUT_MIST]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_MIST); - if(out[RRES_OUT_EMIT]->hasoutput) - out[RRES_OUT_EMIT]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_EMIT); - if(out[RRES_OUT_ENV]->hasoutput) - out[RRES_OUT_ENV]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_ENVIRONMENT); -} - -static void node_composit_exec_rlayers(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out) -{ - Scene *sce= (Scene *)node->id; - Render *re= (sce)? RE_GetRender(sce->id.name): NULL; - RenderData *rd= data; - RenderResult *rr= NULL; - - if(re) - rr= RE_AcquireResultRead(re); - - if(rr) { - SceneRenderLayer *srl= BLI_findlink(&sce->r.layers, node->custom1); - if(srl) { - RenderLayer *rl= RE_GetRenderLayer(rr, srl->name); - if(rl && rl->rectf) { - CompBuf *stackbuf; - - /* we put render rect on stack, cbuf knows rect is from other ibuf when freed! */ - if(rd->scemode & R_COMP_CROP) - stackbuf= get_cropped_compbuf(&rd->disprect, rl->rectf, rr->rectx, rr->recty, CB_RGBA); - else { - stackbuf= alloc_compbuf(rr->rectx, rr->recty, CB_RGBA, 0); - stackbuf->rect= rl->rectf; - } - if(stackbuf==NULL) { - printf("Error; Preview Panel in UV Window returns zero sized image\n"); - } - else { - stackbuf->xof= rr->xof; - stackbuf->yof= rr->yof; - - /* put on stack */ - out[RRES_OUT_IMAGE]->data= stackbuf; - - if(out[RRES_OUT_ALPHA]->hasoutput) - out[RRES_OUT_ALPHA]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A); - - node_composit_rlayers_out(rd, rl, out, rr->rectx, rr->recty); - - generate_preview(data, node, stackbuf); - } - } - } - } - - if(re) - RE_ReleaseResult(re); -} - - -void register_node_type_cmp_rlayers(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_R_LAYERS, "Render Layers", NODE_CLASS_INPUT, NODE_PREVIEW|NODE_OPTIONS, - NULL, cmp_node_rlayers_out); - node_type_size(&ntype, 150, 100, 300); - node_type_exec(&ntype, node_composit_exec_rlayers); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_invert.c b/source/blender/nodes/intern/CMP_nodes/CMP_invert.c deleted file mode 100644 index 27b0324dfe0..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_invert.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_invert.c - * \ingroup cmpnodes - */ - -#include "../CMP_util.h" - -/* **************** INVERT ******************** */ -static bNodeSocketType cmp_node_invert_in[]= { - { SOCK_VALUE, 1, "Fac", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType cmp_node_invert_out[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_invert(bNode *node, float *out, float *in) -{ - if(node->custom1 & CMP_CHAN_RGB) { - out[0] = 1.0f - in[0]; - out[1] = 1.0f - in[1]; - out[2] = 1.0f - in[2]; - } else - VECCOPY(out, in); - - if(node->custom1 & CMP_CHAN_A) - out[3] = 1.0f - in[3]; - else - out[3] = in[3]; -} - -static void do_invert_fac(bNode *node, float *out, float *in, float *fac) -{ - float col[4], facm; - - do_invert(node, col, in); - - /* blend inverted result against original input with fac */ - facm = 1.0 - fac[0]; - - if(node->custom1 & CMP_CHAN_RGB) { - col[0] = fac[0]*col[0] + (facm*in[0]); - col[1] = fac[0]*col[1] + (facm*in[1]); - col[2] = fac[0]*col[2] + (facm*in[2]); - } - if(node->custom1 & CMP_CHAN_A) - col[3] = fac[0]*col[3] + (facm*in[3]); - - QUATCOPY(out, col); -} - -static void node_composit_exec_invert(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order in: fac, Image, Image */ - /* stack order out: Image */ - float *fac= in[0]->vec; - - if(out[0]->hasoutput==0) return; - - /* input no image? then only color operation */ - if(in[1]->data==NULL && in[0]->data==NULL) { - do_invert_fac(node, out[0]->vec, in[1]->vec, fac); - } - else { - /* make output size of first available input image, or then size of fac */ - CompBuf *cbuf= in[1]->data?in[1]->data:in[0]->data; - - /* if neither RGB or A toggled on, pass through */ - if (node->custom1 != 0) { - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ - - if (fac[0] < 1.0f || in[0]->data!=NULL) - composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, fac, do_invert_fac, CB_RGBA, CB_VAL); - else - composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_invert, CB_RGBA); - out[0]->data= stackbuf; - return; - - } else { - out[0]->data = pass_on_compbuf(cbuf); - return; - } - } -} - -static void node_composit_init_invert(bNode *node) -{ - node->custom1 |= CMP_CHAN_RGB; -} - -/* custom1 = mix type */ -void register_node_type_cmp_invert(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - cmp_node_invert_in, cmp_node_invert_out); - node_type_size(&ntype, 120, 120, 140); - node_type_init(&ntype, node_composit_init_invert); - node_type_exec(&ntype, node_composit_exec_invert); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_lensdist.c b/source/blender/nodes/intern/CMP_nodes/CMP_lensdist.c deleted file mode 100644 index 3a005210c6a..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_lensdist.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Alfredo de Greef (eeshlo) - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_lensdist.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -static bNodeSocketType cmp_node_lensdist_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Distort", 0.f, 0.f, 0.f, 0.f, -0.999f, 1.f}, - { SOCK_VALUE, 1, "Dispersion", 0.f, 0.f, 0.f, 0.f, 0.f, 1.f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_lensdist_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -/* assumes *dst is type RGBA */ -static void lensDistort(CompBuf *dst, CompBuf *src, float kr, float kg, float kb, int jit, int proj, int fit) -{ - int x, y, z; - const float cx = 0.5f*(float)dst->x, cy = 0.5f*(float)dst->y; - - if (proj) { - // shift - CompBuf *tsrc = dupalloc_compbuf(src); - - for (z=0; z<tsrc->type; ++z) - IIR_gauss(tsrc, (kr+0.5f)*(kr+0.5f), z, 1); - kr *= 20.f; - - for (y=0; y<dst->y; y++) { - fRGB *colp = (fRGB*)&dst->rect[y*dst->x*dst->type]; - const float v = (y + 0.5f)/(float)dst->y; - - for (x=0; x<dst->x; x++) { - const float u = (x + 0.5f)/(float)dst->x; - - qd_getPixelLerpChan(tsrc, (u*dst->x + kr) - 0.5f, v*dst->y - 0.5f, 0, colp[x]); - if (tsrc->type == CB_VAL) - colp[x][1] = tsrc->rect[x + y*tsrc->x]; - else - colp[x][1] = tsrc->rect[(x + y*tsrc->x)*tsrc->type + 1]; - qd_getPixelLerpChan(tsrc, (u*dst->x - kr) - 0.5f, v*dst->y - 0.5f, 2, colp[x]+2); - - /* set alpha */ - colp[x][3]= 1.0f; - } - } - free_compbuf(tsrc); - } - else { - // Spherical - // Scale factor to make bottom/top & right/left sides fit in window after deform - // so in the case of pincushion (kn < 0), corners will be outside window. - // Now also optionally scales image such that black areas are not visible when distort factor is positive - // (makes distorted corners match window corners, but really only valid if mk<=0.5) - const float mk = MAX3(kr, kg, kb); - const float sc = (fit && (mk > 0.f)) ? (1.f/(1.f + 2.f*mk)) : (1.f/(1.f + mk)); - const float drg = 4.f*(kg - kr), dgb = 4.f*(kb - kg); - - kr *= 4.f, kg *= 4.f, kb *= 4.f; - - for (y=0; y<dst->y; y++) { - fRGB *colp = (fRGB*)&dst->rect[y*dst->x*dst->type]; - const float v = sc*((y + 0.5f) - cy)/cy; - - for (x=0; x<dst->x; x++) { - int dr = 0, dg = 0, db = 0; - float d, t, ln[6] = {0, 0, 0, 0, 0, 0}; - fRGB c1, tc = {0, 0, 0, 0}; - const float u = sc*((x + 0.5f) - cx)/cx; - int sta = 0, mid = 0, end = 0; - - if ((t = 1.f - kr*(u*u + v*v)) >= 0.f) { - d = 1.f/(1.f + sqrtf(t)); - ln[0] = (u*d + 0.5f)*dst->x - 0.5f, ln[1] = (v*d + 0.5f)*dst->y - 0.5f; - sta = 1; - } - if ((t = 1.f - kg*(u*u + v*v)) >= 0.f) { - d = 1.f/(1.f + sqrtf(t)); - ln[2] = (u*d + 0.5f)*dst->x - 0.5f, ln[3] = (v*d + 0.5f)*dst->y - 0.5f; - mid = 1; - } - if ((t = 1.f - kb*(u*u + v*v)) >= 0.f) { - d = 1.f/(1.f + sqrtf(t)); - ln[4] = (u*d + 0.5f)*dst->x - 0.5f, ln[5] = (v*d + 0.5f)*dst->y - 0.5f; - end = 1; - } - - if (sta && mid && end) { - // RG - const int dx = ln[2] - ln[0], dy = ln[3] - ln[1]; - const float dsf = sqrtf(dx*dx + dy*dy) + 1.f; - const int ds = (int)(jit ? ((dsf < 4.f) ? 2.f : sqrtf(dsf)) : dsf); - const float sd = 1.f/(float)ds; - - for (z=0; z<ds; ++z) { - const float tz = ((float)z + (jit ? BLI_frand() : 0.5f))*sd; - t = 1.f - (kr + tz*drg)*(u*u + v*v); - d = 1.f / (1.f + sqrtf(t)); - qd_getPixelLerp(src, (u*d + 0.5f)*dst->x - 0.5f, (v*d + 0.5f)*dst->y - 0.5f, c1); - if (src->type == CB_VAL) c1[1] = c1[2] = c1[0]; - tc[0] += (1.f-tz)*c1[0], tc[1] += tz*c1[1]; - dr++, dg++; - } - // GB - { - const int dx = ln[4] - ln[2], dy = ln[5] - ln[3]; - const float dsf = sqrtf(dx*dx + dy*dy) + 1.f; - const int ds = (int)(jit ? ((dsf < 4.f) ? 2.f : sqrtf(dsf)) : dsf); - const float sd = 1.f/(float)ds; - - for (z=0; z<ds; ++z) { - const float tz = ((float)z + (jit ? BLI_frand() : 0.5f))*sd; - t = 1.f - (kg + tz*dgb)*(u*u + v*v); - d = 1.f / (1.f + sqrtf(t)); - qd_getPixelLerp(src, (u*d + 0.5f)*dst->x - 0.5f, (v*d + 0.5f)*dst->y - 0.5f, c1); - if (src->type == CB_VAL) c1[1] = c1[2] = c1[0]; - tc[1] += (1.f-tz)*c1[1], tc[2] += tz*c1[2]; - dg++, db++; - } - } - } - - if (dr) colp[x][0] = 2.f*tc[0] / (float)dr; - if (dg) colp[x][1] = 2.f*tc[1] / (float)dg; - if (db) colp[x][2] = 2.f*tc[2] / (float)db; - - /* set alpha */ - colp[x][3]= 1.0f; - } - } - } -} - - -static void node_composit_exec_lensdist(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf *new, *img = in[0]->data; - NodeLensDist *nld = node->storage; - const float k = MAX2(MIN2(in[1]->vec[0], 1.f), -0.999f); - // smaller dispersion range for somewhat more control - const float d = 0.25f*MAX2(MIN2(in[2]->vec[0], 1.f), 0.f); - const float kr = MAX2(MIN2((k+d), 1.f), -0.999f), kb = MAX2(MIN2((k-d), 1.f), -0.999f); - - if ((img==NULL) || (out[0]->hasoutput==0)) return; - - new = alloc_compbuf(img->x, img->y, CB_RGBA, 1); - - lensDistort(new, img, (nld->proj ? d : kr), k, kb, nld->jit, nld->proj, nld->fit); - - out[0]->data = new; -} - - -static void node_composit_init_lensdist(bNode* node) -{ - NodeLensDist *nld = MEM_callocN(sizeof(NodeLensDist), "node lensdist data"); - nld->jit = nld->proj = nld->fit = 0; - node->storage = nld; -} - - -void register_node_type_cmp_lensdist(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_LENSDIST, "Lens Distortion", NODE_CLASS_DISTORT, NODE_OPTIONS, - cmp_node_lensdist_in, cmp_node_lensdist_out); - node_type_size(&ntype, 150, 120, 200); - node_type_init(&ntype, node_composit_init_lensdist); - node_type_storage(&ntype, "NodeLensDist", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_lensdist); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_levels.c b/source/blender/nodes/intern/CMP_nodes/CMP_levels.c deleted file mode 100644 index 2c9f7d97f09..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_levels.c +++ /dev/null @@ -1,350 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Bob Holcomb. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_levels.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** LEVELS ******************** */ -static bNodeSocketType cmp_node_view_levels_in[]= { - { SOCK_RGBA, 1, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType cmp_node_view_levels_out[]={ - {SOCK_VALUE, 0,"Mean",0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - {SOCK_VALUE, 0,"Std Dev",0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - {-1,0,""} -}; - -static void rgb_tobw(float r, float g, float b, float* out) -{ - *out= r*0.35f + g*0.45f + b*0.2f; -} - -static void fill_bins(bNode* node, CompBuf* in, int* bins, int colorcor) -{ - float value[4]; - int ivalue=0; - int x,y; - - /*fill bins */ - for(y=0; y<in->y; y++) { - for(x=0; x<in->x; x++) { - - /* get the pixel */ - qd_getPixel(in, x, y, value); - - if(value[3] > 0.0) { /* don't count transparent pixels */ - switch(node->custom1) { - case 1: { /* all colors */ - if(colorcor) - linearrgb_to_srgb_v3_v3(&value[0],&value[0]); - rgb_tobw(value[0],value[1],value[2], &value[0]); - value[0]=value[0]*255; /* scale to 0-255 range */ - ivalue=(int)value[0]; - break; - } - case 2: { /* red channel */ - if(colorcor) - value[0]=linearrgb_to_srgb(value[0]); - value[0]=value[0]*255; /* scale to 0-255 range */ - ivalue=(int)value[0]; - break; - } - case 3: { /* green channel */ - if(colorcor) - value[1]=linearrgb_to_srgb(value[1]); - value[1]=value[1]*255; /* scale to 0-255 range */ - ivalue=(int)value[1]; - break; - } - case 4: /*blue channel */ - { - if(colorcor) - value[2]=linearrgb_to_srgb(value[2]); - value[2]=value[2]*255; /* scale to 0-255 range */ - ivalue=(int)value[2]; - break; - } - case 5: /* luminence */ - { - if(colorcor) - linearrgb_to_srgb_v3_v3(&value[0],&value[0]); - rgb_to_yuv(value[0],value[1],value[2], &value[0], &value[1], &value[2]); - value[0]=value[0]*255; /* scale to 0-255 range */ - ivalue=(int)value[0]; - break; - } - } /*end switch */ - - /*clip*/ - if(ivalue<0) ivalue=0; - if(ivalue>255) ivalue=255; - - /*put in the correct bin*/ - bins[ivalue]+=1; - } /*end if alpha */ - } - } -} - -static float brightness_mean(bNode* node, CompBuf* in) -{ - float sum=0.0; - int numPixels=0.0; - int x,y; - float value[4]; - - for(x=0; x< in->x; x++) { - for(y=0; y < in->y; y++) { - - /* get the pixel */ - qd_getPixel(in, x, y, value); - - if(value[3] > 0.0) { /* don't count transparent pixels */ - numPixels++; - switch(node->custom1) - { - case 1: - { - rgb_tobw(value[0],value[1],value[2], &value[0]); - sum+=value[0]; - break; - } - case 2: - { - sum+=value[0]; - break; - } - case 3: - { - sum+=value[1]; - break; - } - case 4: - { - sum+=value[2]; - break; - } - case 5: - { - rgb_to_yuv(value[0],value[1],value[2], &value[0], &value[1], &value[2]); - sum+=value[0]; - break; - } - } - } - } - } - - return sum/numPixels; -} - -static float brightness_standard_deviation(bNode* node, CompBuf* in, float mean) -{ - float sum=0.0; - int numPixels=0.0; - int x,y; - float value[4]; - - for(x=0; x< in->x; x++) { - for(y=0; y < in->y; y++) { - - /* get the pixel */ - qd_getPixel(in, x, y, value); - - if(value[3] > 0.0) { /* don't count transparent pixels */ - numPixels++; - switch(node->custom1) - { - case 1: - { - rgb_tobw(value[0],value[1],value[2], &value[0]); - sum+=(value[0]-mean)*(value[0]-mean); - break; - } - case 2: - { - sum+=value[0]; - sum+=(value[0]-mean)*(value[0]-mean); - break; - } - case 3: - { - sum+=value[1]; - sum+=(value[1]-mean)*(value[1]-mean); - break; - } - case 4: - { - sum+=value[2]; - sum+=(value[2]-mean)*(value[2]-mean); - break; - } - case 5: - { - rgb_to_yuv(value[0],value[1],value[2], &value[0], &value[1], &value[2]); - sum+=(value[0]-mean)*(value[0]-mean); - break; - } - } - } - } - } - - - return sqrt(sum/(float)(numPixels-1)); -} - -static void draw_histogram(bNode *node, CompBuf *out, int* bins) -{ - int x,y; - float color[4]; - float value; - int max; - - /* find max value */ - max=0; - for(x=0; x<256; x++) { - if(bins[x]>max) max=bins[x]; - } - - /*draw histogram in buffer */ - for(x=0; x<out->x; x++) { - for(y=0;y<out->y; y++) { - - /* get normalized value (0..255) */ - value=((float)bins[x]/(float)max)*255.0; - - if(y < (int)value) { /*if the y value is below the height of the bar for this line then draw with the color */ - switch (node->custom1) { - case 1: { /* draw in black */ - color[0]=0.0; color[1]=0.0; color[2]=0.0; color[3]=1.0; - break; - } - case 2: { /* draw in red */ - color[0]=1.0; color[1]=0.0; color[2]=0.0; color[3]=1.0; - break; - } - case 3: { /* draw in green */ - color[0]=0.0; color[1]=1.0; color[2]=0.0; color[3]=1.0; - break; - } - case 4: { /* draw in blue */ - color[0]=0.0; color[1]=0.0; color[2]=1.0; color[3]=1.0; - break; - } - case 5: { /* draw in white */ - color[0]=1.0; color[1]=1.0; color[2]=1.0; color[3]=1.0; - break; - } - } - } - else{ - color[0]=0.8; color[1]=0.8; color[2]=0.8; color[3]=1.0; - } - - /* set the color */ - qd_setPixel(out, x, y, color); - } - } -} - -static void node_composit_exec_view_levels(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf* cbuf; - CompBuf* histogram; - RenderData *rd=data; - float mean, std_dev; - int bins[256]; - int x; - - if(in[0]->hasinput==0) return; - if(in[0]->data==NULL) return; - - histogram=alloc_compbuf(256, 256, CB_RGBA, 1); - cbuf=typecheck_compbuf(in[0]->data, CB_RGBA); - - /*initalize bins*/ - for(x=0; x<256; x++) { - bins[x]=0; - } - - /*fill bins */ - fill_bins(node, in[0]->data, bins, rd->color_mgt_flag & R_COLOR_MANAGEMENT); - - /* draw the histogram chart */ - draw_histogram(node, histogram, bins); - - /* calculate the average brightness and contrast */ - mean=brightness_mean(node, in[0]->data); - std_dev=brightness_standard_deviation(node, in[0]->data, mean); - - /* Printf debuging ;) - printf("Mean: %f\n", mean); - printf("Std Dev: %f\n", std_dev); - */ - - if(out[0]->hasoutput) - out[0]->vec[0]= mean; - if(out[1]->hasoutput) - out[1]->vec[0]= std_dev; - - generate_preview(data, node, histogram); - - if(cbuf!=in[0]->data) - free_compbuf(cbuf); - free_compbuf(histogram); -} - -static void node_composit_init_view_levels(bNode* node) -{ - node->custom1=1; /*All channels*/ -} - -void register_node_type_cmp_view_levels(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_VIEW_LEVELS, "Levels", NODE_CLASS_OUTPUT, NODE_OPTIONS|NODE_PREVIEW, - cmp_node_view_levels_in, cmp_node_view_levels_out); - node_type_size(&ntype, 140, 100, 320); - node_type_init(&ntype, node_composit_init_view_levels); - node_type_storage(&ntype, "ImageUser", NULL, NULL); - node_type_exec(&ntype, node_composit_exec_view_levels); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_lummaMatte.c b/source/blender/nodes/intern/CMP_nodes/CMP_lummaMatte.c deleted file mode 100644 index 34e58791932..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_lummaMatte.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Bob Holcomb . - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_lummaMatte.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* ******************* Luma Matte Node ********************************* */ -static bNodeSocketType cmp_node_luma_matte_in[]={ - {SOCK_RGBA,1,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - {-1,0,""} -}; - -static bNodeSocketType cmp_node_luma_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 do_luma_matte(bNode *node, float *out, float *in) -{ - NodeChroma *c=(NodeChroma *)node->storage; - float alpha; - - alpha=0.0; - - /* test range*/ - if(in[0]>c->t1) { - alpha=1.0; - } - else if(in[0]<c->t2){ - alpha=0.0; - } - else {/*blend */ - alpha=(in[0]-c->t2)/(c->t1-c->t2); - } - - /* don't make something that was more transparent less transparent */ - if (alpha<in[3]) { - out[3]=alpha; - } - else { - out[3]=in[3]; - } - -} - -static void node_composit_exec_luma_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf *cbuf; - CompBuf *outbuf; - - if(in[0]->hasinput==0) return; - if(in[0]->data==NULL) return; - if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return; - - cbuf=typecheck_compbuf(in[0]->data, CB_RGBA); - - outbuf=dupalloc_compbuf(cbuf); - - composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_yuva, CB_RGBA); - composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_luma_matte, CB_RGBA); - composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_yuva_to_rgba, CB_RGBA); - - generate_preview(data, node, outbuf); - out[0]->data=outbuf; - if (out[1]->hasoutput) - out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A); - if(cbuf!=in[0]->data) - free_compbuf(cbuf); -} - -static void node_composit_init_luma_matte(bNode *node) -{ - NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma"); - node->storage=c; - c->t1= 1.0f; - c->t2= 0.0f; -} - -void register_node_type_cmp_luma_matte(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_LUMA_MATTE, "Luminance Key", NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS, - cmp_node_luma_matte_in, cmp_node_luma_matte_out); - node_type_size(&ntype, 200, 80, 250); - node_type_init(&ntype, node_composit_init_luma_matte); - node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_luma_matte); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_mapUV.c b/source/blender/nodes/intern/CMP_nodes/CMP_mapUV.c deleted file mode 100644 index 6b2c561b14a..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_mapUV.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_mapUV.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** Map UV ******************** */ - -static bNodeSocketType cmp_node_mapuv_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 1, "UV", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_mapuv_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -/* foreach UV, use these values to read in cbuf and write to stackbuf */ -/* stackbuf should be zeroed */ -static void do_mapuv(CompBuf *stackbuf, CompBuf *cbuf, CompBuf *uvbuf, float threshold) -{ - ImBuf *ibuf; - float *out= stackbuf->rect, *uv, *uvnext, *uvprev; - float dx, dy, alpha; - int x, y, sx, sy, row= 3*stackbuf->x; - - /* ibuf needed for sampling */ - ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0); - ibuf->rect_float= cbuf->rect; - - /* vars for efficient looping */ - uv= uvbuf->rect; - uvnext= uv+row; - uvprev= uv-row; - sx= stackbuf->x; - sy= stackbuf->y; - - for(y=0; y<sy; y++) { - for(x=0; x<sx; x++, out+=4, uv+=3, uvnext+=3, uvprev+=3) { - if(x>0 && x<sx-1 && y>0 && y<sy-1) { - if(uv[2]!=0.0f) { - float uv_l, uv_r; - - /* adaptive sampling, red (U) channel */ - - /* prevent alpha zero UVs to be used */ - uv_l= uv[-1]!=0.0f? fabs(uv[0]-uv[-3]) : 0.0f; - uv_r= uv[ 5]!=0.0f? fabs(uv[0]-uv[ 3]) : 0.0f; - - //dx= 0.5f*(fabs(uv[0]-uv[-3]) + fabs(uv[0]-uv[3])); - dx= 0.5f*(uv_l + uv_r); - - uv_l= uvprev[-1]!=0.0f? fabs(uv[0]-uvprev[-3]) : 0.0f; - uv_r= uvnext[-1]!=0.0f? fabs(uv[0]-uvnext[-3]) : 0.0f; - - //dx+= 0.25f*(fabs(uv[0]-uvprev[-3]) + fabs(uv[0]-uvnext[-3])); - dx+= 0.25f*(uv_l + uv_r); - - uv_l= uvprev[ 5]!=0.0f? fabs(uv[0]-uvprev[+3]) : 0.0f; - uv_r= uvnext[ 5]!=0.0f? fabs(uv[0]-uvnext[+3]) : 0.0f; - - //dx+= 0.25f*(fabs(uv[0]-uvprev[+3]) + fabs(uv[0]-uvnext[+3])); - dx+= 0.25f*(uv_l + uv_r); - - /* adaptive sampling, green (V) channel */ - - uv_l= uv[-row+2]!=0.0f? fabs(uv[1]-uv[-row+1]) : 0.0f; - uv_r= uv[ row+2]!=0.0f? fabs(uv[1]-uv[ row+1]) : 0.0f; - - //dy= 0.5f*(fabs(uv[1]-uv[-row+1]) + fabs(uv[1]-uv[row+1])); - dy= 0.5f*(uv_l + uv_r); - - uv_l= uvprev[-1]!=0.0f? fabs(uv[1]-uvprev[+1-3]) : 0.0f; - uv_r= uvnext[-1]!=0.0f? fabs(uv[1]-uvnext[+1-3]) : 0.0f; - - //dy+= 0.25f*(fabs(uv[1]-uvprev[+1-3]) + fabs(uv[1]-uvnext[+1-3])); - dy+= 0.25f*(uv_l + uv_r); - - uv_l= uvprev[ 5]!=0.0f? fabs(uv[1]-uvprev[+1+3]) : 0.0f; - uv_r= uvnext[ 5]!=0.0f? fabs(uv[1]-uvnext[+1+3]) : 0.0f; - - //dy+= 0.25f*(fabs(uv[1]-uvprev[+1+3]) + fabs(uv[1]-uvnext[+1+3])); - dy+= 0.25f*(uv_l + uv_r); - - /* UV to alpha threshold */ - alpha= 1.0f - threshold*(dx+dy); - if(alpha<0.0f) alpha= 0.0f; - else alpha*= uv[2]; - - /* should use mipmap */ - if(dx > 0.20f) dx= 0.20f; - if(dy > 0.20f) dy= 0.20f; - - ibuf_sample(ibuf, uv[0], uv[1], dx, dy, out); - /* premul */ - if(alpha<1.0f) { - out[0]*= alpha; - out[1]*= alpha; - out[2]*= alpha; - out[3]*= alpha; - } - } - } - } - } - - IMB_freeImBuf(ibuf); -} - - -static void node_composit_exec_mapuv(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - if(out[0]->hasoutput==0) - return; - - if(in[0]->data && in[1]->data) { - CompBuf *cbuf= in[0]->data; - CompBuf *uvbuf= in[1]->data; - CompBuf *stackbuf; - - cbuf= typecheck_compbuf(cbuf, CB_RGBA); - uvbuf= typecheck_compbuf(uvbuf, CB_VEC3); - stackbuf= alloc_compbuf(uvbuf->x, uvbuf->y, CB_RGBA, 1); /* allocs */; - - do_mapuv(stackbuf, cbuf, uvbuf, 0.05f*(float)node->custom1); - - out[0]->data= stackbuf; - - if(cbuf!=in[0]->data) - free_compbuf(cbuf); - if(uvbuf!=in[1]->data) - free_compbuf(uvbuf); - } -} - -void register_node_type_cmp_mapuv(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_MAP_UV, "Map UV", NODE_CLASS_DISTORT, NODE_OPTIONS, - cmp_node_mapuv_in, cmp_node_mapuv_out); - node_type_size(&ntype, 140, 100, 320); - node_type_exec(&ntype, node_composit_exec_mapuv); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_mapValue.c b/source/blender/nodes/intern/CMP_nodes/CMP_mapValue.c deleted file mode 100644 index f14e0fbd804..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_mapValue.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_mapValue.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** MAP VALUE ******************** */ -static bNodeSocketType cmp_node_map_value_in[]= { - { SOCK_VALUE, 1, "Value", 1.0f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_map_value_out[]= { - { SOCK_VALUE, 0, "Value", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_map_value(bNode *node, float *out, float *src) -{ - TexMapping *texmap= node->storage; - - out[0]= (src[0] + texmap->loc[0])*texmap->size[0]; - if(texmap->flag & TEXMAP_CLIP_MIN) - if(out[0]<texmap->min[0]) - out[0]= texmap->min[0]; - if(texmap->flag & TEXMAP_CLIP_MAX) - if(out[0]>texmap->max[0]) - out[0]= texmap->max[0]; -} - -static void node_composit_exec_map_value(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order in: valbuf */ - /* stack order out: valbuf */ - if(out[0]->hasoutput==0) return; - - /* input no image? then only value operation */ - if(in[0]->data==NULL) { - do_map_value(node, out[0]->vec, in[0]->vec); - } - else { - /* make output size of input image */ - CompBuf *cbuf= in[0]->data; - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */ - - composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_map_value, CB_VAL); - - out[0]->data= stackbuf; - } -} - - -static void node_composit_init_map_value(bNode* node) -{ - node->storage= add_mapping(); -} - -void register_node_type_cmp_map_value(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_MAP_VALUE, "Map Value", NODE_CLASS_OP_VECTOR, NODE_OPTIONS, - cmp_node_map_value_in, cmp_node_map_value_out); - node_type_size(&ntype, 100, 60, 150); - node_type_init(&ntype, node_composit_init_map_value); - node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_map_value); - - nodeRegisterType(lb, &ntype); -} - - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_math.c b/source/blender/nodes/intern/CMP_nodes/CMP_math.c deleted file mode 100644 index b7a67f3563b..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_math.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_math.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** SCALAR MATH ******************** */ -static bNodeSocketType cmp_node_math_in[]= { - { SOCK_VALUE, 1, "Value", 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f}, - { SOCK_VALUE, 1, "Value", 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType cmp_node_math_out[]= { - { SOCK_VALUE, 0, "Value", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_math(bNode *node, float *out, float *in, float *in2) -{ - switch(node->custom1) - { - case 0: /* Add */ - out[0]= in[0] + in2[0]; - break; - case 1: /* Subtract */ - out[0]= in[0] - in2[0]; - break; - case 2: /* Multiply */ - out[0]= in[0] * in2[0]; - break; - case 3: /* Divide */ - { - if(in2[0]==0) /* We don't want to divide by zero. */ - out[0]= 0.0; - else - out[0]= in[0] / in2[0]; - } - break; - case 4: /* Sine */ - out[0]= sin(in[0]); - break; - case 5: /* Cosine */ - out[0]= cos(in[0]); - break; - case 6: /* Tangent */ - out[0]= tan(in[0]); - break; - case 7: /* Arc-Sine */ - { - /* Can't do the impossible... */ - if(in[0] <= 1 && in[0] >= -1 ) - out[0]= asin(in[0]); - else - out[0]= 0.0; - } - break; - case 8: /* Arc-Cosine */ - { - /* Can't do the impossible... */ - if( in[0] <= 1 && in[0] >= -1 ) - out[0]= acos(in[0]); - else - out[0]= 0.0; - } - break; - case 9: /* Arc-Tangent */ - out[0]= atan(in[0]); - break; - case 10: /* Power */ - { - /* Only raise negative numbers by full integers */ - if( in[0] >= 0 ) { - out[0]= pow(in[0], in2[0]); - } else { - float y_mod_1 = fmod(in2[0], 1); - /* if input value is not nearly an integer, fall back to zero, nicer than straight rounding */ - if (y_mod_1 > 0.999 || y_mod_1 < 0.001) { - out[0]= pow(in[0], floor(in2[0] + 0.5)); - } else { - out[0] = 0.0; - } - } - } - break; - case 11: /* Logarithm */ - { - /* Don't want any imaginary numbers... */ - if( in[0] > 0 && in2[0] > 0 ) - out[0]= log(in[0]) / log(in2[0]); - else - out[0]= 0.0; - } - break; - case 12: /* Minimum */ - { - if( in[0] < in2[0] ) - out[0]= in[0]; - else - out[0]= in2[0]; - } - break; - case 13: /* Maximum */ - { - if( in[0] > in2[0] ) - out[0]= in[0]; - else - out[0]= in2[0]; - } - break; - case 14: /* Round */ - { - /* round by the second value */ - if( in2[0] != 0.0f ) - out[0]= floorf(in[0] / in2[0] + 0.5f) * in2[0]; - else - out[0]= floorf(in[0] + 0.5f); - - } - break; - case 15: /* Less Than */ - { - if( in[0] < in2[0] ) - out[0]= 1.0f; - else - out[0]= 0.0f; - } - break; - case 16: /* Greater Than */ - { - if( in[0] > in2[0] ) - out[0]= 1.0f; - else - out[0]= 0.0f; - } - break; - } -} - -static void node_composit_exec_math(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf *cbuf=in[0]->data; - CompBuf *cbuf2=in[1]->data; - CompBuf *stackbuf; - - /* check for inputs and outputs for early out*/ - if(out[0]->hasoutput==0) return; - - /* no image-color operation */ - if(in[0]->data==NULL && in[1]->data==NULL) { - do_math(node, out[0]->vec, in[0]->vec, in[1]->vec); - return; - } - - /*create output based on first input */ - if(cbuf) { - stackbuf=alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); - } - /* and if it doesn't exist use the second input since we - know that one of them must exist at this point*/ - else { - stackbuf=alloc_compbuf(cbuf2->x, cbuf2->y, CB_VAL, 1); - } - - /* operate in case there's valid size */ - composit2_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_math, CB_VAL, CB_VAL); - out[0]->data= stackbuf; -} - -void register_node_type_cmp_math(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - cmp_node_math_in, cmp_node_math_out); - node_type_size(&ntype, 120, 110, 160); - node_type_label(&ntype, node_math_label); - node_type_exec(&ntype, node_composit_exec_math); - - nodeRegisterType(lb, &ntype); -} - - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_mixrgb.c b/source/blender/nodes/intern/CMP_nodes/CMP_mixrgb.c deleted file mode 100644 index d2454b37c29..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_mixrgb.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_mixrgb.c - * \ingroup cmpnodes - */ - -#include "../CMP_util.h" - -/* **************** MIX RGB ******************** */ -static bNodeSocketType cmp_node_mix_rgb_in[]= { - { SOCK_VALUE, 1, "Fac", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 5.0f}, - { 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_mix_rgb_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_mix_rgb(bNode *node, float *out, float *in1, float *in2, float *fac) -{ - float col[3]; - - VECCOPY(col, in1); - if(node->custom2) - ramp_blend(node->custom1, col, col+1, col+2, in2[3]*fac[0], in2); - else - ramp_blend(node->custom1, col, col+1, col+2, fac[0], in2); - VECCOPY(out, col); - out[3]= in1[3]; -} - -static void node_composit_exec_mix_rgb(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order in: fac, Image, Image */ - /* stack order out: Image */ - float *fac= in[0]->vec; - - if(out[0]->hasoutput==0) return; - - /* input no image? then only color operation */ - if(in[1]->data==NULL && in[2]->data==NULL) { - do_mix_rgb(node, out[0]->vec, in[1]->vec, in[2]->vec, fac); - } - else { - /* make output size of first available input image */ - CompBuf *cbuf= in[1]->data?in[1]->data:in[2]->data; - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ - - composit3_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, in[0]->data, fac, do_mix_rgb, CB_RGBA, CB_RGBA, CB_VAL); - - out[0]->data= stackbuf; - - generate_preview(data, node, out[0]->data); - } -} - -/* custom1 = mix type */ -void register_node_type_cmp_mix_rgb(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, NODE_PREVIEW|NODE_OPTIONS, - cmp_node_mix_rgb_in, cmp_node_mix_rgb_out); - node_type_size(&ntype, 110, 60, 120); - node_type_label(&ntype, node_blend_label); - node_type_exec(&ntype, node_composit_exec_mix_rgb); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_normal.c b/source/blender/nodes/intern/CMP_nodes/CMP_normal.c deleted file mode 100644 index f53d3041947..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_normal.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_normal.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** NORMAL ******************** */ -static bNodeSocketType cmp_node_normal_in[]= { - { SOCK_VECTOR, 1, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType cmp_node_normal_out[]= { - { SOCK_VECTOR, 0, "Normal", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, - { SOCK_VALUE, 0, "Dot", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_normal(bNode *node, float *out, float *in) -{ - bNodeSocket *sock= node->outputs.first; - float *nor= sock->ns.vec; - - /* render normals point inside... the widget points outside */ - out[0]= -INPR(nor, in); -} - -/* generates normal, does dot product */ -static void node_composit_exec_normal(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - bNodeSocket *sock= node->outputs.first; - /* stack order input: normal */ - /* stack order output: normal, value */ - - /* input no image? then only vector op */ - if(in[0]->data==NULL) { - VECCOPY(out[0]->vec, sock->ns.vec); - /* render normals point inside... the widget points outside */ - out[1]->vec[0]= -INPR(out[0]->vec, in[0]->vec); - } - else if(out[1]->hasoutput) { - /* make output size of input image */ - CompBuf *cbuf= in[0]->data; - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */ - - composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_normal, CB_VEC3); - - out[1]->data= stackbuf; - } - - -} - -void register_node_type_cmp_normal(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR, NODE_OPTIONS, - cmp_node_normal_in, cmp_node_normal_out); - node_type_size(&ntype, 100, 60, 200); - node_type_exec(&ntype, node_composit_exec_normal); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_normalize.c b/source/blender/nodes/intern/CMP_nodes/CMP_normalize.c deleted file mode 100644 index 22ebd924f09..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_normalize.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): gsr b3d, and a very minor edit from Robert Holcomb - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_normalize.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** NORMALIZE single channel, useful for Z buffer ******************** */ -static bNodeSocketType cmp_node_normalize_in[]= { - { SOCK_VALUE, 1, "Value", 1.0f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_normalize_out[]= { - { SOCK_VALUE, 0, "Value", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_normalize(bNode *UNUSED(node), float *out, float *src, float *min, float *mult) -{ - float res; - res = (src[0] - min[0]) * mult[0]; - if (res > 1.0f) { - out[0] = 1.0f; - } - else if (res < 0.0f) { - out[0] = 0.0f; - } - else { - out[0] = res; - } -} - -/* The code below assumes all data is inside range +- this, and that input buffer is single channel */ -#define BLENDER_ZMAX 10000.0f - -static void node_composit_exec_normalize(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order in: valbuf */ - /* stack order out: valbuf */ - if(out[0]->hasoutput==0) return; - - /* Input has no image buffer? Then pass the value */ - if(in[0]->data==NULL) { - QUATCOPY(out[0]->vec, in[0]->vec); - } - else { - float min = 1.0f+BLENDER_ZMAX; - float max = -1.0f-BLENDER_ZMAX; - float mult = 1.0f; - float *val; - /* make output size of input image */ - CompBuf *cbuf= in[0]->data; - int tot= cbuf->x*cbuf->y; - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */ - - for (val = cbuf->rect; tot; tot--, val++) { - if ((*val > max) && (*val <= BLENDER_ZMAX)) { - max = *val; - } - if ((*val < min) && (*val >= -BLENDER_ZMAX)) { - min = *val; - } - } - /* In the rare case of flat buffer, which would cause a divide by 0, just pass the input to the output */ - if ((max-min) != 0.0f) { - mult = 1.0f/(max-min); - composit3_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, NULL, &min, NULL, &mult, do_normalize, CB_VAL, CB_VAL, CB_VAL); - } else { - memcpy(stackbuf->rect, cbuf->rect, sizeof(float) * cbuf->x * cbuf->y); - } - - out[0]->data= stackbuf; - } -} - -void register_node_type_cmp_normalize(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_NORMALIZE, "Normalize", NODE_CLASS_OP_VECTOR, NODE_OPTIONS, - cmp_node_normalize_in, cmp_node_normalize_out); - node_type_size(&ntype, 100, 60, 150); - node_type_exec(&ntype, node_composit_exec_normalize); - node_type_storage(&ntype, "TexMapping", NULL, NULL); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_outputFile.c b/source/blender/nodes/intern/CMP_nodes/CMP_outputFile.c deleted file mode 100644 index 1d52e694ea9..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_outputFile.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_outputFile.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** OUTPUT FILE ******************** */ -static bNodeSocketType cmp_node_output_file_in[]= { - { SOCK_RGBA, 1, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Z", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_composit_exec_output_file(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out)) -{ - /* image assigned to output */ - /* stack order input sockets: col, alpha */ - - if(in[0]->data) { - RenderData *rd= data; - NodeImageFile *nif= node->storage; - if(nif->sfra!=nif->efra && (rd->cfra<nif->sfra || rd->cfra>nif->efra)) { - return; /* BAIL OUT RETURN */ - } - else if (!G.rendering) { - /* only output files when rendering a sequence - - * otherwise, it overwrites the output files just - * scrubbing through the timeline when the compositor updates */ - return; - } else { - CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA); - ImBuf *ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0); - char string[256]; - - ibuf->rect_float= cbuf->rect; - ibuf->dither= rd->dither_intensity; - - if (rd->color_mgt_flag & R_COLOR_MANAGEMENT) - ibuf->profile = IB_PROFILE_LINEAR_RGB; - - if(in[1]->data) { - CompBuf *zbuf= in[1]->data; - if(zbuf->type==CB_VAL && zbuf->x==cbuf->x && zbuf->y==cbuf->y) { - nif->subimtype|= R_OPENEXR_ZBUF; - ibuf->zbuf_float= zbuf->rect; - } - } - - BKE_makepicstring(string, nif->name, rd->cfra, nif->imtype, (rd->scemode & R_EXTENSION), TRUE); - - if(0 == BKE_write_ibuf(ibuf, string, nif->imtype, nif->subimtype, nif->imtype==R_OPENEXR?nif->codec:nif->quality)) - printf("Cannot save Node File Output to %s\n", string); - else - printf("Saved: %s\n", string); - - IMB_freeImBuf(ibuf); - - generate_preview(data, node, cbuf); - - if(in[0]->data != cbuf) - free_compbuf(cbuf); - } - } -} - -static void node_composit_init_output_file(bNode *node) -{ - Scene *scene= (Scene *)node->id; - NodeImageFile *nif= MEM_callocN(sizeof(NodeImageFile), "node image file"); - node->storage= nif; - - if(scene) { - BLI_strncpy(nif->name, scene->r.pic, sizeof(nif->name)); - nif->imtype= scene->r.imtype; - nif->subimtype= scene->r.subimtype; - nif->quality= scene->r.quality; - nif->sfra= scene->r.sfra; - nif->efra= scene->r.efra; - } -} - -void register_node_type_cmp_output_file(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_OUTPUT_FILE, "File Output", NODE_CLASS_OUTPUT, NODE_PREVIEW|NODE_OPTIONS, - cmp_node_output_file_in, NULL); - node_type_size(&ntype, 140, 80, 300); - node_type_init(&ntype, node_composit_init_output_file); - node_type_storage(&ntype, "NodeImageFile", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_output_file); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_premulkey.c b/source/blender/nodes/intern/CMP_nodes/CMP_premulkey.c deleted file mode 100644 index 15d2ac25180..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_premulkey.c +++ /dev/null @@ -1,78 +0,0 @@ -/* -* $Id$ -* -* ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - -*/ - -/** \file blender/nodes/intern/CMP_nodes/CMP_premulkey.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** Premul and Key Alpha Convert ******************** */ - -static bNodeSocketType cmp_node_premulkey_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_premulkey_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_composit_exec_premulkey(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - if(out[0]->hasoutput==0) - return; - - if(in[0]->data) { - CompBuf *stackbuf, *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA); - - stackbuf= dupalloc_compbuf(cbuf); - premul_compbuf(stackbuf, node->custom1 == 1); - - out[0]->data = stackbuf; - if(cbuf != in[0]->data) - free_compbuf(cbuf); - } -} - -void register_node_type_cmp_premulkey(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_PREMULKEY, "Alpha Convert", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - cmp_node_premulkey_in, cmp_node_premulkey_out); - node_type_size(&ntype, 140, 100, 320); - node_type_exec(&ntype, node_composit_exec_premulkey); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_rgb.c b/source/blender/nodes/intern/CMP_nodes/CMP_rgb.c deleted file mode 100644 index 36b7988c4e0..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_rgb.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_rgb.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** RGB ******************** */ -static bNodeSocketType cmp_node_rgb_out[]= { - { SOCK_RGBA, 0, "RGBA", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_composit_exec_rgb(void *UNUSED(data), bNode *node, bNodeStack **UNUSED(in), bNodeStack **out) -{ - bNodeSocket *sock= node->outputs.first; - - QUATCOPY(out[0]->vec, sock->ns.vec); -} - -void register_node_type_cmp_rgb(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_RGB, "RGB", NODE_CLASS_INPUT, NODE_OPTIONS, - NULL, cmp_node_rgb_out); - node_type_size(&ntype, 140, 80, 140); - node_type_exec(&ntype, node_composit_exec_rgb); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_rotate.c b/source/blender/nodes/intern/CMP_nodes/CMP_rotate.c deleted file mode 100644 index eccac4f0e6d..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_rotate.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_rotate.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** Rotate ******************** */ - -static bNodeSocketType cmp_node_rotate_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Degr", 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_rotate_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -/* only supports RGBA nodes now */ -static void node_composit_exec_rotate(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - - if(out[0]->hasoutput==0) - return; - - if(in[0]->data) { - CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA); - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* note, this returns zero'd image */ - float rad, u, v, s, c, centx, centy, miny, maxy, minx, maxx; - int x, y, yo, xo; - ImBuf *ibuf, *obuf; - - rad= (M_PI*in[1]->vec[0])/180.0f; - - s= sin(rad); - c= cos(rad); - centx= cbuf->x/2; - centy= cbuf->y/2; - - minx= -centx; - maxx= -centx + (float)cbuf->x; - miny= -centy; - maxy= -centy + (float)cbuf->y; - - - ibuf=IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0); - obuf=IMB_allocImBuf(stackbuf->x, stackbuf->y, 32, 0); - - if(ibuf && obuf){ - ibuf->rect_float=cbuf->rect; - obuf->rect_float=stackbuf->rect; - - for(y=miny; y<maxy; y++) { - yo= y+(int)centy; - - for(x=minx; x<maxx;x++) { - u=c*x + y*s + centx; - v=-s*x + c*y + centy; - xo= x+(int)centx; - - switch(node->custom1) { - case 0: - neareast_interpolation(ibuf, obuf, u, v, xo, yo); - break ; - case 1: - bilinear_interpolation(ibuf, obuf, u, v, xo, yo); - break; - case 2: - bicubic_interpolation(ibuf, obuf, u, v, xo, yo); - break; - } - - } - } - - /* rotate offset vector too, but why negative rad, ehh?? Has to be replaced with [3][3] matrix once (ton) */ - s= sin(-rad); - c= cos(-rad); - centx= (float)cbuf->xof; centy= (float)cbuf->yof; - stackbuf->xof= (int)( c*centx + s*centy); - stackbuf->yof= (int)(-s*centx + c*centy); - - IMB_freeImBuf(ibuf); - IMB_freeImBuf(obuf); - } - - /* pass on output and free */ - out[0]->data= stackbuf; - if(cbuf!=in[0]->data) { - free_compbuf(cbuf); - } - } -} - -static void node_composit_init_rotate(bNode *node) -{ - node->custom1= 1; /* Bilinear Filter*/ -} - -void register_node_type_cmp_rotate(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_ROTATE, "Rotate", NODE_CLASS_DISTORT, NODE_OPTIONS, - cmp_node_rotate_in, cmp_node_rotate_out); - node_type_size(&ntype, 140, 100, 320); - node_type_init(&ntype, node_composit_init_rotate); - node_type_exec(&ntype, node_composit_exec_rotate); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_scale.c b/source/blender/nodes/intern/CMP_nodes/CMP_scale.c deleted file mode 100644 index b6030cc5a5f..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_scale.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_scale.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** Scale ******************** */ - -#define CMP_SCALE_MAX 12000 - -static bNodeSocketType cmp_node_scale_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "X", 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX}, - { SOCK_VALUE, 1, "Y", 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_scale_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -/* only supports RGBA nodes now */ -/* node->custom1 stores if input values are absolute or relative scale */ -static void node_composit_exec_scale(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - if(out[0]->hasoutput==0) - return; - - if(in[0]->data) { - RenderData *rd= data; - CompBuf *stackbuf, *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA); - ImBuf *ibuf; - int newx, newy; - - if(node->custom1==CMP_SCALE_RELATIVE) { - newx= MAX2((int)(in[1]->vec[0]*cbuf->x), 1); - newy= MAX2((int)(in[2]->vec[0]*cbuf->y), 1); - } - else if(node->custom1==CMP_SCALE_SCENEPERCENT) { - newx = cbuf->x * (rd->size / 100.0f); - newy = cbuf->y * (rd->size / 100.0f); - } - else if (node->custom1==CMP_SCALE_RENDERPERCENT) { - newx= (rd->xsch * rd->size)/100; - newy= (rd->ysch * rd->size)/100; - } else { /* CMP_SCALE_ABSOLUTE */ - newx= MAX2((int)in[1]->vec[0], 1); - newy= MAX2((int)in[2]->vec[0], 1); - } - newx= MIN2(newx, CMP_SCALE_MAX); - newy= MIN2(newy, CMP_SCALE_MAX); - - ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0); - if(ibuf) { - ibuf->rect_float= cbuf->rect; - IMB_scaleImBuf(ibuf, newx, newy); - - if(ibuf->rect_float == cbuf->rect) { - /* no scaling happened. */ - stackbuf= pass_on_compbuf(in[0]->data); - } - else { - stackbuf= alloc_compbuf(newx, newy, CB_RGBA, 0); - stackbuf->rect= ibuf->rect_float; - stackbuf->malloc= 1; - } - - ibuf->rect_float= NULL; - ibuf->mall &= ~IB_rectfloat; - IMB_freeImBuf(ibuf); - - /* also do the translation vector */ - stackbuf->xof = (int)(((float)newx/(float)cbuf->x) * (float)cbuf->xof); - stackbuf->yof = (int)(((float)newy/(float)cbuf->y) * (float)cbuf->yof); - } - else { - stackbuf= dupalloc_compbuf(cbuf); - printf("Scaling to %dx%d failed\n", newx, newy); - } - - out[0]->data= stackbuf; - if(cbuf!=in[0]->data) - free_compbuf(cbuf); - } -} - -void register_node_type_cmp_scale(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_SCALE, "Scale", NODE_CLASS_DISTORT, NODE_OPTIONS, - cmp_node_scale_in, cmp_node_scale_out); - node_type_size(&ntype, 140, 100, 320); - node_type_exec(&ntype, node_composit_exec_scale); - - nodeRegisterType(lb, &ntype); -} - - - - - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_sepcombHSVA.c b/source/blender/nodes/intern/CMP_nodes/CMP_sepcombHSVA.c deleted file mode 100644 index 87c4ed1dac0..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_sepcombHSVA.c +++ /dev/null @@ -1,187 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_sepcombHSVA.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** SEPARATE HSVA ******************** */ -static bNodeSocketType cmp_node_sephsva_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_sephsva_out[]= { - { SOCK_VALUE, 0, "H", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "S", 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_sephsva(bNode *UNUSED(node), float *out, float *in) -{ - float h, s, v; - - rgb_to_hsv(in[0], in[1], in[2], &h, &s, &v); - - out[0]= h; - out[1]= s; - out[2]= v; - out[3]= in[3]; -} - -static void node_composit_exec_sephsva(void *UNUSED(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 h, s, v; - - rgb_to_hsv(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &h, &s, &v); - - out[0]->vec[0] = h; - out[1]->vec[0] = s; - 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)) { - /* create new buffer so input buffer doesn't get corrupted */ - CompBuf *cbuf= dupalloc_compbuf(in[0]->data); - CompBuf *cbuf2= typecheck_compbuf(cbuf, CB_RGBA); - - /* convert the RGB stackbuf to an HSV representation */ - composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sephsva, CB_RGBA); - - /* separate each of those channels */ - if(out[0]->hasoutput) - out[0]->data= valbuf_from_rgbabuf(cbuf2, CHAN_R); - if(out[1]->hasoutput) - out[1]->data= valbuf_from_rgbabuf(cbuf2, CHAN_G); - if(out[2]->hasoutput) - out[2]->data= valbuf_from_rgbabuf(cbuf2, CHAN_B); - if(out[3]->hasoutput) - out[3]->data= valbuf_from_rgbabuf(cbuf2, CHAN_A); - - /*not used anymore */ - if(cbuf2!=cbuf) - free_compbuf(cbuf2); - free_compbuf(cbuf); - } -} - -void register_node_type_cmp_sephsva(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_SEPHSVA, "Separate HSVA", NODE_CLASS_CONVERTOR, 0, - cmp_node_sephsva_in, cmp_node_sephsva_out); - node_type_size(&ntype, 80, 40, 140); - node_type_exec(&ntype, node_composit_exec_sephsva); - - nodeRegisterType(lb, &ntype); -} - - -/* **************** COMBINE HSVA ******************** */ -static bNodeSocketType cmp_node_combhsva_in[]= { - { SOCK_VALUE, 1, "H", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "S", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "V", 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_combhsva_out[]= { - { SOCK_RGBA, 0, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_comb_hsva(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4) -{ - float r,g,b; - hsv_to_rgb(in1[0], in2[0], in3[0], &r, &g, &b); - - out[0] = r; - out[1] = g; - out[2] = b; - out[3] = in4[0]; -} - -static void node_composit_exec_combhsva(void *UNUSED(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; - - /* allocate a CompBuf the size of the first available input */ - 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 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_comb_hsva, CB_VAL, CB_VAL, CB_VAL, CB_VAL); - - out[0]->data= stackbuf; - } -} - -void register_node_type_cmp_combhsva(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_COMBHSVA, "Combine HSVA", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - cmp_node_combhsva_in, cmp_node_combhsva_out); - node_type_size(&ntype, 80, 40, 140); - node_type_exec(&ntype, node_composit_exec_combhsva); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_sepcombRGBA.c b/source/blender/nodes/intern/CMP_nodes/CMP_sepcombRGBA.c deleted file mode 100644 index 11afd1eaaef..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_sepcombRGBA.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_sepcombRGBA.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** SEPARATE RGBA ******************** */ -static bNodeSocketType cmp_node_seprgba_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_seprgba_out[]= { - { SOCK_VALUE, 0, "R", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "G", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "B", 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 node_composit_exec_seprgba(void *UNUSED(data), bNode *UNUSED(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) { - out[0]->vec[0] = in[0]->vec[0]; - out[1]->vec[0] = in[0]->vec[1]; - out[2]->vec[0] = in[0]->vec[2]; - out[3]->vec[0] = in[0]->vec[3]; - } - else { - /* make sure we get right rgba buffer */ - CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA); - - /* don't do any pixel processing, just copy the stack directly (faster, I presume) */ - if(out[0]->hasoutput) - out[0]->data= valbuf_from_rgbabuf(cbuf, CHAN_R); - if(out[1]->hasoutput) - out[1]->data= valbuf_from_rgbabuf(cbuf, CHAN_G); - if(out[2]->hasoutput) - out[2]->data= valbuf_from_rgbabuf(cbuf, CHAN_B); - if(out[3]->hasoutput) - out[3]->data= valbuf_from_rgbabuf(cbuf, CHAN_A); - - if(cbuf!=in[0]->data) - free_compbuf(cbuf); - - } -} - -void register_node_type_cmp_seprgba(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_SEPRGBA, "Separate RGBA", NODE_CLASS_CONVERTOR, 0, - cmp_node_seprgba_in, cmp_node_seprgba_out); - node_type_size(&ntype, 80, 40, 140); - node_type_exec(&ntype, node_composit_exec_seprgba); - - nodeRegisterType(lb, &ntype); -} - - - -/* **************** 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 *UNUSED(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 *UNUSED(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; - - /* allocate a CompBuf the size of the first available input */ - 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 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; - } -} - -void register_node_type_cmp_combrgba(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_COMBRGBA, "Combine RGBA", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - cmp_node_combrgba_in, cmp_node_combrgba_out); - node_type_size(&ntype, 80, 40, 140); - node_type_exec(&ntype, node_composit_exec_combrgba); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_sepcombYCCA.c b/source/blender/nodes/intern/CMP_nodes/CMP_sepcombYCCA.c deleted file mode 100644 index 81591602dae..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_sepcombYCCA.c +++ /dev/null @@ -1,313 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_sepcombYCCA.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** 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_601(bNode *UNUSED(node), float *out, float *in) -{ - float y, cb, cr; - - rgb_to_ycc(in[0], in[1], in[2], &y, &cb, &cr, BLI_YCC_ITU_BT601); - - /*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 do_sepycca_709(bNode *UNUSED(node), float *out, float *in) -{ - float y, cb, cr; - - rgb_to_ycc(in[0], in[1], in[2], &y, &cb, &cr, BLI_YCC_ITU_BT709); - - /*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 do_sepycca_jfif(bNode *UNUSED(node), float *out, float *in) -{ - float y, cb, cr; - - rgb_to_ycc(in[0], in[1], in[2], &y, &cb, &cr, BLI_YCC_JFIF_0_255); - - /*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 *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* input no image? then only color operation */ - if(in[0]->data==NULL) { - float y, cb, cr; - - switch(node->custom1) - { - case 1: - rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr, BLI_YCC_ITU_BT709); - break; - case 2: - rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr, BLI_YCC_JFIF_0_255); - break; - case 0: - default: - rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr, BLI_YCC_ITU_BT601); - break; - } - - /*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 copy of buffer so input buffer doesn't get corrupted */ - CompBuf *cbuf= dupalloc_compbuf(in[0]->data); - CompBuf *cbuf2=typecheck_compbuf(cbuf, CB_RGBA); - - /* convert the RGB stackbuf to an HSV representation */ - switch(node->custom1) - { - case 1: - composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepycca_709, CB_RGBA); - break; - case 2: - composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepycca_jfif, CB_RGBA); - break; - case 0: - default: - composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepycca_601, CB_RGBA); - break; - } - - /* separate each of those channels */ - if(out[0]->hasoutput) - out[0]->data= valbuf_from_rgbabuf(cbuf2, CHAN_R); - if(out[1]->hasoutput) - out[1]->data= valbuf_from_rgbabuf(cbuf2, CHAN_G); - if(out[2]->hasoutput) - out[2]->data= valbuf_from_rgbabuf(cbuf2, CHAN_B); - if(out[3]->hasoutput) - out[3]->data= valbuf_from_rgbabuf(cbuf2, CHAN_A); - - /*not used anymore */ - if(cbuf2!=cbuf) - free_compbuf(cbuf2); - free_compbuf(cbuf); - } -} - -void register_node_type_cmp_sepycca(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_SEPYCCA, "Separate YCbCrA", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - cmp_node_sepycca_in, cmp_node_sepycca_out); - node_type_size(&ntype, 80, 40, 140); - node_type_exec(&ntype, node_composit_exec_sepycca); - - nodeRegisterType(lb, &ntype); -} - - - -/* **************** COMBINE YCCA ******************** */ -static bNodeSocketType cmp_node_combycca_in[]= { - { SOCK_VALUE, 1, "Y", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Cb", 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Cr", 0.5f, 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_combycca_out[]= { - { SOCK_RGBA, 0, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_comb_ycca_601(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4) -{ - float r,g,b; - float y, cb, cr; - - /*need to un-normalize the data*/ - y=in1[0]*255; - cb=in2[0]*255; - cr=in3[0]*255; - - ycc_to_rgb(y,cb,cr, &r, &g, &b, BLI_YCC_ITU_BT601); - - out[0] = r; - out[1] = g; - out[2] = b; - out[3] = in4[0]; -} - -static void do_comb_ycca_709(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4) -{ - float r,g,b; - float y, cb, cr; - - /*need to un-normalize the data*/ - y=in1[0]*255; - cb=in2[0]*255; - cr=in3[0]*255; - - ycc_to_rgb(y,cb,cr, &r, &g, &b, BLI_YCC_ITU_BT709); - - out[0] = r; - out[1] = g; - out[2] = b; - out[3] = in4[0]; -} - -static void do_comb_ycca_jfif(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4) -{ - float r,g,b; - float y, cb, cr; - - /*need to un-normalize the data*/ - y=in1[0]*255; - cb=in2[0]*255; - cr=in3[0]*255; - - ycc_to_rgb(y,cb,cr, &r, &g, &b, BLI_YCC_JFIF_0_255); - - out[0] = r; - out[1] = g; - out[2] = b; - out[3] = in4[0]; -} - -static void node_composit_exec_combycca(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order out: 1 ycca 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)) { - float y = in[0]->vec[0] * 255; - float cb = in[1]->vec[0] * 255; - float cr = in[2]->vec[0] * 255; - - switch(node->custom1) - { - case 1: - ycc_to_rgb(y, cb, cr, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2], BLI_YCC_ITU_BT709); - break; - case 2: - ycc_to_rgb(y, cb, cr, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2], BLI_YCC_JFIF_0_255); - break; - case 0: - default: - ycc_to_rgb(y, cb, cr, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2], BLI_YCC_ITU_BT601); - break; - } - - out[0]->vec[3] = in[3]->vec[0]; - } - else { - /* make output size of first available input image */ - CompBuf *cbuf; - CompBuf *stackbuf; - - /* allocate a CompBuf the size of the first available input */ - 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 cbuf = in[3]->data; - - stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ - - - switch(node->custom1) - { - case 1: - 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_comb_ycca_709, CB_VAL, CB_VAL, CB_VAL, CB_VAL); - break; - - case 2: - 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_comb_ycca_jfif, CB_VAL, CB_VAL, CB_VAL, CB_VAL); - break; - case 0: - default: - 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_comb_ycca_601, CB_VAL, CB_VAL, CB_VAL, CB_VAL); - break; - } - - out[0]->data= stackbuf; - } -} - -void register_node_type_cmp_combycca(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_COMBYCCA, "Combine YCbCrA", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - cmp_node_combycca_in, cmp_node_combycca_out); - node_type_size(&ntype, 80, 40, 140); - node_type_exec(&ntype, node_composit_exec_combycca); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_sepcombYUVA.c b/source/blender/nodes/intern/CMP_nodes/CMP_sepcombYUVA.c deleted file mode 100644 index 8687e307df3..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_sepcombYUVA.c +++ /dev/null @@ -1,187 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_sepcombYUVA.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** 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 *UNUSED(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 *UNUSED(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 copy of buffer so input image doesn't get corrupted */ - CompBuf *cbuf= dupalloc_compbuf(in[0]->data); - CompBuf *cbuf2=typecheck_compbuf(cbuf, CB_RGBA); - - /* convert the RGB stackbuf to an YUV representation */ - composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepyuva, CB_RGBA); - - /* separate each of those channels */ - if(out[0]->hasoutput) - out[0]->data= valbuf_from_rgbabuf(cbuf2, CHAN_R); - if(out[1]->hasoutput) - out[1]->data= valbuf_from_rgbabuf(cbuf2, CHAN_G); - if(out[2]->hasoutput) - out[2]->data= valbuf_from_rgbabuf(cbuf2, CHAN_B); - if(out[3]->hasoutput) - out[3]->data= valbuf_from_rgbabuf(cbuf2, CHAN_A); - - /*not used anymore */ - if(cbuf2!=cbuf) - free_compbuf(cbuf2); - free_compbuf(cbuf); - } -} - -void register_node_type_cmp_sepyuva(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_SEPYUVA, "Separate YUVA", NODE_CLASS_CONVERTOR, 0, - cmp_node_sepyuva_in, cmp_node_sepyuva_out); - node_type_size(&ntype, 80, 40, 140); - node_type_exec(&ntype, node_composit_exec_sepyuva); - - nodeRegisterType(lb, &ntype); -} - - - -/* **************** COMBINE YUVA ******************** */ -static bNodeSocketType cmp_node_combyuva_in[]= { - { SOCK_VALUE, 1, "Y", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "U", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "V", 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_combyuva_out[]= { - { SOCK_RGBA, 0, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_comb_yuva(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4) -{ - float r,g,b; - yuv_to_rgb(in1[0], in2[0], in3[0], &r, &g, &b); - - out[0] = r; - out[1] = g; - out[2] = b; - out[3] = in4[0]; -} - -static void node_composit_exec_combyuva(void *UNUSED(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; - - /* allocate a CompBuf the size of the first available input */ - 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 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_comb_yuva, CB_VAL, CB_VAL, CB_VAL, CB_VAL); - - out[0]->data= stackbuf; - } -} - -void register_node_type_cmp_combyuva(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_COMBYUVA, "Combine YUVA", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - cmp_node_combyuva_in, cmp_node_combyuva_out); - node_type_size(&ntype, 80, 40, 140); - node_type_exec(&ntype, node_composit_exec_combyuva); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_setalpha.c b/source/blender/nodes/intern/CMP_nodes/CMP_setalpha.c deleted file mode 100644 index bb8533a79f6..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_setalpha.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_setalpha.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** SET ALPHA ******************** */ -static bNodeSocketType cmp_node_setalpha_in[]= { - { SOCK_RGBA, 1, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_setalpha_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_composit_exec_setalpha(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order out: RGBA image */ - /* stack order in: col, alpha */ - - /* input no image? then only color operation */ - if(in[0]->data==NULL && in[1]->data==NULL) { - out[0]->vec[0] = in[0]->vec[0]; - out[0]->vec[1] = in[0]->vec[1]; - out[0]->vec[2] = in[0]->vec[2]; - out[0]->vec[3] = in[1]->vec[0]; - } - else { - /* make output size of input image */ - CompBuf *cbuf= in[0]->data?in[0]->data:in[1]->data; - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ - - if(in[1]->data==NULL && in[1]->vec[0]==1.0f) { - /* pass on image */ - composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_copy_rgb, CB_RGBA); - } - else { - /* send an compbuf or a value to set as alpha - composit2_pixel_processor handles choosing the right one */ - composit2_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_copy_a_rgba, CB_RGBA, CB_VAL); - } - - out[0]->data= stackbuf; - } -} - -void register_node_type_cmp_setalpha(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_SETALPHA, "Set Alpha", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - cmp_node_setalpha_in, cmp_node_setalpha_out); - node_type_size(&ntype, 120, 40, 140); - node_type_exec(&ntype, node_composit_exec_setalpha); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_splitViewer.c b/source/blender/nodes/intern/CMP_nodes/CMP_splitViewer.c deleted file mode 100644 index 13cb3bcfed5..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_splitViewer.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_splitViewer.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** SPLIT VIEWER ******************** */ -static bNodeSocketType cmp_node_splitviewer_in[]= { - { SOCK_RGBA, 1, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_copy_split_rgba(bNode *UNUSED(node), float *out, float *in1, float *in2, float *fac) -{ - if(*fac==0.0f) { - QUATCOPY(out, in1); - } - else { - QUATCOPY(out, in2); - } -} - -static void node_composit_exec_splitviewer(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out)) -{ - /* image assigned to output */ - /* stack order input sockets: image image */ - - if(in[0]->data==NULL || in[1]->data==NULL) - return; - - if(node->id && (node->flag & NODE_DO_OUTPUT)) { /* only one works on out */ - Image *ima= (Image *)node->id; - RenderData *rd= data; - ImBuf *ibuf; - CompBuf *cbuf, *buf1, *buf2, *mask; - int x, y; - float offset; - void *lock; - - buf1= typecheck_compbuf(in[0]->data, CB_RGBA); - buf2= typecheck_compbuf(in[1]->data, CB_RGBA); - - BKE_image_user_calc_frame(node->storage, rd->cfra, 0); - - /* always returns for viewer image, but we check nevertheless */ - ibuf= BKE_image_acquire_ibuf(ima, node->storage, &lock); - if(ibuf==NULL) { - printf("node_composit_exec_viewer error\n"); - BKE_image_release_ibuf(ima, lock); - return; - } - - /* free all in ibuf */ - imb_freerectImBuf(ibuf); - imb_freerectfloatImBuf(ibuf); - IMB_freezbuffloatImBuf(ibuf); - - /* make ibuf, and connect to ima */ - ibuf->x= buf1->x; - ibuf->y= buf1->y; - imb_addrectfloatImBuf(ibuf); - - ima->ok= IMA_OK_LOADED; - - /* output buf */ - cbuf= alloc_compbuf(buf1->x, buf1->y, CB_RGBA, 0); /* no alloc*/ - cbuf->rect= ibuf->rect_float; - - /* mask buf */ - mask= alloc_compbuf(buf1->x, buf1->y, CB_VAL, 1); - - - /* Check which offset mode is selected and limit offset if needed */ - if(node->custom2 == 0) { - offset = buf1->x / 100.0f * node->custom1; - CLAMP(offset, 0, buf1->x); - } - else { - offset = buf1->y / 100.0f * node->custom1; - CLAMP(offset, 0, buf1->y); - } - - if(node->custom2 == 0) { - for(y=0; y<buf1->y; y++) { - float *fac= mask->rect + y*buf1->x; - for(x=offset; x>0; x--, fac++) - *fac= 1.0f; - } - } - else { - for(y=0; y<offset; y++) { - float *fac= mask->rect + y*buf1->x; - for(x=buf1->x; x>0; x--, fac++) - *fac= 1.0f; - } - } - - composit3_pixel_processor(node, cbuf, buf1, in[0]->vec, buf2, in[1]->vec, mask, NULL, do_copy_split_rgba, CB_RGBA, CB_RGBA, CB_VAL); - - BKE_image_release_ibuf(ima, lock); - - generate_preview(data, node, cbuf); - free_compbuf(cbuf); - free_compbuf(mask); - - if(in[0]->data != buf1) - free_compbuf(buf1); - if(in[1]->data != buf2) - free_compbuf(buf2); - } -} - -static void node_composit_init_splitviewer(bNode* node) -{ - ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user"); - node->storage= iuser; - iuser->sfra= 1; - iuser->fie_ima= 2; - iuser->ok= 1; - node->custom1= 50; /* default 50% split */ -} - -void register_node_type_cmp_splitviewer(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_SPLITVIEWER, "SplitViewer", NODE_CLASS_OUTPUT, NODE_PREVIEW|NODE_OPTIONS, - cmp_node_splitviewer_in, NULL); - node_type_size(&ntype, 140, 100, 320); - node_type_init(&ntype, node_composit_init_splitviewer); - node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_splitviewer); - - nodeRegisterType(lb, &ntype); -} - - - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_texture.c b/source/blender/nodes/intern/CMP_nodes/CMP_texture.c deleted file mode 100644 index 46e71b8b8e5..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_texture.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_texture.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** TEXTURE ******************** */ -static bNodeSocketType cmp_node_texture_in[]= { - { SOCK_VECTOR, 1, "Offset", 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f}, - { SOCK_VECTOR, 1, "Scale", 1.0f, 1.0f, 1.0f, 1.0f, -10.0f, 10.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_texture_out[]= { - { SOCK_VALUE, 0, "Value", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA , 0, "Color", 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -/* called without rect allocated */ -static void texture_procedural(CompBuf *cbuf, float *out, float xco, float yco) -{ - bNode *node= cbuf->node; - TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL}; - float vec[3], *size, nor[3]={0.0f, 0.0f, 0.0f}, col[4]; - int retval, type= cbuf->procedural_type; - - size= cbuf->procedural_size; - - vec[0]= size[0]*(xco + cbuf->procedural_offset[0]); - vec[1]= size[1]*(yco + cbuf->procedural_offset[1]); - vec[2]= size[2]*cbuf->procedural_offset[2]; - - retval= multitex_ext((Tex *)node->id, vec, NULL, NULL, 0, &texres); - - if(type==CB_VAL) { - if(texres.talpha) - col[0]= texres.ta; - else - col[0]= texres.tin; - } - else if(type==CB_RGBA) { - if(texres.talpha) - col[3]= texres.ta; - else - col[3]= texres.tin; - - if((retval & TEX_RGB)) { - col[0]= texres.tr; - col[1]= texres.tg; - col[2]= texres.tb; - } - else col[0]= col[1]= col[2]= col[3]; - } - else { - VECCOPY(col, nor); - } - - typecheck_compbuf_color(out, col, cbuf->type, cbuf->procedural_type); -} - -/* texture node outputs get a small rect, to make sure all other nodes accept it */ -/* only the pixel-processor nodes do something with it though */ -static void node_composit_exec_texture(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* outputs: value, color, normal */ - - if(node->id) { - RenderData *rd= data; - short sizex, sizey; - - /* first make the preview image */ - CompBuf *prevbuf= alloc_compbuf(140, 140, CB_RGBA, 1); /* alloc */ - - prevbuf->rect_procedural= texture_procedural; - prevbuf->node= node; - VECCOPY(prevbuf->procedural_offset, in[0]->vec); - VECCOPY(prevbuf->procedural_size, in[1]->vec); - prevbuf->procedural_type= CB_RGBA; - composit1_pixel_processor(node, prevbuf, prevbuf, out[0]->vec, do_copy_rgba, CB_RGBA); - - generate_preview(data, node, prevbuf); - free_compbuf(prevbuf); - - /* texture procedural buffer type doesnt work well, we now render a buffer in scene size */ - sizex = (rd->size*rd->xsch)/100; - sizey = (rd->size*rd->ysch)/100; - - if(out[0]->hasoutput) { - CompBuf *stackbuf= alloc_compbuf(sizex, sizey, CB_VAL, 1); /* alloc */ - - stackbuf->rect_procedural= texture_procedural; - stackbuf->node= node; - VECCOPY(stackbuf->procedural_offset, in[0]->vec); - VECCOPY(stackbuf->procedural_size, in[1]->vec); - stackbuf->procedural_type= CB_VAL; - composit1_pixel_processor(node, stackbuf, stackbuf, out[0]->vec, do_copy_value, CB_VAL); - stackbuf->rect_procedural= NULL; - - out[0]->data= stackbuf; - } - if(out[1]->hasoutput) { - CompBuf *stackbuf= alloc_compbuf(sizex, sizey, CB_RGBA, 1); /* alloc */ - - stackbuf->rect_procedural= texture_procedural; - stackbuf->node= node; - VECCOPY(stackbuf->procedural_offset, in[0]->vec); - VECCOPY(stackbuf->procedural_size, in[1]->vec); - stackbuf->procedural_type= CB_RGBA; - composit1_pixel_processor(node, stackbuf, stackbuf, out[0]->vec, do_copy_rgba, CB_RGBA); - stackbuf->rect_procedural= NULL; - - out[1]->data= stackbuf; - } - } -} - -void register_node_type_cmp_texture(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT, NODE_OPTIONS|NODE_PREVIEW, - cmp_node_texture_in, cmp_node_texture_out); - node_type_size(&ntype, 120, 80, 240); - node_type_exec(&ntype, node_composit_exec_texture); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_tonemap.c b/source/blender/nodes/intern/CMP_nodes/CMP_tonemap.c deleted file mode 100644 index f15811ec790..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_tonemap.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Alfredo de Greef (eeshlo) - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_tonemap.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -static bNodeSocketType cmp_node_tonemap_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_tonemap_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - - -static float avgLogLum(CompBuf *src, float* auto_key, float* Lav, float* Cav) -{ - float lsum = 0; - int p = src->x*src->y; - fRGB* bc = (fRGB*)src->rect; - float avl, maxl = -1e10f, minl = 1e10f; - const float sc = 1.f/(src->x*src->y); - *Lav = 0.f; - while (p--) { - float L = 0.212671f*bc[0][0] + 0.71516f*bc[0][1] + 0.072169f*bc[0][2]; - *Lav += L; - fRGB_add(Cav, bc[0]); - lsum += (float)log((double)MAX2(L, 0.0) + 1e-5); - maxl = (L > maxl) ? L : maxl; - minl = (L < minl) ? L : minl; - bc++; - } - *Lav *= sc; - fRGB_mult(Cav, sc); - maxl = log((double)maxl + 1e-5); minl = log((double)minl + 1e-5f); avl = lsum*sc; - *auto_key = (maxl > minl) ? ((maxl - avl) / (maxl - minl)) : 1.f; - return exp((double)avl); -} - - -static void tonemap(NodeTonemap* ntm, CompBuf* dst, CompBuf* src) -{ - int x, y; - float dr, dg, db, al, igm = (ntm->gamma==0.f) ? 1 : (1.f / ntm->gamma); - float auto_key, Lav, Cav[3] = {0, 0, 0}; - - al = avgLogLum(src, &auto_key, &Lav, Cav); - al = (al == 0.f) ? 0.f : (ntm->key / al); - - if (ntm->type == 1) { - // Reinhard/Devlin photoreceptor - const float f = exp((double)-ntm->f); - const float m = (ntm->m > 0.f) ? ntm->m : (0.3f + 0.7f*pow((double)auto_key, 1.4)); - const float ic = 1.f - ntm->c, ia = 1.f - ntm->a; - if (ntm->m == 0.f) printf("tonemap node, M: %g\n", m); - for (y=0; y<src->y; ++y) { - fRGB* sp = (fRGB*)&src->rect[y*src->x*src->type]; - fRGB* dp = (fRGB*)&dst->rect[y*src->x*src->type]; - for (x=0; x<src->x; ++x) { - const float L = 0.212671f*sp[x][0] + 0.71516f*sp[x][1] + 0.072169f*sp[x][2]; - float I_l = sp[x][0] + ic*(L - sp[x][0]); - float I_g = Cav[0] + ic*(Lav - Cav[0]); - float I_a = I_l + ia*(I_g - I_l); - dp[x][0] /= (dp[x][0] + pow((double)f*I_a, (double)m)); - I_l = sp[x][1] + ic*(L - sp[x][1]); - I_g = Cav[1] + ic*(Lav - Cav[1]); - I_a = I_l + ia*(I_g - I_l); - dp[x][1] /= (dp[x][1] + pow((double)f*I_a,(double)m)); - I_l = sp[x][2] + ic*(L - sp[x][2]); - I_g = Cav[2] + ic*(Lav - Cav[2]); - I_a = I_l + ia*(I_g - I_l); - dp[x][2] /= (dp[x][2] + pow((double)f*I_a, (double)m)); - } - } - return; - } - - // Reinhard simple photographic tm (simplest, not using whitepoint var) - for (y=0; y<src->y; y++) { - fRGB* sp = (fRGB*)&src->rect[y*src->x*src->type]; - fRGB* dp = (fRGB*)&dst->rect[y*src->x*src->type]; - for (x=0; x<src->x; x++) { - fRGB_copy(dp[x], sp[x]); - fRGB_mult(dp[x], al); - dr = dp[x][0] + ntm->offset; - dg = dp[x][1] + ntm->offset; - db = dp[x][2] + ntm->offset; - dp[x][0] /= ((dr == 0.f) ? 1.f : dr); - dp[x][1] /= ((dg == 0.f) ? 1.f : dg); - dp[x][2] /= ((db == 0.f) ? 1.f : db); - if (igm != 0.f) { - dp[x][0] = pow((double)MAX2(dp[x][0], 0.), igm); - dp[x][1] = pow((double)MAX2(dp[x][1], 0.), igm); - dp[x][2] = pow((double)MAX2(dp[x][2], 0.), igm); - } - } - } -} - - -static void node_composit_exec_tonemap(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf *new, *img = in[0]->data; - - if ((img==NULL) || (out[0]->hasoutput==0)) return; - - if (img->type != CB_RGBA) - img = typecheck_compbuf(img, CB_RGBA); - - new = dupalloc_compbuf(img); - - tonemap(node->storage, new, img); - - out[0]->data = new; - - if(img!=in[0]->data) - free_compbuf(img); -} - -static void node_composit_init_tonemap(bNode* node) -{ - NodeTonemap *ntm = MEM_callocN(sizeof(NodeTonemap), "node tonemap data"); - ntm->type = 1; - ntm->key = 0.18; - ntm->offset = 1; - ntm->gamma = 1; - ntm->f = 0; - ntm->m = 0; // actual value is set according to input - // default a of 1 works well with natural HDR images, but not always so for cgi. - // Maybe should use 0 or at least lower initial value instead - ntm->a = 1; - ntm->c = 0; - node->storage = ntm; -} - -void register_node_type_cmp_tonemap(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_TONEMAP, "Tonemap", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - cmp_node_tonemap_in, cmp_node_tonemap_out); - node_type_size(&ntype, 150, 120, 200); - node_type_init(&ntype, node_composit_init_tonemap); - node_type_storage(&ntype, "NodeTonemap", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_tonemap); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_translate.c b/source/blender/nodes/intern/CMP_nodes/CMP_translate.c deleted file mode 100644 index eb69523e7a9..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_translate.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_translate.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** Translate ******************** */ - -static bNodeSocketType cmp_node_translate_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "X", 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, - { SOCK_VALUE, 1, "Y", 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_translate_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_composit_exec_translate(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **in, bNodeStack **out) -{ - if(in[0]->data) { - CompBuf *cbuf= in[0]->data; - CompBuf *stackbuf= pass_on_compbuf(cbuf); - - stackbuf->xof+= (int)floor(in[1]->vec[0]); - stackbuf->yof+= (int)floor(in[2]->vec[0]); - - out[0]->data= stackbuf; - } -} - -void register_node_type_cmp_translate(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_TRANSLATE, "Translate", NODE_CLASS_DISTORT, NODE_OPTIONS, - cmp_node_translate_in, cmp_node_translate_out); - node_type_size(&ntype, 140, 100, 320); - node_type_exec(&ntype, node_composit_exec_translate); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_valToRgb.c b/source/blender/nodes/intern/CMP_nodes/CMP_valToRgb.c deleted file mode 100644 index 1e1c8c61b46..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_valToRgb.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_valToRgb.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** VALTORGB ******************** */ -static bNodeSocketType cmp_node_valtorgb_in[]= { - { SOCK_VALUE, 1, "Fac", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_valtorgb_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_colorband_composit(bNode *node, float *out, float *in) -{ - do_colorband(node->storage, in[0], out); -} - -static void node_composit_exec_valtorgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order in: fac */ - /* stack order out: col, alpha */ - - if(out[0]->hasoutput==0 && out[1]->hasoutput==0) - return; - - if(node->storage) { - /* input no image? then only color operation */ - if(in[0]->data==NULL) { - do_colorband(node->storage, in[0]->vec[0], out[0]->vec); - } - else { - /* make output size of input image */ - CompBuf *cbuf= in[0]->data; - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ - - composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_colorband_composit, CB_VAL); - - out[0]->data= stackbuf; - - if(out[1]->hasoutput) - out[1]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A); - - } - } -} - -static void node_composit_init_valtorgb(bNode* node) -{ - node->storage= add_colorband(1); -} - -void register_node_type_cmp_valtorgb(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - cmp_node_valtorgb_in, cmp_node_valtorgb_out); - node_type_size(&ntype, 240, 200, 300); - node_type_init(&ntype, node_composit_init_valtorgb); - node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_valtorgb); - - nodeRegisterType(lb, &ntype); -} - - - -/* **************** RGBTOBW ******************** */ -static bNodeSocketType cmp_node_rgbtobw_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_rgbtobw_out[]= { - { SOCK_VALUE, 0, "Val", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void do_rgbtobw(bNode *UNUSED(node), float *out, float *in) -{ - out[0]= in[0]*0.35f + in[1]*0.45f + in[2]*0.2f; -} - -static void node_composit_exec_rgbtobw(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order out: bw */ - /* stack order in: col */ - - if(out[0]->hasoutput==0) - return; - - /* input no image? then only color operation */ - if(in[0]->data==NULL) { - do_rgbtobw(node, out[0]->vec, in[0]->vec); - } - else { - /* make output size of input image */ - CompBuf *cbuf= in[0]->data; - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */ - - composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_rgbtobw, CB_RGBA); - - out[0]->data= stackbuf; - } -} - -void register_node_type_cmp_rgbtobw(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0, - cmp_node_rgbtobw_in, cmp_node_rgbtobw_out); - node_type_size(&ntype, 80, 40, 120); - node_type_exec(&ntype, node_composit_exec_rgbtobw); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_value.c b/source/blender/nodes/intern/CMP_nodes/CMP_value.c deleted file mode 100644 index 46762065bb4..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_value.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_value.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - -/* **************** VALUE ******************** */ -static bNodeSocketType cmp_node_value_out[]= { - { SOCK_VALUE, 0, "Value", 0.5f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, - { -1, 0, "" } -}; - -static void node_composit_exec_value(void *UNUSED(data), bNode *node, bNodeStack **UNUSED(in), bNodeStack **out) -{ - bNodeSocket *sock= node->outputs.first; - - out[0]->vec[0]= sock->ns.vec[0]; -} - -void register_node_type_cmp_value(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_VALUE, "Value", NODE_CLASS_INPUT, NODE_OPTIONS, - NULL, cmp_node_value_out); - node_type_size(&ntype, 80, 40, 120); - node_type_exec(&ntype, node_composit_exec_value); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_vecBlur.c b/source/blender/nodes/intern/CMP_nodes/CMP_vecBlur.c deleted file mode 100644 index c43bfa2435a..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_vecBlur.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_vecBlur.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** VECTOR BLUR ******************** */ -static bNodeSocketType cmp_node_vecblur_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Z", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 1, "Speed", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_vecblur_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - - - -static void node_composit_exec_vecblur(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - NodeBlurData *nbd= node->storage; - CompBuf *new, *img= in[0]->data, *vecbuf= in[2]->data, *zbuf= in[1]->data; - - if(img==NULL || vecbuf==NULL || zbuf==NULL || out[0]->hasoutput==0) - return; - if(vecbuf->x!=img->x || vecbuf->y!=img->y) { - printf("ERROR: cannot do different sized vecbuf yet\n"); - return; - } - if(vecbuf->type!=CB_VEC4) { - printf("ERROR: input should be vecbuf\n"); - return; - } - if(zbuf->type!=CB_VAL) { - printf("ERROR: input should be zbuf\n"); - return; - } - if(zbuf->x!=img->x || zbuf->y!=img->y) { - printf("ERROR: cannot do different sized zbuf yet\n"); - return; - } - - /* allow the input image to be of another type */ - img= typecheck_compbuf(in[0]->data, CB_RGBA); - - new= dupalloc_compbuf(img); - - /* call special zbuffer version */ - RE_zbuf_accumulate_vecblur(nbd, img->x, img->y, new->rect, img->rect, vecbuf->rect, zbuf->rect); - - out[0]->data= new; - - if(img!=in[0]->data) - free_compbuf(img); -} - -static void node_composit_init_vecblur(bNode* node) -{ - NodeBlurData *nbd= MEM_callocN(sizeof(NodeBlurData), "node blur data"); - node->storage= nbd; - nbd->samples= 32; - nbd->fac= 1.0f; -} - -/* custom1: itterations, custom2: maxspeed (0 = nolimit) */ -void register_node_type_cmp_vecblur(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_VECBLUR, "Vector Blur", NODE_CLASS_OP_FILTER, NODE_OPTIONS, - cmp_node_vecblur_in, cmp_node_vecblur_out); - node_type_size(&ntype, 120, 80, 200); - node_type_init(&ntype, node_composit_init_vecblur); - node_type_storage(&ntype, "NodeBlurData", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_vecblur); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_viewer.c b/source/blender/nodes/intern/CMP_nodes/CMP_viewer.c deleted file mode 100644 index c4e719efbf9..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_viewer.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_viewer.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** VIEWER ******************** */ -static bNodeSocketType cmp_node_viewer_in[]= { - { SOCK_RGBA, 1, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Z", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - - -static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out)) -{ - /* image assigned to output */ - /* stack order input sockets: col, alpha, z */ - - if(node->id && (node->flag & NODE_DO_OUTPUT)) { /* only one works on out */ - RenderData *rd= data; - Image *ima= (Image *)node->id; - ImBuf *ibuf; - CompBuf *cbuf, *tbuf; - int rectx, recty; - void *lock; - - BKE_image_user_calc_frame(node->storage, rd->cfra, 0); - - /* always returns for viewer image, but we check nevertheless */ - ibuf= BKE_image_acquire_ibuf(ima, node->storage, &lock); - if(ibuf==NULL) { - printf("node_composit_exec_viewer error\n"); - BKE_image_release_ibuf(ima, lock); - return; - } - - /* free all in ibuf */ - imb_freerectImBuf(ibuf); - imb_freerectfloatImBuf(ibuf); - IMB_freezbuffloatImBuf(ibuf); - - /* get size */ - tbuf= in[0]->data?in[0]->data:(in[1]->data?in[1]->data:in[2]->data); - if(tbuf==NULL) { - rectx= 320; recty= 256; - } - else { - rectx= tbuf->x; - recty= tbuf->y; - } - - /* make ibuf, and connect to ima */ - ibuf->x= rectx; - ibuf->y= recty; - imb_addrectfloatImBuf(ibuf); - - ima->ok= IMA_OK_LOADED; - - /* now we combine the input with ibuf */ - cbuf= alloc_compbuf(rectx, recty, CB_RGBA, 0); /* no alloc*/ - cbuf->rect= ibuf->rect_float; - - /* when no alpha, we can simply copy */ - if(in[1]->data==NULL) { - composit1_pixel_processor(node, cbuf, in[0]->data, in[0]->vec, do_copy_rgba, CB_RGBA); - } - else - composit2_pixel_processor(node, cbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_copy_a_rgba, CB_RGBA, CB_VAL); - - /* zbuf option */ - if(in[2]->data) { - CompBuf *zbuf= alloc_compbuf(rectx, recty, CB_VAL, 1); - ibuf->zbuf_float= zbuf->rect; - ibuf->mall |= IB_zbuffloat; - - composit1_pixel_processor(node, zbuf, in[2]->data, in[2]->vec, do_copy_value, CB_VAL); - - /* free compbuf, but not the rect */ - zbuf->malloc= 0; - free_compbuf(zbuf); - } - - BKE_image_release_ibuf(ima, lock); - - generate_preview(data, node, cbuf); - free_compbuf(cbuf); - - } - else if(in[0]->data) { - generate_preview(data, node, in[0]->data); - } -} - -static void node_composit_init_viewer(bNode* node) -{ - ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user"); - node->storage= iuser; - iuser->sfra= 1; - iuser->fie_ima= 2; - iuser->ok= 1; -} - -void register_node_type_cmp_viewer(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_VIEWER, "Viewer", NODE_CLASS_OUTPUT, NODE_PREVIEW, - cmp_node_viewer_in, NULL); - node_type_size(&ntype, 80, 60, 200); - node_type_init(&ntype, node_composit_init_viewer); - node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_composit_exec_viewer); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_zcombine.c b/source/blender/nodes/intern/CMP_nodes/CMP_zcombine.c deleted file mode 100644 index 0fae0fcd4d5..00000000000 --- a/source/blender/nodes/intern/CMP_nodes/CMP_zcombine.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_nodes/CMP_zcombine.c - * \ingroup cmpnodes - */ - - -#include "../CMP_util.h" - - -/* **************** Z COMBINE ******************** */ - /* lazy coder note: node->custom2 is abused to send signal */ -static bNodeSocketType cmp_node_zcombine_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Z", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 10000.0f}, - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Z", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 10000.0f}, - { -1, 0, "" } -}; -static bNodeSocketType cmp_node_zcombine_out[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "Z", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 10000.0f}, - { -1, 0, "" } -}; - -static void do_zcombine(bNode *node, float *out, float *src1, float *z1, float *src2, float *z2) -{ - float alpha; - float malpha; - - if(*z1 <= *z2) { - if (node->custom1) { - // use alpha in combine operation - alpha= src1[3]; - malpha= 1.0f - alpha; - out[0]= malpha*src2[0] + alpha*src1[0]; - out[1]= malpha*src2[1] + alpha*src1[1]; - out[2]= malpha*src2[2] + alpha*src1[2]; - out[3]= malpha*src2[3] + alpha*src1[3]; - } - else { - // do combination based solely on z value - QUATCOPY(out, src1); - } - } - else { - if (node->custom1) { - // use alpha in combine operation - alpha= src2[3]; - malpha= 1.0f - alpha; - out[0]= malpha*src1[0] + alpha*src2[0]; - out[1]= malpha*src1[1] + alpha*src2[1]; - out[2]= malpha*src1[2] + alpha*src2[2]; - out[3]= malpha*src1[3] + alpha*src2[3]; - } - else { - // do combination based solely on z value - QUATCOPY(out, src1); - } - - if(node->custom2) - *z1= *z2; - } -} - -static void do_zcombine_mask(bNode *node, float *out, float *z1, float *z2) -{ - if(*z1 > *z2) { - *out= 1.0f; - if(node->custom2) - *z1= *z2; - } -} - -static void do_zcombine_add(bNode *node, float *out, float *col1, float *col2, float *acol) -{ - float alpha; - float malpha; - - if (node->custom1) { - // use alpha in combine operation, antialiased mask in used here just as hint for the z value - if (*acol>0.0f) { - alpha= col2[3]; - malpha= 1.0f - alpha; - - - out[0]= malpha*col1[0] + alpha*col2[0]; - out[1]= malpha*col1[1] + alpha*col2[1]; - out[2]= malpha*col1[2] + alpha*col2[2]; - out[3]= malpha*col1[3] + alpha*col2[3]; - } - else { - alpha= col1[3]; - malpha= 1.0f - alpha; - - - out[0]= malpha*col2[0] + alpha*col1[0]; - out[1]= malpha*col2[1] + alpha*col1[1]; - out[2]= malpha*col2[2] + alpha*col1[2]; - out[3]= malpha*col2[3] + alpha*col1[3]; - } - } - else { - // do combination based solely on z value but with antialiased mask - alpha = *acol; - malpha= 1.0f - alpha; - - out[0]= malpha*col1[0] + alpha*col2[0]; - out[1]= malpha*col1[1] + alpha*col2[1]; - out[2]= malpha*col1[2] + alpha*col2[2]; - out[3]= malpha*col1[3] + alpha*col2[3]; - } -} - -static void node_composit_exec_zcombine(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - RenderData *rd= data; - CompBuf *cbuf= in[0]->data; - CompBuf *zbuf; - - /* stack order in: col z col z */ - /* stack order out: col z */ - if(out[0]->hasoutput==0 && out[1]->hasoutput==0) - return; - - /* no input image; do nothing now */ - if(in[0]->data==NULL) { - return; - } - - if(out[1]->hasoutput) { - /* copy or make a buffer for for the first z value, here we write result in */ - if(in[1]->data) - zbuf= dupalloc_compbuf(in[1]->data); - else { - float *zval; - int tot= cbuf->x*cbuf->y; - - zbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); - for(zval= zbuf->rect; tot; tot--, zval++) - *zval= in[1]->vec[0]; - } - /* lazy coder hack */ - node->custom2= 1; - out[1]->data= zbuf; - } - else { - node->custom2= 0; - zbuf= in[1]->data; - } - - if(rd->scemode & R_FULL_SAMPLE) { - /* make output size of first input image */ - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); // allocs - - composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, zbuf, in[1]->vec, in[2]->data, in[2]->vec, - in[3]->data, in[3]->vec, do_zcombine, CB_RGBA, CB_VAL, CB_RGBA, CB_VAL); - - out[0]->data= stackbuf; - } - else { - /* make output size of first input image */ - CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ - CompBuf *mbuf; - float *fp; - int x; - char *aabuf; - - - /* make a mask based on comparison, optionally write zvalue */ - mbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); - composit2_pixel_processor(node, mbuf, zbuf, in[1]->vec, in[3]->data, in[3]->vec, do_zcombine_mask, CB_VAL, CB_VAL); - - /* convert to char */ - aabuf= MEM_mallocN(cbuf->x*cbuf->y, "aa buf"); - fp= mbuf->rect; - for(x= cbuf->x*cbuf->y-1; x>=0; x--) - if(fp[x]==0.0f) aabuf[x]= 0; - else aabuf[x]= 255; - - antialias_tagbuf(cbuf->x, cbuf->y, aabuf); - - /* convert to float */ - fp= mbuf->rect; - for(x= cbuf->x*cbuf->y-1; x>=0; x--) - if(aabuf[x]>1) - fp[x]= (1.0f/255.0f)*(float)aabuf[x]; - - composit3_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[2]->data, in[2]->vec, mbuf, NULL, - do_zcombine_add, CB_RGBA, CB_RGBA, CB_VAL); - /* free */ - free_compbuf(mbuf); - MEM_freeN(aabuf); - - out[0]->data= stackbuf; - } - -} - -void register_node_type_cmp_zcombine(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, CMP_NODE_ZCOMBINE, "Z Combine", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - cmp_node_zcombine_in, cmp_node_zcombine_out); - node_type_size(&ntype, 80, 40, 120); - node_type_exec(&ntype, node_composit_exec_zcombine); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/CMP_util.c b/source/blender/nodes/intern/CMP_util.c deleted file mode 100644 index a763f34a644..00000000000 --- a/source/blender/nodes/intern/CMP_util.c +++ /dev/null @@ -1,1413 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_util.c - * \ingroup nodes - */ - - -#include "CMP_util.h" - -CompBuf *alloc_compbuf(int sizex, int sizey, int type, int alloc) -{ - CompBuf *cbuf= MEM_callocN(sizeof(CompBuf), "compbuf"); - - cbuf->x= sizex; - cbuf->y= sizey; - cbuf->xrad= sizex/2; - cbuf->yrad= sizey/2; - - cbuf->type= type; - if(alloc) { - if(cbuf->type==CB_RGBA) - cbuf->rect= MEM_mapallocN(4*sizeof(float)*sizex*sizey, "compbuf RGBA rect"); - else if(cbuf->type==CB_VEC3) - cbuf->rect= MEM_mapallocN(3*sizeof(float)*sizex*sizey, "compbuf Vector3 rect"); - else if(cbuf->type==CB_VEC2) - cbuf->rect= MEM_mapallocN(2*sizeof(float)*sizex*sizey, "compbuf Vector2 rect"); - else - cbuf->rect= MEM_mapallocN(sizeof(float)*sizex*sizey, "compbuf Fac rect"); - cbuf->malloc= 1; - } - cbuf->disprect.xmin= 0; - cbuf->disprect.ymin= 0; - cbuf->disprect.xmax= sizex; - cbuf->disprect.ymax= sizey; - - return cbuf; -} - -CompBuf *dupalloc_compbuf(CompBuf *cbuf) -{ - CompBuf *dupbuf= alloc_compbuf(cbuf->x, cbuf->y, cbuf->type, 1); - if(dupbuf) { - memmove(dupbuf->rect, cbuf->rect, cbuf->type*sizeof(float)*cbuf->x*cbuf->y); - - dupbuf->xof= cbuf->xof; - dupbuf->yof= cbuf->yof; - } - return dupbuf; -} - -/* instead of reference counting, we create a list */ -CompBuf *pass_on_compbuf(CompBuf *cbuf) -{ - CompBuf *dupbuf= (cbuf)? alloc_compbuf(cbuf->x, cbuf->y, cbuf->type, 0): NULL; - CompBuf *lastbuf; - - if(dupbuf) { - dupbuf->rect= cbuf->rect; - dupbuf->xof= cbuf->xof; - dupbuf->yof= cbuf->yof; - dupbuf->malloc= 0; - - /* get last buffer in list, and append dupbuf */ - for(lastbuf= cbuf; lastbuf; lastbuf= lastbuf->next) - if(lastbuf->next==NULL) - break; - lastbuf->next= dupbuf; - dupbuf->prev= lastbuf; - } - return dupbuf; -} - - -void free_compbuf(CompBuf *cbuf) -{ - /* check referencing, then remove from list and set malloc tag */ - if(cbuf->prev || cbuf->next) { - if(cbuf->prev) - cbuf->prev->next= cbuf->next; - if(cbuf->next) - cbuf->next->prev= cbuf->prev; - if(cbuf->malloc) { - if(cbuf->prev) - cbuf->prev->malloc= 1; - else - cbuf->next->malloc= 1; - cbuf->malloc= 0; - } - } - - if(cbuf->malloc && cbuf->rect) - MEM_freeN(cbuf->rect); - - MEM_freeN(cbuf); -} - -void print_compbuf(char *str, CompBuf *cbuf) -{ - printf("Compbuf %s %d %d %p\n", str, cbuf->x, cbuf->y, (void *)cbuf->rect); - -} - -void compbuf_set_node(CompBuf *cbuf, bNode *node) -{ - if (cbuf) cbuf->node = node; -} - -/* used for disabling node (similar code in node_draw.c for disable line and node_edit for untangling nodes) */ -void node_compo_pass_on(bNode *node, bNodeStack **nsin, bNodeStack **nsout) -{ - CompBuf *valbuf= NULL, *colbuf= NULL, *vecbuf= NULL; - bNodeSocket *sock; - int a; - - /* connect the first value buffer in with first value out */ - /* connect the first RGBA buffer in with first RGBA out */ - - /* test the inputs */ - for(a=0, sock= node->inputs.first; sock; sock= sock->next, a++) { - if(nsin[a]->data) { - CompBuf *cbuf= nsin[a]->data; - if(cbuf->type==1 && valbuf==NULL) valbuf= cbuf; - if(cbuf->type==3 && vecbuf==NULL) vecbuf= cbuf; - if(cbuf->type==4 && colbuf==NULL) colbuf= cbuf; - } - } - - /* outputs */ - if(valbuf || colbuf || vecbuf) { - for(a=0, sock= node->outputs.first; sock; sock= sock->next, a++) { - if(nsout[a]->hasoutput) { - if(sock->type==SOCK_VALUE && valbuf) { - nsout[a]->data= pass_on_compbuf(valbuf); - valbuf= NULL; - } - if(sock->type==SOCK_VECTOR && vecbuf) { - nsout[a]->data= pass_on_compbuf(vecbuf); - vecbuf= NULL; - } - if(sock->type==SOCK_RGBA && colbuf) { - nsout[a]->data= pass_on_compbuf(colbuf); - colbuf= NULL; - } - } - } - } -} - - -CompBuf *get_cropped_compbuf(rcti *drect, float *rectf, int rectx, int recty, int type) -{ - CompBuf *cbuf; - rcti disprect= *drect; - float *outfp; - int dx, y; - - if(disprect.xmax>rectx) disprect.xmax= rectx; - if(disprect.ymax>recty) disprect.ymax= recty; - if(disprect.xmin>= disprect.xmax) return NULL; - if(disprect.ymin>= disprect.ymax) return NULL; - - cbuf= alloc_compbuf(disprect.xmax-disprect.xmin, disprect.ymax-disprect.ymin, type, 1); - outfp= cbuf->rect; - rectf += type*(disprect.ymin*rectx + disprect.xmin); - dx= type*cbuf->x; - for(y=cbuf->y; y>0; y--, outfp+=dx, rectf+=type*rectx) - memcpy(outfp, rectf, sizeof(float)*dx); - - return cbuf; -} - -CompBuf *scalefast_compbuf(CompBuf *inbuf, int newx, int newy) -{ - CompBuf *outbuf; - float *rectf, *newrectf, *rf; - int x, y, c, pixsize= inbuf->type; - int ofsx, ofsy, stepx, stepy; - - if(inbuf->x==newx && inbuf->y==newy) - return dupalloc_compbuf(inbuf); - - outbuf= alloc_compbuf(newx, newy, inbuf->type, 1); - newrectf= outbuf->rect; - - stepx = (65536.0 * (inbuf->x - 1.0) / (newx - 1.0)) + 0.5; - stepy = (65536.0 * (inbuf->y - 1.0) / (newy - 1.0)) + 0.5; - ofsy = 32768; - - for (y = newy; y > 0 ; y--){ - rectf = inbuf->rect; - rectf += pixsize * (ofsy >> 16) * inbuf->x; - - ofsy += stepy; - ofsx = 32768; - - for (x = newx ; x>0 ; x--) { - - rf= rectf + pixsize*(ofsx >> 16); - for(c=0; c<pixsize; c++) - newrectf[c] = rf[c]; - - newrectf+= pixsize; - - ofsx += stepx; - } - } - - return outbuf; -} - -void typecheck_compbuf_color(float *out, float *in, int outtype, int intype) -{ - if(intype == outtype) { - memcpy(out, in, sizeof(float)*outtype); - } - else if(outtype==CB_VAL) { - if(intype==CB_VEC2) { - *out= 0.5f*(in[0]+in[1]); - } - else if(intype==CB_VEC3) { - *out= 0.333333f*(in[0]+in[1]+in[2]); - } - else if(intype==CB_RGBA) { - *out= in[0]*0.35f + in[1]*0.45f + in[2]*0.2f; - } - } - else if(outtype==CB_VEC2) { - if(intype==CB_VAL) { - out[0]= in[0]; - out[1]= in[0]; - } - else if(intype==CB_VEC3) { - out[0]= in[0]; - out[1]= in[1]; - } - else if(intype==CB_RGBA) { - out[0]= in[0]; - out[1]= in[1]; - } - } - else if(outtype==CB_VEC3) { - if(intype==CB_VAL) { - out[0]= in[0]; - out[1]= in[0]; - out[2]= in[0]; - } - else if(intype==CB_VEC2) { - out[0]= in[0]; - out[1]= in[1]; - out[2]= 0.0f; - } - else if(intype==CB_RGBA) { - out[0]= in[0]; - out[1]= in[1]; - out[2]= in[2]; - } - } - else if(outtype==CB_RGBA) { - if(intype==CB_VAL) { - out[0]= in[0]; - out[1]= in[0]; - out[2]= in[0]; - out[3]= 1.0f; - } - else if(intype==CB_VEC2) { - out[0]= in[0]; - out[1]= in[1]; - out[2]= 0.0f; - out[3]= 1.0f; - } - else if(intype==CB_VEC3) { - out[0]= in[0]; - out[1]= in[1]; - out[2]= in[2]; - out[3]= 1.0f; - } - } -} - -CompBuf *typecheck_compbuf(CompBuf *inbuf, int type) -{ - if(inbuf && inbuf->type!=type) { - CompBuf *outbuf; - float *inrf, *outrf; - int x; - - outbuf= alloc_compbuf(inbuf->x, inbuf->y, type, 1); - - /* warning note: xof and yof are applied in pixelprocessor, but should be copied otherwise? */ - outbuf->xof= inbuf->xof; - outbuf->yof= inbuf->yof; - - if(inbuf->rect_procedural) { - outbuf->rect_procedural= inbuf->rect_procedural; - VECCOPY(outbuf->procedural_size, inbuf->procedural_size); - VECCOPY(outbuf->procedural_offset, inbuf->procedural_offset); - outbuf->procedural_type= inbuf->procedural_type; - outbuf->node= inbuf->node; - return outbuf; - } - - inrf= inbuf->rect; - outrf= outbuf->rect; - x= inbuf->x*inbuf->y; - - if(type==CB_VAL) { - if(inbuf->type==CB_VEC2) { - for(; x>0; x--, outrf+= 1, inrf+= 2) - *outrf= 0.5f*(inrf[0]+inrf[1]); - } - else if(inbuf->type==CB_VEC3) { - for(; x>0; x--, outrf+= 1, inrf+= 3) - *outrf= 0.333333f*(inrf[0]+inrf[1]+inrf[2]); - } - else if(inbuf->type==CB_RGBA) { - for(; x>0; x--, outrf+= 1, inrf+= 4) - *outrf= inrf[0]*0.35f + inrf[1]*0.45f + inrf[2]*0.2f; - } - } - else if(type==CB_VEC2) { - if(inbuf->type==CB_VAL) { - for(; x>0; x--, outrf+= 2, inrf+= 1) { - outrf[0]= inrf[0]; - outrf[1]= inrf[0]; - } - } - else if(inbuf->type==CB_VEC3) { - for(; x>0; x--, outrf+= 2, inrf+= 3) { - outrf[0]= inrf[0]; - outrf[1]= inrf[1]; - } - } - else if(inbuf->type==CB_RGBA) { - for(; x>0; x--, outrf+= 2, inrf+= 4) { - outrf[0]= inrf[0]; - outrf[1]= inrf[1]; - } - } - } - else if(type==CB_VEC3) { - if(inbuf->type==CB_VAL) { - for(; x>0; x--, outrf+= 3, inrf+= 1) { - outrf[0]= inrf[0]; - outrf[1]= inrf[0]; - outrf[2]= inrf[0]; - } - } - else if(inbuf->type==CB_VEC2) { - for(; x>0; x--, outrf+= 3, inrf+= 2) { - outrf[0]= inrf[0]; - outrf[1]= inrf[1]; - outrf[2]= 0.0f; - } - } - else if(inbuf->type==CB_RGBA) { - for(; x>0; x--, outrf+= 3, inrf+= 4) { - outrf[0]= inrf[0]; - outrf[1]= inrf[1]; - outrf[2]= inrf[2]; - } - } - } - else if(type==CB_RGBA) { - if(inbuf->type==CB_VAL) { - for(; x>0; x--, outrf+= 4, inrf+= 1) { - outrf[0]= inrf[0]; - outrf[1]= inrf[0]; - outrf[2]= inrf[0]; - outrf[3]= 1.0f; - } - } - else if(inbuf->type==CB_VEC2) { - for(; x>0; x--, outrf+= 4, inrf+= 2) { - outrf[0]= inrf[0]; - outrf[1]= inrf[1]; - outrf[2]= 0.0f; - outrf[3]= 1.0f; - } - } - else if(inbuf->type==CB_VEC3) { - for(; x>0; x--, outrf+= 4, inrf+= 3) { - outrf[0]= inrf[0]; - outrf[1]= inrf[1]; - outrf[2]= inrf[2]; - outrf[3]= 1.0f; - } - } - } - - return outbuf; - } - return inbuf; -} - -static float *compbuf_get_pixel(CompBuf *cbuf, float *defcol, float *use, int x, int y, int xrad, int yrad) -{ - if(cbuf) { - if(cbuf->rect_procedural) { - cbuf->rect_procedural(cbuf, use, (float)x/(float)xrad, (float)y/(float)yrad); - return use; - } - else { - static float col[4]= {0.0f, 0.0f, 0.0f, 0.0f}; - - /* map coords */ - x-= cbuf->xof; - y-= cbuf->yof; - - if(y<-cbuf->yrad || y>= -cbuf->yrad+cbuf->y) return col; - if(x<-cbuf->xrad || x>= -cbuf->xrad+cbuf->x) return col; - - return cbuf->rect + cbuf->type*( (cbuf->yrad+y)*cbuf->x + (cbuf->xrad+x) ); - } - } - else return defcol; -} - -/* **************************************************** */ - -/* Pixel-to-Pixel operation, 1 Image in, 1 out */ -void composit1_pixel_processor(bNode *node, CompBuf *out, CompBuf *src_buf, float *src_col, - void (*func)(bNode *, float *, float *), - int src_type) -{ - CompBuf *src_use; - float *outfp=out->rect, *srcfp; - float color[4]; /* local color if compbuf is procedural */ - int xrad, yrad, x, y; - - src_use= typecheck_compbuf(src_buf, src_type); - - xrad= out->xrad; - yrad= out->yrad; - - for(y= -yrad; y<-yrad+out->y; y++) { - for(x= -xrad; x<-xrad+out->x; x++, outfp+=out->type) { - srcfp= compbuf_get_pixel(src_use, src_col, color, x, y, xrad, yrad); - func(node, outfp, srcfp); - } - } - - if(src_use!=src_buf) - free_compbuf(src_use); -} - -/* Pixel-to-Pixel operation, 2 Images in, 1 out */ -void composit2_pixel_processor(bNode *node, CompBuf *out, CompBuf *src_buf, float *src_col, - CompBuf *fac_buf, float *fac, void (*func)(bNode *, float *, float *, float *), - int src_type, int fac_type) -{ - CompBuf *src_use, *fac_use; - float *outfp=out->rect, *srcfp, *facfp; - float color[4]; /* local color if compbuf is procedural */ - int xrad, yrad, x, y; - - src_use= typecheck_compbuf(src_buf, src_type); - fac_use= typecheck_compbuf(fac_buf, fac_type); - - xrad= out->xrad; - yrad= out->yrad; - - for(y= -yrad; y<-yrad+out->y; y++) { - for(x= -xrad; x<-xrad+out->x; x++, outfp+=out->type) { - srcfp= compbuf_get_pixel(src_use, src_col, color, x, y, xrad, yrad); - facfp= compbuf_get_pixel(fac_use, fac, color, x, y, xrad, yrad); - - func(node, outfp, srcfp, facfp); - } - } - if(src_use!=src_buf) - free_compbuf(src_use); - if(fac_use!=fac_buf) - free_compbuf(fac_use); -} - -/* Pixel-to-Pixel operation, 3 Images in, 1 out */ -void composit3_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, float *src1_col, CompBuf *src2_buf, float *src2_col, - CompBuf *fac_buf, float *fac, void (*func)(bNode *, float *, float *, float *, float *), - int src1_type, int src2_type, int fac_type) -{ - CompBuf *src1_use, *src2_use, *fac_use; - float *outfp=out->rect, *src1fp, *src2fp, *facfp; - float color[4]; /* local color if compbuf is procedural */ - int xrad, yrad, x, y; - - src1_use= typecheck_compbuf(src1_buf, src1_type); - src2_use= typecheck_compbuf(src2_buf, src2_type); - fac_use= typecheck_compbuf(fac_buf, fac_type); - - xrad= out->xrad; - yrad= out->yrad; - - for(y= -yrad; y<-yrad+out->y; y++) { - for(x= -xrad; x<-xrad+out->x; x++, outfp+=out->type) { - src1fp= compbuf_get_pixel(src1_use, src1_col, color, x, y, xrad, yrad); - src2fp= compbuf_get_pixel(src2_use, src2_col, color, x, y, xrad, yrad); - facfp= compbuf_get_pixel(fac_use, fac, color, x, y, xrad, yrad); - - func(node, outfp, src1fp, src2fp, facfp); - } - } - - if(src1_use!=src1_buf) - free_compbuf(src1_use); - if(src2_use!=src2_buf) - free_compbuf(src2_use); - if(fac_use!=fac_buf) - free_compbuf(fac_use); -} - -/* Pixel-to-Pixel operation, 4 Images in, 1 out */ -void composit4_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, float *src1_col, CompBuf *fac1_buf, float *fac1, - CompBuf *src2_buf, float *src2_col, CompBuf *fac2_buf, float *fac2, - void (*func)(bNode *, float *, float *, float *, float *, float *), - int src1_type, int fac1_type, int src2_type, int fac2_type) -{ - CompBuf *src1_use, *src2_use, *fac1_use, *fac2_use; - float *outfp=out->rect, *src1fp, *src2fp, *fac1fp, *fac2fp; - float color[4]; /* local color if compbuf is procedural */ - int xrad, yrad, x, y; - - src1_use= typecheck_compbuf(src1_buf, src1_type); - src2_use= typecheck_compbuf(src2_buf, src2_type); - fac1_use= typecheck_compbuf(fac1_buf, fac1_type); - fac2_use= typecheck_compbuf(fac2_buf, fac2_type); - - xrad= out->xrad; - yrad= out->yrad; - - for(y= -yrad; y<-yrad+out->y; y++) { - for(x= -xrad; x<-xrad+out->x; x++, outfp+=out->type) { - src1fp= compbuf_get_pixel(src1_use, src1_col, color, x, y, xrad, yrad); - src2fp= compbuf_get_pixel(src2_use, src2_col, color, x, y, xrad, yrad); - fac1fp= compbuf_get_pixel(fac1_use, fac1, color, x, y, xrad, yrad); - fac2fp= compbuf_get_pixel(fac2_use, fac2, color, x, y, xrad, yrad); - - func(node, outfp, src1fp, fac1fp, src2fp, fac2fp); - } - } - - if(src1_use!=src1_buf) - free_compbuf(src1_use); - if(src2_use!=src2_buf) - free_compbuf(src2_use); - if(fac1_use!=fac1_buf) - free_compbuf(fac1_use); - if(fac2_use!=fac2_buf) - free_compbuf(fac2_use); -} - - -CompBuf *valbuf_from_rgbabuf(CompBuf *cbuf, int channel) -{ - CompBuf *valbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); - float *valf, *rectf; - int tot; - - /* warning note: xof and yof are applied in pixelprocessor, but should be copied otherwise? */ - valbuf->xof= cbuf->xof; - valbuf->yof= cbuf->yof; - - valf= valbuf->rect; - - /* defaults to returning alpha channel */ - if ((channel < CHAN_R) || (channel > CHAN_A)) channel = CHAN_A; - - rectf= cbuf->rect + channel; - - for(tot= cbuf->x*cbuf->y; tot>0; tot--, valf++, rectf+=4) - *valf= *rectf; - - return valbuf; -} - -static CompBuf *generate_procedural_preview(CompBuf *cbuf, int newx, int newy) -{ - CompBuf *outbuf; - float *outfp; - int xrad, yrad, x, y; - - outbuf= alloc_compbuf(newx, newy, CB_RGBA, 1); - - outfp= outbuf->rect; - xrad= outbuf->xrad; - yrad= outbuf->yrad; - - for(y= -yrad; y<-yrad+outbuf->y; y++) - for(x= -xrad; x<-xrad+outbuf->x; x++, outfp+=outbuf->type) - cbuf->rect_procedural(cbuf, outfp, (float)x/(float)xrad, (float)y/(float)yrad); - - return outbuf; -} - -void generate_preview(void *data, bNode *node, CompBuf *stackbuf) -{ - RenderData *rd= data; - bNodePreview *preview= node->preview; - int xsize, ysize; - int color_manage= rd->color_mgt_flag & R_COLOR_MANAGEMENT; - unsigned char *rect; - - if(preview && stackbuf) { - CompBuf *cbuf, *stackbuf_use; - - if(stackbuf->rect==NULL && stackbuf->rect_procedural==NULL) return; - - stackbuf_use= typecheck_compbuf(stackbuf, CB_RGBA); - - if(stackbuf->x > stackbuf->y) { - xsize= 140; - ysize= (140*stackbuf->y)/stackbuf->x; - } - else { - ysize= 140; - xsize= (140*stackbuf->x)/stackbuf->y; - } - - if(stackbuf_use->rect_procedural) - cbuf= generate_procedural_preview(stackbuf_use, xsize, ysize); - else - cbuf= scalefast_compbuf(stackbuf_use, xsize, ysize); - - /* convert to byte for preview */ - rect= MEM_callocN(sizeof(unsigned char)*4*xsize*ysize, "bNodePreview.rect"); - - if(color_manage) - floatbuf_to_srgb_byte(cbuf->rect, rect, 0, xsize, 0, ysize, xsize); - else - floatbuf_to_byte(cbuf->rect, rect, 0, xsize, 0, ysize, xsize); - - free_compbuf(cbuf); - if(stackbuf_use!=stackbuf) - free_compbuf(stackbuf_use); - - BLI_lock_thread(LOCK_PREVIEW); - - if(preview->rect) - MEM_freeN(preview->rect); - preview->xsize= xsize; - preview->ysize= ysize; - preview->rect= rect; - - BLI_unlock_thread(LOCK_PREVIEW); - } -} - -void do_rgba_to_yuva(bNode *UNUSED(node), float *out, float *in) -{ - rgb_to_yuv(in[0],in[1],in[2], &out[0], &out[1], &out[2]); - out[3]=in[3]; -} - -void do_rgba_to_hsva(bNode *UNUSED(node), float *out, float *in) -{ - rgb_to_hsv(in[0],in[1],in[2], &out[0], &out[1], &out[2]); - out[3]=in[3]; -} - -void do_rgba_to_ycca(bNode *UNUSED(node), float *out, float *in) -{ - rgb_to_ycc(in[0],in[1],in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601); - out[3]=in[3]; -} - -void do_yuva_to_rgba(bNode *UNUSED(node), float *out, float *in) -{ - yuv_to_rgb(in[0],in[1],in[2], &out[0], &out[1], &out[2]); - out[3]=in[3]; -} - -void do_hsva_to_rgba(bNode *UNUSED(node), float *out, float *in) -{ - hsv_to_rgb(in[0],in[1],in[2], &out[0], &out[1], &out[2]); - out[3]=in[3]; -} - -void do_ycca_to_rgba(bNode *UNUSED(node), float *out, float *in) -{ - ycc_to_rgb(in[0],in[1],in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601); - out[3]=in[3]; -} - -void do_copy_rgba(bNode *UNUSED(node), float *out, float *in) -{ - QUATCOPY(out, in); -} - -void do_copy_rgb(bNode *UNUSED(node), float *out, float *in) -{ - VECCOPY(out, in); - out[3]= 1.0f; -} - -void do_copy_value(bNode *UNUSED(node), float *out, float *in) -{ - out[0]= in[0]; -} - -void do_copy_a_rgba(bNode *UNUSED(node), float *out, float *in, float *fac) -{ - VECCOPY(out, in); - out[3]= *fac; -} - -/* only accepts RGBA buffers */ -void gamma_correct_compbuf(CompBuf *img, int inversed) -{ - float *drect; - int x; - - if(img->type!=CB_RGBA) return; - - drect= img->rect; - if(inversed) { - for(x=img->x*img->y; x>0; x--, drect+=4) { - if(drect[0]>0.0f) drect[0]= sqrt(drect[0]); else drect[0]= 0.0f; - if(drect[1]>0.0f) drect[1]= sqrt(drect[1]); else drect[1]= 0.0f; - if(drect[2]>0.0f) drect[2]= sqrt(drect[2]); else drect[2]= 0.0f; - } - } - else { - for(x=img->x*img->y; x>0; x--, drect+=4) { - if(drect[0]>0.0f) drect[0]*= drect[0]; else drect[0]= 0.0f; - if(drect[1]>0.0f) drect[1]*= drect[1]; else drect[1]= 0.0f; - if(drect[2]>0.0f) drect[2]*= drect[2]; else drect[2]= 0.0f; - } - } -} - -void premul_compbuf(CompBuf *img, int inversed) -{ - float *drect; - int x; - - if(img->type!=CB_RGBA) return; - - drect= img->rect; - if(inversed) { - for(x=img->x*img->y; x>0; x--, drect+=4) { - if(fabs(drect[3]) < 1e-5f) { - drect[0]= 0.0f; - drect[1]= 0.0f; - drect[2]= 0.0f; - } - else { - drect[0] /= drect[3]; - drect[1] /= drect[3]; - drect[2] /= drect[3]; - } - } - } - else { - for(x=img->x*img->y; x>0; x--, drect+=4) { - drect[0] *= drect[3]; - drect[1] *= drect[3]; - drect[2] *= drect[3]; - } - } -} - - - -/* - * 2D Fast Hartley Transform, used for convolution - */ - -typedef float fREAL; - -// returns next highest power of 2 of x, as well it's log2 in L2 -static unsigned int nextPow2(unsigned int x, unsigned int* L2) -{ - unsigned int pw, x_notpow2 = x & (x-1); - *L2 = 0; - while (x>>=1) ++(*L2); - pw = 1 << (*L2); - if (x_notpow2) { (*L2)++; pw<<=1; } - return pw; -} - -//------------------------------------------------------------------------------ - -// from FXT library by Joerg Arndt, faster in order bitreversal -// use: r = revbin_upd(r, h) where h = N>>1 -static unsigned int revbin_upd(unsigned int r, unsigned int h) -{ - while (!((r^=h)&h)) h >>= 1; - return r; -} -//------------------------------------------------------------------------------ -static void FHT(fREAL* data, unsigned int M, unsigned int inverse) -{ - double tt, fc, dc, fs, ds, a = M_PI; - fREAL t1, t2; - int n2, bd, bl, istep, k, len = 1 << M, n = 1; - - int i, j = 0; - unsigned int Nh = len >> 1; - for (i=1;i<(len-1);++i) { - j = revbin_upd(j, Nh); - if (j>i) { - t1 = data[i]; - data[i] = data[j]; - data[j] = t1; - } - } - - do { - fREAL* data_n = &data[n]; - - istep = n << 1; - for (k=0; k<len; k+=istep) { - t1 = data_n[k]; - data_n[k] = data[k] - t1; - data[k] += t1; - } - - n2 = n >> 1; - if (n>2) { - fc = dc = cos(a); - fs = ds = sqrt(1.0 - fc*fc); //sin(a); - bd = n-2; - for (bl=1; bl<n2; bl++) { - fREAL* data_nbd = &data_n[bd]; - fREAL* data_bd = &data[bd]; - for (k=bl; k<len; k+=istep) { - t1 = fc*data_n[k] + fs*data_nbd[k]; - t2 = fs*data_n[k] - fc*data_nbd[k]; - data_n[k] = data[k] - t1; - data_nbd[k] = data_bd[k] - t2; - data[k] += t1; - data_bd[k] += t2; - } - tt = fc*dc - fs*ds; - fs = fs*dc + fc*ds; - fc = tt; - bd -= 2; - } - } - - if (n>1) { - for (k=n2; k<len; k+=istep) { - t1 = data_n[k]; - data_n[k] = data[k] - t1; - data[k] += t1; - } - } - - n = istep; - a *= 0.5; - } while (n<len); - - if (inverse) { - fREAL sc = (fREAL)1 / (fREAL)len; - for (k=0; k<len; ++k) - data[k] *= sc; - } -} -//------------------------------------------------------------------------------ -/* 2D Fast Hartley Transform, Mx/My -> log2 of width/height, - nzp -> the row where zero pad data starts, - inverse -> see above */ -static void FHT2D(fREAL *data, unsigned int Mx, unsigned int My, - unsigned int nzp, unsigned int inverse) -{ - unsigned int i, j, Nx, Ny, maxy; - fREAL t; - - Nx = 1 << Mx; - Ny = 1 << My; - - // rows (forward transform skips 0 pad data) - maxy = inverse ? Ny : nzp; - for (j=0; j<maxy; ++j) - FHT(&data[Nx*j], Mx, inverse); - - // transpose data - if (Nx==Ny) { // square - for (j=0; j<Ny; ++j) - for (i=j+1; i<Nx; ++i) { - unsigned int op = i + (j << Mx), np = j + (i << My); - t=data[op], data[op]=data[np], data[np]=t; - } - } - else { // rectangular - unsigned int k, Nym = Ny-1, stm = 1 << (Mx + My); - for (i=0; stm>0; i++) { - #define pred(k) (((k & Nym) << Mx) + (k >> My)) - for (j=pred(i); j>i; j=pred(j)); - if (j < i) continue; - for (k=i, j=pred(i); j!=i; k=j, j=pred(j), stm--) - { t=data[j], data[j]=data[k], data[k]=t; } - #undef pred - stm--; - } - } - // swap Mx/My & Nx/Ny - i = Nx, Nx = Ny, Ny = i; - i = Mx, Mx = My, My = i; - - // now columns == transposed rows - for (j=0; j<Ny; ++j) - FHT(&data[Nx*j], Mx, inverse); - - // finalize - for (j=0; j<=(Ny >> 1); j++) { - unsigned int jm = (Ny - j) & (Ny-1); - unsigned int ji = j << Mx; - unsigned int jmi = jm << Mx; - for (i=0; i<=(Nx >> 1); i++) { - unsigned int im = (Nx - i) & (Nx-1); - fREAL A = data[ji + i]; - fREAL B = data[jmi + i]; - fREAL C = data[ji + im]; - fREAL D = data[jmi + im]; - fREAL E = (fREAL)0.5*((A + D) - (B + C)); - data[ji + i] = A - E; - data[jmi + i] = B + E; - data[ji + im] = C + E; - data[jmi + im] = D - E; - } - } - -} - -//------------------------------------------------------------------------------ - -/* 2D convolution calc, d1 *= d2, M/N - > log2 of width/height */ -static void fht_convolve(fREAL* d1, fREAL* d2, unsigned int M, unsigned int N) -{ - fREAL a, b; - unsigned int i, j, k, L, mj, mL; - unsigned int m = 1 << M, n = 1 << N; - unsigned int m2 = 1 << (M-1), n2 = 1 << (N-1); - unsigned int mn2 = m << (N-1); - - d1[0] *= d2[0]; - d1[mn2] *= d2[mn2]; - d1[m2] *= d2[m2]; - d1[m2 + mn2] *= d2[m2 + mn2]; - for (i=1; i<m2; i++) { - k = m - i; - a = d1[i]*d2[i] - d1[k]*d2[k]; - b = d1[k]*d2[i] + d1[i]*d2[k]; - d1[i] = (b + a)*(fREAL)0.5; - d1[k] = (b - a)*(fREAL)0.5; - a = d1[i + mn2]*d2[i + mn2] - d1[k + mn2]*d2[k + mn2]; - b = d1[k + mn2]*d2[i + mn2] + d1[i + mn2]*d2[k + mn2]; - d1[i + mn2] = (b + a)*(fREAL)0.5; - d1[k + mn2] = (b - a)*(fREAL)0.5; - } - for (j=1; j<n2; j++) { - L = n - j; - mj = j << M; - mL = L << M; - a = d1[mj]*d2[mj] - d1[mL]*d2[mL]; - b = d1[mL]*d2[mj] + d1[mj]*d2[mL]; - d1[mj] = (b + a)*(fREAL)0.5; - d1[mL] = (b - a)*(fREAL)0.5; - a = d1[m2 + mj]*d2[m2 + mj] - d1[m2 + mL]*d2[m2 + mL]; - b = d1[m2 + mL]*d2[m2 + mj] + d1[m2 + mj]*d2[m2 + mL]; - d1[m2 + mj] = (b + a)*(fREAL)0.5; - d1[m2 + mL] = (b - a)*(fREAL)0.5; - } - for (i=1; i<m2; i++) { - k = m - i; - for (j=1; j<n2; j++) { - L = n - j; - mj = j << M; - mL = L << M; - a = d1[i + mj]*d2[i + mj] - d1[k + mL]*d2[k + mL]; - b = d1[k + mL]*d2[i + mj] + d1[i + mj]*d2[k + mL]; - d1[i + mj] = (b + a)*(fREAL)0.5; - d1[k + mL] = (b - a)*(fREAL)0.5; - a = d1[i + mL]*d2[i + mL] - d1[k + mj]*d2[k + mj]; - b = d1[k + mj]*d2[i + mL] + d1[i + mL]*d2[k + mj]; - d1[i + mL] = (b + a)*(fREAL)0.5; - d1[k + mj] = (b - a)*(fREAL)0.5; - } - } -} - -//------------------------------------------------------------------------------ - -void convolve(CompBuf* dst, CompBuf* in1, CompBuf* in2) -{ - fREAL *data1, *data2, *fp; - unsigned int w2, h2, hw, hh, log2_w, log2_h; - fRGB wt, *colp; - int x, y, ch; - int xbl, ybl, nxb, nyb, xbsz, ybsz; - int in2done = 0; - - CompBuf* rdst = alloc_compbuf(in1->x, in1->y, in1->type, 1); - - // convolution result width & height - w2 = 2*in2->x - 1; - h2 = 2*in2->y - 1; - // FFT pow2 required size & log2 - w2 = nextPow2(w2, &log2_w); - h2 = nextPow2(h2, &log2_h); - - // alloc space - data1 = (fREAL*)MEM_callocN(3*w2*h2*sizeof(fREAL), "convolve_fast FHT data1"); - data2 = (fREAL*)MEM_callocN(w2*h2*sizeof(fREAL), "convolve_fast FHT data2"); - - // normalize convolutor - wt[0] = wt[1] = wt[2] = 0.f; - for (y=0; y<in2->y; y++) { - colp = (fRGB*)&in2->rect[y*in2->x*in2->type]; - for (x=0; x<in2->x; x++) - fRGB_add(wt, colp[x]); - } - if (wt[0] != 0.f) wt[0] = 1.f/wt[0]; - if (wt[1] != 0.f) wt[1] = 1.f/wt[1]; - if (wt[2] != 0.f) wt[2] = 1.f/wt[2]; - for (y=0; y<in2->y; y++) { - colp = (fRGB*)&in2->rect[y*in2->x*in2->type]; - for (x=0; x<in2->x; x++) - fRGB_colormult(colp[x], wt); - } - - // copy image data, unpacking interleaved RGBA into separate channels - // only need to calc data1 once - - // block add-overlap - hw = in2->x >> 1; - hh = in2->y >> 1; - xbsz = (w2 + 1) - in2->x; - ybsz = (h2 + 1) - in2->y; - nxb = in1->x / xbsz; - if (in1->x % xbsz) nxb++; - nyb = in1->y / ybsz; - if (in1->y % ybsz) nyb++; - for (ybl=0; ybl<nyb; ybl++) { - for (xbl=0; xbl<nxb; xbl++) { - - // each channel one by one - for (ch=0; ch<3; ch++) { - fREAL* data1ch = &data1[ch*w2*h2]; - - // only need to calc fht data from in2 once, can re-use for every block - if (!in2done) { - // in2, channel ch -> data1 - for (y=0; y<in2->y; y++) { - fp = &data1ch[y*w2]; - colp = (fRGB*)&in2->rect[y*in2->x*in2->type]; - for (x=0; x<in2->x; x++) - fp[x] = colp[x][ch]; - } - } - - // in1, channel ch -> data2 - memset(data2, 0, w2*h2*sizeof(fREAL)); - for (y=0; y<ybsz; y++) { - int yy = ybl*ybsz + y; - if (yy >= in1->y) continue; - fp = &data2[y*w2]; - colp = (fRGB*)&in1->rect[yy*in1->x*in1->type]; - for (x=0; x<xbsz; x++) { - int xx = xbl*xbsz + x; - if (xx >= in1->x) continue; - fp[x] = colp[xx][ch]; - } - } - - // forward FHT - // zero pad data start is different for each == height+1 - if (!in2done) FHT2D(data1ch, log2_w, log2_h, in2->y+1, 0); - FHT2D(data2, log2_w, log2_h, in2->y+1, 0); - - // FHT2D transposed data, row/col now swapped - // convolve & inverse FHT - fht_convolve(data2, data1ch, log2_h, log2_w); - FHT2D(data2, log2_h, log2_w, 0, 1); - // data again transposed, so in order again - - // overlap-add result - for (y=0; y<(int)h2; y++) { - const int yy = ybl*ybsz + y - hh; - if ((yy < 0) || (yy >= in1->y)) continue; - fp = &data2[y*w2]; - colp = (fRGB*)&rdst->rect[yy*in1->x*in1->type]; - for (x=0; x<(int)w2; x++) { - const int xx = xbl*xbsz + x - hw; - if ((xx < 0) || (xx >= in1->x)) continue; - colp[xx][ch] += fp[x]; - } - } - - } - in2done = 1; - } - } - - MEM_freeN(data2); - MEM_freeN(data1); - memcpy(dst->rect, rdst->rect, sizeof(float)*dst->x*dst->y*dst->type); - free_compbuf(rdst); -} - - -/* - * - * Utility functions qd_* should probably be intergrated better with other functions here. - * - */ -// sets fcol to pixelcolor at (x, y) -void qd_getPixel(CompBuf* src, int x, int y, float* col) -{ - if(src->rect_procedural) { - float bc[4]; - src->rect_procedural(src, bc, (float)x/(float)src->xrad, (float)y/(float)src->yrad); - - switch(src->type){ - /* these fallthrough to get all the channels */ - case CB_RGBA: col[3]=bc[3]; - case CB_VEC3: col[2]=bc[2]; - case CB_VEC2: col[1]=bc[1]; - case CB_VAL: col[0]=bc[0]; - } - } - else if ((x >= 0) && (x < src->x) && (y >= 0) && (y < src->y)) { - float* bc = &src->rect[(x + y*src->x)*src->type]; - switch(src->type){ - /* these fallthrough to get all the channels */ - case CB_RGBA: col[3]=bc[3]; - case CB_VEC3: col[2]=bc[2]; - case CB_VEC2: col[1]=bc[1]; - case CB_VAL: col[0]=bc[0]; - } - } - else { - switch(src->type){ - /* these fallthrough to get all the channels */ - case CB_RGBA: col[3]=0.0; - case CB_VEC3: col[2]=0.0; - case CB_VEC2: col[1]=0.0; - case CB_VAL: col[0]=0.0; - } - } -} - -// sets pixel (x, y) to color col -void qd_setPixel(CompBuf* src, int x, int y, float* col) -{ - if ((x >= 0) && (x < src->x) && (y >= 0) && (y < src->y)) { - float* bc = &src->rect[(x + y*src->x)*src->type]; - switch(src->type){ - /* these fallthrough to get all the channels */ - case CB_RGBA: bc[3]=col[3]; - case CB_VEC3: bc[2]=col[2]; - case CB_VEC2: bc[1]=col[1]; - case CB_VAL: bc[0]=col[0]; - } - } -} - -// adds fcol to pixelcolor (x, y) -void qd_addPixel(CompBuf* src, int x, int y, float* col) -{ - if ((x >= 0) && (x < src->x) && (y >= 0) && (y < src->y)) { - float* bc = &src->rect[(x + y*src->x)*src->type]; - bc[0] += col[0], bc[1] += col[1], bc[2] += col[2]; - } -} - -// multiplies pixel by factor value f -void qd_multPixel(CompBuf* src, int x, int y, float f) -{ - if ((x >= 0) && (x < src->x) && (y >= 0) && (y < src->y)) { - float* bc = &src->rect[(x + y*src->x)*src->type]; - bc[0] *= f, bc[1] *= f, bc[2] *= f; - } -} - -// bilinear interpolation with wraparound -void qd_getPixelLerpWrap(CompBuf* src, float u, float v, float* col) -{ - const float ufl = floor(u), vfl = floor(v); - const int nx = (int)ufl % src->x, ny = (int)vfl % src->y; - const int x1 = (nx < 0) ? (nx + src->x) : nx; - const int y1 = (ny < 0) ? (ny + src->y) : ny; - const int x2 = (x1 + 1) % src->x, y2 = (y1 + 1) % src->y; - const float* c00 = &src->rect[(x1 + y1*src->x)*src->type]; - const float* c10 = &src->rect[(x2 + y1*src->x)*src->type]; - const float* c01 = &src->rect[(x1 + y2*src->x)*src->type]; - const float* c11 = &src->rect[(x2 + y2*src->x)*src->type]; - const float uf = u - ufl, vf = v - vfl; - const float w00=(1.f-uf)*(1.f-vf), w10=uf*(1.f-vf), w01=(1.f-uf)*vf, w11=uf*vf; - col[0] = w00*c00[0] + w10*c10[0] + w01*c01[0] + w11*c11[0]; - if (src->type != CB_VAL) { - col[1] = w00*c00[1] + w10*c10[1] + w01*c01[1] + w11*c11[1]; - col[2] = w00*c00[2] + w10*c10[2] + w01*c01[2] + w11*c11[2]; - col[3] = w00*c00[3] + w10*c10[3] + w01*c01[3] + w11*c11[3]; - } -} - -// as above, without wrap around -void qd_getPixelLerp(CompBuf* src, float u, float v, float* col) -{ - const float ufl = floor(u), vfl = floor(v); - const int x1 = (int)ufl, y1 = (int)vfl; - const int x2 = (int)ceil(u), y2 = (int)ceil(v); - if ((x2 >= 0) && (y2 >= 0) && (x1 < src->x) && (y1 < src->y)) { - const float B[4] = {0,0,0,0}; - const int ox1 = (x1 < 0), oy1 = (y1 < 0), ox2 = (x2 >= src->x), oy2 = (y2 >= src->y); - const float* c00 = (ox1 || oy1) ? B : &src->rect[(x1 + y1*src->x)*src->type]; - const float* c10 = (ox2 || oy1) ? B : &src->rect[(x2 + y1*src->x)*src->type]; - const float* c01 = (ox1 || oy2) ? B : &src->rect[(x1 + y2*src->x)*src->type]; - const float* c11 = (ox2 || oy2) ? B : &src->rect[(x2 + y2*src->x)*src->type]; - const float uf = u - ufl, vf = v - vfl; - const float w00=(1.f-uf)*(1.f-vf), w10=uf*(1.f-vf), w01=(1.f-uf)*vf, w11=uf*vf; - col[0] = w00*c00[0] + w10*c10[0] + w01*c01[0] + w11*c11[0]; - if (src->type != CB_VAL) { - col[1] = w00*c00[1] + w10*c10[1] + w01*c01[1] + w11*c11[1]; - col[2] = w00*c00[2] + w10*c10[2] + w01*c01[2] + w11*c11[2]; - col[3] = w00*c00[3] + w10*c10[3] + w01*c01[3] + w11*c11[3]; - } - } - else col[0] = col[1] = col[2] = col[3] = 0.f; -} - -// as above, sampling only one channel -void qd_getPixelLerpChan(CompBuf* src, float u, float v, int chan, float* out) -{ - const float ufl = floor(u), vfl = floor(v); - const int x1 = (int)ufl, y1 = (int)vfl; - const int x2 = (int)ceil(u), y2 = (int)ceil(v); - if (chan >= src->type) chan = 0; - if ((x2 >= 0) && (y2 >= 0) && (x1 < src->x) && (y1 < src->y)) { - const float B[4] = {0,0,0,0}; - const int ox1 = (x1 < 0), oy1 = (y1 < 0), ox2 = (x2 >= src->x), oy2 = (y2 >= src->y); - const float* c00 = (ox1 || oy1) ? B : &src->rect[(x1 + y1*src->x)*src->type + chan]; - const float* c10 = (ox2 || oy1) ? B : &src->rect[(x2 + y1*src->x)*src->type + chan]; - const float* c01 = (ox1 || oy2) ? B : &src->rect[(x1 + y2*src->x)*src->type + chan]; - const float* c11 = (ox2 || oy2) ? B : &src->rect[(x2 + y2*src->x)*src->type + chan]; - const float uf = u - ufl, vf = v - vfl; - const float w00=(1.f-uf)*(1.f-vf), w10=uf*(1.f-vf), w01=(1.f-uf)*vf, w11=uf*vf; - out[0] = w00*c00[0] + w10*c10[0] + w01*c01[0] + w11*c11[0]; - } - else *out = 0.f; -} - - -CompBuf* qd_downScaledCopy(CompBuf* src, int scale) -{ - CompBuf* fbuf; - if (scale <= 1) - fbuf = dupalloc_compbuf(src); - else { - int nw = src->x/scale, nh = src->y/scale; - if ((2*(src->x % scale)) > scale) nw++; - if ((2*(src->y % scale)) > scale) nh++; - fbuf = alloc_compbuf(nw, nh, src->type, 1); - { - int x, y, xx, yy, sx, sy, mx, my; - float colsum[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - float fscale = 1.f/(float)(scale*scale); - for (y=0; y<nh; y++) { - fRGB* fcolp = (fRGB*)&fbuf->rect[y*fbuf->x*fbuf->type]; - yy = y*scale; - my = yy + scale; - if (my > src->y) my = src->y; - for (x=0; x<nw; x++) { - xx = x*scale; - mx = xx + scale; - if (mx > src->x) mx = src->x; - colsum[0] = colsum[1] = colsum[2] = 0.f; - for (sy=yy; sy<my; sy++) { - fRGB* scolp = (fRGB*)&src->rect[sy*src->x*src->type]; - for (sx=xx; sx<mx; sx++) - fRGB_add(colsum, scolp[sx]); - } - fRGB_mult(colsum, fscale); - fRGB_copy(fcolp[x], colsum); - } - } - } - } - return fbuf; -} - -// fast g.blur, per channel -// xy var. bits 1 & 2 ca be used to blur in x or y direction separately -void IIR_gauss(CompBuf* src, float sigma, int chan, int xy) -{ - double q, q2, sc, cf[4], tsM[9], tsu[3], tsv[3]; - double *X, *Y, *W; - int i, x, y, sz; - - // <0.5 not valid, though can have a possibly useful sort of sharpening effect - if (sigma < 0.5) return; - - if ((xy < 1) || (xy > 3)) xy = 3; - - // XXX The YVV macro defined below explicitely expects sources of at least 3x3 pixels, - // so just skiping blur along faulty direction if src's def is below that limit! - if (src->x < 3) xy &= ~(int) 1; - if (src->y < 3) xy &= ~(int) 2; - if (xy < 1) return; - - // see "Recursive Gabor Filtering" by Young/VanVliet - // all factors here in double.prec. Required, because for single.prec it seems to blow up if sigma > ~200 - if (sigma >= 3.556) - q = 0.9804*(sigma - 3.556) + 2.5091; - else // sigma >= 0.5 - q = (0.0561*sigma + 0.5784)*sigma - 0.2568; - q2 = q*q; - sc = (1.1668 + q)*(3.203729649 + (2.21566 + q)*q); - // no gabor filtering here, so no complex multiplies, just the regular coefs. - // all negated here, so as not to have to recalc Triggs/Sdika matrix - cf[1] = q*(5.788961737 + (6.76492 + 3.0*q)*q)/ sc; - cf[2] = -q2*(3.38246 + 3.0*q)/sc; - // 0 & 3 unchanged - cf[3] = q2*q/sc; - cf[0] = 1.0 - cf[1] - cf[2] - cf[3]; - - // Triggs/Sdika border corrections, - // it seems to work, not entirely sure if it is actually totally correct, - // Besides J.M.Geusebroek's anigauss.c (see http://www.science.uva.nl/~mark), - // found one other implementation by Cristoph Lampert, - // but neither seem to be quite the same, result seems to be ok sofar anyway. - // Extra scale factor here to not have to do it in filter, - // though maybe this had something to with the precision errors - sc = cf[0]/((1.0 + cf[1] - cf[2] + cf[3])*(1.0 - cf[1] - cf[2] - cf[3])*(1.0 + cf[2] + (cf[1] - cf[3])*cf[3])); - tsM[0] = sc*(-cf[3]*cf[1] + 1.0 - cf[3]*cf[3] - cf[2]); - tsM[1] = sc*((cf[3] + cf[1])*(cf[2] + cf[3]*cf[1])); - tsM[2] = sc*(cf[3]*(cf[1] + cf[3]*cf[2])); - tsM[3] = sc*(cf[1] + cf[3]*cf[2]); - tsM[4] = sc*(-(cf[2] - 1.0)*(cf[2] + cf[3]*cf[1])); - tsM[5] = sc*(-(cf[3]*cf[1] + cf[3]*cf[3] + cf[2] - 1.0)*cf[3]); - tsM[6] = sc*(cf[3]*cf[1] + cf[2] + cf[1]*cf[1] - cf[2]*cf[2]); - tsM[7] = sc*(cf[1]*cf[2] + cf[3]*cf[2]*cf[2] - cf[1]*cf[3]*cf[3] - cf[3]*cf[3]*cf[3] - cf[3]*cf[2] + cf[3]); - tsM[8] = sc*(cf[3]*(cf[1] + cf[3]*cf[2])); - -#define YVV(L)\ -{\ - W[0] = cf[0]*X[0] + cf[1]*X[0] + cf[2]*X[0] + cf[3]*X[0];\ - W[1] = cf[0]*X[1] + cf[1]*W[0] + cf[2]*X[0] + cf[3]*X[0];\ - W[2] = cf[0]*X[2] + cf[1]*W[1] + cf[2]*W[0] + cf[3]*X[0];\ - for (i=3; i<L; i++)\ - W[i] = cf[0]*X[i] + cf[1]*W[i-1] + cf[2]*W[i-2] + cf[3]*W[i-3];\ - tsu[0] = W[L-1] - X[L-1];\ - tsu[1] = W[L-2] - X[L-1];\ - tsu[2] = W[L-3] - X[L-1];\ - tsv[0] = tsM[0]*tsu[0] + tsM[1]*tsu[1] + tsM[2]*tsu[2] + X[L-1];\ - tsv[1] = tsM[3]*tsu[0] + tsM[4]*tsu[1] + tsM[5]*tsu[2] + X[L-1];\ - tsv[2] = tsM[6]*tsu[0] + tsM[7]*tsu[1] + tsM[8]*tsu[2] + X[L-1];\ - Y[L-1] = cf[0]*W[L-1] + cf[1]*tsv[0] + cf[2]*tsv[1] + cf[3]*tsv[2];\ - Y[L-2] = cf[0]*W[L-2] + cf[1]*Y[L-1] + cf[2]*tsv[0] + cf[3]*tsv[1];\ - Y[L-3] = cf[0]*W[L-3] + cf[1]*Y[L-2] + cf[2]*Y[L-1] + cf[3]*tsv[0];\ - for (i=L-4; i>=0; i--)\ - Y[i] = cf[0]*W[i] + cf[1]*Y[i+1] + cf[2]*Y[i+2] + cf[3]*Y[i+3];\ -} - - // intermediate buffers - sz = MAX2(src->x, src->y); - X = MEM_callocN(sz*sizeof(double), "IIR_gauss X buf"); - Y = MEM_callocN(sz*sizeof(double), "IIR_gauss Y buf"); - W = MEM_callocN(sz*sizeof(double), "IIR_gauss W buf"); - if (xy & 1) { // H - for (y=0; y<src->y; ++y) { - const int yx = y*src->x; - for (x=0; x<src->x; ++x) - X[x] = src->rect[(x + yx)*src->type + chan]; - YVV(src->x); - for (x=0; x<src->x; ++x) - src->rect[(x + yx)*src->type + chan] = Y[x]; - } - } - if (xy & 2) { // V - for (x=0; x<src->x; ++x) { - for (y=0; y<src->y; ++y) - X[y] = src->rect[(x + y*src->x)*src->type + chan]; - YVV(src->y); - for (y=0; y<src->y; ++y) - src->rect[(x + y*src->x)*src->type + chan] = Y[y]; - } - } - - MEM_freeN(X); - MEM_freeN(W); - MEM_freeN(Y); -#undef YVV -} - diff --git a/source/blender/nodes/intern/CMP_util.h b/source/blender/nodes/intern/CMP_util.h deleted file mode 100644 index 3f37eae2af9..00000000000 --- a/source/blender/nodes/intern/CMP_util.h +++ /dev/null @@ -1,211 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/CMP_util.h - * \ingroup nodes - */ - - -#ifndef CMP_NODE_UTILS_H_ -#define CMP_NODE_UTILS_H_ - -#include <stdlib.h> -#include <string.h> -#include <math.h> - -#include "MEM_guardedalloc.h" - -#include "DNA_camera_types.h" /* qdn: defocus node, need camera info */ -#include "DNA_color_types.h" -#include "DNA_ID.h" -#include "DNA_image_types.h" -#include "DNA_material_types.h" -#include "DNA_node_types.h" -#include "DNA_object_types.h" -#include "DNA_scene_types.h" -#include "DNA_texture_types.h" - -#include "BLI_math.h" -#include "BLI_blenlib.h" -#include "BLI_rand.h" -#include "BLI_threads.h" -#include "BLI_utildefines.h" -#include "BLI_utildefines.h" - -#include "BKE_blender.h" -#include "BKE_colortools.h" -#include "BKE_global.h" -#include "BKE_image.h" -#include "BKE_main.h" -#include "BKE_material.h" -#include "BKE_node.h" -#include "BKE_texture.h" - -#include "BKE_library.h" -#include "BKE_object.h" - -#include "../CMP_node.h" -#include "node_util.h" - -#include "IMB_imbuf_types.h" -#include "IMB_imbuf.h" - -#include "RE_pipeline.h" -#include "RE_shader_ext.h" -#include "RE_render_ext.h" - -/* *************************** operations support *************************** */ - -/* general signal that's in output sockets, and goes over the wires */ -typedef struct CompBuf { - float *rect; - int x, y, xrad, yrad; - short type, malloc; - rcti disprect; /* cropped part of image */ - int xof, yof; /* relative to center of target image */ - - void (*rect_procedural)(struct CompBuf *, float *, float, float); - float procedural_size[3], procedural_offset[3]; - int procedural_type; - bNode *node; /* only in use for procedural bufs */ - - struct CompBuf *next, *prev; /* for pass-on, works nicer than reference counting */ -} CompBuf; - -/* defines also used for pixel size */ -#define CB_RGBA 4 -#define CB_VEC4 4 -#define CB_VEC3 3 -#define CB_VEC2 2 -#define CB_VAL 1 - -/* defines for RGBA channels */ -#define CHAN_R 0 -#define CHAN_G 1 -#define CHAN_B 2 -#define CHAN_A 3 - - - -CompBuf *alloc_compbuf(int sizex, int sizey, int type, int alloc); -CompBuf *dupalloc_compbuf(CompBuf *cbuf); -CompBuf *pass_on_compbuf(CompBuf *cbuf); -void free_compbuf(CompBuf *cbuf); -void print_compbuf(char *str, CompBuf *cbuf); -void compbuf_set_node(struct CompBuf *cbuf, struct bNode *node); -void node_compo_pass_on(struct bNode *node, struct bNodeStack **nsin, struct bNodeStack **nsout); - -CompBuf *get_cropped_compbuf(rcti *drect, float *rectf, int rectx, int recty, int type); -CompBuf *scalefast_compbuf(CompBuf *inbuf, int newx, int newy); -CompBuf *typecheck_compbuf(CompBuf *inbuf, int type); -void typecheck_compbuf_color(float *out, float *in, int outtype, int intype); - -/* **************************************************** */ - -/* Pixel-to-Pixel operation, 1 Image in, 1 out */ -void composit1_pixel_processor(bNode *node, CompBuf *out, CompBuf *src_buf, float *src_col, - void (*func)(bNode *, float *, float *), - int src_type); -/* Pixel-to-Pixel operation, 2 Images in, 1 out */ -void composit2_pixel_processor(bNode *node, CompBuf *out, CompBuf *src_buf, float *src_col, - CompBuf *fac_buf, float *fac, void (*func)(bNode *, float *, float *, float *), - int src_type, int fac_type); - -/* Pixel-to-Pixel operation, 3 Images in, 1 out */ -void composit3_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, float *src1_col, CompBuf *src2_buf, float *src2_col, - CompBuf *fac_buf, float *fac, void (*func)(bNode *, float *, float *, float *, float *), - int src1_type, int src2_type, int fac_type); - -/* Pixel-to-Pixel operation, 4 Images in, 1 out */ -void composit4_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, float *src1_col, CompBuf *fac1_buf, float *fac1, - CompBuf *src2_buf, float *src2_col, CompBuf *fac2_buf, float *fac2, - void (*func)(bNode *, float *, float *, float *, float *, float *), - int src1_type, int fac1_type, int src2_type, int fac2_type); - -CompBuf *valbuf_from_rgbabuf(CompBuf *cbuf, int channel); -void generate_preview(void *data, bNode *node, CompBuf *stackbuf); - -void do_copy_rgba(bNode *node, float *out, float *in); -void do_copy_rgb(bNode *node, float *out, float *in); -void do_copy_value(bNode *node, float *out, float *in); -void do_copy_a_rgba(bNode *node, float *out, float *in, float *fac); - -void do_rgba_to_yuva(bNode *node, float *out, float *in); -void do_rgba_to_hsva(bNode *node, float *out, float *in); -void do_rgba_to_ycca(bNode *node, float *out, float *in); -void do_yuva_to_rgba(bNode *node, float *out, float *in); -void do_hsva_to_rgba(bNode *node, float *out, float *in); -void do_ycca_to_rgba(bNode *node, float *out, float *in); - -void gamma_correct_compbuf(CompBuf *img, int inversed); -void premul_compbuf(CompBuf *img, int inversed); -void convolve(CompBuf* dst, CompBuf* in1, CompBuf* in2); - -extern void node_ID_title_cb(void *node_v, void *unused_v); - - -/* utility functions used by glare, tonemap and lens distortion */ -/* soms macros for color handling */ -typedef float fRGB[4]; -/* clear color */ -#define fRGB_clear(c) { c[0]=c[1]=c[2]=0.f; } -/* copy c2 to c1 */ -#define fRGB_copy(c1, c2) { c1[0]=c2[0]; c1[1]=c2[1]; c1[2]=c2[2]; c1[3]=c2[3]; } -/* add c2 to c1 */ -#define fRGB_add(c1, c2) { c1[0]+=c2[0]; c1[1]+=c2[1]; c1[2]+=c2[2]; } -/* subtract c2 from c1 */ -#define fRGB_sub(c1, c2) { c1[0]-=c2[0]; c1[1]-=c2[1]; c1[2]-=c2[2]; } -/* multiply c by float value s */ -#define fRGB_mult(c, s) { c[0]*=s; c[1]*=s; c[2]*=s; } -/* multiply c2 by s and add to c1 */ -#define fRGB_madd(c1, c2, s) { c1[0]+=c2[0]*s; c1[1]+=c2[1]*s; c1[2]+=c2[2]*s; } -/* multiply c2 by color c1 */ -#define fRGB_colormult(c, cs) { c[0]*=cs[0]; c[1]*=cs[1]; c[2]*=cs[2]; } -/* multiply c2 by color c3 and add to c1 */ -#define fRGB_colormadd(c1, c2, c3) { c1[0]+=c2[0]*c3[0]; c1[1]+=c2[1]*c3[1]; c1[2]+=c2[2]*c3[2]; } -/* multiply c2 by color rgb, rgb as separate arguments */ -#define fRGB_rgbmult(c, r, g, b) { c[0]*=(r); c[1]*=(g); c[2]*=(b); } -/* swap colors c1 & c2 */ -#define fRGB_swap(c1, c2) { float _t=c1[0]; c1[0]=c2[0]; c2[0]=_t;\ - _t=c1[1]; c1[1]=c2[1]; c2[1]=_t;\ - _t=c1[2]; c1[2]=c2[2]; c2[2]=_t;\ - _t=c1[3]; c1[3]=c2[3]; c3[3]=_t;} - -void qd_getPixel(CompBuf* src, int x, int y, float* col); -void qd_setPixel(CompBuf* src, int x, int y, float* col); -void qd_addPixel(CompBuf* src, int x, int y, float* col); -void qd_multPixel(CompBuf* src, int x, int y, float f); -void qd_getPixelLerpWrap(CompBuf* src, float u, float v, float* col); -void qd_getPixelLerp(CompBuf* src, float u, float v, float* col); -void qd_getPixelLerpChan(CompBuf* src, float u, float v, int chan, float* out); -CompBuf* qd_downScaledCopy(CompBuf* src, int scale); -void IIR_gauss(CompBuf* src, float sigma, int chan, int xy); -/* end utility funcs */ - -#endif diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_camera.c b/source/blender/nodes/intern/SHD_nodes/SHD_camera.c deleted file mode 100644 index eea572bf271..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_camera.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_camera.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - -/* **************** CAMERA INFO ******************** */ -static bNodeSocketType sh_node_camera_out[]= { - { SOCK_VECTOR, 0, "View Vector", 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f}, /* None of these actually */ - { SOCK_VALUE, 0, "View Z Depth", 0.f, 0.0f, 0.0f, 0.0f, 0.0f, 99999999999.0f}, /* have any limits on their */ - { SOCK_VALUE, 0, "View Distance", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 99999999999.0f}, /* values. */ - { -1, 0, "" } -}; - - -static void node_shader_exec_camera(void *data, bNode *UNUSED(node), bNodeStack **UNUSED(in), bNodeStack **out) -{ - if(data) { - ShadeInput *shi= ((ShaderCallData *)data)->shi; /* Data we need for shading. */ - - VECCOPY(out[0]->vec, shi->co); /* get view vector */ - out[1]->vec[0]= fabs(shi->co[2]); /* get view z-depth */ - out[2]->vec[0]= normalize_v3(out[0]->vec); /* get view distance */ - } -} - -static int gpu_shader_camera(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out) -{ - return GPU_stack_link(mat, "camera", in, out, GPU_builtin(GPU_VIEW_POSITION)); -} - -void register_node_type_sh_camera(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_CAMERA, "Camera Data", NODE_CLASS_INPUT, 0, - NULL, sh_node_camera_out); - node_type_size(&ntype, 95, 95, 120); - node_type_storage(&ntype, "node_camera", NULL, NULL); - node_type_exec(&ntype, node_shader_exec_camera); - node_type_gpu(&ntype, gpu_shader_camera); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_curves.c b/source/blender/nodes/intern/SHD_nodes/SHD_curves.c deleted file mode 100644 index a39a639897e..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_curves.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_curves.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - - -/* **************** CURVE VEC ******************** */ -static bNodeSocketType sh_node_curve_vec_in[]= { - { SOCK_VALUE, 0, "Fac", 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType sh_node_curve_vec_out[]= { - { SOCK_VECTOR, 0, "Vector", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_curve_vec(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - float vec[3]; - - /* stack order input: vec */ - /* stack order output: vec */ - nodestack_get_vec(vec, SOCK_VECTOR, in[1]); - curvemapping_evaluate3F(node->storage, out[0]->vec, vec); -} - -static void node_shader_init_curve_vec(bNode* node) -{ - node->storage= curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f); -} - -static int gpu_shader_curve_vec(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - float *array; - int size; - - curvemapping_table_RGBA(node->storage, &array, &size); - return GPU_stack_link(mat, "curves_vec", in, out, GPU_texture(size, array)); -} - -void register_node_type_sh_curve_vec(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_CURVE_VEC, "Vector Curves", NODE_CLASS_OP_VECTOR, NODE_OPTIONS, - sh_node_curve_vec_in, sh_node_curve_vec_out); - node_type_size(&ntype, 200, 140, 320); - node_type_init(&ntype, node_shader_init_curve_vec); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - node_type_exec(&ntype, node_shader_exec_curve_vec); - node_type_gpu(&ntype, gpu_shader_curve_vec); - - nodeRegisterType(lb, &ntype); -} - - -/* **************** CURVE RGB ******************** */ -static bNodeSocketType sh_node_curve_rgb_in[]= { - { SOCK_VALUE, 1, "Fac", 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType sh_node_curve_rgb_out[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_curve_rgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - float vec[3]; - - /* stack order input: vec */ - /* stack order output: vec */ - nodestack_get_vec(vec, SOCK_VECTOR, in[1]); - curvemapping_evaluateRGBF(node->storage, out[0]->vec, vec); - if(in[0]->vec[0] != 1.0f) { - interp_v3_v3v3(out[0]->vec, vec, out[0]->vec, *in[0]->vec); - } -} - -static void node_shader_init_curve_rgb(bNode *node) -{ - node->storage= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f); -} - -static int gpu_shader_curve_rgb(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - float *array; - int size; - curvemapping_table_RGBA(node->storage, &array, &size); - return GPU_stack_link(mat, "curves_rgb", in, out, GPU_texture(size, array)); -} - -void register_node_type_sh_curve_rgb(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - sh_node_curve_rgb_in, sh_node_curve_rgb_out); - node_type_size(&ntype, 200, 140, 320); - node_type_init(&ntype, node_shader_init_curve_rgb); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - node_type_exec(&ntype, node_shader_exec_curve_rgb); - node_type_gpu(&ntype, gpu_shader_curve_rgb); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c b/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c deleted file mode 100644 index d5e5d5eeb93..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c +++ /dev/null @@ -1,792 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2007 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Nathan Letwory - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_dynamic.c - * \ingroup shdnodes - */ - - -/* TODO, support python3.x */ -#undef WITH_PYTHON - -#ifdef WITH_PYTHON -#include <Python.h> -#include <compile.h> -#include <eval.h> -#endif - -#include "DNA_text_types.h" -#include "BKE_text.h" - - -// XXX -#if 0 -#ifdef WITH_PYTHON -#include "api2_2x/Node.h" -#include "api2_2x/gen_utils.h" -#include "BPY_extern.h" -#endif -#endif - -#include "../SHD_util.h" - -// XXX -#if 0 -static void node_dynamic_setup(bNode *node); -static void node_dynamic_exec_cb(void *data, bNode *node, bNodeStack **in, bNodeStack **out); -static void node_dynamic_free_storage_cb(bNode *node); - -#ifdef WITH_PYTHON -static PyObject *init_dynamicdict(void) { - PyObject *newscriptdict, *item; - PyGILState_STATE gilstate = PyGILState_Ensure(); - - newscriptdict= PyDict_New(); - - PyDict_SetItemString(newscriptdict, "__builtins__", PyEval_GetBuiltins()); - item= PyString_FromString("__main__"); - PyDict_SetItemString(newscriptdict, "__name__", item); - Py_DECREF(item); - - PyGILState_Release(gilstate); - - return newscriptdict; -} -#endif - -static bNodeType *node_dynamic_find_typeinfo(ListBase *list, ID *id) -{ - bNodeType *ntype = list->first; - - while(ntype) { - if (ntype->type == NODE_DYNAMIC && ntype->id == id) - break; - ntype = ntype->next; - } - - return ntype; /* NULL if doesn't exist */ -} - -static void node_dynamic_free_typeinfo_sockets(bNodeType *tinfo) -{ - bNodeSocketType *sock; - - if (!tinfo) return; - - if (tinfo->inputs) { - sock = tinfo->inputs; - while (sock->type != -1) { - MEM_freeN(sock->name); - sock++; - } - MEM_freeN(tinfo->inputs); - tinfo->inputs = NULL; - } - if (tinfo->outputs) { - sock = tinfo->outputs; - while (sock->type != -1) { - MEM_freeN(sock->name); - sock++; - } - MEM_freeN(tinfo->outputs); - tinfo->outputs = NULL; - } -} - -static void node_dynamic_free_typeinfo(bNodeType *tinfo) -{ - if (!tinfo) return; - - node_dynamic_free_typeinfo_sockets(tinfo); - - if (tinfo->name) { MEM_freeN(tinfo->name); } - - MEM_freeN(tinfo); -} - -static void node_dynamic_free_sockets(bNode *node) -{ - BLI_freelistN(&node->inputs); - BLI_freelistN(&node->outputs); -} - -/* For now we just remove the socket links. It's the safest - * route, since an update in the script may change completely the - * inputs and outputs. Trying to recreate the node links would be - * nicer for pynode authors, though. */ -static void node_dynamic_update_socket_links(bNode *node, bNodeTree *ntree) -{ - if (ntree) { - nodeVerifyType(ntree, node); - } - else { - Material *ma; - - for (ma= G.main->mat.first; ma; ma= ma->id.next) { - if (ma->nodetree) { - bNode *nd; - for (nd= ma->nodetree->nodes.first; nd; nd = nd->next) { - if (nd == node) nodeVerifyType(ma->nodetree, node); - } - } - } - } -} - -static void node_dynamic_free_storage_cb(bNode *node) -{ -#ifdef WITH_PYTHON - NodeScriptDict *nsd; - PyObject *pydict; - BPy_Node *pynode; - - if (!node->storage) return; - nsd = (NodeScriptDict *)(node->storage); - pydict = nsd->dict; - if (pydict) { - Py_DECREF(pydict); - } - pynode = nsd->node; - if (pynode) { - Py_DECREF(pynode); - } -#endif - MEM_freeN(node->storage); - node->storage = NULL; -} - -/* Disable pynode when its script fails */ -static void node_dynamic_disable(bNode *node) -{ - node->custom1 = 0; - node->custom1 = BSET(node->custom1, NODE_DYNAMIC_ERROR); -} - -/* Disable all pynodes using the given text (script) id */ -static void node_dynamic_disable_all_by_id(ID *id) -{ -#ifdef WITH_PYTHON - Material *ma; /* XXX hardcoded for shaders */ - - for (ma= G.main->mat.first; ma; ma= ma->id.next) { - if (ma->nodetree) { - bNode *nd; - bNodeTree *ntree = ma->nodetree; - for (nd= ntree->nodes.first; nd; nd= nd->next) { - if (nd->id == id) { - nd->custom1 = 0; - nd->custom1 = BSET(nd->custom1, NODE_DYNAMIC_ERROR); - } - } - } - } -#endif -} - -static void node_rem_socklist_links(bNodeTree *ntree, ListBase *lb) -{ - bNodeLink *link, *next; - bNodeSocket *sock; - - if (!lb) return; - - for (sock= lb->first; sock; sock= sock->next) { - for (link= ntree->links.first; link; link= next) { - next= link->next; - if (link->fromsock==sock || link->tosock==sock) { - nodeRemLink(ntree, link); - } - } - } -} - -/* XXX hardcoded for shaders */ -static void node_dynamic_rem_all_links(bNodeType *tinfo) -{ - Material *ma; - int in, out; - - in = tinfo->inputs ? 1 : 0; - out = tinfo->outputs ? 1 : 0; - - if (!in && !out) return; - - for (ma= G.main->mat.first; ma; ma= ma->id.next) { - if (ma->nodetree) { - bNode *nd; - bNodeTree *ntree = ma->nodetree; - for (nd= ntree->nodes.first; nd; nd= nd->next) { - if (nd->typeinfo == tinfo) { - if (in) - node_rem_socklist_links(ntree, &nd->inputs); - if (out) - node_rem_socklist_links(ntree, &nd->outputs); - } - } - } - } -} - -/* node_dynamic_reset: clean a pynode, getting rid of all - * data dynamically created for it. */ -static void node_dynamic_reset(bNode *node, int unlink_text) -{ - bNodeType *tinfo, *tinfo_default; - Material *ma; - - tinfo = node->typeinfo; - tinfo_default = node_dynamic_find_typeinfo(&node_all_shaders, NULL); - - if ((tinfo == tinfo_default) && unlink_text) { - ID *textID = node->id; - /* already at default (empty) state, which happens if this node's - * script failed to parse at the first stage: definition. We're here - * because its text was removed from Blender. */ - for (ma= G.main->mat.first; ma; ma= ma->id.next) { - if (ma->nodetree) { - bNode *nd; - for (nd= ma->nodetree->nodes.first; nd; nd = nd->next) { - if (nd->id == textID) { - nd->id = NULL; - nd->custom1 = 0; - nd->custom1 = BSET(nd->custom1, NODE_DYNAMIC_NEW); - BLI_strncpy(nd->name, "Dynamic", 8); - return; - } - } - } - } - } - - node_dynamic_rem_all_links(tinfo); - node_dynamic_free_typeinfo_sockets(tinfo); - - /* reset all other XXX shader nodes sharing this typeinfo */ - for (ma= G.main->mat.first; ma; ma= ma->id.next) { - if (ma->nodetree) { - bNode *nd; - for (nd= ma->nodetree->nodes.first; nd; nd = nd->next) { - if (nd->typeinfo == tinfo) { - node_dynamic_free_storage_cb(nd); - node_dynamic_free_sockets(nd); - //node_dynamic_update_socket_links(nd, ma->nodetree); - nd->typeinfo = tinfo_default; - if (unlink_text) { - nd->id = NULL; - nd->custom1 = 0; - nd->custom1 = BSET(nd->custom1, NODE_DYNAMIC_NEW); - BLI_strncpy(nd->name, "Dynamic", 8); - } - } - } - } - } - - /* XXX hardcoded for shaders: */ - if (tinfo->id) { BLI_remlink(&node_all_shaders, tinfo); } - node_dynamic_free_typeinfo(tinfo); -} - -/* Special case of the above function: for working pynodes - * that were saved on a .blend but fail for some reason when - * the file is opened. We need this because pynodes are initialized - * before G.main. */ -static void node_dynamic_reset_loaded(bNode *node) -{ - bNodeType *tinfo = node->typeinfo; - - node_dynamic_rem_all_links(tinfo); - node_dynamic_free_typeinfo_sockets(tinfo); - node_dynamic_free_storage_cb(node); - /* XXX hardcoded for shaders: */ - if (tinfo->id) { BLI_remlink(&node_all_shaders, tinfo); } - - node_dynamic_free_typeinfo(tinfo); - node->typeinfo = node_dynamic_find_typeinfo(&node_all_shaders, NULL); -} - -int nodeDynamicUnlinkText(ID *txtid) { - Material *ma; - bNode *nd; - - /* find one node that uses this text */ - for (ma= G.main->mat.first; ma; ma= ma->id.next) { - if (ma->nodetree) { - for (nd= ma->nodetree->nodes.first; nd; nd = nd->next) { - if ((nd->type == NODE_DYNAMIC) && (nd->id == txtid)) { - node_dynamic_reset(nd, 1); /* found, reset all */ - return 1; - } - } - } - } - return 0; /* no pynodes used this text */ -} - -static void node_dynamic_pyerror_print(bNode *node) -{ -#ifdef WITH_PYTHON - PyGILState_STATE gilstate = PyGILState_Ensure(); - - fprintf(stderr, "\nError in dynamic node script \"%s\":\n", node->name); - if (PyErr_Occurred()) { - PyErr_Print(); - PyErr_Clear(); - PySys_SetObject("last_traceback", NULL); - } - else { fprintf(stderr, "Not a valid dynamic node Python script.\n"); } - - PyGILState_Release(gilstate); -#endif -} - -static void node_dynamic_register_type(bNode *node) -{ - nodeRegisterType(&node_all_shaders, node->typeinfo); - /* nodeRegisterType copied it to a new one, so we - * free the typeinfo itself, but not what it - * points to: */ - MEM_freeN(node->typeinfo); - node->typeinfo = node_dynamic_find_typeinfo(&node_all_shaders, node->id); - MEM_freeN(node->typeinfo->name); - node->typeinfo->name = BLI_strdup(node->name); -} - -#ifdef WITH_PYTHON -/* node_dynamic_get_pynode: - * Find the pynode definition from the script */ -static PyObject *node_dynamic_get_pynode(PyObject *dict) -{ - PyObject *key= NULL; - Py_ssize_t pos = 0; - PyObject *value = NULL; - - /* script writer specified a node? */ - value = PyDict_GetItemString(dict, "__node__"); - - if (value) { - if (PyObject_TypeCheck(value, &PyType_Type)) { - Py_INCREF(value); - return value; - } - else { - PyErr_SetString(PyExc_TypeError, - "expected class object derived from Scripted node"); - return NULL; - } - } - - /* case not, search for it in the script's global dictionary */ - while (PyDict_Next(dict, &pos, &key, &value)) { - /* skip names we know belong to other available objects */ - if (strcmp("Socket", PyString_AsString(key)) == 0) - continue; - else if (strcmp("Scripted", PyString_AsString(key)) == 0) - continue; - /* naive: we grab the first ob of type 'type': */ - else if (PyObject_TypeCheck(value, &PyType_Type)) { - Py_INCREF(value); - return value; - } - } - - PyErr_SetString(PyExc_TypeError, - "no PyNode definition found in the script!"); - return NULL; -} -#endif /* WITH_PYTHON */ - -static int node_dynamic_parse(struct bNode *node) -{ -#ifndef WITH_PYTHON - return -1; -#else - PyObject *dict= NULL; - PyObject *pynode_data= NULL; - PyObject *pynode= NULL; - PyObject *args= NULL; - NodeScriptDict *nsd = NULL; - PyObject *pyresult = NULL; - char *buf = NULL; - int is_valid_script = 0; - PyGILState_STATE gilstate; - - if (!node->id || !node->storage) - return 0; - - /* READY, no need to be here */ - if (BTST(node->custom1, NODE_DYNAMIC_READY)) - return 0; - - /* for threading */ - gilstate = PyGILState_Ensure(); - - nsd = (NodeScriptDict *)node->storage; - - dict = (PyObject *)(nsd->dict); - buf = txt_to_buf((Text *)node->id); - - pyresult = PyRun_String(buf, Py_file_input, dict, dict); - - MEM_freeN(buf); - - if (!pyresult) { - if (BTST(node->custom1, NODE_DYNAMIC_LOADED)) { - node_dynamic_disable(node); - } else { - node_dynamic_disable_all_by_id(node->id); - } - node_dynamic_pyerror_print(node); - PyGILState_Release(gilstate); - return -1; - } - - Py_DECREF(pyresult); - - pynode_data = node_dynamic_get_pynode(dict); - - if (pynode_data) { - BPy_NodeSocketLists *socklists = Node_CreateSocketLists(node); - - args = Py_BuildValue("(O)", socklists); - - /* init it to get the input and output sockets */ - pynode = PyObject_Call(pynode_data, args, NULL); - - Py_DECREF(pynode_data); - Py_DECREF(socklists); - Py_DECREF(args); - - if (!PyErr_Occurred() && pynode && pytype_is_pynode(pynode)) { - InitNode((BPy_Node *)(pynode), node); - nsd->node = pynode; - node->typeinfo->execfunc = node_dynamic_exec_cb; - is_valid_script = 1; - - /* for NEW, LOADED, REPARSE */ - if (BNTST(node->custom1, NODE_DYNAMIC_ADDEXIST)) { - node->typeinfo->pydict = dict; - node->typeinfo->pynode = pynode; - node->typeinfo->id = node->id; - if (BNTST(node->custom1, NODE_DYNAMIC_LOADED)) - nodeAddSockets(node, node->typeinfo); - if (BNTST(node->custom1, NODE_DYNAMIC_REPARSE)) - node_dynamic_register_type(node); - } - - node->custom1 = 0; - node->custom1 = BSET(node->custom1, NODE_DYNAMIC_READY); - } - } - - PyGILState_Release(gilstate); - - if (!is_valid_script) { /* not a valid pynode script */ - node_dynamic_disable_all_by_id(node->id); - node_dynamic_pyerror_print(node); - return -1; - } - - return 0; -#endif -} - -/* node_dynamic_setup: prepare for execution (state: NODE_DYNAMIC_READY) - * pynodes already linked to a script (node->id != NULL). */ -static void node_dynamic_setup(bNode *node) -{ -#ifdef WITH_PYTHON - NodeScriptDict *nsd = NULL; - bNodeTree *nodetree = NULL; - bNodeType *ntype = NULL; - PyGILState_STATE gilstate; - - /* Possible cases: - * NEW - * ADDEXIST - * LOADED - * REPARSE - * ERROR - * READY - */ - - /* NEW, but not linked to a script: link default (empty) typeinfo */ - if (!node->id) { - node->typeinfo = node_dynamic_find_typeinfo(&node_all_shaders, - NULL); - return; - } - - /* READY, no need to be here */ - if (BTST(node->custom1, NODE_DYNAMIC_READY)) - return; - - gilstate = PyGILState_Ensure(); - - /* ERROR, reset to (empty) defaults */ - if (BCLR(node->custom1, NODE_DYNAMIC_ERROR) == 0) { - node_dynamic_reset(node, 0); - PyGILState_Release(gilstate); - return; - } - - /* User asked to update this pynode, prepare it for reparsing */ - if (BTST(node->custom1, NODE_DYNAMIC_REPARSE)) { - int needs_parsing = 1; - - node->custom1 = BSET(node->custom1, NODE_DYNAMIC_NEW); - - if (BTST(node->custom1, NODE_DYNAMIC_ERROR)) { - node->custom1 = BCLR(node->custom1, NODE_DYNAMIC_REPARSE); - ntype = node_dynamic_find_typeinfo(&node_all_shaders, node->id); - - if (ntype) { - node->typeinfo = ntype; - node->custom1 = BSET(node->custom1, NODE_DYNAMIC_ADDEXIST); - node->custom1 = BCLR(node->custom1, NODE_DYNAMIC_ERROR); - needs_parsing = 0; - } - else { nodeMakeDynamicType(node); } - - } else { - node_dynamic_rem_all_links(node->typeinfo); - node_dynamic_free_typeinfo_sockets(node->typeinfo); - node_dynamic_update_socket_links(node, NULL); - node_dynamic_free_storage_cb(node); - } - - if (needs_parsing) { - nsd = MEM_callocN(sizeof(NodeScriptDict), "node script dictionary"); - nsd->dict = init_dynamicdict(); - node->storage = nsd; - /* prepared, now reparse: */ - node_dynamic_parse(node); - PyGILState_Release(gilstate); - return; - } - } - else if (BTST(node->custom1, NODE_DYNAMIC_LOADED)) { - /* when loading from a .blend we don't have G.main yet, so we - * quickly abuse node->storage in ntreeInitTypes (node.c) to have - * our nodetree ptr (needed if a pynode script that worked before - * saving the .blend for some reason fails upon loading): */ - nodetree = (bNodeTree *)node->storage; - node->storage = NULL; - } - - if (node->storage) - fprintf(stderr, "\nDEBUG: PYNODES ERROR: non NULL node->storage in node_dynamic_setup()\n"); - - nsd = MEM_callocN(sizeof(NodeScriptDict), "node script dictionary"); - node->storage = nsd; - - /* NEW, LOADED or REPARSE */ - if (BNTST(node->custom1, NODE_DYNAMIC_ADDEXIST)) { - /* check if there's already a bNodeType linked to this script */ - /* (XXX hardcoded for shader nodes for now) */ - ntype = node_dynamic_find_typeinfo(&node_all_shaders, node->id); - - if (ntype) { /* if so, reuse it */ - node->typeinfo = ntype; - /* so this is actually an ADDEXIST type */ - node->custom1 = BSET(node->custom1, NODE_DYNAMIC_ADDEXIST); - } - else { /* create bNodeType for this pynode */ - nodeMakeDynamicType(node); - nsd->dict = init_dynamicdict(); - if ((node_dynamic_parse(node) == -1) && nodetree) { - node_dynamic_reset_loaded(node); - } - PyGILState_Release(gilstate); - return; - } - } - - /* ADDEXIST: new pynode linked to an already registered dynamic type, - * we just reuse existing py dict and pynode */ - nsd->dict = node->typeinfo->pydict; - nsd->node = node->typeinfo->pynode; - - Py_INCREF((PyObject *)(nsd->dict)); - Py_INCREF((PyObject *)(nsd->node)); - - if (BTST(node->custom1, NODE_DYNAMIC_NEW)) { - nodeAddSockets(node, node->typeinfo); - node->custom1 = BCLR(node->custom1, NODE_DYNAMIC_NEW); - } - - node->custom1 = BCLR(node->custom1, NODE_DYNAMIC_ADDEXIST); - node->custom1 = BSET(node->custom1, NODE_DYNAMIC_READY); - - PyGILState_Release(gilstate); -#endif /* WITH_PYTHON */ - return; -} - -/* node_dynamic_init_cb callback: called when a pynode is created. - * The pynode type is passed via node->custom2. It can be: - * 0: for loaded empty nodes - * NODE_DYNAMIC_MENU: for the default Dynamic node type - * > NODE_DYNAMIC_MENU: for the new types defined by scripts -*/ -static void node_dynamic_init_cb(bNode *node) { - int type = node->custom2; - - node->custom2 = 0; - - if (type >= NODE_DYNAMIC_MENU) { - node->custom1 = 0; - - if (type == NODE_DYNAMIC_MENU) { - node->custom1 = BSET(node->custom1, NODE_DYNAMIC_NEW); - return; - } - - node->custom1 = BSET(node->custom1, NODE_DYNAMIC_ADDEXIST); - node->id = node->typeinfo->id; - } - - node_dynamic_setup(node); -} - -/* node_dynamic_copy_cb: pynode copy callback */ -static void node_dynamic_copy_cb(bNode *orig_node, bNode *new_node) -{ -#ifndef WITH_PYTHON - return; -#else - NodeScriptDict *nsd; - PyGILState_STATE gilstate; - - if (!orig_node->storage) return; - - nsd = (NodeScriptDict *)(orig_node->storage); - new_node->storage = MEM_dupallocN(orig_node->storage); - - gilstate = PyGILState_Ensure(); - - if (nsd->node) - Py_INCREF((PyObject *)(nsd->node)); - if (nsd->dict) - Py_INCREF((PyObject *)(nsd->dict)); - - PyGILState_Release(gilstate); -#endif -} - -/* node_dynamic_exec_cb: the execution callback called per pixel - * during rendering. */ -static void node_dynamic_exec_cb(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { -#ifndef WITH_PYTHON - return; -#else - BPy_Node *mynode = NULL; - NodeScriptDict *nsd = NULL; - PyObject *pyresult = NULL; - PyObject *args = NULL; - ShadeInput *shi; - PyGILState_STATE gilstate; - - if (!node->id) - return; - - /*if (G.scene->r.threads > 1) - return;*/ - - if (BTST2(node->custom1, NODE_DYNAMIC_NEW, NODE_DYNAMIC_REPARSE)) { - node_dynamic_setup(node); - return; - } - - if (BTST(node->custom1, NODE_DYNAMIC_ERROR)) { - if (node->storage) node_dynamic_setup(node); - return; - } - - if (BTST(node->custom1, NODE_DYNAMIC_READY)) { - nsd = (NodeScriptDict *)node->storage; - mynode = (BPy_Node *)(nsd->node); - - - if (mynode && PyCallable_Check((PyObject *)mynode)) { - - gilstate = PyGILState_Ensure(); - - mynode->node = node; - shi = ((ShaderCallData *)data)->shi; - - Node_SetStack(mynode, in, NODE_INPUTSTACK); - Node_SetStack(mynode, out, NODE_OUTPUTSTACK); - Node_SetShi(mynode, shi); - - args=Py_BuildValue("()"); - pyresult= PyObject_Call((PyObject *)mynode, args, NULL); - Py_DECREF(args); - - if (!pyresult) { - PyGILState_Release(gilstate); - node_dynamic_disable_all_by_id(node->id); - node_dynamic_pyerror_print(node); - node_dynamic_setup(node); - return; - } - Py_DECREF(pyresult); - PyGILState_Release(gilstate); - } - } -#endif -} - -void register_node_type_sh_dynamic(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, NODE_DYNAMIC, "Dynamic", NODE_CLASS_OP_DYNAMIC, NODE_OPTIONS, NULL, NULL); - node_type_size(&ntype, 150, 60, 300); - node_type_init(&ntype, node_dynamic_init_cb); - node_type_storage(&ntype, "NodeScriptDict", node_dynamic_free_storage_cb, node_dynamic_copy_cb); - node_type_exec(&ntype, node_dynamic_exec_cb); - - nodeRegisterType(lb, &ntype); -} - -#else - -void register_node_type_sh_dynamic(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, NODE_DYNAMIC, "Dynamic", NODE_CLASS_OP_DYNAMIC, 0, NULL, NULL); - - nodeRegisterType(lb, &ntype); -} - -#endif - - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_geom.c b/source/blender/nodes/intern/SHD_nodes/SHD_geom.c deleted file mode 100644 index 379f54bec57..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_geom.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_geom.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - -#include "DNA_customdata_types.h" - -/* **************** GEOMETRY ******************** */ - -/* output socket type definition */ -static bNodeSocketType sh_node_geom_out[]= { - { SOCK_VECTOR, 0, "Global", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, /* btw; uses no limit */ - { SOCK_VECTOR, 0, "Local", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { SOCK_VECTOR, 0, "View", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { SOCK_VECTOR, 0, "Orco", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { SOCK_VECTOR, 0, "UV", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { SOCK_VECTOR, 0, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { SOCK_RGBA, 0, "Vertex Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "Front/Back", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -/* node execute callback */ -static void node_shader_exec_geom(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out) -{ - if(data) { - ShadeInput *shi= ((ShaderCallData *)data)->shi; - NodeGeometry *ngeo= (NodeGeometry*)node->storage; - ShadeInputUV *suv= &shi->uv[shi->actuv]; - static float defaultvcol[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - int i; - - if(ngeo->uvname[0]) { - /* find uv layer by name */ - for(i = 0; i < shi->totuv; i++) { - if(strcmp(shi->uv[i].name, ngeo->uvname)==0) { - suv= &shi->uv[i]; - break; - } - } - } - - /* out: global, local, view, orco, uv, normal, vertex color */ - VECCOPY(out[GEOM_OUT_GLOB]->vec, shi->gl); - VECCOPY(out[GEOM_OUT_LOCAL]->vec, shi->co); - VECCOPY(out[GEOM_OUT_VIEW]->vec, shi->view); - VECCOPY(out[GEOM_OUT_ORCO]->vec, shi->lo); - VECCOPY(out[GEOM_OUT_UV]->vec, suv->uv); - VECCOPY(out[GEOM_OUT_NORMAL]->vec, shi->vno); - - if (shi->totcol) { - /* find vertex color layer by name */ - ShadeInputCol *scol= &shi->col[0]; - - if(ngeo->colname[0]) { - for(i = 0; i < shi->totcol; i++) { - if(strcmp(shi->col[i].name, ngeo->colname)==0) { - scol= &shi->col[i]; - break; - } - } - } - - VECCOPY(out[GEOM_OUT_VCOL]->vec, scol->col); - out[GEOM_OUT_VCOL]->vec[3]= 1.0f; - } - else - memcpy(out[GEOM_OUT_VCOL]->vec, defaultvcol, sizeof(defaultvcol)); - - if(shi->osatex) { - out[GEOM_OUT_GLOB]->data= shi->dxgl; - out[GEOM_OUT_GLOB]->datatype= NS_OSA_VECTORS; - out[GEOM_OUT_LOCAL]->data= shi->dxco; - out[GEOM_OUT_LOCAL]->datatype= NS_OSA_VECTORS; - out[GEOM_OUT_VIEW]->data= &shi->dxview; - out[GEOM_OUT_VIEW]->datatype= NS_OSA_VALUES; - out[GEOM_OUT_ORCO]->data= shi->dxlo; - out[GEOM_OUT_ORCO]->datatype= NS_OSA_VECTORS; - out[GEOM_OUT_UV]->data= suv->dxuv; - out[GEOM_OUT_UV]->datatype= NS_OSA_VECTORS; - out[GEOM_OUT_NORMAL]->data= shi->dxno; - out[GEOM_OUT_NORMAL]->datatype= NS_OSA_VECTORS; - } - - /* front/back, normal flipping was stored */ - out[GEOM_OUT_FRONTBACK]->vec[0]= (shi->flippednor)? 0.0f: 1.0f; - } -} - -static void node_shader_init_geometry(bNode *node) -{ - node->storage= MEM_callocN(sizeof(NodeGeometry), "NodeGeometry"); -} - -static int gpu_shader_geom(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - NodeGeometry *ngeo= (NodeGeometry*)node->storage; - GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); - GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ngeo->uvname); - GPUNodeLink *mcol = GPU_attribute(CD_MCOL, ngeo->colname); - - return GPU_stack_link(mat, "geom", in, out, - GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL), - GPU_builtin(GPU_INVERSE_VIEW_MATRIX), orco, mtface, mcol); -} - -/* node type definition */ -void register_node_type_sh_geom(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_GEOMETRY, "Geometry", NODE_CLASS_INPUT, NODE_OPTIONS, - NULL, sh_node_geom_out); - node_type_size(&ntype, 120, 80, 160); - node_type_init(&ntype, node_shader_init_geometry); - node_type_storage(&ntype, "NodeGeometry", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_shader_exec_geom); - node_type_gpu(&ntype, gpu_shader_geom); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_hueSatVal.c b/source/blender/nodes/intern/SHD_nodes/SHD_hueSatVal.c deleted file mode 100644 index 91fd995dbbe..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_hueSatVal.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Juho Vepsäläinen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_hueSatVal.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - - -/* **************** Hue Saturation ******************** */ -static bNodeSocketType sh_node_hue_sat_in[]= { - { SOCK_VALUE, 1, "Hue", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Saturation", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f}, - { SOCK_VALUE, 1, "Value", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f}, - { SOCK_VALUE, 1, "Fac", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, "Color", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType sh_node_hue_sat_out[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -/* note: it would be possible to use CMP version for both nodes */ -static void do_hue_sat_fac(bNode *UNUSED(node), float *out, float *hue, float *sat, float *val, float *in, float *fac) -{ - if(*fac!=0.0f && (*hue!=0.5f || *sat!=1.0f || *val!=1.0f)) { - float col[3], hsv[3], mfac= 1.0f - *fac; - - rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2); - hsv[0]+= (*hue - 0.5f); - if(hsv[0]>1.0f) hsv[0]-=1.0f; else if(hsv[0]<0.0f) hsv[0]+= 1.0f; - hsv[1]*= *sat; - hsv[2]*= *val; - hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2); - - out[0]= mfac*in[0] + *fac*col[0]; - out[1]= mfac*in[1] + *fac*col[1]; - out[2]= mfac*in[2] + *fac*col[2]; - } - else { - QUATCOPY(out, in); - } -} - -static void node_shader_exec_hue_sat(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - do_hue_sat_fac(node, out[0]->vec, in[0]->vec, in[1]->vec, in[2]->vec, in[4]->vec, in[3]->vec); -} - - -static int gpu_shader_hue_sat(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out) -{ - return GPU_stack_link(mat, "hue_sat", in, out); -} - -void register_node_type_sh_hue_sat(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - sh_node_hue_sat_in, sh_node_hue_sat_out); - node_type_size(&ntype, 150, 80, 250); - node_type_exec(&ntype, node_shader_exec_hue_sat); - node_type_gpu(&ntype, gpu_shader_hue_sat); - - nodeRegisterType(lb, &ntype); -} - - - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_invert.c b/source/blender/nodes/intern/SHD_nodes/SHD_invert.c deleted file mode 100644 index f8d6e54859e..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_invert.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_invert.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - - - -/* **************** INVERT ******************** */ -static bNodeSocketType sh_node_invert_in[]= { - { SOCK_VALUE, 1, "Fac", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType sh_node_invert_out[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_invert(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **in, -bNodeStack **out) -{ - float col[3], facm; - - col[0] = 1.0f - in[1]->vec[0]; - col[1] = 1.0f - in[1]->vec[1]; - col[2] = 1.0f - in[1]->vec[2]; - - /* if fac, blend result against original input */ - if (in[0]->vec[0] < 1.0f) { - facm = 1.0f - in[0]->vec[0]; - - col[0] = in[0]->vec[0]*col[0] + (facm*in[1]->vec[0]); - col[1] = in[0]->vec[0]*col[1] + (facm*in[1]->vec[1]); - col[2] = in[0]->vec[0]*col[2] + (facm*in[1]->vec[2]); - } - - VECCOPY(out[0]->vec, col); -} - -static int gpu_shader_invert(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out) -{ - return GPU_stack_link(mat, "invert", in, out); -} - -void register_node_type_sh_invert(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - sh_node_invert_in, sh_node_invert_out); - node_type_size(&ntype, 90, 80, 100); - node_type_exec(&ntype, node_shader_exec_invert); - node_type_gpu(&ntype, gpu_shader_invert); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_mapping.c b/source/blender/nodes/intern/SHD_nodes/SHD_mapping.c deleted file mode 100644 index eb300301ce2..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_mapping.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_mapping.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - -/* **************** MAPPING ******************** */ -static bNodeSocketType sh_node_mapping_in[]= { - { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType sh_node_mapping_out[]= { - { SOCK_VECTOR, 0, "Vector", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -/* do the regular mapping options for blender textures */ -static void node_shader_exec_mapping(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - TexMapping *texmap= node->storage; - float *vec= out[0]->vec; - - /* stack order input: vector */ - /* stack order output: vector */ - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - mul_m4_v3(texmap->mat, vec); - - if(texmap->flag & TEXMAP_CLIP_MIN) { - if(vec[0]<texmap->min[0]) vec[0]= texmap->min[0]; - if(vec[1]<texmap->min[1]) vec[1]= texmap->min[1]; - if(vec[2]<texmap->min[2]) vec[2]= texmap->min[2]; - } - if(texmap->flag & TEXMAP_CLIP_MAX) { - if(vec[0]>texmap->max[0]) vec[0]= texmap->max[0]; - if(vec[1]>texmap->max[1]) vec[1]= texmap->max[1]; - if(vec[2]>texmap->max[2]) vec[2]= texmap->max[2]; - } -} - - -static void node_shader_init_mapping(bNode *node) -{ - node->storage= add_mapping(); -} - -static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - TexMapping *texmap= node->storage; - float domin= (texmap->flag & TEXMAP_CLIP_MIN) != 0; - float domax= (texmap->flag & TEXMAP_CLIP_MAX) != 0; - GPUNodeLink *tmat = GPU_uniform((float*)texmap->mat); - GPUNodeLink *tmin = GPU_uniform(texmap->min); - GPUNodeLink *tmax = GPU_uniform(texmap->max); - GPUNodeLink *tdomin = GPU_uniform(&domin); - GPUNodeLink *tdomax = GPU_uniform(&domax); - - return GPU_stack_link(mat, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax); -} - -void register_node_type_sh_mapping(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_MAPPING, "Mapping", NODE_CLASS_OP_VECTOR, NODE_OPTIONS, - sh_node_mapping_in, sh_node_mapping_out); - node_type_size(&ntype, 240, 160, 320); - node_type_init(&ntype, node_shader_init_mapping); - node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_shader_exec_mapping); - node_type_gpu(&ntype, gpu_shader_mapping); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_material.c b/source/blender/nodes/intern/SHD_nodes/SHD_material.c deleted file mode 100644 index f78dd9ec727..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_material.c +++ /dev/null @@ -1,336 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_material.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - -/* **************** MATERIAL ******************** */ - -static bNodeSocketType sh_node_material_in[]= { - { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, "Spec", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Refl", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 1, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType sh_node_material_out[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -/* **************** EXTENDED MATERIAL ******************** */ - -static bNodeSocketType sh_node_material_ext_in[]= { - { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, "Spec", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Refl", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 1, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { SOCK_RGBA, 1, "Mirror", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Ambient", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Emit", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "SpecTra", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Ray Mirror", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Alpha", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Translucency", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType sh_node_material_ext_out[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { SOCK_RGBA, 0, "Diffuse", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, "Spec", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, "AO", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_material(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - if(data && node->id) { - ShadeResult shrnode; - ShadeInput *shi; - ShaderCallData *shcd= data; - float col[4]; - bNodeSocket *sock; - char hasinput[NUM_MAT_IN]= {'\0'}; - int i; - - /* note: cannot use the in[]->hasinput flags directly, as these are not necessarily - * the constant input stack values (e.g. in case material node is inside a group). - * we just want to know if a node input uses external data or the material setting. - * this is an ugly hack, but so is this node as a whole. - */ - for (sock=node->inputs.first, i=0; sock; sock=sock->next, ++i) - hasinput[i] = (sock->link != NULL); - - shi= shcd->shi; - shi->mat= (Material *)node->id; - - /* copy all relevant material vars, note, keep this synced with render_types.h */ - memcpy(&shi->r, &shi->mat->r, 23*sizeof(float)); - shi->har= shi->mat->har; - - /* write values */ - if(hasinput[MAT_IN_COLOR]) - nodestack_get_vec(&shi->r, SOCK_VECTOR, in[MAT_IN_COLOR]); - - if(hasinput[MAT_IN_SPEC]) - nodestack_get_vec(&shi->specr, SOCK_VECTOR, in[MAT_IN_SPEC]); - - if(hasinput[MAT_IN_REFL]) - nodestack_get_vec(&shi->refl, SOCK_VALUE, in[MAT_IN_REFL]); - - /* retrieve normal */ - if(hasinput[MAT_IN_NORMAL]) { - nodestack_get_vec(shi->vn, SOCK_VECTOR, in[MAT_IN_NORMAL]); - normalize_v3(shi->vn); - } - else - VECCOPY(shi->vn, shi->vno); - - /* custom option to flip normal */ - if(node->custom1 & SH_NODE_MAT_NEG) { - shi->vn[0]= -shi->vn[0]; - shi->vn[1]= -shi->vn[1]; - shi->vn[2]= -shi->vn[2]; - } - - if (node->type == SH_NODE_MATERIAL_EXT) { - if(hasinput[MAT_IN_MIR]) - nodestack_get_vec(&shi->mirr, SOCK_VECTOR, in[MAT_IN_MIR]); - if(hasinput[MAT_IN_AMB]) - nodestack_get_vec(&shi->amb, SOCK_VALUE, in[MAT_IN_AMB]); - if(hasinput[MAT_IN_EMIT]) - nodestack_get_vec(&shi->emit, SOCK_VALUE, in[MAT_IN_EMIT]); - if(hasinput[MAT_IN_SPECTRA]) - nodestack_get_vec(&shi->spectra, SOCK_VALUE, in[MAT_IN_SPECTRA]); - if(hasinput[MAT_IN_RAY_MIRROR]) - nodestack_get_vec(&shi->ray_mirror, SOCK_VALUE, in[MAT_IN_RAY_MIRROR]); - if(hasinput[MAT_IN_ALPHA]) - nodestack_get_vec(&shi->alpha, SOCK_VALUE, in[MAT_IN_ALPHA]); - if(hasinput[MAT_IN_TRANSLUCENCY]) - nodestack_get_vec(&shi->translucency, SOCK_VALUE, in[MAT_IN_TRANSLUCENCY]); - } - - shi->nodes= 1; /* temp hack to prevent trashadow recursion */ - node_shader_lamp_loop(shi, &shrnode); /* clears shrnode */ - shi->nodes= 0; - - /* write to outputs */ - if(node->custom1 & SH_NODE_MAT_DIFF) { - VECCOPY(col, shrnode.combined); - if(!(node->custom1 & SH_NODE_MAT_SPEC)) { - sub_v3_v3(col, shrnode.spec); - } - } - else if(node->custom1 & SH_NODE_MAT_SPEC) { - VECCOPY(col, shrnode.spec); - } - else - col[0]= col[1]= col[2]= 0.0f; - - col[3]= shrnode.alpha; - - if(shi->do_preview) - nodeAddToPreview(node, col, shi->xs, shi->ys, shi->do_manage); - - VECCOPY(out[MAT_OUT_COLOR]->vec, col); - out[MAT_OUT_ALPHA]->vec[0]= shrnode.alpha; - - if(node->custom1 & SH_NODE_MAT_NEG) { - shi->vn[0]= -shi->vn[0]; - shi->vn[1]= -shi->vn[1]; - shi->vn[2]= -shi->vn[2]; - } - - VECCOPY(out[MAT_OUT_NORMAL]->vec, shi->vn); - - /* Extended material options */ - if (node->type == SH_NODE_MATERIAL_EXT) { - /* Shadow, Reflect, Refract, Radiosity, Speed seem to cause problems inside - * a node tree :( */ - VECCOPY(out[MAT_OUT_DIFFUSE]->vec, shrnode.diff); - VECCOPY(out[MAT_OUT_SPEC]->vec, shrnode.spec); - VECCOPY(out[MAT_OUT_AO]->vec, shrnode.ao); - } - - /* copy passes, now just active node */ - if(node->flag & NODE_ACTIVE_ID) { - float combined[4], alpha; - - copy_v4_v4(combined, shcd->shr->combined); - alpha= shcd->shr->alpha; - - *(shcd->shr)= shrnode; - - copy_v4_v4(shcd->shr->combined, combined); - shcd->shr->alpha= alpha; - } - } -} - - -static void node_shader_init_material(bNode* node) -{ - node->custom1= SH_NODE_MAT_DIFF|SH_NODE_MAT_SPEC; -} - -/* XXX this is also done as a local static function in gpu_codegen.c, - * but we need this to hack around the crappy material node. - */ -static GPUNodeLink *gpu_get_input_link(GPUNodeStack *in) -{ - if (in->link) - return in->link; - else - return GPU_uniform(in->vec); -} - -static int gpu_shader_material(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - if(node->id) { - GPUShadeInput shi; - GPUShadeResult shr; - bNodeSocket *sock; - char hasinput[NUM_MAT_IN]= {'\0'}; - int i; - - /* note: cannot use the in[]->hasinput flags directly, as these are not necessarily - * the constant input stack values (e.g. in case material node is inside a group). - * we just want to know if a node input uses external data or the material setting. - */ - for (sock=node->inputs.first, i=0; sock; sock=sock->next, ++i) - hasinput[i] = (sock->link != NULL); - - GPU_shadeinput_set(mat, (Material*)node->id, &shi); - - /* write values */ - if(hasinput[MAT_IN_COLOR]) - shi.rgb = gpu_get_input_link(&in[MAT_IN_COLOR]); - - if(hasinput[MAT_IN_SPEC]) - shi.specrgb = gpu_get_input_link(&in[MAT_IN_SPEC]); - - if(hasinput[MAT_IN_REFL]) - shi.refl = gpu_get_input_link(&in[MAT_IN_REFL]); - - /* retrieve normal */ - if(hasinput[MAT_IN_NORMAL]) { - GPUNodeLink *tmp; - shi.vn = gpu_get_input_link(&in[MAT_IN_NORMAL]); - GPU_link(mat, "vec_math_normalize", shi.vn, &shi.vn, &tmp); - } - - /* custom option to flip normal */ - if(node->custom1 & SH_NODE_MAT_NEG) - GPU_link(mat, "vec_math_negate", shi.vn, &shi.vn); - - if (node->type == SH_NODE_MATERIAL_EXT) { - if(hasinput[MAT_IN_AMB]) - shi.amb= gpu_get_input_link(&in[MAT_IN_AMB]); - if(hasinput[MAT_IN_EMIT]) - shi.emit= gpu_get_input_link(&in[MAT_IN_EMIT]); - if(hasinput[MAT_IN_ALPHA]) - shi.alpha= gpu_get_input_link(&in[MAT_IN_ALPHA]); - } - - GPU_shaderesult_set(&shi, &shr); /* clears shr */ - - /* write to outputs */ - if(node->custom1 & SH_NODE_MAT_DIFF) { - out[MAT_OUT_COLOR].link= shr.combined; - - if(!(node->custom1 & SH_NODE_MAT_SPEC)) { - GPUNodeLink *link; - GPU_link(mat, "vec_math_sub", shr.combined, shr.spec, &out[MAT_OUT_COLOR].link, &link); - } - } - else if(node->custom1 & SH_NODE_MAT_SPEC) { - out[MAT_OUT_COLOR].link= shr.spec; - } - else - GPU_link(mat, "set_rgb_zero", &out[MAT_OUT_COLOR].link); - - GPU_link(mat, "mtex_alpha_to_col", out[MAT_OUT_COLOR].link, shr.alpha, &out[MAT_OUT_COLOR].link); - - out[MAT_OUT_ALPHA].link = shr.alpha; // - - if(node->custom1 & SH_NODE_MAT_NEG) - GPU_link(mat, "vec_math_negate", shi.vn, &shi.vn); - out[MAT_OUT_NORMAL].link = shi.vn; - - if (node->type == SH_NODE_MATERIAL_EXT) { - out[MAT_OUT_DIFFUSE].link = shr.diff; - out[MAT_OUT_SPEC].link = shr.spec; - } - - return 1; - } - - return 0; -} - -void register_node_type_sh_material(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_MATERIAL, "Material", NODE_CLASS_INPUT, NODE_OPTIONS|NODE_PREVIEW, - sh_node_material_in, sh_node_material_out); - node_type_size(&ntype, 120, 80, 240); - node_type_init(&ntype, node_shader_init_material); - node_type_exec(&ntype, node_shader_exec_material); - node_type_gpu(&ntype, gpu_shader_material); - - nodeRegisterType(lb, &ntype); -} - - -void register_node_type_sh_material_ext(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_MATERIAL_EXT, "Extended Material", NODE_CLASS_INPUT, NODE_OPTIONS|NODE_PREVIEW, - sh_node_material_ext_in, sh_node_material_ext_out); - node_type_size(&ntype, 120, 80, 240); - node_type_init(&ntype, node_shader_init_material); - node_type_exec(&ntype, node_shader_exec_material); - node_type_gpu(&ntype, gpu_shader_material); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_math.c b/source/blender/nodes/intern/SHD_nodes/SHD_math.c deleted file mode 100644 index dd0a564dc4b..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_math.c +++ /dev/null @@ -1,256 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_math.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - - -/* **************** SCALAR MATH ******************** */ -static bNodeSocketType sh_node_math_in[]= { - { SOCK_VALUE, 1, "Value", 0.5f, 0.5f, 0.5f, 1.0f, -100.0f, 100.0f}, - { SOCK_VALUE, 1, "Value", 0.5f, 0.5f, 0.5f, 1.0f, -100.0f, 100.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType sh_node_math_out[]= { - { SOCK_VALUE, 0, "Value", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_math(void *UNUSED(data), bNode *node, bNodeStack **in, -bNodeStack **out) -{ - switch(node->custom1){ - - case 0: /* Add */ - out[0]->vec[0]= in[0]->vec[0] + in[1]->vec[0]; - break; - case 1: /* Subtract */ - out[0]->vec[0]= in[0]->vec[0] - in[1]->vec[0]; - break; - case 2: /* Multiply */ - out[0]->vec[0]= in[0]->vec[0] * in[1]->vec[0]; - break; - case 3: /* Divide */ - { - if(in[1]->vec[0]==0) /* We don't want to divide by zero. */ - out[0]->vec[0]= 0.0; - else - out[0]->vec[0]= in[0]->vec[0] / in[1]->vec[0]; - } - break; - case 4: /* Sine */ - { - if(in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ - out[0]->vec[0]= sin(in[0]->vec[0]); - else - out[0]->vec[0]= sin(in[1]->vec[0]); - } - break; - case 5: /* Cosine */ - { - if(in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ - out[0]->vec[0]= cos(in[0]->vec[0]); - else - out[0]->vec[0]= cos(in[1]->vec[0]); - } - break; - case 6: /* Tangent */ - { - if(in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ - out[0]->vec[0]= tan(in[0]->vec[0]); - else - out[0]->vec[0]= tan(in[1]->vec[0]); - } - break; - case 7: /* Arc-Sine */ - { - if(in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ - /* Can't do the impossible... */ - if( in[0]->vec[0] <= 1 && in[0]->vec[0] >= -1 ) - out[0]->vec[0]= asin(in[0]->vec[0]); - else - out[0]->vec[0]= 0.0; - } - else { - /* Can't do the impossible... */ - if( in[1]->vec[0] <= 1 && in[1]->vec[0] >= -1 ) - out[0]->vec[0]= asin(in[1]->vec[0]); - else - out[0]->vec[0]= 0.0; - } - } - break; - case 8: /* Arc-Cosine */ - { - if(in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ - /* Can't do the impossible... */ - if( in[0]->vec[0] <= 1 && in[0]->vec[0] >= -1 ) - out[0]->vec[0]= acos(in[0]->vec[0]); - else - out[0]->vec[0]= 0.0; - } - else { - /* Can't do the impossible... */ - if( in[1]->vec[0] <= 1 && in[1]->vec[0] >= -1 ) - out[0]->vec[0]= acos(in[1]->vec[0]); - else - out[0]->vec[0]= 0.0; - } - } - break; - case 9: /* Arc-Tangent */ - { - if(in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ - out[0]->vec[0]= atan(in[0]->vec[0]); - else - out[0]->vec[0]= atan(in[1]->vec[0]); - } - break; - case 10: /* Power */ - { - /* Don't want any imaginary numbers... */ - if( in[0]->vec[0] >= 0 ) - out[0]->vec[0]= pow(in[0]->vec[0], in[1]->vec[0]); - else - out[0]->vec[0]= 0.0; - } - break; - case 11: /* Logarithm */ - { - /* Don't want any imaginary numbers... */ - if( in[0]->vec[0] > 0 && in[1]->vec[0] > 0 ) - out[0]->vec[0]= log(in[0]->vec[0]) / log(in[1]->vec[0]); - else - out[0]->vec[0]= 0.0; - } - break; - case 12: /* Minimum */ - { - if( in[0]->vec[0] < in[1]->vec[0] ) - out[0]->vec[0]= in[0]->vec[0]; - else - out[0]->vec[0]= in[1]->vec[0]; - } - break; - case 13: /* Maximum */ - { - if( in[0]->vec[0] > in[1]->vec[0] ) - out[0]->vec[0]= in[0]->vec[0]; - else - out[0]->vec[0]= in[1]->vec[0]; - } - break; - case 14: /* Round */ - { - if(in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ - out[0]->vec[0]= (in[0]->vec[0]<0)?(int)(in[0]->vec[0] - 0.5f):(int)(in[0]->vec[0] + 0.5f); - else - out[0]->vec[0]= (in[1]->vec[0]<0)?(int)(in[1]->vec[0] - 0.5f):(int)(in[1]->vec[0] + 0.5f); - } - break; - case 15: /* Less Than */ - { - if( in[0]->vec[0] < in[1]->vec[0] ) - out[0]->vec[0]= 1.0f; - else - out[0]->vec[0]= 0.0f; - } - break; - case 16: /* Greater Than */ - { - if( in[0]->vec[0] > in[1]->vec[0] ) - out[0]->vec[0]= 1.0f; - else - out[0]->vec[0]= 0.0f; - } - break; - } -} - -static int gpu_shader_math(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - static const char *names[] = {"math_add", "math_subtract", "math_multiply", - "math_divide", "math_sine", "math_cosine", "math_tangent", "math_asin", - "math_acos", "math_atan", "math_pow", "math_log", "math_min", "math_max", - "math_round", "math_less_than", "math_greater_than"}; - - switch (node->custom1) { - case 0: - case 1: - case 2: - case 3: - case 10: - case 11: - case 12: - case 13: - case 15: - case 16: - GPU_stack_link(mat, names[node->custom1], NULL, out, - GPU_socket(&in[0]), GPU_socket(&in[1])); - break; - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - case 14: - if(in[0].hasinput || !in[1].hasinput) - GPU_stack_link(mat, names[node->custom1], NULL, out, GPU_socket(&in[0])); - else - GPU_stack_link(mat, names[node->custom1], NULL, out, GPU_socket(&in[1])); - break; - default: - return 0; - } - - return 1; -} - -void register_node_type_sh_math(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - sh_node_math_in, sh_node_math_out); - node_type_size(&ntype, 120, 110, 160); - node_type_label(&ntype, node_math_label); - node_type_storage(&ntype, "node_math", NULL, NULL); - node_type_exec(&ntype, node_shader_exec_math); - node_type_gpu(&ntype, gpu_shader_math); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_mixRgb.c b/source/blender/nodes/intern/SHD_nodes/SHD_mixRgb.c deleted file mode 100644 index 8b3033a98ca..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_mixRgb.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_mixRgb.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - -/* **************** MIX RGB ******************** */ -static bNodeSocketType sh_node_mix_rgb_in[]= { - { SOCK_VALUE, 1, "Fac", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, "Color1", 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, "Color2", 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType sh_node_mix_rgb_out[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_mix_rgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order in: fac, col1, col2 */ - /* stack order out: col */ - float col[3]; - float fac; - float vec[3]; - - nodestack_get_vec(&fac, SOCK_VALUE, in[0]); - CLAMP(fac, 0.0f, 1.0f); - - nodestack_get_vec(col, SOCK_VECTOR, in[1]); - nodestack_get_vec(vec, SOCK_VECTOR, in[2]); - - ramp_blend(node->custom1, col, col+1, col+2, fac, vec); - VECCOPY(out[0]->vec, col); -} - -static int gpu_shader_mix_rgb(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - static const char *names[] = {"mix_blend", "mix_add", "mix_mult", "mix_sub", - "mix_screen", "mix_div", "mix_diff", "mix_dark", "mix_light", - "mix_overlay", "mix_dodge", "mix_burn", "mix_hue", "mix_sat", - "mix_val", "mix_color", "mix_soft", "mix_linear"}; - - return GPU_stack_link(mat, names[node->custom1], in, out); -} - - -void register_node_type_sh_mix_rgb(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - sh_node_mix_rgb_in, sh_node_mix_rgb_out); - node_type_size(&ntype, 100, 60, 150); - node_type_label(&ntype, node_blend_label); - node_type_exec(&ntype, node_shader_exec_mix_rgb); - node_type_gpu(&ntype, gpu_shader_mix_rgb); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_normal.c b/source/blender/nodes/intern/SHD_nodes/SHD_normal.c deleted file mode 100644 index a4e39935cea..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_normal.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_normal.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - -/* **************** NORMAL ******************** */ -static bNodeSocketType sh_node_normal_in[]= { - { SOCK_VECTOR, 1, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType sh_node_normal_out[]= { - { SOCK_VECTOR, 0, "Normal", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, - { SOCK_VALUE, 0, "Dot", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -/* generates normal, does dot product */ -static void node_shader_exec_normal(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - bNodeSocket *sock= node->outputs.first; - float vec[3]; - - /* stack order input: normal */ - /* stack order output: normal, value */ - - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - - VECCOPY(out[0]->vec, sock->ns.vec); - /* render normals point inside... the widget points outside */ - out[1]->vec[0]= -INPR(out[0]->vec, vec); -} - -static int gpu_shader_normal(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - bNodeSocket *sock= node->outputs.first; - GPUNodeLink *vec = GPU_uniform(sock->ns.vec); - - return GPU_stack_link(mat, "normal", in, out, vec); -} - -void register_node_type_sh_normal(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR, NODE_OPTIONS, - sh_node_normal_in, sh_node_normal_out); - node_type_exec(&ntype, node_shader_exec_normal); - node_type_gpu(&ntype, gpu_shader_normal); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_output.c b/source/blender/nodes/intern/SHD_nodes/SHD_output.c deleted file mode 100644 index e42caabff34..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_output.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_output.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - -/* **************** OUTPUT ******************** */ -static bNodeSocketType sh_node_output_in[]= { - { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_output(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out)) -{ - if(data) { - ShadeInput *shi= ((ShaderCallData *)data)->shi; - float col[4]; - - /* stack order input sockets: col, alpha, normal */ - nodestack_get_vec(col, SOCK_VECTOR, in[0]); - nodestack_get_vec(col+3, SOCK_VALUE, in[1]); - - if(shi->do_preview) { - nodeAddToPreview(node, col, shi->xs, shi->ys, shi->do_manage); - node->lasty= shi->ys; - } - - if(node->flag & NODE_DO_OUTPUT) { - ShadeResult *shr= ((ShaderCallData *)data)->shr; - - QUATCOPY(shr->combined, col); - shr->alpha= col[3]; - - // VECCOPY(shr->nor, in[3]->vec); - } - } -} - -static int gpu_shader_output(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out) -{ - GPUNodeLink *outlink; - - /*if(in[1].hasinput) - GPU_material_enable_alpha(mat);*/ - - GPU_stack_link(mat, "output_node", in, out, &outlink); - GPU_material_output_link(mat, outlink); - - return 1; -} - -void register_node_type_sh_output(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_OUTPUT, "Output", NODE_CLASS_OUTPUT, NODE_PREVIEW, - sh_node_output_in, NULL); - node_type_size(&ntype, 80, 60, 200); - node_type_exec(&ntype, node_shader_exec_output); - node_type_gpu(&ntype, gpu_shader_output); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_rgb.c b/source/blender/nodes/intern/SHD_nodes/SHD_rgb.c deleted file mode 100644 index 3d7f401b055..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_rgb.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_rgb.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - -/* **************** RGB ******************** */ -static bNodeSocketType sh_node_rgb_out[]= { - { SOCK_RGBA, 0, "Color", 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_rgb(void *UNUSED(data), bNode *node, bNodeStack **UNUSED(in), bNodeStack **out) -{ - bNodeSocket *sock= node->outputs.first; - - VECCOPY(out[0]->vec, sock->ns.vec); -} - -static int gpu_shader_rgb(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - bNodeSocket *sock= node->outputs.first; - GPUNodeLink *vec = GPU_uniform(sock->ns.vec); - - return GPU_stack_link(mat, "set_rgba", in, out, vec); -} - -void register_node_type_sh_rgb(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_RGB, "RGB", NODE_CLASS_INPUT, NODE_OPTIONS, - NULL, sh_node_rgb_out); - node_type_size(&ntype, 140, 80, 140); - node_type_exec(&ntype, node_shader_exec_rgb); - node_type_gpu(&ntype, gpu_shader_rgb); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_sepcombRGB.c b/source/blender/nodes/intern/SHD_nodes/SHD_sepcombRGB.c deleted file mode 100644 index e4fa0b02521..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_sepcombRGB.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Juho Vepsäläinen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_sepcombRGB.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - -/* **************** SEPARATE RGBA ******************** */ -static bNodeSocketType sh_node_seprgb_in[]= { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType sh_node_seprgb_out[]= { - { SOCK_VALUE, 0, "R", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "G", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "B", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_seprgb(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **in, bNodeStack **out) -{ - out[0]->vec[0] = in[0]->vec[0]; - out[1]->vec[0] = in[0]->vec[1]; - out[2]->vec[0] = in[0]->vec[2]; -} - -static int gpu_shader_seprgb(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out) -{ - return GPU_stack_link(mat, "separate_rgb", in, out); -} - -void register_node_type_sh_seprgb(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_SEPRGB, "Separate RGB", NODE_CLASS_CONVERTOR, 0, - sh_node_seprgb_in, sh_node_seprgb_out); - node_type_size(&ntype, 80, 40, 140); - node_type_exec(&ntype, node_shader_exec_seprgb); - node_type_gpu(&ntype, gpu_shader_seprgb); - - nodeRegisterType(lb, &ntype); -} - - - -/* **************** COMBINE RGB ******************** */ -static bNodeSocketType sh_node_combrgb_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}, - { -1, 0, "" } -}; -static bNodeSocketType sh_node_combrgb_out[]= { - { SOCK_RGBA, 0, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_combrgb(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **in, bNodeStack **out) -{ - out[0]->vec[0] = in[0]->vec[0]; - out[0]->vec[1] = in[1]->vec[0]; - out[0]->vec[2] = in[2]->vec[0]; -} - -static int gpu_shader_combrgb(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out) -{ - return GPU_stack_link(mat, "combine_rgb", in, out); -} - -void register_node_type_sh_combrgb(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_COMBRGB, "Combine RGB", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - sh_node_combrgb_in, sh_node_combrgb_out); - node_type_size(&ntype, 80, 40, 140); - node_type_exec(&ntype, node_shader_exec_combrgb); - node_type_gpu(&ntype, gpu_shader_combrgb); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_squeeze.c b/source/blender/nodes/intern/SHD_nodes/SHD_squeeze.c deleted file mode 100644 index 80693ff08f0..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_squeeze.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_squeeze.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - -/* **************** VALUE SQUEEZE ******************** */ -static bNodeSocketType sh_node_squeeze_in[]= { - { SOCK_VALUE, 1, "Value", 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f}, - { SOCK_VALUE, 1, "Width", 1.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f}, - { SOCK_VALUE, 1, "Center", 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType sh_node_squeeze_out[]= { - { SOCK_VALUE, 0, "Value", 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_squeeze(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **in, -bNodeStack **out) -{ - float vec[3]; - - nodestack_get_vec(vec, SOCK_VALUE, in[0]); - nodestack_get_vec(vec+1, SOCK_VALUE, in[1]); - nodestack_get_vec(vec+2, SOCK_VALUE, in[2]); - - out[0]->vec[0] = 1.0f / (1.0f + pow(2.71828183,-((vec[0]-vec[2])*vec[1]))) ; -} - -static int gpu_shader_squeeze(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out) -{ - return GPU_stack_link(mat, "squeeze", in, out); -} - -void register_node_type_sh_squeeze(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_SQUEEZE, "Squeeze Value", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - sh_node_squeeze_in, sh_node_squeeze_out); - node_type_size(&ntype, 120, 110, 160); - node_type_storage(&ntype, "node_squeeze", NULL, NULL); - node_type_exec(&ntype, node_shader_exec_squeeze); - node_type_gpu(&ntype, gpu_shader_squeeze); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_texture.c b/source/blender/nodes/intern/SHD_nodes/SHD_texture.c deleted file mode 100644 index 249e4eeca5d..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_texture.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_texture.c - * \ingroup shdnodes - */ - - -#include "DNA_texture_types.h" - -#include "../SHD_util.h" - -/* **************** TEXTURE ******************** */ -static bNodeSocketType sh_node_texture_in[]= { - { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, /* no limit */ - { -1, 0, "" } -}; -static bNodeSocketType sh_node_texture_out[]= { - { SOCK_VALUE, 0, "Value", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA , 0, "Color", 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_texture(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - if(data && node->id) { - ShadeInput *shi= ((ShaderCallData *)data)->shi; - TexResult texres; - float vec[3], nor[3]={0.0f, 0.0f, 0.0f}; - int retval; - short which_output = node->custom1; - - short thread = shi->thread; - - /* out: value, color, normal */ - - /* we should find out if a normal as output is needed, for now we do all */ - texres.nor= nor; - texres.tr= texres.tg= texres.tb= 0.0f; - - if(in[0]->hasinput) { - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - - if(in[0]->datatype==NS_OSA_VECTORS) { - float *fp= in[0]->data; - retval= multitex_nodes((Tex *)node->id, vec, fp, fp+3, shi->osatex, &texres, thread, which_output, NULL, NULL); - } - else if(in[0]->datatype==NS_OSA_VALUES) { - float *fp= in[0]->data; - float dxt[3], dyt[3]; - - dxt[0]= fp[0]; dxt[1]= dxt[2]= 0.0f; - dyt[0]= fp[1]; dyt[1]= dyt[2]= 0.0f; - retval= multitex_nodes((Tex *)node->id, vec, dxt, dyt, shi->osatex, &texres, thread, which_output, NULL, NULL); - } - else - retval= multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL); - } - else { - VECCOPY(vec, shi->lo); - retval= multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL); - } - - /* stupid exception */ - if( ((Tex *)node->id)->type==TEX_STUCCI) { - texres.tin= 0.5f + 0.7f*texres.nor[0]; - CLAMP(texres.tin, 0.0f, 1.0f); - } - - /* intensity and color need some handling */ - if(texres.talpha) - out[0]->vec[0]= texres.ta; - else - out[0]->vec[0]= texres.tin; - - if((retval & TEX_RGB)==0) { - out[1]->vec[0]= out[0]->vec[0]; - out[1]->vec[1]= out[0]->vec[0]; - out[1]->vec[2]= out[0]->vec[0]; - out[1]->vec[3]= 1.0f; - } - else { - out[1]->vec[0]= texres.tr; - out[1]->vec[1]= texres.tg; - out[1]->vec[2]= texres.tb; - out[1]->vec[3]= 1.0f; - } - - VECCOPY(out[2]->vec, nor); - - if(shi->do_preview) - nodeAddToPreview(node, out[1]->vec, shi->xs, shi->ys, shi->do_manage); - - } -} - -static int gpu_shader_texture(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - Tex *tex = (Tex*)node->id; - - if(tex && tex->type == TEX_IMAGE && tex->ima) { - GPUNodeLink *texlink = GPU_image(tex->ima, NULL); - return GPU_stack_link(mat, "texture_image", in, out, texlink); - } - else - return 0; -} - -void register_node_type_sh_texture(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT, NODE_OPTIONS|NODE_PREVIEW, - sh_node_texture_in, sh_node_texture_out); - node_type_size(&ntype, 120, 80, 240); - node_type_exec(&ntype, node_shader_exec_texture); - node_type_gpu(&ntype, gpu_shader_texture); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_valToRgb.c b/source/blender/nodes/intern/SHD_nodes/SHD_valToRgb.c deleted file mode 100644 index 86f832c12ee..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_valToRgb.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_valToRgb.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - -/* **************** VALTORGB ******************** */ -static bNodeSocketType sh_node_valtorgb_in[]= { - { SOCK_VALUE, 1, "Fac", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType sh_node_valtorgb_out[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_valtorgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - /* stack order in: fac */ - /* stack order out: col, alpha */ - - if(node->storage) { - float fac; - nodestack_get_vec(&fac, SOCK_VALUE, in[0]); - - do_colorband(node->storage, fac, out[0]->vec); - out[1]->vec[0]= out[0]->vec[3]; - } -} - -static void node_shader_init_valtorgb(bNode *node) -{ - node->storage= add_colorband(1); -} - -static int gpu_shader_valtorgb(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - float *array; - int size; - - colorband_table_RGBA(node->storage, &array, &size); - return GPU_stack_link(mat, "valtorgb", in, out, GPU_texture(size, array)); -} - -void register_node_type_sh_valtorgb(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - sh_node_valtorgb_in, sh_node_valtorgb_out); - node_type_size(&ntype, 240, 200, 300); - node_type_init(&ntype, node_shader_init_valtorgb); - node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_shader_exec_valtorgb); - node_type_gpu(&ntype, gpu_shader_valtorgb); - - nodeRegisterType(lb, &ntype); -} - - -/* **************** RGBTOBW ******************** */ -static bNodeSocketType sh_node_rgbtobw_in[]= { - { SOCK_RGBA, 1, "Color", 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType sh_node_rgbtobw_out[]= { - { SOCK_VALUE, 0, "Val", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - - -static void node_shader_exec_rgbtobw(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **in, bNodeStack **out) -{ - /* stack order out: bw */ - /* stack order in: col */ - - out[0]->vec[0]= in[0]->vec[0]*0.35f + in[0]->vec[1]*0.45f + in[0]->vec[2]*0.2f; -} - -static int gpu_shader_rgbtobw(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out) -{ - return GPU_stack_link(mat, "rgbtobw", in, out); -} - -void register_node_type_sh_rgbtobw(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0, - sh_node_rgbtobw_in, sh_node_rgbtobw_out); - node_type_size(&ntype, 80, 40, 120); - node_type_exec(&ntype, node_shader_exec_rgbtobw); - node_type_gpu(&ntype, gpu_shader_rgbtobw); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_value.c b/source/blender/nodes/intern/SHD_nodes/SHD_value.c deleted file mode 100644 index 29a75bbf36d..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_value.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_value.c - * \ingroup shdnodes - */ - - -#include "../SHD_util.h" - -/* **************** VALUE ******************** */ -static bNodeSocketType sh_node_value_out[]= { - { SOCK_VALUE, 0, "Value", 0.5f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_value(void *UNUSED(data), bNode *node, bNodeStack **UNUSED(in), bNodeStack **out) -{ - bNodeSocket *sock= node->outputs.first; - - out[0]->vec[0]= sock->ns.vec[0]; -} - -static int gpu_shader_value(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - bNodeSocket *sock= node->outputs.first; - GPUNodeLink *vec = GPU_uniform(sock->ns.vec); - - return GPU_stack_link(mat, "set_value", in, out, vec); -} - -void register_node_type_sh_value(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_VALUE, "Value", NODE_CLASS_INPUT, NODE_OPTIONS, - NULL, sh_node_value_out); - node_type_size(&ntype, 80, 50, 120); - node_type_exec(&ntype, node_shader_exec_value); - node_type_gpu(&ntype, gpu_shader_value); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_vectMath.c b/source/blender/nodes/intern/SHD_nodes/SHD_vectMath.c deleted file mode 100644 index 9979e488a71..00000000000 --- a/source/blender/nodes/intern/SHD_nodes/SHD_vectMath.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_nodes/SHD_vectMath.c - * \ingroup shdnodes - */ - - - -#include "../SHD_util.h" - - -/* **************** VECTOR MATH ******************** */ -static bNodeSocketType sh_node_vect_math_in[]= { - { SOCK_VECTOR, 1, "Vector", 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 1, "Vector", 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType sh_node_vect_math_out[]= { - { SOCK_VECTOR, 0, "Vector", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 0, "Value", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_exec_vect_math(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - float vec1[3], vec2[3]; - - nodestack_get_vec(vec1, SOCK_VECTOR, in[0]); - nodestack_get_vec(vec2, SOCK_VECTOR, in[1]); - - if(node->custom1 == 0) { /* Add */ - out[0]->vec[0]= vec1[0] + vec2[0]; - out[0]->vec[1]= vec1[1] + vec2[1]; - out[0]->vec[2]= vec1[2] + vec2[2]; - - out[1]->vec[0]= (fabs(out[0]->vec[0]) + fabs(out[0]->vec[0]) + fabs(out[0]->vec[0])) / 3; - } - else if(node->custom1 == 1) { /* Subtract */ - out[0]->vec[0]= vec1[0] - vec2[0]; - out[0]->vec[1]= vec1[1] - vec2[1]; - out[0]->vec[2]= vec1[2] - vec2[2]; - - out[1]->vec[0]= (fabs(out[0]->vec[0]) + fabs(out[0]->vec[0]) + fabs(out[0]->vec[0])) / 3; - } - else if(node->custom1 == 2) { /* Average */ - out[0]->vec[0]= vec1[0] + vec2[0]; - out[0]->vec[1]= vec1[1] + vec2[1]; - out[0]->vec[2]= vec1[2] + vec2[2]; - - out[1]->vec[0] = normalize_v3( out[0]->vec ); - } - else if(node->custom1 == 3) { /* Dot product */ - out[1]->vec[0]= (vec1[0] * vec2[0]) + (vec1[1] * vec2[1]) + (vec1[2] * vec2[2]); - } - else if(node->custom1 == 4) { /* Cross product */ - out[0]->vec[0]= (vec1[1] * vec2[2]) - (vec1[2] * vec2[1]); - out[0]->vec[1]= (vec1[2] * vec2[0]) - (vec1[0] * vec2[2]); - out[0]->vec[2]= (vec1[0] * vec2[1]) - (vec1[1] * vec2[0]); - - out[1]->vec[0] = normalize_v3( out[0]->vec ); - } - else if(node->custom1 == 5) { /* Normalize */ - if(in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ - out[0]->vec[0]= vec1[0]; - out[0]->vec[1]= vec1[1]; - out[0]->vec[2]= vec1[2]; - } - else { - out[0]->vec[0]= vec2[0]; - out[0]->vec[1]= vec2[1]; - out[0]->vec[2]= vec2[2]; - } - - out[1]->vec[0] = normalize_v3( out[0]->vec ); - } - -} - -static int gpu_shader_vect_math(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - static const char *names[] = {"vec_math_add", "vec_math_sub", - "vec_math_average", "vec_math_dot", "vec_math_cross", - "vec_math_normalize"}; - - switch (node->custom1) { - case 0: - case 1: - case 2: - case 3: - case 4: - GPU_stack_link(mat, names[node->custom1], NULL, out, - GPU_socket(&in[0]), GPU_socket(&in[1])); - break; - case 5: - if(in[0].hasinput || !in[1].hasinput) - GPU_stack_link(mat, names[node->custom1], NULL, out, GPU_socket(&in[0])); - else - GPU_stack_link(mat, names[node->custom1], NULL, out, GPU_socket(&in[1])); - break; - default: - return 0; - } - - return 1; -} - -void register_node_type_sh_vect_math(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_VECT_MATH, "Vector Math", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - sh_node_vect_math_in, sh_node_vect_math_out); - node_type_size(&ntype, 80, 75, 140); - node_type_label(&ntype, node_vect_math_label); - node_type_storage(&ntype, "node_vect_math", NULL, NULL); - node_type_exec(&ntype, node_shader_exec_vect_math); - node_type_gpu(&ntype, gpu_shader_vect_math); - - nodeRegisterType(lb, &ntype); -} - - diff --git a/source/blender/nodes/intern/SHD_util.c b/source/blender/nodes/intern/SHD_util.c deleted file mode 100644 index 190f68ce19a..00000000000 --- a/source/blender/nodes/intern/SHD_util.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_util.c - * \ingroup nodes - */ - - -#include "SHD_util.h" - - - - - -/* ****** */ - -void nodestack_get_vec(float *in, short type_in, bNodeStack *ns) -{ - float *from= ns->vec; - - if(type_in==SOCK_VALUE) { - if(ns->sockettype==SOCK_VALUE) - *in= *from; - else - *in= 0.333333f*(from[0]+from[1]+from[2]); - } - else if(type_in==SOCK_VECTOR) { - if(ns->sockettype==SOCK_VALUE) { - in[0]= from[0]; - in[1]= from[0]; - in[2]= from[0]; - } - else { - VECCOPY(in, from); - } - } - else { /* type_in==SOCK_RGBA */ - if(ns->sockettype==SOCK_RGBA) { - QUATCOPY(in, from); - } - else if(ns->sockettype==SOCK_VALUE) { - in[0]= from[0]; - in[1]= from[0]; - in[2]= from[0]; - in[3]= 1.0f; - } - else { - VECCOPY(in, from); - in[3]= 1.0f; - } - } -} - - -/* ******************* execute and parse ************ */ - -void ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr) -{ - ShaderCallData scd; - /* - @note: preserve material from ShadeInput for material id, nodetree execs change it - fix for bug "[#28012] Mat ID messy with shader nodes" - */ - Material *mat = shi->mat; - /* convert caller data to struct */ - scd.shi= shi; - scd.shr= shr; - - /* each material node has own local shaderesult, with optional copying */ - memset(shr, 0, sizeof(ShadeResult)); - - ntreeExecTree(ntree, &scd, shi->thread); /* threads */ - // @note: set material back to preserved material - shi->mat = mat; - /* better not allow negative for now */ - if(shr->combined[0]<0.0f) shr->combined[0]= 0.0f; - if(shr->combined[1]<0.0f) shr->combined[1]= 0.0f; - if(shr->combined[2]<0.0f) shr->combined[2]= 0.0f; - -} - -/* go over all used Geometry and Texture nodes, and return a texco flag */ -/* no group inside needed, this function is called for groups too */ -void ntreeShaderGetTexcoMode(bNodeTree *ntree, int r_mode, short *texco, int *mode) -{ - bNode *node; - bNodeSocket *sock; - int a; - - ntreeSocketUseFlags(ntree); - - for(node= ntree->nodes.first; node; node= node->next) { - if(node->type==SH_NODE_TEXTURE) { - if((r_mode & R_OSA) && node->id) { - Tex *tex= (Tex *)node->id; - if ELEM3(tex->type, TEX_IMAGE, TEX_PLUGIN, TEX_ENVMAP) - *texco |= TEXCO_OSA|NEED_UV; - } - /* usability exception... without input we still give the node orcos */ - sock= node->inputs.first; - if(sock==NULL || sock->link==NULL) - *texco |= TEXCO_ORCO|NEED_UV; - } - else if(node->type==SH_NODE_GEOMETRY) { - /* note; sockets always exist for the given type! */ - for(a=0, sock= node->outputs.first; sock; sock= sock->next, a++) { - if(sock->flag & SOCK_IN_USE) { - switch(a) { - case GEOM_OUT_GLOB: - *texco |= TEXCO_GLOB|NEED_UV; break; - case GEOM_OUT_VIEW: - *texco |= TEXCO_VIEW|NEED_UV; break; - case GEOM_OUT_ORCO: - *texco |= TEXCO_ORCO|NEED_UV; break; - case GEOM_OUT_UV: - *texco |= TEXCO_UV|NEED_UV; break; - case GEOM_OUT_NORMAL: - *texco |= TEXCO_NORM|NEED_UV; break; - case GEOM_OUT_VCOL: - *texco |= NEED_UV; *mode |= MA_VERTEXCOL; break; - } - } - } - } - } -} - -/* nodes that use ID data get synced with local data */ -void nodeShaderSynchronizeID(bNode *node, int copyto) -{ - if(node->id==NULL) return; - - if(ELEM(node->type, SH_NODE_MATERIAL, SH_NODE_MATERIAL_EXT)) { - bNodeSocket *sock; - Material *ma= (Material *)node->id; - int a; - - /* hrmf, case in loop isnt super fast, but we dont edit 100s of material at same time either! */ - for(a=0, sock= node->inputs.first; sock; sock= sock->next, a++) { - if(!(sock->flag & SOCK_HIDDEN)) { - if(copyto) { - switch(a) { - case MAT_IN_COLOR: - VECCOPY(&ma->r, sock->ns.vec); break; - case MAT_IN_SPEC: - VECCOPY(&ma->specr, sock->ns.vec); break; - case MAT_IN_REFL: - ma->ref= sock->ns.vec[0]; break; - case MAT_IN_MIR: - VECCOPY(&ma->mirr, sock->ns.vec); break; - case MAT_IN_AMB: - ma->amb= sock->ns.vec[0]; break; - case MAT_IN_EMIT: - ma->emit= sock->ns.vec[0]; break; - case MAT_IN_SPECTRA: - ma->spectra= sock->ns.vec[0]; break; - case MAT_IN_RAY_MIRROR: - ma->ray_mirror= sock->ns.vec[0]; break; - case MAT_IN_ALPHA: - ma->alpha= sock->ns.vec[0]; break; - case MAT_IN_TRANSLUCENCY: - ma->translucency= sock->ns.vec[0]; break; - } - } - else { - switch(a) { - case MAT_IN_COLOR: - VECCOPY(sock->ns.vec, &ma->r); break; - case MAT_IN_SPEC: - VECCOPY(sock->ns.vec, &ma->specr); break; - case MAT_IN_REFL: - sock->ns.vec[0]= ma->ref; break; - case MAT_IN_MIR: - VECCOPY(sock->ns.vec, &ma->mirr); break; - case MAT_IN_AMB: - sock->ns.vec[0]= ma->amb; break; - case MAT_IN_EMIT: - sock->ns.vec[0]= ma->emit; break; - case MAT_IN_SPECTRA: - sock->ns.vec[0]= ma->spectra; break; - case MAT_IN_RAY_MIRROR: - sock->ns.vec[0]= ma->ray_mirror; break; - case MAT_IN_ALPHA: - sock->ns.vec[0]= ma->alpha; break; - case MAT_IN_TRANSLUCENCY: - sock->ns.vec[0]= ma->translucency; break; - } - } - } - } - } - -} diff --git a/source/blender/nodes/intern/SHD_util.h b/source/blender/nodes/intern/SHD_util.h deleted file mode 100644 index e6b1377067d..00000000000 --- a/source/blender/nodes/intern/SHD_util.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/SHD_util.h - * \ingroup nodes - */ - - -#ifndef SHD_NODE_UTIL_H_ -#define SHD_NODE_UTIL_H_ - -#include <math.h> -#include <float.h> -#include <string.h> - -#include "MEM_guardedalloc.h" - -#include "DNA_color_types.h" -#include "DNA_ID.h" -#include "DNA_image_types.h" -#include "DNA_material_types.h" -#include "DNA_node_types.h" -#include "DNA_object_types.h" -#include "DNA_scene_types.h" -#include "DNA_texture_types.h" - -#include "BKE_blender.h" -#include "BKE_colortools.h" -#include "BKE_global.h" -#include "BKE_image.h" -#include "BKE_main.h" -#include "BKE_material.h" -#include "BKE_node.h" -#include "BKE_texture.h" - -#include "BKE_library.h" - -#include "../SHD_node.h" -#include "node_util.h" - -#include "BLI_math.h" -#include "BLI_blenlib.h" -#include "BLI_rand.h" -#include "BLI_threads.h" -#include "BLI_utildefines.h" - -#include "IMB_imbuf_types.h" -#include "IMB_imbuf.h" - -#include "RE_pipeline.h" -#include "RE_shader_ext.h" - -#include "GPU_material.h" - -/* ********* exec data struct, remains internal *********** */ - -typedef struct ShaderCallData { - ShadeInput *shi; /* from render pipe */ - ShadeResult *shr; /* from render pipe */ -} ShaderCallData; - -/* output socket defines */ -#define GEOM_OUT_GLOB 0 -#define GEOM_OUT_LOCAL 1 -#define GEOM_OUT_VIEW 2 -#define GEOM_OUT_ORCO 3 -#define GEOM_OUT_UV 4 -#define GEOM_OUT_NORMAL 5 -#define GEOM_OUT_VCOL 6 -#define GEOM_OUT_FRONTBACK 7 - - -/* input socket defines */ -#define MAT_IN_COLOR 0 -#define MAT_IN_SPEC 1 -#define MAT_IN_REFL 2 -#define MAT_IN_NORMAL 3 -#define MAT_IN_MIR 4 -#define MAT_IN_AMB 5 -#define MAT_IN_EMIT 6 -#define MAT_IN_SPECTRA 7 -#define MAT_IN_RAY_MIRROR 8 -#define MAT_IN_ALPHA 9 -#define MAT_IN_TRANSLUCENCY 10 -#define NUM_MAT_IN 11 /* for array size */ - -/* output socket defines */ -#define MAT_OUT_COLOR 0 -#define MAT_OUT_ALPHA 1 -#define MAT_OUT_NORMAL 2 -#define MAT_OUT_DIFFUSE 3 -#define MAT_OUT_SPEC 4 -#define MAT_OUT_AO 5 - - -extern void node_ID_title_cb(void *node_v, void *unused_v); -void nodestack_get_vec(float *in, short type_in, bNodeStack *ns); - -#endif diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_at.c b/source/blender/nodes/intern/TEX_nodes/TEX_at.c deleted file mode 100644 index d5980b786b0..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_at.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): R Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_at.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - -static bNodeSocketType inputs[]= { - { SOCK_RGBA, 1, "Texture", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { SOCK_VECTOR, 1, "Coordinates", 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f }, - { -1, 0, "" } -}; -static bNodeSocketType outputs[]= { - { SOCK_RGBA, 0, "Texture", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; - -static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) -{ - TexParams np = *p; - float new_co[3]; - np.co = new_co; - - tex_input_vec(new_co, in[1], p, thread); - tex_input_rgba(out, in[0], &np, thread); -} - -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &colorfn, data); -} - -void register_node_type_tex_at(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_AT, "At", NODE_CLASS_DISTORT, 0, - inputs, outputs); - node_type_size(&ntype, 140, 100, 320); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_bricks.c b/source/blender/nodes/intern/TEX_nodes/TEX_bricks.c deleted file mode 100644 index 0eb982496a9..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_bricks.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_bricks.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - -#include <math.h> - -static bNodeSocketType inputs[]= { - { SOCK_RGBA, 1, "Bricks 1", 0.596f, 0.282f, 0.0f, 1.0f, 0.0f, 1.0f }, - { SOCK_RGBA, 1, "Bricks 2", 0.632f, 0.504f, 0.05f, 1.0f, 0.0f, 1.0f }, - { SOCK_RGBA, 1, "Mortar", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { SOCK_VALUE, 1, "Thickness", 0.02f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }, - { SOCK_VALUE, 1, "Bias", 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f }, - { SOCK_VALUE, 1, "Brick Width", 0.5f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f }, - { SOCK_VALUE, 1, "Row Height", 0.25f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f }, - { -1, 0, "" } -}; -static bNodeSocketType outputs[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void init(bNode *node) { - node->custom3 = 0.5; /* offset */ - node->custom4 = 1.0; /* squash */ -} - -static float noise(int n) /* fast integer noise */ -{ - int nn; - n = (n >> 13) ^ n; - nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff; - return 0.5f * ((float)nn / 1073741824.0f); -} - -static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) -{ - float *co = p->co; - - float x = co[0]; - float y = co[1]; - - int bricknum, rownum; - float offset = 0; - float ins_x, ins_y; - float tint; - - float bricks1[4]; - float bricks2[4]; - float mortar[4]; - - float mortar_thickness = tex_input_value(in[3], p, thread); - float bias = tex_input_value(in[4], p, thread); - float brick_width = tex_input_value(in[5], p, thread); - float row_height = tex_input_value(in[6], p, thread); - - tex_input_rgba(bricks1, in[0], p, thread); - tex_input_rgba(bricks2, in[1], p, thread); - tex_input_rgba(mortar, in[2], p, thread); - - rownum = (int)floor(y / row_height); - - if( node->custom1 && node->custom2 ) { - brick_width *= ((int)(rownum) % node->custom2 ) ? 1.0f : node->custom4; /* squash */ - offset = ((int)(rownum) % node->custom1 ) ? 0 : (brick_width*node->custom3); /* offset */ - } - - bricknum = (int)floor((x+offset) / brick_width); - - ins_x = (x+offset) - brick_width*bricknum; - ins_y = y - row_height*rownum; - - tint = noise((rownum << 16) + (bricknum & 0xFFFF)) + bias; - CLAMP(tint,0.0f,1.0f); - - if( ins_x < mortar_thickness || ins_y < mortar_thickness || - ins_x > (brick_width - mortar_thickness) || - ins_y > (row_height - mortar_thickness) ) { - QUATCOPY( out, mortar ); - } else { - QUATCOPY( out, bricks1 ); - ramp_blend( MA_RAMP_BLEND, out, out+1, out+2, tint, bricks2 ); - } -} - -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &colorfn, data); -} - -void register_node_type_tex_bricks(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_BRICKS, "Bricks", NODE_CLASS_PATTERN, NODE_PREVIEW|NODE_OPTIONS, - inputs, outputs); - node_type_size(&ntype, 150, 60, 150); - node_type_init(&ntype, init); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_checker.c b/source/blender/nodes/intern/TEX_nodes/TEX_checker.c deleted file mode 100644 index c6c25ba1a8a..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_checker.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_checker.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" -#include <math.h> - -static bNodeSocketType inputs[]= { - { SOCK_RGBA, 1, "Color1", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { SOCK_RGBA, 1, "Color2", 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f }, - { SOCK_VALUE, 1, "Size", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 100.0f }, - { -1, 0, "" } -}; -static bNodeSocketType outputs[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; - -static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) -{ - float x = p->co[0]; - float y = p->co[1]; - float z = p->co[2]; - float sz = tex_input_value(in[2], p, thread); - - /* 0.00001 because of unit sized stuff */ - int xi = (int)fabs(floor(0.00001f + x / sz)); - int yi = (int)fabs(floor(0.00001f + y / sz)); - int zi = (int)fabs(floor(0.00001f + z / sz)); - - if( (xi % 2 == yi % 2) == (zi % 2) ) { - tex_input_rgba(out, in[0], p, thread); - } else { - tex_input_rgba(out, in[1], p, thread); - } -} - -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &colorfn, data); -} - -void register_node_type_tex_checker(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_CHECKER, "Checker", NODE_CLASS_PATTERN, NODE_PREVIEW|NODE_OPTIONS, - inputs, outputs); - node_type_size(&ntype, 100, 60, 150); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_compose.c b/source/blender/nodes/intern/TEX_nodes/TEX_compose.c deleted file mode 100644 index 6eae78ec3de..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_compose.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_compose.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - -static bNodeSocketType inputs[]= { - { SOCK_VALUE, 1, "Red", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }, - { SOCK_VALUE, 1, "Green", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }, - { SOCK_VALUE, 1, "Blue", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }, - { SOCK_VALUE, 1, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; -static bNodeSocketType outputs[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; - -static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) -{ - int i; - for(i = 0; i < 4; i++) - out[i] = tex_input_value(in[i], p, thread); -} - -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &colorfn, data); -} - -void register_node_type_tex_compose(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_COMPOSE, "Compose RGBA", NODE_CLASS_OP_COLOR, 0, - inputs, outputs); - node_type_size(&ntype, 100, 60, 150); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_coord.c b/source/blender/nodes/intern/TEX_nodes/TEX_coord.c deleted file mode 100644 index 3c46971f0d4..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_coord.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Mathias Panzenböck (panzi) <grosser.meister.morti@gmx.net>. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_coord.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - -static bNodeSocketType outputs[]= { - { SOCK_VECTOR, 0, "Coordinates", 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f }, - { -1, 0, "" } -}; - -static void vectorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **UNUSED(in), short UNUSED(thread)) -{ - out[0] = p->co[0]; - out[1] = p->co[1]; - out[2] = p->co[2]; -} - -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &vectorfn, data); -} - -void register_node_type_tex_coord(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_COORD, "Coordinates", NODE_CLASS_INPUT, NODE_OPTIONS, - NULL, outputs); - node_type_size(&ntype, 120, 110, 160); - node_type_storage(&ntype, "node_coord", NULL, NULL); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_curves.c b/source/blender/nodes/intern/TEX_nodes/TEX_curves.c deleted file mode 100644 index b7af6c748ff..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_curves.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_curves.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - -/* **************** CURVE Time ******************** */ - -/* custom1 = sfra, custom2 = efra */ -static bNodeSocketType time_outputs[]= { - { SOCK_VALUE, 0, "Value", 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; - -static void time_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread)) -{ - /* stack order output: fac */ - float fac= 0.0f; - - if(node->custom1 < node->custom2) - fac = (p->cfra - node->custom1)/(float)(node->custom2-node->custom1); - - fac = curvemapping_evaluateF(node->storage, 0, fac); - out[0] = CLAMPIS(fac, 0.0f, 1.0f); -} - -static void time_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &time_colorfn, data); -} - - -static void time_init(bNode* node) -{ - node->custom1= 1; - node->custom2= 250; - node->storage= curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); -} - -void register_node_type_tex_curve_time(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_CURVE_TIME, "Time", NODE_CLASS_INPUT, NODE_OPTIONS, - NULL, time_outputs); - node_type_size(&ntype, 140, 100, 320); - node_type_init(&ntype, time_init); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - node_type_exec(&ntype, time_exec); - - nodeRegisterType(lb, &ntype); -} - -/* **************** CURVE RGB ******************** */ -static bNodeSocketType rgb_inputs[]= { - { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType rgb_outputs[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, - { -1, 0, "" } -}; - -static void rgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) -{ - float cin[4]; - tex_input_rgba(cin, in[0], p, thread); - - curvemapping_evaluateRGBF(node->storage, out, cin); - out[3] = cin[3]; -} - -static void rgb_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &rgb_colorfn, data); -} - -static void rgb_init(bNode *node) -{ - node->storage= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f); -} - -void register_node_type_tex_curve_rgb(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - rgb_inputs, rgb_outputs); - node_type_size(&ntype, 200, 140, 320); - node_type_init(&ntype, rgb_init); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - node_type_exec(&ntype, rgb_exec); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_decompose.c b/source/blender/nodes/intern/TEX_nodes/TEX_decompose.c deleted file mode 100644 index f27d8c98716..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_decompose.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_decompose.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" -#include <math.h> - -static bNodeSocketType inputs[]= { - { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; -static bNodeSocketType outputs[]= { - { SOCK_VALUE, 0, "Red", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }, - { SOCK_VALUE, 0, "Green", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }, - { SOCK_VALUE, 0, "Blue", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }, - { SOCK_VALUE, 0, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; - -static void valuefn_r(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) -{ - tex_input_rgba(out, in[0], p, thread); - *out = out[0]; -} - -static void valuefn_g(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) -{ - tex_input_rgba(out, in[0], p, thread); - *out = out[1]; -} - -static void valuefn_b(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) -{ - tex_input_rgba(out, in[0], p, thread); - *out = out[2]; -} - -static void valuefn_a(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) -{ - tex_input_rgba(out, in[0], p, thread); - *out = out[3]; -} - -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &valuefn_r, data); - tex_output(node, in, out[1], &valuefn_g, data); - tex_output(node, in, out[2], &valuefn_b, data); - tex_output(node, in, out[3], &valuefn_a, data); -} - -void register_node_type_tex_decompose(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_DECOMPOSE, "Decompose RGBA", NODE_CLASS_OP_COLOR, 0, - inputs, outputs); - node_type_size(&ntype, 100, 60, 150); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_distance.c b/source/blender/nodes/intern/TEX_nodes/TEX_distance.c deleted file mode 100644 index b460844ba4a..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_distance.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Mathias Panzenböck (panzi) <grosser.meister.morti@gmx.net>. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_distance.c - * \ingroup texnodes - */ - - -#include <math.h> -#include "BLI_math.h" -#include "../TEX_util.h" -#include "TEX_node.h" - -static bNodeSocketType inputs[]= { - { SOCK_VECTOR, 1, "Coordinate 1", 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f }, - { SOCK_VECTOR, 1, "Coordinate 2", 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f }, - { -1, 0, "" } -}; - -static bNodeSocketType outputs[]= { - { SOCK_VALUE, 0, "Value", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; - -static void valuefn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) -{ - float co1[3], co2[3]; - - tex_input_vec(co1, in[0], p, thread); - tex_input_vec(co2, in[1], p, thread); - - *out = len_v3v3(co2, co1); -} - -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &valuefn, data); -} - -void register_node_type_tex_distance(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_DISTANCE, "Distance", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - inputs, outputs); - node_type_size(&ntype, 120, 110, 160); - node_type_storage(&ntype, "node_distance", NULL, NULL); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_hueSatVal.c b/source/blender/nodes/intern/TEX_nodes/TEX_hueSatVal.c deleted file mode 100644 index 471d8db2c03..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_hueSatVal.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Juho Vepsäläinen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_hueSatVal.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - - -static bNodeSocketType inputs[]= { - { SOCK_VALUE, 1, "Hue", 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.5f }, - { SOCK_VALUE, 1, "Saturation", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f }, - { SOCK_VALUE, 1, "Value", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f }, - { SOCK_VALUE, 1, "Factor", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }, - { SOCK_RGBA, 1, "Color", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; -static bNodeSocketType outputs[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; - -static void do_hue_sat_fac(bNode *UNUSED(node), float *out, float hue, float sat, float val, float *in, float fac) -{ - if(fac != 0 && (hue != 0.5f || sat != 1 || val != 1)) { - float col[3], hsv[3], mfac= 1.0f - fac; - - rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2); - hsv[0]+= (hue - 0.5f); - if(hsv[0]>1.0f) hsv[0]-=1.0f; else if(hsv[0]<0.0f) hsv[0]+= 1.0f; - hsv[1]*= sat; - if(hsv[1]>1.0f) hsv[1]= 1.0f; else if(hsv[1]<0.0f) hsv[1]= 0.0f; - hsv[2]*= val; - if(hsv[2]>1.0f) hsv[2]= 1.0f; else if(hsv[2]<0.0f) hsv[2]= 0.0f; - hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2); - - out[0]= mfac*in[0] + fac*col[0]; - out[1]= mfac*in[1] + fac*col[1]; - out[2]= mfac*in[2] + fac*col[2]; - } - else { - QUATCOPY(out, in); - } -} - -static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) -{ - float hue = tex_input_value(in[0], p, thread); - float sat = tex_input_value(in[1], p, thread); - float val = tex_input_value(in[2], p, thread); - float fac = tex_input_value(in[3], p, thread); - - float col[4]; - tex_input_rgba(col, in[4], p, thread); - - hue += 0.5f; /* [-.5, .5] -> [0, 1] */ - - do_hue_sat_fac(node, out, hue, sat, val, col, fac); - - out[3] = col[3]; -} - -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &colorfn, data); -} - -void register_node_type_tex_hue_sat(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - inputs, outputs); - node_type_size(&ntype, 150, 80, 250); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_image.c b/source/blender/nodes/intern/TEX_nodes/TEX_image.c deleted file mode 100644 index a54ca4bb119..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_image.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_image.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - -static bNodeSocketType outputs[]= { - { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread)) -{ - float x = p->co[0]; - float y = p->co[1]; - Image *ima= (Image *)node->id; - ImageUser *iuser= (ImageUser *)node->storage; - - if( ima ) { - ImBuf *ibuf = BKE_image_get_ibuf(ima, iuser); - if( ibuf ) { - float xsize, ysize; - float xoff, yoff; - int px, py; - - float *result; - - xsize = ibuf->x / 2; - ysize = ibuf->y / 2; - xoff = yoff = -1; - - px = (int)( (x-xoff) * xsize ); - py = (int)( (y-yoff) * ysize ); - - if( (!xsize) || (!ysize) ) return; - - if( !ibuf->rect_float ) { - BLI_lock_thread(LOCK_IMAGE); - if( !ibuf->rect_float ) - IMB_float_from_rect(ibuf); - BLI_unlock_thread(LOCK_IMAGE); - } - - while( px < 0 ) px += ibuf->x; - while( py < 0 ) py += ibuf->y; - while( px >= ibuf->x ) px -= ibuf->x; - while( py >= ibuf->y ) py -= ibuf->y; - - result = ibuf->rect_float + py*ibuf->x*4 + px*4; - QUATCOPY( out, result ); - } - } -} - -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &colorfn, data); -} - -static void init(bNode* node) -{ - ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user"); - node->storage= iuser; - iuser->sfra= 1; - iuser->fie_ima= 2; - iuser->ok= 1; -} - -void register_node_type_tex_image(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_IMAGE, "Image", NODE_CLASS_INPUT, NODE_PREVIEW|NODE_OPTIONS, - NULL, outputs); - node_type_size(&ntype, 120, 80, 300); - node_type_init(&ntype, init); - node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_invert.c b/source/blender/nodes/intern/TEX_nodes/TEX_invert.c deleted file mode 100644 index e908bdcff07..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_invert.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_invert.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - -/* **************** INVERT ******************** */ -static bNodeSocketType inputs[]= { - { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType outputs[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) -{ - float col[4]; - - tex_input_rgba(col, in[0], p, thread); - - col[0] = 1.0f - col[0]; - col[1] = 1.0f - col[1]; - col[2] = 1.0f - col[2]; - - VECCOPY(out, col); - out[3] = col[3]; -} - -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &colorfn, data); -} - -void register_node_type_tex_invert(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - inputs, outputs); - node_type_size(&ntype, 90, 80, 100); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_math.c b/source/blender/nodes/intern/TEX_nodes/TEX_math.c deleted file mode 100644 index 18468bdd55c..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_math.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_math.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - - -/* **************** SCALAR MATH ******************** */ -static bNodeSocketType inputs[]= { - { SOCK_VALUE, 1, "Value", 0.5f, 0.5f, 0.5f, 1.0f, -100.0f, 100.0f}, - { SOCK_VALUE, 1, "Value", 0.5f, 0.5f, 0.5f, 1.0f, -100.0f, 100.0f}, - { -1, 0, "" } -}; - -static bNodeSocketType outputs[]= { - { SOCK_VALUE, 0, "Value", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) -{ - float in0 = tex_input_value(in[0], p, thread); - float in1 = tex_input_value(in[1], p, thread); - - switch(node->custom1){ - - case 0: /* Add */ - *out= in0 + in1; - break; - case 1: /* Subtract */ - *out= in0 - in1; - break; - case 2: /* Multiply */ - *out= in0 * in1; - break; - case 3: /* Divide */ - { - if(in1==0) /* We don't want to divide by zero. */ - *out= 0.0; - else - *out= in0 / in1; - } - break; - case 4: /* Sine */ - { - *out= sin(in0); - } - break; - case 5: /* Cosine */ - { - *out= cos(in0); - } - break; - case 6: /* Tangent */ - { - *out= tan(in0); - } - break; - case 7: /* Arc-Sine */ - { - /* Can't do the impossible... */ - if( in0 <= 1 && in0 >= -1 ) - *out= asin(in0); - else - *out= 0.0; - } - break; - case 8: /* Arc-Cosine */ - { - /* Can't do the impossible... */ - if( in0 <= 1 && in0 >= -1 ) - *out= acos(in0); - else - *out= 0.0; - } - break; - case 9: /* Arc-Tangent */ - { - *out= atan(in0); - } - break; - case 10: /* Power */ - { - /* Only raise negative numbers by full integers */ - if( in0 >= 0 ) { - out[0]= pow(in0, in1); - } else { - float y_mod_1 = fmod(in1, 1); - if (y_mod_1 > 0.999f || y_mod_1 < 0.001f) { - *out = pow(in0, floor(in1 + 0.5f)); - } else { - *out = 0.0; - } - } - } - break; - case 11: /* Logarithm */ - { - /* Don't want any imaginary numbers... */ - if( in0 > 0 && in1 > 0 ) - *out= log(in0) / log(in1); - else - *out= 0.0; - } - break; - case 12: /* Minimum */ - { - if( in0 < in1 ) - *out= in0; - else - *out= in1; - } - break; - case 13: /* Maximum */ - { - if( in0 > in1 ) - *out= in0; - else - *out= in1; - } - break; - case 14: /* Round */ - { - *out= (in0<0)?(int)(in0 - 0.5f):(int)(in0 + 0.5f); - } - break; - - case 15: /* Less Than */ - { - if( in0 < in1 ) - *out= 1.0f; - else - *out= 0.0f; - } - break; - - case 16: /* Greater Than */ - { - if( in0 > in1 ) - *out= 1.0f; - else - *out= 0.0f; - } - break; - - default: - fprintf(stderr, - "%s:%d: unhandeld value in switch statement: %d\n", - __FILE__, __LINE__, node->custom1); - } -} - -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &valuefn, data); -} - -void register_node_type_tex_math(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - inputs, outputs); - node_type_size(&ntype, 120, 110, 160); - node_type_label(&ntype, node_math_label); - node_type_storage(&ntype, "node_math", NULL, NULL); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_mixRgb.c b/source/blender/nodes/intern/TEX_nodes/TEX_mixRgb.c deleted file mode 100644 index c7668c27b99..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_mixRgb.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_mixRgb.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - -/* **************** MIX RGB ******************** */ -static bNodeSocketType inputs[]= { - { SOCK_VALUE, 1, "Factor", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }, - { SOCK_RGBA, 1, "Color1", 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f }, - { SOCK_RGBA , 1, "Color2", 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; -static bNodeSocketType outputs[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; - -static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) -{ - float fac = tex_input_value(in[0], p, thread); - float col1[4], col2[4]; - - tex_input_rgba(col1, in[1], p, thread); - tex_input_rgba(col2, in[2], p, thread); - - CLAMP(fac, 0.0f, 1.0f); - - QUATCOPY(out, col1); - ramp_blend(node->custom1, out, out+1, out+2, fac, col2); -} - -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &colorfn, data); -} - -void register_node_type_tex_mix_rgb(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, NODE_OPTIONS, - inputs, outputs); - node_type_size(&ntype, 100, 60, 150); - node_type_label(&ntype, node_blend_label); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_output.c b/source/blender/nodes/intern/TEX_nodes/TEX_output.c deleted file mode 100644 index 046ad724507..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_output.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2006 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_output.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - -/* **************** COMPOSITE ******************** */ -static bNodeSocketType inputs[]= { - { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 1, "Normal", 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -/* applies to render pipeline */ -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out)) -{ - TexCallData *cdata = (TexCallData *)data; - TexResult *target = cdata->target; - - if(cdata->do_preview) { - TexParams params; - params_from_cdata(¶ms, cdata); - - if(in[1] && in[1]->hasinput && !in[0]->hasinput) - tex_input_rgba(&target->tr, in[1], ¶ms, cdata->thread); - else - tex_input_rgba(&target->tr, in[0], ¶ms, cdata->thread); - tex_do_preview(node, params.co, &target->tr); - } - else { - /* 0 means don't care, so just use first */ - if(cdata->which_output == node->custom1 || (cdata->which_output == 0 && node->custom1 == 1)) { - TexParams params; - params_from_cdata(¶ms, cdata); - - tex_input_rgba(&target->tr, in[0], ¶ms, cdata->thread); - - target->tin = (target->tr + target->tg + target->tb) / 3.0f; - target->talpha = 1; - - if(target->nor) { - if(in[1] && in[1]->hasinput) - tex_input_vec(target->nor, in[1], ¶ms, cdata->thread); - else - target->nor = NULL; - } - } - } -} - -static void unique_name(bNode *node) -{ - TexNodeOutput *tno = (TexNodeOutput *)node->storage; - char *new_name = NULL; - int new_len = 0; - int suffix; - bNode *i; - char *name = tno->name; - - i = node; - while(i->prev) i = i->prev; - for(; i; i=i->next) { - if( - i == node || - i->type != TEX_NODE_OUTPUT || - strcmp(name, ((TexNodeOutput*)(i->storage))->name) - ) - continue; - - if(!new_name) { - int len = strlen(name); - if(len >= 4 && sscanf(name + len - 4, ".%03d", &suffix) == 1) { - new_len = len; - } else { - suffix = 0; - new_len = len + 4; - if(new_len > 31) - new_len = 31; - } - - new_name = MEM_mallocN(new_len + 1, "new_name"); - strcpy(new_name, name); - name = new_name; - } - sprintf(new_name + new_len - 4, ".%03d", ++suffix); - } - - if(new_name) { - strcpy(tno->name, new_name); - MEM_freeN(new_name); - } -} - -static void assign_index(struct bNode *node) -{ - bNode *tnode; - int index = 1; - - tnode = node; - while(tnode->prev) - tnode = tnode->prev; - - check_index: - for(; tnode; tnode= tnode->next) - if(tnode->type == TEX_NODE_OUTPUT && tnode != node) - if(tnode->custom1 == index) { - index ++; - goto check_index; - } - - node->custom1 = index; -} - -static void init(bNode *node) -{ - TexNodeOutput *tno = MEM_callocN(sizeof(TexNodeOutput), "TEX_output"); - node->storage= tno; - - strcpy(tno->name, "Default"); - unique_name(node); - assign_index(node); -} - -static void copy(bNode *orig, bNode *new) -{ - node_copy_standard_storage(orig, new); - unique_name(new); - assign_index(new); -} - -void register_node_type_tex_output(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_OUTPUT, "Output", NODE_CLASS_OUTPUT, NODE_PREVIEW|NODE_OPTIONS, - inputs, NULL); - node_type_size(&ntype, 150, 60, 200); - node_type_init(&ntype, init); - node_type_storage(&ntype, "TexNodeOutput", node_free_standard_storage, copy); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_proc.c b/source/blender/nodes/intern/TEX_nodes/TEX_proc.c deleted file mode 100644 index 294c1f7322f..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_proc.c +++ /dev/null @@ -1,325 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_proc.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - -#include "RE_shader_ext.h" - -/* - In this file: wrappers to use procedural textures as nodes -*/ - - -static bNodeSocketType outputs_both[]= { - { SOCK_RGBA, 0, "Color", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { SOCK_VECTOR, 0, "Normal", 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; -static bNodeSocketType outputs_color_only[]= { - { SOCK_RGBA, 0, "Color", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; - -/* Inputs common to all, #defined because nodes will need their own inputs too */ -#define I 2 /* count */ -#define COMMON_INPUTS \ - { SOCK_RGBA, 1, "Color 1", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, \ - { SOCK_RGBA, 1, "Color 2", 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f } - -/* Calls multitex and copies the result to the outputs. Called by xxx_exec, which handles inputs. */ -static void do_proc(float *result, TexParams *p, float *col1, float *col2, char is_normal, Tex *tex, short thread) -{ - TexResult texres; - int textype; - - if(is_normal) { - texres.nor = result; - } - else - texres.nor = NULL; - - textype = multitex_nodes(tex, p->co, p->dxt, p->dyt, p->osatex, - &texres, thread, 0, p->shi, p->mtex); - - if(is_normal) - return; - - if(textype & TEX_RGB) { - QUATCOPY(result, &texres.tr); - } - else { - QUATCOPY(result, col1); - ramp_blend(MA_RAMP_BLEND, result, result+1, result+2, texres.tin, col2); - } -} - -typedef void (*MapFn) (Tex *tex, bNodeStack **in, TexParams *p, short thread); - -static void texfn( - float *result, - TexParams *p, - bNode *node, - bNodeStack **in, - char is_normal, - MapFn map_inputs, - short thread) -{ - Tex tex = *((Tex*)(node->storage)); - float col1[4], col2[4]; - tex_input_rgba(col1, in[0], p, thread); - tex_input_rgba(col2, in[1], p, thread); - - map_inputs(&tex, in, p, thread); - - do_proc(result, p, col1, col2, is_normal, &tex, thread); -} - -static int count_outputs(bNode *node) -{ - bNodeSocket *sock; - int num = 0; - for(sock= node->outputs.first; sock; sock= sock->next) { - num++; - } - return num; -} - -/* Boilerplate generators */ - -#define ProcNoInputs(name) \ - static void name##_map_inputs(Tex *UNUSED(tex), bNodeStack **UNUSED(in), TexParams *UNUSED(p), short UNUSED(thread)) \ - {} - -#define ProcDef(name) \ - static void name##_colorfn(float *result, TexParams *p, bNode *node, bNodeStack **in, short thread) \ - { \ - texfn(result, p, node, in, 0, &name##_map_inputs, thread); \ - } \ - static void name##_normalfn(float *result, TexParams *p, bNode *node, bNodeStack **in, short thread) \ - { \ - texfn(result, p, node, in, 1, &name##_map_inputs, thread); \ - } \ - static void name##_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) \ - { \ - int outs = count_outputs(node); \ - if(outs >= 1) tex_output(node, in, out[0], &name##_colorfn, data); \ - if(outs >= 2) tex_output(node, in, out[1], &name##_normalfn, data); \ - } - - -/* --- VORONOI -- */ -static bNodeSocketType voronoi_inputs[]= { - COMMON_INPUTS, - { SOCK_VALUE, 1, "W1", 1.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f }, - { SOCK_VALUE, 1, "W2", 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f }, - { SOCK_VALUE, 1, "W3", 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f }, - { SOCK_VALUE, 1, "W4", 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f }, - - { SOCK_VALUE, 1, "iScale", 1.0f, 0.0f, 0.0f, 0.0f, 0.01f, 10.0f }, - { SOCK_VALUE, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 4.0f }, - - { -1, 0, "" } -}; -static void voronoi_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) -{ - tex->vn_w1 = tex_input_value(in[I+0], p, thread); - tex->vn_w2 = tex_input_value(in[I+1], p, thread); - tex->vn_w3 = tex_input_value(in[I+2], p, thread); - tex->vn_w4 = tex_input_value(in[I+3], p, thread); - - tex->ns_outscale = tex_input_value(in[I+4], p, thread); - tex->noisesize = tex_input_value(in[I+5], p, thread); -} -ProcDef(voronoi) - -/* --- BLEND -- */ -static bNodeSocketType blend_inputs[]= { - COMMON_INPUTS, - { -1, 0, "" } -}; -ProcNoInputs(blend) -ProcDef(blend) - -/* -- MAGIC -- */ -static bNodeSocketType magic_inputs[]= { - COMMON_INPUTS, - { SOCK_VALUE, 1, "Turbulence", 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f }, - { -1, 0, "" } -}; -static void magic_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) -{ - tex->turbul = tex_input_value(in[I+0], p, thread); -} -ProcDef(magic) - -/* --- MARBLE --- */ -static bNodeSocketType marble_inputs[]= { - COMMON_INPUTS, - { SOCK_VALUE, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f }, - { SOCK_VALUE, 1, "Turbulence", 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f }, - { -1, 0, "" } -}; -static void marble_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) -{ - tex->noisesize = tex_input_value(in[I+0], p, thread); - tex->turbul = tex_input_value(in[I+1], p, thread); -} -ProcDef(marble) - -/* --- CLOUDS --- */ -static bNodeSocketType clouds_inputs[]= { - COMMON_INPUTS, - { SOCK_VALUE, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f }, - { -1, 0, "" } -}; -static void clouds_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) -{ - tex->noisesize = tex_input_value(in[I+0], p, thread); -} -ProcDef(clouds) - -/* --- DISTORTED NOISE --- */ -static bNodeSocketType distnoise_inputs[]= { - COMMON_INPUTS, - { SOCK_VALUE, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f }, - { SOCK_VALUE, 1, "Distortion", 1.00f, 0.0f, 0.0f, 0.0f, 0.0000f, 10.0f }, - { -1, 0, "" } -}; -static void distnoise_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) -{ - tex->noisesize = tex_input_value(in[I+0], p, thread); - tex->dist_amount = tex_input_value(in[I+1], p, thread); -} -ProcDef(distnoise) - -/* --- WOOD --- */ -static bNodeSocketType wood_inputs[]= { - COMMON_INPUTS, - { SOCK_VALUE, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f }, - { SOCK_VALUE, 1, "Turbulence", 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f }, - { -1, 0, "" } -}; -static void wood_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) -{ - tex->noisesize = tex_input_value(in[I+0], p, thread); - tex->turbul = tex_input_value(in[I+1], p, thread); -} -ProcDef(wood) - -/* --- MUSGRAVE --- */ -static bNodeSocketType musgrave_inputs[]= { - COMMON_INPUTS, - { SOCK_VALUE, 1, "H", 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f }, - { SOCK_VALUE, 1, "Lacunarity", 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 6.0f }, - { SOCK_VALUE, 1, "Octaves", 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 8.0f }, - - { SOCK_VALUE, 1, "iScale", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f }, - { SOCK_VALUE, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f }, - { -1, 0, "" } -}; -static void musgrave_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) -{ - tex->mg_H = tex_input_value(in[I+0], p, thread); - tex->mg_lacunarity = tex_input_value(in[I+1], p, thread); - tex->mg_octaves = tex_input_value(in[I+2], p, thread); - tex->ns_outscale = tex_input_value(in[I+3], p, thread); - tex->noisesize = tex_input_value(in[I+4], p, thread); -} -ProcDef(musgrave) - -/* --- NOISE --- */ -static bNodeSocketType noise_inputs[]= { - COMMON_INPUTS, - { -1, 0, "" } -}; -ProcNoInputs(noise) -ProcDef(noise) - -/* --- STUCCI --- */ -static bNodeSocketType stucci_inputs[]= { - COMMON_INPUTS, - { SOCK_VALUE, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f }, - { SOCK_VALUE, 1, "Turbulence", 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f }, - { -1, 0, "" } -}; -static void stucci_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) -{ - tex->noisesize = tex_input_value(in[I+0], p, thread); - tex->turbul = tex_input_value(in[I+1], p, thread); -} -ProcDef(stucci) - -/* --- */ - -static void init(bNode *node) -{ - Tex *tex = MEM_callocN(sizeof(Tex), "Tex"); - node->storage= tex; - - default_tex(tex); - tex->type = node->type - TEX_NODE_PROC; - - if(tex->type == TEX_WOOD) - tex->stype = TEX_BANDNOISE; - -} - -/* Node type definitions */ -#define TexDef(TEXTYPE, outputs, name, Name) \ -void register_node_type_tex_proc_##name(ListBase *lb) \ -{ \ - static bNodeType ntype; \ - \ - node_type_base(&ntype, TEX_NODE_PROC+TEXTYPE, Name, NODE_CLASS_TEXTURE, NODE_PREVIEW|NODE_OPTIONS, name##_inputs, outputs); \ - node_type_size(&ntype, 140, 80, 140); \ - node_type_init(&ntype, init); \ - node_type_storage(&ntype, "Tex", node_free_standard_storage, node_copy_standard_storage); \ - node_type_exec(&ntype, name##_exec); \ - \ - nodeRegisterType(lb, &ntype); \ -} - -#define C outputs_color_only -#define CV outputs_both - -TexDef(TEX_VORONOI, CV, voronoi, "Voronoi" ) -TexDef(TEX_BLEND, C, blend, "Blend" ) -TexDef(TEX_MAGIC, C, magic, "Magic" ) -TexDef(TEX_MARBLE, CV, marble, "Marble" ) -TexDef(TEX_CLOUDS, CV, clouds, "Clouds" ) -TexDef(TEX_WOOD, CV, wood, "Wood" ) -TexDef(TEX_MUSGRAVE, CV, musgrave, "Musgrave" ) -TexDef(TEX_NOISE, C, noise, "Noise" ) -TexDef(TEX_STUCCI, CV, stucci, "Stucci" ) -TexDef(TEX_DISTNOISE, CV, distnoise, "Distorted Noise" ) diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c b/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c deleted file mode 100644 index 1be6152a2b3..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_rotate.c - * \ingroup texnodes - */ - - -#include <math.h> - -#include "../TEX_util.h" -#include "TEX_node.h" - -static bNodeSocketType inputs[]= { - { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VALUE, 1, "Turns", 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f }, - { SOCK_VECTOR, 1, "Axis", 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f }, - { -1, 0, "" } -}; - -static bNodeSocketType outputs[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void rotate(float new_co[3], float a, float ax[3], float co[3]) -{ - float para[3]; - float perp[3]; - float cp[3]; - - float cos_a = cos(a * (float)(2*M_PI)); - float sin_a = sin(a * (float)(2*M_PI)); - - // x' = xcosa + n(n.x)(1-cosa) + (x*n)sina - - mul_v3_v3fl(perp, co, cos_a); - mul_v3_v3fl(para, ax, dot_v3v3(co, ax)*(1 - cos_a)); - - cross_v3_v3v3(cp, ax, co); - mul_v3_fl(cp, sin_a); - - new_co[0] = para[0] + perp[0] + cp[0]; - new_co[1] = para[1] + perp[1] + cp[1]; - new_co[2] = para[2] + perp[2] + cp[2]; -} - -static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) -{ - float new_co[3], new_dxt[3], new_dyt[3], a, ax[3]; - - a= tex_input_value(in[1], p, thread); - tex_input_vec(ax, in[2], p, thread); - - rotate(new_co, a, ax, p->co); - if (p->osatex) { - rotate(new_dxt, a, ax, p->dxt); - rotate(new_dyt, a, ax, p->dyt); - } - - { - TexParams np = *p; - np.co = new_co; - np.dxt = new_dxt; - np.dyt = new_dyt; - tex_input_rgba(out, in[0], &np, thread); - } -} -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &colorfn, data); -} - -void register_node_type_tex_rotate(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_ROTATE, "Rotate", NODE_CLASS_DISTORT, NODE_OPTIONS, - inputs, outputs); - node_type_size(&ntype, 140, 100, 320); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_scale.c b/source/blender/nodes/intern/TEX_nodes/TEX_scale.c deleted file mode 100644 index cfffcfda2e5..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_scale.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_scale.c - * \ingroup texnodes - */ - - -#include <math.h> -#include "../TEX_util.h" - -static bNodeSocketType inputs[]= { - { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { SOCK_VECTOR, 1, "Scale", 1.0f, 1.0f, 1.0f, 0.0f, -10.0f, 10.0f }, - { -1, 0, "" } -}; - -static bNodeSocketType outputs[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) -{ - float scale[3], new_co[3], new_dxt[3], new_dyt[3]; - TexParams np = *p; - - np.co = new_co; - np.dxt = new_dxt; - np.dyt = new_dyt; - - tex_input_vec(scale, in[1], p, thread); - - mul_v3_v3v3(new_co, p->co, scale); - if (p->osatex) { - mul_v3_v3v3(new_dxt, p->dxt, scale); - mul_v3_v3v3(new_dyt, p->dyt, scale); - } - - tex_input_rgba(out, in[0], &np, thread); -} -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &colorfn, data); -} - -void register_node_type_tex_scale(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_SCALE, "Scale", NODE_CLASS_DISTORT, NODE_OPTIONS, - inputs, outputs); - node_type_size(&ntype, 90, 80, 100); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_texture.c b/source/blender/nodes/intern/TEX_nodes/TEX_texture.c deleted file mode 100644 index c58595866af..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_texture.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_texture.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - -#include "RE_shader_ext.h" - -static bNodeSocketType inputs[]= { - { SOCK_RGBA, 1, "Color1", 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f }, - { SOCK_RGBA, 1, "Color2", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; - -static bNodeSocketType outputs[]= { - { SOCK_RGBA, 0, "Color", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; - -static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) -{ - Tex *nodetex = (Tex *)node->id; - static float red[] = {1,0,0,1}; - static float white[] = {1,1,1,1}; - float co[3], dxt[3], dyt[3]; - - copy_v3_v3(co, p->co); - copy_v3_v3(dxt, p->dxt); - copy_v3_v3(dyt, p->dyt); - - if(node->custom2 || node->need_exec==0) { - /* this node refers to its own texture tree! */ - QUATCOPY(out, (fabs(co[0] - co[1]) < .01) ? white : red ); - } - else if(nodetex) { - TexResult texres; - int textype; - float nor[] = {0,0,0}; - float col1[4], col2[4]; - - tex_input_rgba(col1, in[0], p, thread); - tex_input_rgba(col2, in[1], p, thread); - - texres.nor = nor; - textype = multitex_nodes(nodetex, co, dxt, dyt, p->osatex, - &texres, thread, 0, p->shi, p->mtex); - - if(textype & TEX_RGB) { - QUATCOPY(out, &texres.tr); - } - else { - QUATCOPY(out, col1); - ramp_blend(MA_RAMP_BLEND, out, out+1, out+2, texres.tin, col2); - } - } -} - -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &colorfn, data); -} - -void register_node_type_tex_texture(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT, NODE_PREVIEW|NODE_OPTIONS, - inputs, outputs); - node_type_size(&ntype, 120, 80, 240); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_translate.c b/source/blender/nodes/intern/TEX_nodes/TEX_translate.c deleted file mode 100644 index 8f7d6d837d7..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_translate.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_translate.c - * \ingroup texnodes - */ - - -#include <math.h> -#include "../TEX_util.h" -#include "TEX_node.h" - -static bNodeSocketType inputs[]= { - { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 1, "Offset", 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f }, - { -1, 0, "" } -}; - -static bNodeSocketType outputs[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) -{ - float offset[3], new_co[3]; - TexParams np = *p; - np.co = new_co; - - tex_input_vec(offset, in[1], p, thread); - - new_co[0] = p->co[0] + offset[0]; - new_co[1] = p->co[1] + offset[1]; - new_co[2] = p->co[2] + offset[2]; - - tex_input_rgba(out, in[0], &np, thread); -} -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &colorfn, data); -} - -void register_node_type_tex_translate(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_TRANSLATE, "Translate", NODE_CLASS_DISTORT, NODE_OPTIONS, - inputs, outputs); - node_type_size(&ntype, 90, 80, 100); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_valToNor.c b/source/blender/nodes/intern/TEX_nodes/TEX_valToNor.c deleted file mode 100644 index e430c0c9a95..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_valToNor.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Jucas. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_valToNor.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - -static bNodeSocketType inputs[]= { - { SOCK_VALUE, 1, "Val", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { SOCK_VALUE, 1, "Nabla", 0.025f, 0.0f, 0.0f, 0.0f, 0.001f, 0.1f }, - { -1, 0, "" } -}; - -static bNodeSocketType outputs[]= { - { SOCK_VECTOR, 0, "Normal", 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; - -static void normalfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) -{ - float new_co[3]; - float *co = p->co; - - float nabla = tex_input_value(in[1], p, thread); - float val; - float nor[3]; - - TexParams np = *p; - np.co = new_co; - - val = tex_input_value(in[0], p, thread); - - new_co[0] = co[0] + nabla; - new_co[1] = co[1]; - new_co[2] = co[2]; - nor[0] = tex_input_value(in[0], &np, thread); - - new_co[0] = co[0]; - new_co[1] = co[1] + nabla; - nor[1] = tex_input_value(in[0], &np, thread); - - new_co[1] = co[1]; - new_co[2] = co[2] + nabla; - nor[2] = tex_input_value(in[0], &np, thread); - - out[0] = val-nor[0]; - out[1] = val-nor[1]; - out[2] = val-nor[2]; -} -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &normalfn, data); -} - -void register_node_type_tex_valtonor(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_VALTONOR, "Value to Normal", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - inputs, outputs); - node_type_size(&ntype, 90, 80, 100); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_valToRgb.c b/source/blender/nodes/intern/TEX_nodes/TEX_valToRgb.c deleted file mode 100644 index 8f59828081c..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_valToRgb.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * $Id$ - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_valToRgb.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" - -/* **************** VALTORGB ******************** */ -static bNodeSocketType valtorgb_in[]= { - { SOCK_VALUE, 1, "Fac", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType valtorgb_out[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void valtorgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) -{ - if(node->storage) { - float fac = tex_input_value(in[0], p, thread); - - do_colorband(node->storage, fac, out); - } -} - -static void valtorgb_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &valtorgb_colorfn, data); -} - -static void valtorgb_init(bNode *node) -{ - node->storage = add_colorband(1); -} - -void register_node_type_tex_valtorgb(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, NODE_OPTIONS, - valtorgb_in, valtorgb_out); - node_type_size(&ntype, 240, 200, 300); - node_type_init(&ntype, valtorgb_init); - node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, valtorgb_exec); - - nodeRegisterType(lb, &ntype); -} - -/* **************** RGBTOBW ******************** */ -static bNodeSocketType rgbtobw_in[]= { - { SOCK_RGBA, 1, "Color", 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketType rgbtobw_out[]= { - { SOCK_VALUE, 0, "Val", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - - -static void rgbtobw_valuefn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) -{ - float cin[4]; - tex_input_rgba(cin, in[0], p, thread); - - *out = cin[0] * 0.35f + cin[1] * 0.45f + cin[2] * 0.2f; -} - -static void rgbtobw_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - tex_output(node, in, out[0], &rgbtobw_valuefn, data); -} - -void register_node_type_tex_rgbtobw(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0, - rgbtobw_in, rgbtobw_out); - node_type_size(&ntype, 80, 40, 120); - node_type_exec(&ntype, rgbtobw_exec); - - nodeRegisterType(lb, &ntype); -} - diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_viewer.c b/source/blender/nodes/intern/TEX_nodes/TEX_viewer.c deleted file mode 100644 index e917e525e17..00000000000 --- a/source/blender/nodes/intern/TEX_nodes/TEX_viewer.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Robin Allen - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/intern/TEX_nodes/TEX_viewer.c - * \ingroup texnodes - */ - - -#include "../TEX_util.h" -#include "TEX_node.h" -#include <math.h> - -static bNodeSocketType inputs[]= { - { SOCK_RGBA, 1, "Color", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, - { -1, 0, "" } -}; -static bNodeSocketType outputs[]= { - { -1, 0, "" } -}; - -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out)) -{ - TexCallData *cdata = (TexCallData *)data; - - if(cdata->do_preview) { - TexParams params; - float col[4]; - params_from_cdata(¶ms, cdata); - - tex_input_rgba(col, in[0], ¶ms, cdata->thread); - tex_do_preview(node, params.previewco, col); - } -} - -void register_node_type_tex_viewer(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, TEX_NODE_VIEWER, "Viewer", NODE_CLASS_OUTPUT, NODE_PREVIEW, - inputs, outputs); - node_type_size(&ntype, 100, 60, 150); - node_type_exec(&ntype, exec); - - nodeRegisterType(lb, &ntype); -} diff --git a/source/blender/nodes/intern/TEX_util.c b/source/blender/nodes/intern/TEX_util.c deleted file mode 100644 index b5e27ca2ccb..00000000000 --- a/source/blender/nodes/intern/TEX_util.c +++ /dev/null @@ -1,214 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/TEX_util.c - * \ingroup nodes - */ - - -/* - HOW TEXTURE NODES WORK - - In contrast to Shader nodes, which place a color into the output - stack when executed, Texture nodes place a TexDelegate* there. To - obtain a color value from this, a node further up the chain reads - the TexDelegate* from its input stack, and uses tex_call_delegate to - retrieve the color from the delegate. - - comments: (ton) - - This system needs recode, a node system should rely on the stack, and - callbacks for nodes only should evaluate own node, not recursively go - over other previous ones. -*/ - -#include <assert.h> -#include "TEX_util.h" - -#define PREV_RES 128 /* default preview resolution */ - -void tex_call_delegate(TexDelegate *dg, float *out, TexParams *params, short thread) -{ - if(dg->node->need_exec) { - dg->fn(out, params, dg->node, dg->in, thread); - - if(dg->cdata->do_preview) - tex_do_preview(dg->node, params->previewco, out); - } -} - -static void tex_input(float *out, int sz, bNodeStack *in, TexParams *params, short thread) -{ - TexDelegate *dg = in->data; - if(dg) { - tex_call_delegate(dg, in->vec, params, thread); - - if(in->hasoutput && in->sockettype == SOCK_VALUE) - in->vec[1] = in->vec[2] = in->vec[0]; - } - memcpy(out, in->vec, sz * sizeof(float)); -} - -void tex_input_vec(float *out, bNodeStack *in, TexParams *params, short thread) -{ - tex_input(out, 3, in, params, thread); -} - -void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread) -{ - tex_input(out, 4, in, params, thread); - - if(in->hasoutput && in->sockettype == SOCK_VALUE) - { - out[1] = out[2] = out[0]; - out[3] = 1; - } - - if(in->hasoutput && in->sockettype == SOCK_VECTOR) { - out[0] = out[0] * .5f + .5f; - out[1] = out[1] * .5f + .5f; - out[2] = out[2] * .5f + .5f; - out[3] = 1; - } -} - -float tex_input_value(bNodeStack *in, TexParams *params, short thread) -{ - float out[4]; - tex_input_vec(out, in, params, thread); - return out[0]; -} - -void params_from_cdata(TexParams *out, TexCallData *in) -{ - out->co = in->co; - out->dxt = in->dxt; - out->dyt = in->dyt; - out->previewco = in->co; - out->osatex = in->osatex; - out->cfra = in->cfra; - out->shi = in->shi; - out->mtex = in->mtex; -} - -void tex_do_preview(bNode *node, float *co, float *col) -{ - bNodePreview *preview= node->preview; - - if(preview) { - int xs= ((co[0] + 1.0f)*0.5f)*preview->xsize; - int ys= ((co[1] + 1.0f)*0.5f)*preview->ysize; - - nodeAddToPreview(node, col, xs, ys, 0); /* 0 = no color management */ - } -} - -void tex_output(bNode *node, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata) -{ - TexDelegate *dg; - if(!out->data) - /* Freed in tex_end_exec (node.c) */ - dg = out->data = MEM_mallocN(sizeof(TexDelegate), "tex delegate"); - else - dg = out->data; - - dg->cdata= cdata; - dg->fn = texfn; - dg->node = node; - memcpy(dg->in, in, MAX_SOCKET * sizeof(bNodeStack*)); - dg->type = out->sockettype; -} - -void ntreeTexCheckCyclics(struct bNodeTree *ntree) -{ - bNode *node; - for(node= ntree->nodes.first; node; node= node->next) { - - if(node->type == TEX_NODE_TEXTURE && node->id) - { - /* custom2 stops the node from rendering */ - if(node->custom1) { - node->custom2 = 1; - node->custom1 = 0; - } else { - Tex *tex = (Tex *)node->id; - - node->custom2 = 0; - - node->custom1 = 1; - if(tex->use_nodes && tex->nodetree) { - ntreeTexCheckCyclics(tex->nodetree); - } - node->custom1 = 0; - } - } - - } -} - -int ntreeTexExecTree( - bNodeTree *nodes, - TexResult *texres, - float *co, - float *dxt, float *dyt, - int osatex, - short thread, - Tex *UNUSED(tex), - short which_output, - int cfra, - int preview, - ShadeInput *shi, - MTex *mtex -){ - TexCallData data; - float *nor= texres->nor; - int retval = TEX_INT; - - data.co = co; - data.dxt = dxt; - data.dyt = dyt; - data.osatex = osatex; - data.target = texres; - data.do_preview = preview; - data.thread = thread; - data.which_output = which_output; - data.cfra= cfra; - data.mtex= mtex; - data.shi= shi; - - ntreeExecTree(nodes, &data, thread); - - if(texres->nor) retval |= TEX_NOR; - retval |= TEX_RGB; - /* confusing stuff; the texture output node sets this to NULL to indicate no normal socket was set - however, the texture code checks this for other reasons (namely, a normal is required for material) */ - texres->nor= nor; - - return retval; -} - diff --git a/source/blender/nodes/intern/TEX_util.h b/source/blender/nodes/intern/TEX_util.h deleted file mode 100644 index 0875bcd52bf..00000000000 --- a/source/blender/nodes/intern/TEX_util.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * - * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ***** - */ - -/** \file blender/nodes/intern/TEX_util.h - * \ingroup nodes - */ - - -#ifndef TEX_NODE_UTIL_H_ -#define TEX_NODE_UTIL_H_ - -#include <math.h> -#include <string.h> - -#include "MEM_guardedalloc.h" - -#include "DNA_color_types.h" -#include "DNA_ipo_types.h" -#include "DNA_ID.h" -#include "DNA_image_types.h" -#include "DNA_material_types.h" -#include "DNA_node_types.h" -#include "DNA_object_types.h" -#include "DNA_scene_types.h" -#include "DNA_texture_types.h" - -#include "BKE_blender.h" -#include "BKE_colortools.h" -#include "BKE_global.h" -#include "BKE_image.h" -#include "BKE_main.h" -#include "BKE_material.h" -#include "BKE_node.h" -#include "BKE_texture.h" - -#include "BKE_library.h" - -#include "../SHD_node.h" -#include "node_util.h" - -#include "BLI_math.h" -#include "BLI_blenlib.h" -#include "BLI_rand.h" -#include "BLI_threads.h" -#include "BLI_utildefines.h" - -#include "IMB_imbuf_types.h" -#include "IMB_imbuf.h" - -#include "RE_pipeline.h" -#include "RE_shader_ext.h" - -typedef struct TexCallData { - TexResult *target; - float *co; - float *dxt, *dyt; - int osatex; - char do_preview; - short thread; - short which_output; - int cfra; - - ShadeInput *shi; - MTex *mtex; -} TexCallData; - -typedef struct TexParams { - float *co; - float *dxt, *dyt; - float *previewco; - int cfra; - int osatex; - - /* optional. we don't really want these here, but image - textures need to do mapping & color correction */ - ShadeInput *shi; - MTex *mtex; -} TexParams; - -typedef void(*TexFn) (float *out, TexParams *params, bNode *node, bNodeStack **in, short thread); - -typedef struct TexDelegate { - TexCallData *cdata; - TexFn fn; - bNode *node; - bNodeStack *in[MAX_SOCKET]; - int type; -} TexDelegate; - -void tex_call_delegate(TexDelegate*, float *out, TexParams *params, short thread); - -void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread); -void tex_input_vec(float *out, bNodeStack *in, TexParams *params, short thread); -float tex_input_value(bNodeStack *in, TexParams *params, short thread); - -void tex_output(bNode *node, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *data); -void tex_do_preview(bNode *node, float *coord, float *col); - -void params_from_cdata(TexParams *out, TexCallData *in); - -#endif diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c new file mode 100644 index 00000000000..76203c52293 --- /dev/null +++ b/source/blender/nodes/intern/node_common.c @@ -0,0 +1,982 @@ +/** + * + * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2007 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Lukas Toenne. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/nodes/intern/node_common.c + * \ingroup nodes + */ + + +#include <string.h> + +#include "DNA_action_types.h" +#include "DNA_anim_types.h" +#include "DNA_node_types.h" + +#include "BLI_listbase.h" +#include "BLI_string.h" +#include "BLI_utildefines.h" + +#include "BKE_action.h" +#include "BKE_animsys.h" +#include "BKE_global.h" +#include "BKE_library.h" +#include "BKE_main.h" +#include "BLI_math.h" +#include "BKE_node.h" +#include "BKE_utildefines.h" + +#include "RNA_access.h" +#include "RNA_types.h" + +#include "MEM_guardedalloc.h" + +#include "node_common.h" +#include "node_exec.h" +#include "NOD_socket.h" + +/**** Group ****/ + +bNodeSocket *node_group_find_input(bNode *gnode, bNodeSocket *gsock) +{ + bNodeSocket *sock; + for (sock=gnode->inputs.first; sock; sock=sock->next) + if (sock->groupsock == gsock) + return sock; + return NULL; +} + +bNodeSocket *node_group_find_output(bNode *gnode, bNodeSocket *gsock) +{ + bNodeSocket *sock; + for (sock=gnode->outputs.first; sock; sock=sock->next) + if (sock->groupsock == gsock) + return sock; + return NULL; +} + +bNodeSocket *node_group_add_extern_socket(bNodeTree *UNUSED(ntree), ListBase *lb, int in_out, bNodeSocket *gsock) +{ + bNodeSocket *sock; + + if (gsock->flag & SOCK_INTERNAL) + return NULL; + + sock= MEM_callocN(sizeof(bNodeSocket), "sock"); + + /* make a copy of the group socket */ + *sock = *gsock; + sock->link = NULL; + sock->next = sock->prev = NULL; + sock->new_sock = NULL; + + /* group sockets are dynamically added */ + sock->flag |= SOCK_DYNAMIC; + + sock->own_index = gsock->own_index; + sock->groupsock = gsock; + sock->limit = (in_out==SOCK_IN ? 1 : 0xFFF); + + if (gsock->default_value) + sock->default_value = MEM_dupallocN(gsock->default_value); + + if(lb) + BLI_addtail(lb, sock); + + return sock; +} + +bNode *node_group_make_from_selected(bNodeTree *ntree) +{ + bNodeLink *link, *linkn; + bNode *node, *gnode, *nextn; + bNodeTree *ngroup; + bNodeSocket *gsock; + ListBase anim_basepaths = {NULL, NULL}; + float min[2], max[2]; + int totnode=0; + bNodeTemplate ntemp; + + INIT_MINMAX2(min, max); + + /* is there something to group? also do some clearing */ + for(node= ntree->nodes.first; node; node= node->next) { + if(node->flag & NODE_SELECT) { + /* no groups in groups */ + if(node->type==NODE_GROUP) + return NULL; + DO_MINMAX2( (&node->locx), min, max); + totnode++; + } + node->done= 0; + } + if(totnode==0) return NULL; + + /* check if all connections are OK, no unselected node has both + inputs and outputs to a selection */ + for(link= ntree->links.first; link; link= link->next) { + if(link->fromnode && link->tonode && link->fromnode->flag & NODE_SELECT) + link->tonode->done |= 1; + if(link->fromnode && link->tonode && link->tonode->flag & NODE_SELECT) + link->fromnode->done |= 2; + } + + for(node= ntree->nodes.first; node; node= node->next) { + if((node->flag & NODE_SELECT)==0) + if(node->done==3) + break; + } + if(node) + return NULL; + + /* OK! new nodetree */ + ngroup= ntreeAddTree("NodeGroup", ntree->type, NODE_GROUP); + + /* move nodes over */ + for(node= ntree->nodes.first; node; node= nextn) { + nextn= node->next; + if(node->flag & NODE_SELECT) { + /* keep track of this node's RNA "base" path (the part of the pat identifying the node) + * if the old nodetree has animation data which potentially covers this node + */ + if (ntree->adt) { + PointerRNA ptr; + char *path; + + RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); + path = RNA_path_from_ID_to_struct(&ptr); + + if (path) + BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); + } + + /* change node-collection membership */ + BLI_remlink(&ntree->nodes, node); + BLI_addtail(&ngroup->nodes, node); + + node->locx-= 0.5f*(min[0]+max[0]); + node->locy-= 0.5f*(min[1]+max[1]); + } + } + + /* move animation data over */ + if (ntree->adt) { + LinkData *ld, *ldn=NULL; + + BKE_animdata_separate_by_basepath(&ntree->id, &ngroup->id, &anim_basepaths); + + /* paths + their wrappers need to be freed */ + for (ld = anim_basepaths.first; ld; ld = ldn) { + ldn = ld->next; + + MEM_freeN(ld->data); + BLI_freelinkN(&anim_basepaths, ld); + } + } + + /* make group node */ + ntemp.type = NODE_GROUP; + ntemp.ngroup = ngroup; + gnode= nodeAddNode(ntree, &ntemp); + gnode->locx= 0.5f*(min[0]+max[0]); + gnode->locy= 0.5f*(min[1]+max[1]); + + /* relink external sockets */ + for(link= ntree->links.first; link; link= linkn) { + linkn= link->next; + + if(link->fromnode && link->tonode && (link->fromnode->flag & link->tonode->flag & NODE_SELECT)) { + BLI_remlink(&ntree->links, link); + BLI_addtail(&ngroup->links, link); + } + else if(link->tonode && (link->tonode->flag & NODE_SELECT)) { + gsock = node_group_expose_socket(ngroup, link->tosock, SOCK_IN); + link->tosock->link = nodeAddLink(ngroup, NULL, gsock, link->tonode, link->tosock); + link->tosock = node_group_add_extern_socket(ntree, &gnode->inputs, SOCK_IN, gsock); + link->tonode = gnode; + } + else if(link->fromnode && (link->fromnode->flag & NODE_SELECT)) { + /* search for existing group node socket */ + for (gsock=ngroup->outputs.first; gsock; gsock=gsock->next) + if (gsock->link && gsock->link->fromsock==link->fromsock) + break; + if (!gsock) { + gsock = node_group_expose_socket(ngroup, link->fromsock, SOCK_OUT); + gsock->link = nodeAddLink(ngroup, link->fromnode, link->fromsock, NULL, gsock); + link->fromsock = node_group_add_extern_socket(ntree, &gnode->outputs, SOCK_OUT, gsock); + } + else + link->fromsock = node_group_find_output(gnode, gsock); + link->fromnode = gnode; + } + } + + ngroup->update |= NTREE_UPDATE; + ntreeUpdateTree(ngroup); + ntree->update |= NTREE_UPDATE_NODES|NTREE_UPDATE_LINKS; + ntreeUpdateTree(ntree); + + return gnode; +} + +/* XXX This is a makeshift function to have useful initial group socket values. + * In the end this should be implemented by a flexible socket data conversion system, + * which is yet to be implemented. The idea is that beside default standard conversions, + * such as int-to-float, it should be possible to quickly select a conversion method or + * a chain of conversions for each input, whenever there is more than one option. + * E.g. a vector-to-float conversion could use either of the x/y/z components or + * the vector length. + * + * In the interface this could be implemented by a pseudo-script textbox on linked inputs, + * with quick selection from a predefined list of conversion options. Some Examples: + * - vector component 'z' (vector->float): "z" + * - greyscale color (float->color): "grey" + * - color luminance (color->float): "lum" + * - matrix column 2 length (matrix->vector->float): "col[1].len" + * - mesh vertex coordinate 'y' (mesh->vertex->vector->float): "vertex.co.y" + * + * The actual conversion is then done by a series of conversion functions, + * which are defined in the socket type structs. + */ +static void convert_socket_value(bNodeSocket *from, bNodeSocket *to) +{ + /* XXX only one of these pointers is valid! just putting them here for convenience */ + bNodeSocketValueFloat *fromfloat= (bNodeSocketValueFloat*)from->default_value; + bNodeSocketValueInt *fromint= (bNodeSocketValueInt*)from->default_value; + bNodeSocketValueBoolean *frombool= (bNodeSocketValueBoolean*)from->default_value; + bNodeSocketValueVector *fromvector= (bNodeSocketValueVector*)from->default_value; + bNodeSocketValueRGBA *fromrgba= (bNodeSocketValueRGBA*)from->default_value; + + bNodeSocketValueFloat *tofloat= (bNodeSocketValueFloat*)to->default_value; + bNodeSocketValueInt *toint= (bNodeSocketValueInt*)to->default_value; + bNodeSocketValueBoolean *tobool= (bNodeSocketValueBoolean*)to->default_value; + bNodeSocketValueVector *tovector= (bNodeSocketValueVector*)to->default_value; + bNodeSocketValueRGBA *torgba= (bNodeSocketValueRGBA*)to->default_value; + + switch (from->type) { + case SOCK_FLOAT: + switch (to->type) { + case SOCK_FLOAT: + tofloat->value = fromfloat->value; + break; + case SOCK_INT: + toint->value = (int)fromfloat->value; + break; + case SOCK_BOOLEAN: + tobool->value = (fromfloat->value > 0.0f); + break; + case SOCK_VECTOR: + tovector->value[0] = tovector->value[1] = tovector->value[2] = fromfloat->value; + break; + case SOCK_RGBA: + torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = fromfloat->value; + break; + } + break; + case SOCK_INT: + switch (to->type) { + case SOCK_FLOAT: + tofloat->value = (float)fromint->value; + break; + case SOCK_INT: + toint->value = fromint->value; + break; + case SOCK_BOOLEAN: + tobool->value = (fromint->value > 0); + break; + case SOCK_VECTOR: + tovector->value[0] = tovector->value[1] = tovector->value[2] = (float)fromint->value; + break; + case SOCK_RGBA: + torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = (float)fromint->value; + break; + } + break; + case SOCK_BOOLEAN: + switch (to->type) { + case SOCK_FLOAT: + tofloat->value = (float)frombool->value; + break; + case SOCK_INT: + toint->value = (int)frombool->value; + break; + case SOCK_BOOLEAN: + tobool->value = frombool->value; + break; + case SOCK_VECTOR: + tovector->value[0] = tovector->value[1] = tovector->value[2] = (float)frombool->value; + break; + case SOCK_RGBA: + torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = (float)frombool->value; + break; + } + break; + case SOCK_VECTOR: + switch (to->type) { + case SOCK_FLOAT: + tofloat->value = fromvector->value[0]; + break; + case SOCK_INT: + toint->value = (int)fromvector->value[0]; + break; + case SOCK_BOOLEAN: + tobool->value = (fromvector->value[0] > 0.0f); + break; + case SOCK_VECTOR: + copy_v3_v3(tovector->value, fromvector->value); + break; + case SOCK_RGBA: + copy_v3_v3(torgba->value, fromvector->value); + torgba->value[3] = 1.0f; + break; + } + break; + case SOCK_RGBA: + switch (to->type) { + case SOCK_FLOAT: + tofloat->value = fromrgba->value[0]; + break; + case SOCK_INT: + toint->value = (int)fromrgba->value[0]; + break; + case SOCK_BOOLEAN: + tobool->value = (fromrgba->value[0] > 0.0f); + break; + case SOCK_VECTOR: + copy_v3_v3(tovector->value, fromrgba->value); + break; + case SOCK_RGBA: + copy_v4_v4(torgba->value, fromrgba->value); + break; + } + break; + } +} + +static void copy_socket_value(bNodeSocket *from, bNodeSocket *to) +{ + /* XXX only one of these pointers is valid! just putting them here for convenience */ + bNodeSocketValueFloat *fromfloat= (bNodeSocketValueFloat*)from->default_value; + bNodeSocketValueInt *fromint= (bNodeSocketValueInt*)from->default_value; + bNodeSocketValueBoolean *frombool= (bNodeSocketValueBoolean*)from->default_value; + bNodeSocketValueVector *fromvector= (bNodeSocketValueVector*)from->default_value; + bNodeSocketValueRGBA *fromrgba= (bNodeSocketValueRGBA*)from->default_value; + + bNodeSocketValueFloat *tofloat= (bNodeSocketValueFloat*)to->default_value; + bNodeSocketValueInt *toint= (bNodeSocketValueInt*)to->default_value; + bNodeSocketValueBoolean *tobool= (bNodeSocketValueBoolean*)to->default_value; + bNodeSocketValueVector *tovector= (bNodeSocketValueVector*)to->default_value; + bNodeSocketValueRGBA *torgba= (bNodeSocketValueRGBA*)to->default_value; + + if (from->type != to->type) + return; + + switch (from->type) { + case SOCK_FLOAT: + *tofloat = *fromfloat; + break; + case SOCK_INT: + *toint = *fromint; + break; + case SOCK_BOOLEAN: + *tobool = *frombool; + break; + case SOCK_VECTOR: + *tovector = *fromvector; + break; + case SOCK_RGBA: + *torgba = *fromrgba; + break; + } +} + +/* returns 1 if its OK */ +int node_group_ungroup(bNodeTree *ntree, bNode *gnode) +{ + bNodeLink *link, *linkn; + bNode *node, *nextn; + bNodeTree *ngroup, *wgroup; + ListBase anim_basepaths = {NULL, NULL}; + + ngroup= (bNodeTree *)gnode->id; + if(ngroup==NULL) return 0; + + /* clear new pointers, set in copytree */ + for(node= ntree->nodes.first; node; node= node->next) + node->new_node= NULL; + + /* wgroup is a temporary copy of the NodeTree we're merging in + * - all of wgroup's nodes are transferred across to their new home + * - ngroup (i.e. the source NodeTree) is left unscathed + */ + wgroup= ntreeCopyTree(ngroup); + + /* add the nodes into the ntree */ + for(node= wgroup->nodes.first; node; node= nextn) { + nextn= node->next; + + /* keep track of this node's RNA "base" path (the part of the pat identifying the node) + * if the old nodetree has animation data which potentially covers this node + */ + if (wgroup->adt) { + PointerRNA ptr; + char *path; + + RNA_pointer_create(&wgroup->id, &RNA_Node, node, &ptr); + path = RNA_path_from_ID_to_struct(&ptr); + + if (path) + BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); + } + + /* migrate node */ + BLI_remlink(&wgroup->nodes, node); + BLI_addtail(&ntree->nodes, node); + + node->locx+= gnode->locx; + node->locy+= gnode->locy; + + node->flag |= NODE_SELECT; + } + + /* restore external links to and from the gnode */ + for(link= ntree->links.first; link; link= link->next) { + if (link->fromnode==gnode) { + if (link->fromsock->groupsock) { + bNodeSocket *gsock= link->fromsock->groupsock; + if (gsock->link) { + if (gsock->link->fromnode) { + /* NB: using the new internal copies here! the groupsock pointer still maps to the old tree */ + link->fromnode = (gsock->link->fromnode ? gsock->link->fromnode->new_node : NULL); + link->fromsock = gsock->link->fromsock->new_sock; + } + else { + /* group output directly maps to group input */ + bNodeSocket *insock= node_group_find_input(gnode, gsock->link->fromsock); + if (insock->link) { + link->fromnode = insock->link->fromnode; + link->fromsock = insock->link->fromsock; + } + } + } + else { + /* copy the default input value from the group socket default to the external socket */ + convert_socket_value(gsock, link->tosock); + } + } + } + } + /* remove internal output links, these are not used anymore */ + for(link=wgroup->links.first; link; link= linkn) { + linkn = link->next; + if (!link->tonode) + nodeRemLink(wgroup, link); + } + /* restore links from internal nodes */ + for(link= wgroup->links.first; link; link= link->next) { + /* indicates link to group input */ + if (!link->fromnode) { + /* NB: can't use find_group_node_input here, + * because gnode sockets still point to the old tree! + */ + bNodeSocket *insock; + for (insock= gnode->inputs.first; insock; insock= insock->next) + if (insock->groupsock->new_sock == link->fromsock) + break; + if (insock->link) { + link->fromnode = insock->link->fromnode; + link->fromsock = insock->link->fromsock; + } + else { + /* copy the default input value from the group node socket default to the internal socket */ + convert_socket_value(insock, link->tosock); + nodeRemLink(wgroup, link); + } + } + } + + /* add internal links to the ntree */ + for(link= wgroup->links.first; link; link= linkn) { + linkn= link->next; + BLI_remlink(&wgroup->links, link); + BLI_addtail(&ntree->links, link); + } + + /* and copy across the animation */ + if (wgroup->adt) { + LinkData *ld, *ldn=NULL; + bAction *waction; + + /* firstly, wgroup needs to temporary dummy action that can be destroyed, as it shares copies */ + waction = wgroup->adt->action = copy_action(wgroup->adt->action); + + /* now perform the moving */ + BKE_animdata_separate_by_basepath(&wgroup->id, &ntree->id, &anim_basepaths); + + /* paths + their wrappers need to be freed */ + for (ld = anim_basepaths.first; ld; ld = ldn) { + ldn = ld->next; + + MEM_freeN(ld->data); + BLI_freelinkN(&anim_basepaths, ld); + } + + /* free temp action too */ + free_libblock(&G.main->action, waction); + } + + /* delete the group instance. this also removes old input links! */ + nodeFreeNode(ntree, gnode); + + /* free the group tree (takes care of user count) */ + free_libblock(&G.main->nodetree, wgroup); + + ntree->update |= NTREE_UPDATE_NODES|NTREE_UPDATE_LINKS; + ntreeUpdateTree(ntree); + + return 1; +} + +bNodeSocket *node_group_add_socket(bNodeTree *ngroup, const char *name, int type, int in_out) +{ + bNodeSocketType *stype = ntreeGetSocketType(type); + bNodeSocket *gsock = MEM_callocN(sizeof(bNodeSocket), "bNodeSocket"); + + strncpy(gsock->name, name, sizeof(gsock->name)); + gsock->type = type; + /* group sockets are dynamically added */ + gsock->flag |= SOCK_DYNAMIC; + + gsock->next = gsock->prev = NULL; + gsock->new_sock = NULL; + gsock->link = NULL; + /* assign new unique index */ + gsock->own_index = ngroup->cur_index++; + gsock->limit = (in_out==SOCK_IN ? 0xFFF : 1); + + if (stype->value_structsize > 0) + gsock->default_value = MEM_callocN(stype->value_structsize, "default socket value"); + + BLI_addtail(in_out==SOCK_IN ? &ngroup->inputs : &ngroup->outputs, gsock); + + ngroup->update |= (in_out==SOCK_IN ? NTREE_UPDATE_GROUP_IN : NTREE_UPDATE_GROUP_OUT); + + return gsock; +} + +bNodeSocket *node_group_expose_socket(bNodeTree *ngroup, bNodeSocket *sock, int in_out) +{ + bNodeSocket *gsock= node_group_add_socket(ngroup, sock->name, sock->type, in_out); + + /* initialize the default value. */ + copy_socket_value(sock, gsock); + + return gsock; +} + +void node_group_expose_all_sockets(bNodeTree *ngroup) +{ + bNode *node; + bNodeSocket *sock, *gsock; + + for (node=ngroup->nodes.first; node; node=node->next) { + for (sock=node->inputs.first; sock; sock=sock->next) { + if (!sock->link && !(sock->flag & SOCK_HIDDEN)) { + gsock = node_group_add_socket(ngroup, sock->name, sock->type, SOCK_IN); + + /* initialize the default value. */ + copy_socket_value(sock, gsock); + + sock->link = nodeAddLink(ngroup, NULL, gsock, node, sock); + } + } + for (sock=node->outputs.first; sock; sock=sock->next) { + if (nodeCountSocketLinks(ngroup, sock)==0 && !(sock->flag & SOCK_HIDDEN)) { + gsock = node_group_add_socket(ngroup, sock->name, sock->type, SOCK_OUT); + + /* initialize the default value. */ + copy_socket_value(sock, gsock); + + gsock->link = nodeAddLink(ngroup, node, sock, NULL, gsock); + } + } + } +} + +void node_group_remove_socket(bNodeTree *ngroup, bNodeSocket *gsock, int in_out) +{ + nodeRemSocketLinks(ngroup, gsock); + + switch (in_out) { + case SOCK_IN: + BLI_remlink(&ngroup->inputs, gsock); + ngroup->update |= NTREE_UPDATE_GROUP_IN; + break; + case SOCK_OUT: + BLI_remlink(&ngroup->outputs, gsock); + ngroup->update |= NTREE_UPDATE_GROUP_OUT; + break; + } + + if (gsock->default_value) + MEM_freeN(gsock->default_value); + + MEM_freeN(gsock); +} + +/* groups display their internal tree name as label */ +const char *node_group_label(bNode *node) +{ + return (node->id)? node->id->name+2: "Missing Datablock"; +} + +int node_group_valid(bNodeTree *ntree, bNodeTemplate *ntemp) +{ + bNodeTemplate childtemp; + bNode *node; + + /* regular groups cannot be recursive */ + if (ntree == ntemp->ngroup) + return 0; + + /* make sure all children are valid */ + for (node=ntemp->ngroup->nodes.first; node; node=node->next) { + childtemp = nodeMakeTemplate(node); + if (!nodeValid(ntree, &childtemp)) + return 0; + } + + return 1; +} + +bNodeTemplate node_group_template(bNode *node) +{ + bNodeTemplate ntemp; + ntemp.type = NODE_GROUP; + ntemp.ngroup = (bNodeTree*)node->id; + return ntemp; +} + +void node_group_init(bNodeTree *ntree, bNode *node, bNodeTemplate *ntemp) +{ + node->id = (ID*)ntemp->ngroup; + + /* NB: group socket input/output roles are inverted internally! + * Group "inputs" work as outputs in links and vice versa. + */ + if (ntemp->ngroup) { + bNodeSocket *gsock; + for (gsock=ntemp->ngroup->inputs.first; gsock; gsock=gsock->next) + node_group_add_extern_socket(ntree, &node->inputs, SOCK_IN, gsock); + for (gsock=ntemp->ngroup->outputs.first; gsock; gsock=gsock->next) + node_group_add_extern_socket(ntree, &node->outputs, SOCK_OUT, gsock); + } +} + +static bNodeSocket *group_verify_socket(bNodeTree *ntree, ListBase *lb, int in_out, bNodeSocket *gsock) +{ + bNodeSocket *sock; + + /* group sockets tagged as internal are not exposed ever */ + if (gsock->flag & SOCK_INTERNAL) + return NULL; + + for(sock= lb->first; sock; sock= sock->next) { + if(sock->own_index==gsock->own_index) + break; + } + if(sock) { + sock->groupsock = gsock; + + strcpy(sock->name, gsock->name); + sock->type= gsock->type; + + /* XXX hack: group socket input/output roles are inverted internally, + * need to change the limit value when making actual node sockets from them. + */ + sock->limit = (in_out==SOCK_IN ? 1 : 0xFFF); + + BLI_remlink(lb, sock); + + return sock; + } + else { + return node_group_add_extern_socket(ntree, NULL, in_out, gsock); + } +} + +static void group_verify_socket_list(bNodeTree *ntree, bNode *node, ListBase *lb, int in_out, ListBase *glb) +{ + bNodeSocket *sock, *nextsock, *gsock; + + /* step by step compare */ + for (gsock= glb->first; gsock; gsock=gsock->next) { + /* abusing new_sock pointer for verification here! only used inside this function */ + gsock->new_sock= group_verify_socket(ntree, lb, in_out, gsock); + } + /* leftovers are removed */ + for (sock=lb->first; sock; sock=nextsock) { + nextsock=sock->next; + if (sock->flag & SOCK_DYNAMIC) + nodeRemoveSocket(ntree, node, sock); + } + /* and we put back the verified sockets */ + for (gsock= glb->first; gsock; gsock=gsock->next) { + if (gsock->new_sock) { + BLI_addtail(lb, gsock->new_sock); + gsock->new_sock = NULL; + } + } +} + +/* make sure all group node in ntree, which use ngroup, are sync'd */ +void node_group_verify(struct bNodeTree *ntree, struct bNode *node, struct ID *id) +{ + /* check inputs and outputs, and remove or insert them */ + if (node->id==id) { + bNodeTree *ngroup= (bNodeTree*)node->id; + group_verify_socket_list(ntree, node, &node->inputs, SOCK_IN, &ngroup->inputs); + group_verify_socket_list(ntree, node, &node->outputs, SOCK_OUT, &ngroup->outputs); + } +} + +struct bNodeTree *node_group_edit_get(bNode *node) +{ + if (node->flag & NODE_GROUP_EDIT) + return (bNodeTree*)node->id; + else + return NULL; +} + +struct bNodeTree *node_group_edit_set(bNode *node, int edit) +{ + if (edit) { + bNodeTree *ngroup= (bNodeTree*)node->id; + if (ngroup) { + if(ngroup->id.lib) + ntreeMakeLocal(ngroup); + + node->flag |= NODE_GROUP_EDIT; + } + return ngroup; + } + else { + node->flag &= ~NODE_GROUP_EDIT; + return NULL; + } +} + +void node_group_edit_clear(bNode *node) +{ + bNodeTree *ngroup= (bNodeTree*)node->id; + bNode *inode; + + node->flag &= ~NODE_GROUP_EDIT; + + if (ngroup) + for (inode=ngroup->nodes.first; inode; inode=inode->next) + nodeGroupEditClear(inode); +} + +void node_group_link(bNodeTree *ntree, bNodeSocket *sock, int in_out) +{ + node_group_expose_socket(ntree, sock, in_out); +} + +/**** For Loop ****/ + +/* Essentially a group node with slightly different behavior. + * The internal tree is executed several times, with each output being re-used + * as an input in the next iteration. For this purpose, input and output socket + * lists are kept identical! + */ + +bNodeTemplate node_forloop_template(bNode *node) +{ + bNodeTemplate ntemp; + ntemp.type = NODE_FORLOOP; + ntemp.ngroup = (bNodeTree*)node->id; + return ntemp; +} + +void node_forloop_init(bNodeTree *ntree, bNode *node, bNodeTemplate *ntemp) +{ + bNodeSocket *sock; + + node->id = (ID*)ntemp->ngroup; + + sock = nodeAddInputFloat(ntree, node, "Iterations", PROP_UNSIGNED, 1, 0, 10000); + + /* NB: group socket input/output roles are inverted internally! + * Group "inputs" work as outputs in links and vice versa. + */ + if (ntemp->ngroup) { + bNodeSocket *gsock; + for (gsock=ntemp->ngroup->inputs.first; gsock; gsock=gsock->next) + node_group_add_extern_socket(ntree, &node->inputs, SOCK_IN, gsock); + for (gsock=ntemp->ngroup->outputs.first; gsock; gsock=gsock->next) + node_group_add_extern_socket(ntree, &node->outputs, SOCK_OUT, gsock); + } +} + +void node_forloop_init_tree(bNodeTree *ntree) +{ + bNodeSocket *sock; + sock = node_group_add_socket(ntree, "Iteration", SOCK_FLOAT, SOCK_IN); + sock->flag |= SOCK_INTERNAL; +} + +static void loop_sync(bNodeTree *ntree, int sync_in_out) +{ + bNodeSocket *sock, *sync, *nsync, *mirror; + ListBase *sync_lb; + + if (sync_in_out==SOCK_IN) { + sock = ntree->outputs.first; + + sync = ntree->inputs.first; + sync_lb = &ntree->inputs; + } + else { + sock = ntree->inputs.first; + + sync = ntree->outputs.first; + sync_lb = &ntree->outputs; + } + + /* NB: the sock->storage pointer is used here directly to store the own_index int + * out the mirrored socket counterpart! + */ + + while (sock) { + /* skip static and internal sockets on the sync side (preserves socket order!) */ + while (sync && ((sync->flag & SOCK_INTERNAL) || !(sync->flag & SOCK_DYNAMIC))) + sync = sync->next; + + if (!(sync->flag & SOCK_INTERNAL) && (sync->flag & SOCK_DYNAMIC)) { + if (sock->storage==NULL) { + /* if mirror index is 0, the sockets is newly added and a new mirror must be created. */ + mirror = node_group_expose_socket(ntree, sock, sync_in_out); + /* store the mirror index */ + sock->storage = SET_INT_IN_POINTER(mirror->own_index); + mirror->storage = SET_INT_IN_POINTER(sock->own_index); + /* move mirror to the right place */ + BLI_remlink(sync_lb, mirror); + if (sync) + BLI_insertlinkbefore(sync_lb, sync, mirror); + else + BLI_addtail(sync_lb, mirror); + } + else { + /* look up the mirror socket */ + for (mirror=sync; mirror; mirror=mirror->next) + if (mirror->own_index == GET_INT_FROM_POINTER(sock->storage)) + break; + /* make sure the name is the same (only for identification by user, no deeper meaning) */ + strcpy(mirror->name, sock->name); + /* fix the socket order if necessary */ + if (mirror != sync) { + BLI_remlink(sync_lb, mirror); + BLI_insertlinkbefore(sync_lb, sync, mirror); + } + else + sync = sync->next; + } + } + + sock = sock->next; + } + + /* remaining sockets in sync_lb are leftovers from deleted sockets, remove them */ + while (sync) { + nsync = sync->next; + if (!(sync->flag & SOCK_INTERNAL) && (sync->flag & SOCK_DYNAMIC)) + node_group_remove_socket(ntree, sync, sync_in_out); + sync = nsync; + } +} + +void node_loop_update_tree(bNodeTree *ngroup) +{ + /* make sure inputs & outputs are identical */ + if (ngroup->update & NTREE_UPDATE_GROUP_IN) + loop_sync(ngroup, SOCK_OUT); + if (ngroup->update & NTREE_UPDATE_GROUP_OUT) + loop_sync(ngroup, SOCK_IN); +} + +void node_whileloop_init(bNodeTree *ntree, bNode *node, bNodeTemplate *ntemp) +{ + bNodeSocket *sock; + + node->id = (ID*)ntemp->ngroup; + + sock = nodeAddInputFloat(ntree, node, "Condition", PROP_NONE, 1, 0, 1); + + /* max iterations */ + node->custom1 = 10000; + + /* NB: group socket input/output roles are inverted internally! + * Group "inputs" work as outputs in links and vice versa. + */ + if (ntemp->ngroup) { + bNodeSocket *gsock; + for (gsock=ntemp->ngroup->inputs.first; gsock; gsock=gsock->next) + node_group_add_extern_socket(ntree, &node->inputs, SOCK_IN, gsock); + for (gsock=ntemp->ngroup->outputs.first; gsock; gsock=gsock->next) + node_group_add_extern_socket(ntree, &node->outputs, SOCK_OUT, gsock); + } +} + +void node_whileloop_init_tree(bNodeTree *ntree) +{ + bNodeSocket *sock; + sock = node_group_add_socket(ntree, "Condition", SOCK_FLOAT, SOCK_OUT); + sock->flag |= SOCK_INTERNAL; +} + +bNodeTemplate node_whileloop_template(bNode *node) +{ + bNodeTemplate ntemp; + ntemp.type = NODE_WHILELOOP; + ntemp.ngroup = (bNodeTree*)node->id; + return ntemp; +} + +/**** FRAME ****/ + +void register_node_type_frame(ListBase *lb) +{ + /* frame type is used for all tree types, needs dynamic allocation */ + bNodeType *ntype= MEM_callocN(sizeof(bNodeType), "frame node type"); + + node_type_base(ntype, NODE_FRAME, "Frame", NODE_CLASS_LAYOUT, NODE_BACKGROUND); + node_type_size(ntype, 150, 100, 0); + + ntype->needs_free = 1; + nodeRegisterType(lb, ntype); +} diff --git a/source/blender/nodes/intern/node_common.h b/source/blender/nodes/intern/node_common.h new file mode 100644 index 00000000000..31a13d8168d --- /dev/null +++ b/source/blender/nodes/intern/node_common.h @@ -0,0 +1,65 @@ +/** + * + * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2007 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Lukas Toenne. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/nodes/intern/node_common.h + * \ingroup nodes + */ + + +#ifndef NODE_COMMON_H_ +#define NODE_COMMON_H_ + +#include "DNA_listBase.h" + +struct bNodeTree; + +struct bNodeSocket *node_group_add_extern_socket(struct bNodeTree *ntree, ListBase *lb, int in_out, struct bNodeSocket *gsock); + +void node_group_init(struct bNodeTree *ntree, struct bNode *node, struct bNodeTemplate *ntemp); +void node_forloop_init(struct bNodeTree *ntree, struct bNode *node, struct bNodeTemplate *ntemp); +void node_whileloop_init(struct bNodeTree *ntree, struct bNode *node, struct bNodeTemplate *ntemp); + +void node_forloop_init_tree(struct bNodeTree *ntree); +void node_whileloop_init_tree(struct bNodeTree *ntree); + +const char *node_group_label(struct bNode *node); + +struct bNodeTemplate node_group_template(struct bNode *node); +struct bNodeTemplate node_forloop_template(struct bNode *node); +struct bNodeTemplate node_whileloop_template(struct bNode *node); + +int node_group_valid(struct bNodeTree *ntree, struct bNodeTemplate *ntemp); +void node_group_verify(struct bNodeTree *ntree, struct bNode *node, struct ID *id); + +struct bNodeTree *node_group_edit_get(struct bNode *node); +struct bNodeTree *node_group_edit_set(struct bNode *node, int edit); +void node_group_edit_clear(bNode *node); + +void node_loop_update_tree(struct bNodeTree *ngroup); + +#endif diff --git a/source/blender/nodes/intern/node_exec.c b/source/blender/nodes/intern/node_exec.c new file mode 100644 index 00000000000..0d688438cf9 --- /dev/null +++ b/source/blender/nodes/intern/node_exec.c @@ -0,0 +1,308 @@ +/** + * + * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2007 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Nathan Letwory. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/nodes/intern/node_exec.c + * \ingroup nodes + */ + + +#include "DNA_node_types.h" + +#include "BLI_listbase.h" +#include "BLI_math.h" +#include "BLI_utildefines.h" + +#include "BKE_node.h" + +#include "MEM_guardedalloc.h" + +#include "node_exec.h" + + +/* for a given socket, find the actual stack entry */ +bNodeStack *node_get_socket_stack(bNodeStack *stack, bNodeSocket *sock) +{ + return stack + sock->stack_index; +} + +void node_get_stack(bNode *node, bNodeStack *stack, bNodeStack **in, bNodeStack **out) +{ + bNodeSocket *sock; + + /* build pointer stack */ + if (in) { + for(sock= node->inputs.first; sock; sock= sock->next) { + *(in++) = node_get_socket_stack(stack, sock); + } + } + + if (out) { + for(sock= node->outputs.first; sock; sock= sock->next) { + *(out++) = node_get_socket_stack(stack, sock); + } + } +} + +void node_init_input_index(bNodeSocket *sock, int *index) +{ + if (sock->link && sock->link->fromsock) { + sock->stack_index = sock->link->fromsock->stack_index; + } + else { + sock->stack_index = (*index)++; + } +} + +void node_init_output_index(bNodeSocket *sock, int *index) +{ + sock->stack_index = (*index)++; +} + +/* basic preparation of socket stacks */ +static struct bNodeStack *setup_stack(bNodeStack *stack, bNodeSocket *sock) +{ + bNodeStack *ns = node_get_socket_stack(stack, sock); + float null_value[4]= {0.0f, 0.0f, 0.0f, 0.0f}; + + /* don't mess with remote socket stacks, these are initialized by other nodes! */ + if (sock->link) + return ns; + + ns->sockettype = sock->type; + + if (sock->default_value) { + switch (sock->type) { + case SOCK_FLOAT: + ns->vec[0] = ((bNodeSocketValueFloat*)sock->default_value)->value; + break; + case SOCK_VECTOR: + copy_v3_v3(ns->vec, ((bNodeSocketValueVector*)sock->default_value)->value); + break; + case SOCK_RGBA: + copy_v4_v4(ns->vec, ((bNodeSocketValueRGBA*)sock->default_value)->value); + break; + } + } + else { + switch (sock->type) { + case SOCK_FLOAT: + ns->vec[0] = 0.0f; + break; + case SOCK_VECTOR: + copy_v3_v3(ns->vec, null_value); + break; + case SOCK_RGBA: + copy_v4_v4(ns->vec, null_value); + break; + } + } + + return ns; +} + +bNodeTreeExec *ntree_exec_begin(bNodeTree *ntree) +{ + bNodeTreeExec *exec; + bNode *node; + bNodeExec *nodeexec; + bNodeSocket *sock, *gsock; + bNodeStack *ns; + int index= 0; + bNode **nodelist; + int totnodes, n; + + if((ntree->init & NTREE_TYPE_INIT)==0) + ntreeInitTypes(ntree); + + /* get a dependency-sorted list of nodes */ + ntreeGetDependencyList(ntree, &nodelist, &totnodes); + + /* XXX could let callbacks do this for specialized data */ + exec = MEM_callocN(sizeof(bNodeTreeExec), "node tree execution data"); + /* backpointer to node tree */ + exec->nodetree = ntree; + + /* group inputs essentially work as outputs */ + for(gsock=ntree->inputs.first; gsock; gsock = gsock->next) + node_init_output_index(gsock, &index); + /* set stack indexes */ + for(n=0; n < totnodes; ++n) { + node = nodelist[n]; + + node->stack_index = index; + + /* init node socket stack indexes */ + for (sock=node->inputs.first; sock; sock=sock->next) + node_init_input_index(sock, &index); + for (sock=node->outputs.first; sock; sock=sock->next) + node_init_output_index(sock, &index); + } + /* group outputs essentially work as inputs */ + for(gsock=ntree->outputs.first; gsock; gsock = gsock->next) + node_init_input_index(gsock, &index); + + /* allocated exec data pointers for nodes */ + exec->totnodes = totnodes; + exec->nodeexec = MEM_callocN(exec->totnodes * sizeof(bNodeExec), "node execution data"); + /* allocate data pointer for node stack */ + exec->stacksize = index; + exec->stack = MEM_callocN(exec->stacksize * sizeof(bNodeStack), "bNodeStack"); + + /* prepare group tree inputs */ + for (sock=ntree->inputs.first; sock; sock=sock->next) { + ns = setup_stack(exec->stack, sock); + if (ns->hasoutput) + ns->hasinput = 1; + } + /* prepare all internal nodes for execution */ + for(n=0, nodeexec= exec->nodeexec; n < totnodes; ++n, ++nodeexec) { + node = nodeexec->node = nodelist[n]; + + /* tag inputs */ + for (sock=node->inputs.first; sock; sock=sock->next) { + /* disable the node if an input link is invalid */ + if(sock->link && !(sock->link->flag & NODE_LINK_VALID)) + node->need_exec= 0; + + ns = setup_stack(exec->stack, sock); + if (ns->hasoutput) + ns->hasinput = 1; + } + + /* tag all outputs */ + for (sock=node->outputs.first; sock; sock=sock->next) { + ns = setup_stack(exec->stack, sock); + ns->hasoutput = 1; + } + + if(node->typeinfo->initexecfunc) + nodeexec->data = node->typeinfo->initexecfunc(node); + } + /* prepare group tree outputs */ + for (sock=ntree->outputs.first; sock; sock=sock->next) { + ns = setup_stack(exec->stack, sock); + ns->hasoutput = 1; + } + + if (nodelist) + MEM_freeN(nodelist); + + return exec; +} + +void ntree_exec_end(bNodeTreeExec *exec) +{ + bNodeExec *nodeexec; + int n; + + if (exec->stack) + MEM_freeN(exec->stack); + + for(n=0, nodeexec= exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) { + if (nodeexec->node->typeinfo->freeexecfunc) + nodeexec->node->typeinfo->freeexecfunc(nodeexec->node, nodeexec->data); + } + + if (exec->nodeexec) + MEM_freeN(exec->nodeexec); + + MEM_freeN(exec); +} + +/**** Compositor/Material/Texture trees ****/ + +bNodeThreadStack *ntreeGetThreadStack(bNodeTreeExec *exec, int thread) +{ + ListBase *lb= &exec->threadstack[thread]; + bNodeThreadStack *nts; + + for(nts=lb->first; nts; nts=nts->next) { + if(!nts->used) { + nts->used= 1; + break; + } + } + + if (!nts) { + nts= MEM_callocN(sizeof(bNodeThreadStack), "bNodeThreadStack"); + nts->stack= MEM_dupallocN(exec->stack); + nts->used= 1; + BLI_addtail(lb, nts); + } + + return nts; +} + +void ntreeReleaseThreadStack(bNodeThreadStack *nts) +{ + nts->used = 0; +} + +void ntreeExecNodes(bNodeTreeExec *exec, void *callerdata, int thread) +{ + bNodeStack *nsin[MAX_SOCKET]; /* arbitrary... watch this */ + bNodeStack *nsout[MAX_SOCKET]; /* arbitrary... watch this */ + bNodeExec *nodeexec; + bNode *node; + int n; + + /* nodes are presorted, so exec is in order of list */ + + for(n=0, nodeexec= exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) { + node = nodeexec->node; + if(node->need_exec) { + node_get_stack(node, exec->stack, nsin, nsout); + if(node->typeinfo->execfunc) + node->typeinfo->execfunc(callerdata, node, nsin, nsout); + else if (node->typeinfo->newexecfunc) + node->typeinfo->newexecfunc(callerdata, thread, node, nodeexec->data, nsin, nsout); + } + } +} + +void ntreeExecThreadNodes(bNodeTreeExec *exec, bNodeThreadStack *nts, void *callerdata, int thread) +{ + bNodeStack *nsin[MAX_SOCKET]; /* arbitrary... watch this */ + bNodeStack *nsout[MAX_SOCKET]; /* arbitrary... watch this */ + bNodeExec *nodeexec; + bNode *node; + int n; + + /* nodes are presorted, so exec is in order of list */ + + for(n=0, nodeexec= exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) { + node = nodeexec->node; + if(node->need_exec) { + node_get_stack(node, nts->stack, nsin, nsout); + if(node->typeinfo->execfunc) + node->typeinfo->execfunc(callerdata, node, nsin, nsout); + else if (node->typeinfo->newexecfunc) + node->typeinfo->newexecfunc(callerdata, thread, node, nodeexec->data, nsin, nsout); + } + } +} diff --git a/source/blender/nodes/intern/node_exec.h b/source/blender/nodes/intern/node_exec.h new file mode 100644 index 00000000000..457e119613b --- /dev/null +++ b/source/blender/nodes/intern/node_exec.h @@ -0,0 +1,89 @@ +/** + * + * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2007 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Nathan Letwory. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/nodes/intern/node_exec.h + * \ingroup nodes + */ + + +#ifndef NODE_EXEC_H_ +#define NODE_EXEC_H_ + +#include "DNA_listBase.h" + +#include "BLI_utildefines.h" + +#include "BKE_node.h" + +#include "RNA_types.h" + +struct bNodeTree; +struct bNode; +struct bNodeStack; + +/* Node execution data */ +typedef struct bNodeExec { + struct bNode *node; /* backpointer to node */ + void *data; /* custom data storage */ +} bNodeExec; + +/* Execution Data for each instance of node tree execution */ +typedef struct bNodeTreeExec { + struct bNodeTree *nodetree; /* backpointer to node tree */ + + int totnodes; /* total node count */ + struct bNodeExec *nodeexec; /* per-node execution data */ + + int stacksize; + struct bNodeStack *stack; /* socket data stack */ + /* only used by material and texture trees to keep one stack for each thread */ + ListBase *threadstack; /* one instance of the stack for each thread */ +} bNodeTreeExec; + +/* stores one stack copy for each thread (material and texture trees) */ +typedef struct bNodeThreadStack { + struct bNodeThreadStack *next, *prev; + struct bNodeStack *stack; + int used; +} bNodeThreadStack; + +struct bNodeStack *node_get_socket_stack(struct bNodeStack *stack, struct bNodeSocket *sock); +void node_get_stack(struct bNode *node, struct bNodeStack *stack, struct bNodeStack **in, struct bNodeStack **out); +void node_init_input_index(struct bNodeSocket *sock, int *index); +void node_init_output_index(struct bNodeSocket *sock, int *index); + +struct bNodeTreeExec *ntree_exec_begin(struct bNodeTree *ntree); +void ntree_exec_end(struct bNodeTreeExec *exec); + +void ntreeExecNodes(struct bNodeTreeExec *exec, void *callerdata, int thread); + +struct bNodeThreadStack *ntreeGetThreadStack(struct bNodeTreeExec *exec, int thread); +void ntreeReleaseThreadStack(struct bNodeThreadStack *nts); +void ntreeExecThreadNodes(struct bNodeTreeExec *exec, struct bNodeThreadStack *nts, void *callerdata, int thread); + +#endif diff --git a/source/blender/nodes/intern/node_socket.c b/source/blender/nodes/intern/node_socket.c new file mode 100644 index 00000000000..ef8b3e797ce --- /dev/null +++ b/source/blender/nodes/intern/node_socket.c @@ -0,0 +1,428 @@ +/** + * + * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2007 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Lukas Toennne + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/nodes/intern/node_socket.c + * \ingroup nodes + */ + + +#include "DNA_node_types.h" + +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" + +#include "BLI_listbase.h" +#include "BLI_math.h" +#include "BLI_utildefines.h" + +#include "BKE_DerivedMesh.h" +#include "BKE_node.h" + +#include "RNA_access.h" +#include "RNA_types.h" + +#include "MEM_guardedalloc.h" + +#include "NOD_socket.h" + +/****************** FLOAT ******************/ + +static bNodeSocketType node_socket_type_float = { + /* type */ SOCK_FLOAT, + /* ui_name */ "Float", + /* ui_description */ "Floating Point", + /* ui_icon */ 0, + /* ui_color */ {160,160,160,255}, + + /* value_structname */ "bNodeSocketValueFloat", + /* value_structsize */ sizeof(bNodeSocketValueFloat), + + /* buttonfunc */ NULL, +}; + +/****************** VECTOR ******************/ + +static bNodeSocketType node_socket_type_vector = { + /* type */ SOCK_VECTOR, + /* ui_name */ "Vector", + /* ui_description */ "3-dimensional floating point vector", + /* ui_icon */ 0, + /* ui_color */ {100,100,200,255}, + + /* value_structname */ "bNodeSocketValueVector", + /* value_structsize */ sizeof(bNodeSocketValueVector), + + /* buttonfunc */ NULL, +}; + +/****************** RGBA ******************/ + +static bNodeSocketType node_socket_type_rgba = { + /* type */ SOCK_RGBA, + /* ui_name */ "RGBA", + /* ui_description */ "RGBA color", + /* ui_icon */ 0, + /* ui_color */ {200,200,40,255}, + + /* value_structname */ "bNodeSocketValueRGBA", + /* value_structsize */ sizeof(bNodeSocketValueRGBA), + + /* buttonfunc */ NULL, +}; + +/****************** INT ******************/ + +static bNodeSocketType node_socket_type_int = { + /* type */ SOCK_INT, + /* ui_name */ "Int", + /* ui_description */ "Integer", + /* ui_icon */ 0, + /* ui_color */ {17,133,37,255}, + + /* value_structname */ "bNodeSocketValueInt", + /* value_structsize */ sizeof(bNodeSocketValueInt), + + /* buttonfunc */ NULL, +}; + +/****************** BOOLEAN ******************/ + +static bNodeSocketType node_socket_type_boolean = { + /* type */ SOCK_BOOLEAN, + /* ui_name */ "Boolean", + /* ui_description */ "Boolean", + /* ui_icon */ 0, + /* ui_color */ {158,139,63,255}, + + /* value_structname */ "bNodeSocketValueBoolean", + /* value_structsize */ sizeof(bNodeSocketValueBoolean), + + /* buttonfunc */ NULL, +}; + +/****************** MESH ******************/ + +static bNodeSocketType node_socket_type_mesh = { + /* type */ SOCK_MESH, + /* ui_name */ "Mesh", + /* ui_description */ "Mesh geometry data", + /* ui_icon */ 0, + /* ui_color */ {255,133,7,255}, + + /* value_structname */ NULL, + /* value_structsize */ 0, + + /* buttonfunc */ NULL, +}; + + +void node_socket_type_init(bNodeSocketType *types[]) +{ + #define INIT_TYPE(name) types[node_socket_type_##name.type] = &node_socket_type_##name; + + INIT_TYPE(float); + INIT_TYPE(vector); + INIT_TYPE(rgba); + INIT_TYPE(int); + INIT_TYPE(boolean); + INIT_TYPE(mesh); + + #undef INIT_TYPE +} + +struct bNodeSocket *nodeAddInputInt(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype, + int value, int min, int max) +{ + bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_INT); + bNodeSocketValueInt *dval= (bNodeSocketValueInt*)sock->default_value; + dval->subtype = subtype; + dval->value = value; + dval->min = min; + dval->max = max; + return sock; +} +struct bNodeSocket *nodeAddOutputInt(struct bNodeTree *ntree, struct bNode *node, const char *name) +{ + bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_INT); + return sock; +} + +struct bNodeSocket *nodeAddInputFloat(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype, + float value, float min, float max) +{ + bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_FLOAT); + bNodeSocketValueFloat *dval= (bNodeSocketValueFloat*)sock->default_value; + dval->subtype = subtype; + dval->value = value; + dval->min = min; + dval->max = max; + return sock; +} +struct bNodeSocket *nodeAddOutputFloat(struct bNodeTree *ntree, struct bNode *node, const char *name) +{ + bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_FLOAT); + return sock; +} + +struct bNodeSocket *nodeAddInputBoolean(struct bNodeTree *ntree, struct bNode *node, const char *name, char value) +{ + bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_BOOLEAN); + bNodeSocketValueBoolean *dval= (bNodeSocketValueBoolean*)sock->default_value; + dval->value = value; + return sock; +} +struct bNodeSocket *nodeAddOutputBoolean(struct bNodeTree *ntree, struct bNode *node, const char *name) +{ + bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_BOOLEAN); + return sock; +} + +struct bNodeSocket *nodeAddInputVector(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype, + float x, float y, float z, float min, float max) +{ + bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_VECTOR); + bNodeSocketValueVector *dval= (bNodeSocketValueVector*)sock->default_value; + dval->subtype = subtype; + dval->value[0] = x; + dval->value[1] = y; + dval->value[2] = z; + dval->min = min; + dval->max = max; + return sock; +} +struct bNodeSocket *nodeAddOutputVector(struct bNodeTree *ntree, struct bNode *node, const char *name) +{ + bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_VECTOR); + return sock; +} + +struct bNodeSocket *nodeAddInputRGBA(struct bNodeTree *ntree, struct bNode *node, const char *name, + float r, float g, float b, float a) +{ + bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_RGBA); + bNodeSocketValueRGBA *dval= (bNodeSocketValueRGBA*)sock->default_value; + dval->value[0] = r; + dval->value[1] = g; + dval->value[2] = b; + dval->value[3] = a; + return sock; +} +struct bNodeSocket *nodeAddOutputRGBA(struct bNodeTree *ntree, struct bNode *node, const char *name) +{ + bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_RGBA); + return sock; +} + +struct bNodeSocket *nodeAddInputMesh(struct bNodeTree *ntree, struct bNode *node, const char *name) +{ + bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_MESH); + return sock; +} +struct bNodeSocket *nodeAddOutputMesh(struct bNodeTree *ntree, struct bNode *node, const char *name) +{ + bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_MESH); + return sock; +} + +struct bNodeSocket *node_add_input_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp) +{ + bNodeSocket *sock; + switch (stemp->type) { + case SOCK_INT: + sock = nodeAddInputInt(ntree, node, stemp->name, stemp->subtype, (int)stemp->val1, (int)stemp->min, (int)stemp->max); + break; + case SOCK_FLOAT: + sock = nodeAddInputFloat(ntree, node, stemp->name, stemp->subtype, stemp->val1, stemp->min, stemp->max); + break; + case SOCK_BOOLEAN: + sock = nodeAddInputBoolean(ntree, node, stemp->name, (char)stemp->val1); + break; + case SOCK_VECTOR: + sock = nodeAddInputVector(ntree, node, stemp->name, stemp->subtype, stemp->val1, stemp->val2, stemp->val3, stemp->min, stemp->max); + break; + case SOCK_RGBA: + sock = nodeAddInputRGBA(ntree, node, stemp->name, stemp->val1, stemp->val2, stemp->val3, stemp->val4); + break; + case SOCK_MESH: + sock = nodeAddInputMesh(ntree, node, stemp->name); + break; + default: + sock = nodeAddSocket(ntree, node, SOCK_IN, stemp->name, stemp->type); + } + return sock; +} + +struct bNodeSocket *node_add_output_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp) +{ + bNodeSocket *sock; + switch (stemp->type) { + case SOCK_INT: + sock = nodeAddOutputInt(ntree, node, stemp->name); + break; + case SOCK_FLOAT: + sock = nodeAddOutputFloat(ntree, node, stemp->name); + break; + case SOCK_BOOLEAN: + sock = nodeAddOutputBoolean(ntree, node, stemp->name); + break; + case SOCK_VECTOR: + sock = nodeAddOutputVector(ntree, node, stemp->name); + break; + case SOCK_RGBA: + sock = nodeAddOutputRGBA(ntree, node, stemp->name); + break; + case SOCK_MESH: + sock = nodeAddOutputMesh(ntree, node, stemp->name); + break; + default: + sock = nodeAddSocket(ntree, node, SOCK_OUT, stemp->name, stemp->type); + } + return sock; +} + +static bNodeSocket *verify_socket_template(bNodeTree *ntree, bNode *node, int in_out, ListBase *socklist, bNodeSocketTemplate *stemp) +{ + bNodeSocket *sock; + + for(sock= socklist->first; sock; sock= sock->next) { + if(!(sock->flag & SOCK_DYNAMIC) && strncmp(sock->name, stemp->name, NODE_MAXSTR)==0) + break; + } + if(sock) { + sock->type= stemp->type; /* in future, read this from tydefs! */ + if(stemp->limit==0) sock->limit= 0xFFF; + else sock->limit= stemp->limit; + + /* Copy the property range and subtype parameters in case the template changed. + * NOT copying the actual value here, only button behavior changes! + */ + switch (sock->type) { + case SOCK_FLOAT: + { + bNodeSocketValueFloat *dval= sock->default_value; + dval->min = stemp->min; + dval->max = stemp->max; + dval->subtype = stemp->subtype; + } + break; + case SOCK_INT: + { + bNodeSocketValueInt *dval= sock->default_value; + dval->min = stemp->min; + dval->max = stemp->max; + dval->subtype = stemp->subtype; + } + break; + case SOCK_VECTOR: + { + bNodeSocketValueVector *dval= sock->default_value; + dval->min = stemp->min; + dval->max = stemp->max; + dval->subtype = stemp->subtype; + } + break; + } + + BLI_remlink(socklist, sock); + + return sock; + } + else { + /* no socket for this template found, make a new one */ + if (in_out==SOCK_IN) + sock = node_add_input_from_template(ntree, node, stemp); + else + sock = node_add_output_from_template(ntree, node, stemp); + /* remove the new socket from the node socket list first, + * will be added back after verification. + */ + BLI_remlink(socklist, sock); + } + + return sock; +} + +static void verify_socket_template_list(bNodeTree *ntree, bNode *node, int in_out, ListBase *socklist, bNodeSocketTemplate *stemp_first) +{ + bNodeSocket *sock; + bNodeSocketTemplate *stemp; + + /* no inputs anymore? */ + if(stemp_first==NULL) { + while(socklist->first) { + sock = (bNodeSocket*)socklist->first; + if (!(sock->flag & SOCK_DYNAMIC)) + nodeRemoveSocket(ntree, node, socklist->first); + } + } + else { + /* step by step compare */ + stemp= stemp_first; + while(stemp->type != -1) { + stemp->sock= verify_socket_template(ntree, node, in_out, socklist, stemp); + stemp++; + } + /* leftovers are removed */ + while(socklist->first) { + sock = (bNodeSocket*)socklist->first; + if (!(sock->flag & SOCK_DYNAMIC)) + nodeRemoveSocket(ntree, node, socklist->first); + } + + /* and we put back the verified sockets */ + stemp= stemp_first; + if (socklist->first) { + /* some dynamic sockets left, store the list start + * so we can add static sockets infront of it. + */ + sock = socklist->first; + while(stemp->type != -1) { + /* put static sockets infront of dynamic */ + BLI_insertlinkbefore(socklist, sock, stemp->sock); + stemp++; + } + } + else { + while(stemp->type != -1) { + BLI_addtail(socklist, stemp->sock); + stemp++; + } + } + } +} + +void node_verify_socket_templates(bNodeTree *ntree, bNode *node) +{ + bNodeType *ntype= node->typeinfo; + if(ntype) { + verify_socket_template_list(ntree, node, SOCK_IN, &node->inputs, ntype->inputs); + verify_socket_template_list(ntree, node, SOCK_OUT, &node->outputs, ntype->outputs); + } +} diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c index 1cc8c282179..bdf53df06af 100644 --- a/source/blender/nodes/intern/node_util.c +++ b/source/blender/nodes/intern/node_util.c @@ -32,12 +32,24 @@ */ -#include "CMP_util.h" -#include "SHD_util.h" +#include "DNA_action_types.h" +#include "DNA_node_types.h" + +#include "BLI_listbase.h" +#include "BLI_utildefines.h" + +#include "BKE_colortools.h" +#include "BKE_node.h" #include "RNA_access.h" #include "RNA_enum_types.h" +#include "MEM_guardedalloc.h" + +#include "node_util.h" + +/**** Storage Data ****/ + void node_free_curves(bNode *node) { curvemapping_free(node->storage); @@ -58,6 +70,8 @@ void node_copy_standard_storage(bNode *orig_node, bNode *new_node) new_node->storage= MEM_dupallocN(orig_node->storage); } +/**** Labels ****/ + const char *node_blend_label(bNode *node) { const char *name; diff --git a/source/blender/nodes/intern/node_util.h b/source/blender/nodes/intern/node_util.h index 5a78fc07883..8d38d57f577 100644 --- a/source/blender/nodes/intern/node_util.h +++ b/source/blender/nodes/intern/node_util.h @@ -35,14 +35,27 @@ #ifndef NODE_UTIL_H_ #define NODE_UTIL_H_ +#include "DNA_listBase.h" + +#include "BKE_node.h" + #include "MEM_guardedalloc.h" +#include "NOD_socket.h" + +struct bNodeTree; +struct bNode; + +/**** Storage Data ****/ + extern void node_free_curves(struct bNode *node); extern void node_free_standard_storage(struct bNode *node); extern void node_copy_curves(struct bNode *orig_node, struct bNode *new_node); extern void node_copy_standard_storage(struct bNode *orig_node, struct bNode *new_node); +/**** Labels ****/ + const char *node_blend_label(struct bNode *node); const char *node_math_label(struct bNode *node); const char *node_vect_math_label(struct bNode *node); |