2
* $Id: CMP_math.c,v 1.4 2007/04/04 13:58:10 jesterking Exp $
4
* ***** BEGIN GPL LICENSE BLOCK *****
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software Foundation,
18
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
* The Original Code is Copyright (C) 2006 Blender Foundation.
21
* All rights reserved.
23
* The Original Code is: all of this file.
25
* Contributor(s): none yet.
27
* ***** END GPL LICENSE BLOCK *****
30
#include "../CMP_util.h"
33
/* **************** SCALAR MATH ******************** */
34
static bNodeSocketType cmp_node_math_in[]= {
35
{ SOCK_VALUE, 1, "Value", 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f},
36
{ SOCK_VALUE, 1, "Value", 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f},
40
static bNodeSocketType cmp_node_math_out[]= {
41
{ SOCK_VALUE, 0, "Value", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
45
static void do_math(bNode *node, float *out, float *in, float *in2)
50
out[0]= in[0] + in2[0];
52
case 1: /* Subtract */
53
out[0]= in[0] - in2[0];
55
case 2: /* Multiply */
56
out[0]= in[0] * in2[0];
60
if(in[1]==0) /* We don't want to divide by zero. */
63
out[0]= in[0] / in2[0];
75
case 7: /* Arc-Sine */
77
/* Can't do the impossible... */
78
if(in[0] <= 1 && in[0] >= -1 )
84
case 8: /* Arc-Cosine */
86
/* Can't do the impossible... */
87
if( in[0] <= 1 && in[0] >= -1 )
93
case 9: /* Arc-Tangent */
98
/* Don't want any imaginary numbers... */
100
out[0]= pow(in[0], in2[0]);
105
case 11: /* Logarithm */
107
/* Don't want any imaginary numbers... */
108
if( in[0] > 0 && in2[0] > 0 )
109
out[0]= log(in[0]) / log(in2[0]);
114
case 12: /* Minimum */
122
case 13: /* Maximum */
132
out[0]= (int)(in[0] + 0.5f);
138
static void node_composit_exec_math(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
140
/* stack order out: bw */
141
/* stack order in: col */
143
if(out[0]->hasoutput==0)
146
/* input no image? then only color operation */
147
if(in[0]->data==NULL) {
148
do_math(node, out[0]->vec, in[0]->vec, in[1]->vec);
151
/* make output size of input image */
152
CompBuf *cbuf= in[0]->data;
153
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */
155
composit2_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_math, CB_VAL, CB_VAL);
157
out[0]->data= stackbuf;
161
bNodeType cmp_node_math= {
162
/* *next,*prev */ NULL, NULL,
163
/* type code */ CMP_NODE_MATH,
165
/* width+range */ 120, 110, 160,
166
/* class+opts */ NODE_CLASS_CONVERTOR, NODE_OPTIONS,
167
/* input sock */ cmp_node_math_in,
168
/* output sock */ cmp_node_math_out,
170
/* execfunc */ node_composit_exec_math,
173
/* freestoragefunc */ NULL,
174
/* copystoragefunc */ NULL,