~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/nodes/intern/CMP_nodes/CMP_math.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * $Id: CMP_math.c,v 1.4 2007/04/04 13:58:10 jesterking Exp $
 
3
 *
 
4
 * ***** BEGIN GPL LICENSE BLOCK *****
 
5
 *
 
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. 
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 *
 
20
 * The Original Code is Copyright (C) 2006 Blender Foundation.
 
21
 * All rights reserved.
 
22
 *
 
23
 * The Original Code is: all of this file.
 
24
 *
 
25
 * Contributor(s): none yet.
 
26
 *
 
27
 * ***** END GPL LICENSE BLOCK *****
 
28
 */
 
29
 
 
30
#include "../CMP_util.h"
 
31
 
 
32
 
 
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}, 
 
37
        { -1, 0, "" } 
 
38
};
 
39
 
 
40
static bNodeSocketType cmp_node_math_out[]= { 
 
41
        { SOCK_VALUE, 0, "Value", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, 
 
42
        { -1, 0, "" } 
 
43
};
 
44
 
 
45
static void do_math(bNode *node, float *out, float *in, float *in2)
 
46
{
 
47
        switch(node->custom1)
 
48
        {
 
49
        case 0: /* Add */
 
50
                out[0]= in[0] + in2[0]; 
 
51
                break; 
 
52
        case 1: /* Subtract */
 
53
                out[0]= in[0] - in2[0];
 
54
                break; 
 
55
        case 2: /* Multiply */
 
56
                out[0]= in[0] * in2[0]; 
 
57
                break; 
 
58
        case 3: /* Divide */
 
59
                {
 
60
                        if(in[1]==0)    /* We don't want to divide by zero. */
 
61
                                out[0]= 0.0;
 
62
                        else
 
63
                                out[0]= in[0] / in2[0];
 
64
                        }
 
65
                break;
 
66
        case 4: /* Sine */
 
67
                out[0]= sin(in[0]);
 
68
                break;
 
69
        case 5: /* Cosine */
 
70
                out[0]= cos(in[0]);
 
71
                break;
 
72
        case 6: /* Tangent */
 
73
                out[0]= tan(in[0]);
 
74
                break;
 
75
        case 7: /* Arc-Sine */
 
76
                {
 
77
                        /* Can't do the impossible... */
 
78
                        if(in[0] <= 1 && in[0] >= -1 )
 
79
                                out[0]= asin(in[0]);
 
80
                        else
 
81
                                out[0]= 0.0;
 
82
                }
 
83
                break;
 
84
        case 8: /* Arc-Cosine */
 
85
                {
 
86
                        /* Can't do the impossible... */
 
87
                        if( in[0] <= 1 && in[0] >= -1 )
 
88
                                out[0]= acos(in[0]);
 
89
                        else
 
90
                                out[0]= 0.0;
 
91
                }
 
92
                break;
 
93
        case 9: /* Arc-Tangent */
 
94
                out[0]= atan(in[0]);
 
95
                break;
 
96
        case 10: /* Power */
 
97
                {
 
98
                        /* Don't want any imaginary numbers... */
 
99
                        if( in[0] >= 0 )
 
100
                                out[0]= pow(in[0], in2[0]);
 
101
                        else
 
102
                                out[0]= 0.0;
 
103
                }
 
104
                break;
 
105
        case 11: /* Logarithm */
 
106
                {
 
107
                        /* Don't want any imaginary numbers... */
 
108
                        if( in[0] > 0  && in2[0] > 0 )
 
109
                                out[0]= log(in[0]) / log(in2[0]);
 
110
                        else
 
111
                                out[0]= 0.0;
 
112
                }
 
113
                break;
 
114
        case 12: /* Minimum */
 
115
                {
 
116
                        if( in[0] < in2[0] )
 
117
                                out[0]= in[0];
 
118
                        else
 
119
                                out[0]= in2[0];
 
120
                }
 
121
                break;
 
122
        case 13: /* Maximum */
 
123
                {
 
124
                        if( in[0] > in2[0] )
 
125
                                out[0]= in[0];
 
126
                        else
 
127
                                out[0]= in2[0];
 
128
                }
 
129
                break;
 
130
        case 14: /* Round */
 
131
                {
 
132
                                out[0]= (int)(in[0] + 0.5f);
 
133
                }
 
134
                break; 
 
135
        }
 
136
}
 
137
 
 
138
static void node_composit_exec_math(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 
139
{
 
140
        /* stack order out: bw */
 
141
        /* stack order in: col */
 
142
        
 
143
        if(out[0]->hasoutput==0)
 
144
                return;
 
145
        
 
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);
 
149
        }
 
150
        else {
 
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 */
 
154
                
 
155
                composit2_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_math, CB_VAL, CB_VAL);
 
156
                
 
157
                out[0]->data= stackbuf;
 
158
        }
 
159
}
 
160
 
 
161
bNodeType cmp_node_math= {
 
162
        /* *next,*prev */       NULL, NULL,
 
163
        /* type code   */       CMP_NODE_MATH,
 
164
        /* name        */       "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,
 
169
        /* storage     */       "",
 
170
        /* execfunc    */       node_composit_exec_math,
 
171
        /* butfunc     */       NULL,
 
172
        /* initfunc    */       NULL,
 
173
        /* freestoragefunc    */        NULL,
 
174
        /* copystoragefunc    */        NULL,
 
175
        /* id          */       NULL
 
176
};
 
177
 
 
178
 
 
179