2
* $Id: CMP_curves.c,v 1.4 2007/04/04 13:58:09 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
/* **************** CURVE Time ******************** */
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},
41
static void node_composit_exec_curves_time(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
43
/* stack order output: fac */
46
if(node->custom1 < node->custom2)
47
fac= (G.scene->r.cfra - node->custom1)/(float)(node->custom2-node->custom1);
49
fac= curvemapping_evaluateF(node->storage, 0, fac);
50
out[0]->vec[0]= CLAMPIS(fac, 0.0f, 1.0f);
54
static void node_composit_init_curves_time(bNode* node)
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);
61
bNodeType cmp_node_curve_time= {
62
/* *next,*prev */ NULL, NULL,
63
/* type code */ CMP_NODE_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,
72
/* initfunc */ node_composit_init_curves_time,
73
/* freestoragefunc */ node_free_curves,
74
/* copystoragefunc */ node_copy_curves,
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},
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},
91
static void node_composit_exec_curve_vec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
93
/* stack order input: vec */
94
/* stack order output: vec */
96
curvemapping_evaluate_premulRGBF(node->storage, out[0]->vec, in[0]->vec);
99
static void node_composit_init_curve_vec(bNode* node)
101
node->storage= curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f);
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,
115
/* initfunc */ node_composit_init_curve_vec,
116
/* freestoragefunc */ node_free_curves,
117
/* copystoragefunc */ node_copy_curves,
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},
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},
134
static void do_curves(bNode *node, float *out, float *in)
136
curvemapping_evaluate_premulRGBF(node->storage, out, in);
140
static void do_curves_fac(bNode *node, float *out, float *in, float *fac)
144
curvemapping_evaluate_premulRGBF(node->storage, out, in);
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];
158
static void node_composit_exec_curve_rgb(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
160
/* stack order input: fac, image */
161
/* stack order output: image */
163
if(out[0]->hasoutput==0)
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);
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 */
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);
178
composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_curves, CB_RGBA);
180
out[0]->data= stackbuf;
185
static void node_composit_init_curve_rgb(bNode* node)
187
node->storage= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
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,
201
/* initfunc */ node_composit_init_curve_rgb,
202
/* freestoragefunc */ node_free_curves,
203
/* copystoragefunc */ node_copy_curves,