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

« back to all changes in this revision

Viewing changes to source/blender/nodes/intern/CMP_nodes/CMP_curves.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_curves.c,v 1.4 2007/04/04 13:58:09 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
/* **************** CURVE Time  ******************** */
 
34
 
 
35
/* custom1 = sfra, custom2 = efra */
 
36
static bNodeSocketType cmp_node_time_out[]= {
 
37
        {       SOCK_VALUE, 0, "Fac",   1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f},
 
38
        {       -1, 0, ""       }
 
39
};
 
40
 
 
41
static void node_composit_exec_curves_time(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 
42
{
 
43
        /* stack order output: fac */
 
44
        float fac= 0.0f;
 
45
        
 
46
        if(node->custom1 < node->custom2)
 
47
                fac= (G.scene->r.cfra - node->custom1)/(float)(node->custom2-node->custom1);
 
48
        
 
49
        fac= curvemapping_evaluateF(node->storage, 0, fac);
 
50
        out[0]->vec[0]= CLAMPIS(fac, 0.0f, 1.0f);
 
51
}
 
52
 
 
53
 
 
54
static void node_composit_init_curves_time(bNode* node)
 
55
{
 
56
   node->custom1= G.scene->r.sfra;
 
57
   node->custom2= G.scene->r.efra;
 
58
   node->storage= curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
 
59
}
 
60
 
 
61
bNodeType cmp_node_curve_time= {
 
62
        /* *next,*prev */       NULL, NULL,
 
63
        /* type code   */       CMP_NODE_TIME,
 
64
        /* name        */       "Time",
 
65
        /* width+range */       140, 100, 320,
 
66
        /* class+opts  */       NODE_CLASS_INPUT, NODE_OPTIONS,
 
67
        /* input sock  */       NULL,
 
68
        /* output sock */       cmp_node_time_out,
 
69
        /* storage     */       "CurveMapping",
 
70
        /* execfunc    */       node_composit_exec_curves_time,
 
71
        /* butfunc     */       NULL,
 
72
        /* initfunc    */       node_composit_init_curves_time,
 
73
        /* freestoragefunc    */        node_free_curves,
 
74
        /* copystoragefunc    */        node_copy_curves,
 
75
        /* id          */       NULL
 
76
};
 
77
 
 
78
 
 
79
 
 
80
/* **************** CURVE VEC  ******************** */
 
81
static bNodeSocketType cmp_node_curve_vec_in[]= {
 
82
        {       SOCK_VECTOR, 1, "Vector",       0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
 
83
        {       -1, 0, ""       }
 
84
};
 
85
 
 
86
static bNodeSocketType cmp_node_curve_vec_out[]= {
 
87
        {       SOCK_VECTOR, 0, "Vector",       0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f},
 
88
        {       -1, 0, ""       }
 
89
};
 
90
 
 
91
static void node_composit_exec_curve_vec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 
92
{
 
93
        /* stack order input:  vec */
 
94
        /* stack order output: vec */
 
95
        
 
96
        curvemapping_evaluate_premulRGBF(node->storage, out[0]->vec, in[0]->vec);
 
97
};
 
98
 
 
99
static void node_composit_init_curve_vec(bNode* node)
 
100
{
 
101
   node->storage= curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f);
 
102
};
 
103
 
 
104
bNodeType cmp_node_curve_vec= {
 
105
        /* *next,*prev */       NULL, NULL,
 
106
        /* type code   */       CMP_NODE_CURVE_VEC,
 
107
        /* name        */       "Vector Curves",
 
108
        /* width+range */       200, 140, 320,
 
109
        /* class+opts  */       NODE_CLASS_OP_VECTOR, NODE_OPTIONS,
 
110
        /* input sock  */       cmp_node_curve_vec_in,
 
111
        /* output sock */       cmp_node_curve_vec_out,
 
112
        /* storage     */       "CurveMapping",
 
113
        /* execfunc    */       node_composit_exec_curve_vec,
 
114
        /* butfunc     */       NULL,
 
115
        /* initfunc    */       node_composit_init_curve_vec,
 
116
        /* freestoragefunc    */        node_free_curves,
 
117
        /* copystoragefunc    */        node_copy_curves,
 
118
        /* id          */       NULL
 
119
        
 
120
};
 
121
 
 
122
/* **************** CURVE RGB  ******************** */
 
123
static bNodeSocketType cmp_node_curve_rgb_in[]= {
 
124
        {       SOCK_VALUE, 1, "Fac",   1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
 
125
        {       SOCK_RGBA, 1, "Image",  0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
 
126
        {       -1, 0, ""       }
 
127
};
 
128
 
 
129
static bNodeSocketType cmp_node_curve_rgb_out[]= {
 
130
        {       SOCK_RGBA, 0, "Image",  0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f},
 
131
        {       -1, 0, ""       }
 
132
};
 
133
 
 
134
static void do_curves(bNode *node, float *out, float *in)
 
135
{
 
136
        curvemapping_evaluate_premulRGBF(node->storage, out, in);
 
137
        out[3]= in[3];
 
138
}
 
139
 
 
140
static void do_curves_fac(bNode *node, float *out, float *in, float *fac)
 
141
{
 
142
        
 
143
        if(*fac>=1.0)
 
144
                curvemapping_evaluate_premulRGBF(node->storage, out, in);
 
145
        else if(*fac<=0.0) {
 
146
                VECCOPY(out, in);
 
147
        }
 
148
        else {
 
149
                float col[4], mfac= 1.0f-*fac;
 
150
                curvemapping_evaluate_premulRGBF(node->storage, col, in);
 
151
                out[0]= mfac*in[0] + *fac*col[0];
 
152
                out[1]= mfac*in[1] + *fac*col[1];
 
153
                out[2]= mfac*in[2] + *fac*col[2];
 
154
        }
 
155
        out[3]= in[3];
 
156
}
 
157
 
 
158
static void node_composit_exec_curve_rgb(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 
159
{
 
160
        /* stack order input:  fac, image */
 
161
        /* stack order output: image */
 
162
        
 
163
        if(out[0]->hasoutput==0)
 
164
                return;
 
165
 
 
166
        /* input no image? then only color operation */
 
167
        if(in[1]->data==NULL) {
 
168
                curvemapping_evaluateRGBF(node->storage, out[0]->vec, in[1]->vec);
 
169
        }
 
170
        else {
 
171
                /* make output size of input image */
 
172
                CompBuf *cbuf= in[1]->data;
 
173
                CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
 
174
                
 
175
                if(in[0]->data)
 
176
                        composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_curves_fac, CB_RGBA, CB_VAL);
 
177
                else
 
178
                        composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_curves, CB_RGBA);
 
179
                
 
180
                out[0]->data= stackbuf;
 
181
        }
 
182
        
 
183
};
 
184
 
 
185
static void node_composit_init_curve_rgb(bNode* node)
 
186
{
 
187
   node->storage= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
 
188
};
 
189
 
 
190
bNodeType cmp_node_curve_rgb= {
 
191
        /* *next,*prev */       NULL, NULL,
 
192
        /* type code   */       CMP_NODE_CURVE_RGB,
 
193
        /* name        */       "RGB Curves",
 
194
        /* width+range */       200, 140, 320,
 
195
        /* class+opts  */       NODE_CLASS_OP_COLOR, NODE_OPTIONS,
 
196
        /* input sock  */       cmp_node_curve_rgb_in,
 
197
        /* output sock */       cmp_node_curve_rgb_out,
 
198
        /* storage     */       "CurveMapping",
 
199
        /* execfunc    */       node_composit_exec_curve_rgb,
 
200
        /* butfunc     */       NULL,
 
201
        /* initfunc    */       node_composit_init_curve_rgb,
 
202
        /* freestoragefunc    */        node_free_curves,
 
203
        /* copystoragefunc    */        node_copy_curves,
 
204
        /* id          */       NULL
 
205
};
 
206