Blender V2.61 - r43446

node_composite_curves.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2006 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): Björn C. Schaefer
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #include "node_composite_util.h"
00034 
00035 
00036 /* **************** CURVE Time  ******************** */
00037 
00038 /* custom1 = sfra, custom2 = efra */
00039 static bNodeSocketTemplate cmp_node_time_out[]= {
00040     {   SOCK_FLOAT, 0, "Fac"},
00041     {   -1, 0, ""   }
00042 };
00043 
00044 static void node_composit_exec_curves_time(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out)
00045 {
00046     RenderData *rd= data;
00047     /* stack order output: fac */
00048     float fac= 0.0f;
00049     
00050     if(node->custom1 < node->custom2)
00051         fac= (rd->cfra - node->custom1)/(float)(node->custom2-node->custom1);
00052     
00053     fac= curvemapping_evaluateF(node->storage, 0, fac);
00054     out[0]->vec[0]= CLAMPIS(fac, 0.0f, 1.0f);
00055 }
00056 
00057 
00058 static void node_composit_init_curves_time(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
00059 {
00060     node->custom1= 1;
00061     node->custom2= 250;
00062     node->storage= curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
00063 }
00064 
00065 void register_node_type_cmp_curve_time(bNodeTreeType *ttype)
00066 {
00067     static bNodeType ntype;
00068 
00069     node_type_base(ttype, &ntype, CMP_NODE_TIME, "Time", NODE_CLASS_INPUT, NODE_OPTIONS);
00070     node_type_socket_templates(&ntype, NULL, cmp_node_time_out);
00071     node_type_size(&ntype, 140, 100, 320);
00072     node_type_init(&ntype, node_composit_init_curves_time);
00073     node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
00074     node_type_exec(&ntype, node_composit_exec_curves_time);
00075 
00076     nodeRegisterType(ttype, &ntype);
00077 }
00078 
00079 
00080 
00081 /* **************** CURVE VEC  ******************** */
00082 static bNodeSocketTemplate cmp_node_curve_vec_in[]= {
00083     {   SOCK_VECTOR, 1, "Vector",   0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE},
00084     {   -1, 0, ""   }
00085 };
00086 
00087 static bNodeSocketTemplate cmp_node_curve_vec_out[]= {
00088     {   SOCK_VECTOR, 0, "Vector"},
00089     {   -1, 0, ""   }
00090 };
00091 
00092 static void node_composit_exec_curve_vec(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
00093 {
00094     /* stack order input:  vec */
00095     /* stack order output: vec */
00096     
00097     curvemapping_evaluate_premulRGBF(node->storage, out[0]->vec, in[0]->vec);
00098 }
00099 
00100 static void node_composit_init_curve_vec(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
00101 {
00102     node->storage= curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f);
00103 }
00104 
00105 void register_node_type_cmp_curve_vec(bNodeTreeType *ttype)
00106 {
00107     static bNodeType ntype;
00108 
00109     node_type_base(ttype, &ntype, CMP_NODE_CURVE_VEC, "Vector Curves", NODE_CLASS_OP_VECTOR, NODE_OPTIONS);
00110     node_type_socket_templates(&ntype, cmp_node_curve_vec_in, cmp_node_curve_vec_out);
00111     node_type_size(&ntype, 200, 140, 320);
00112     node_type_init(&ntype, node_composit_init_curve_vec);
00113     node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
00114     node_type_exec(&ntype, node_composit_exec_curve_vec);
00115 
00116     nodeRegisterType(ttype, &ntype);
00117 }
00118 
00119 
00120 /* **************** CURVE RGB  ******************** */
00121 static bNodeSocketTemplate cmp_node_curve_rgb_in[]= {
00122     {   SOCK_FLOAT, 1, "Fac",   1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_FACTOR},
00123     {   SOCK_RGBA, 1, "Image",  1.0f, 1.0f, 1.0f, 1.0f},
00124     {   SOCK_RGBA, 1, "Black Level",    0.0f, 0.0f, 0.0f, 1.0f},
00125     {   SOCK_RGBA, 1, "White Level",    1.0f, 1.0f, 1.0f, 1.0f},
00126     {   -1, 0, ""   }
00127 };
00128 
00129 static bNodeSocketTemplate cmp_node_curve_rgb_out[]= {
00130     {   SOCK_RGBA, 0, "Image"},
00131     {   -1, 0, ""   }
00132 };
00133 
00134 static void do_curves(bNode *node, float *out, float *in)
00135 {
00136     curvemapping_evaluate_premulRGBF(node->storage, out, in);
00137     out[3]= in[3];
00138 }
00139 
00140 static void do_curves_fac(bNode *node, float *out, float *in, float *fac)
00141 {
00142     
00143     if(*fac >= 1.0f)
00144         curvemapping_evaluate_premulRGBF(node->storage, out, in);
00145     else if(*fac <= 0.0f) {
00146         copy_v3_v3(out, in);
00147     }
00148     else {
00149         float col[4], mfac= 1.0f-*fac;
00150         curvemapping_evaluate_premulRGBF(node->storage, col, in);
00151         out[0]= mfac*in[0] + *fac*col[0];
00152         out[1]= mfac*in[1] + *fac*col[1];
00153         out[2]= mfac*in[2] + *fac*col[2];
00154     }
00155     out[3]= in[3];
00156 }
00157 
00158 static void node_composit_exec_curve_rgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
00159 {
00160     /* stack order input:  fac, image, black level, white level */
00161     /* stack order output: image */
00162     
00163     if(out[0]->hasoutput==0)
00164         return;
00165 
00166     /* input no image? then only color operation */
00167     if(in[1]->data==NULL) {
00168         curvemapping_evaluateRGBF(node->storage, out[0]->vec, in[1]->vec);
00169     }
00170     else {
00171         /* make output size of input image */
00172         CompBuf *cbuf= in[1]->data;
00173         CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
00174         
00175         curvemapping_set_black_white(node->storage, in[2]->vec, in[3]->vec);
00176         
00177         if(in[0]->data==NULL && in[0]->vec[0] == 1.0f)
00178             composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_curves, CB_RGBA);
00179         else
00180             composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_curves_fac, CB_RGBA, CB_VAL);
00181         
00182         out[0]->data= stackbuf;
00183     }
00184     
00185 }
00186 
00187 static void node_composit_init_curve_rgb(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
00188 {
00189     node->storage= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
00190 }
00191 
00192 void register_node_type_cmp_curve_rgb(bNodeTreeType *ttype)
00193 {
00194     static bNodeType ntype;
00195 
00196     node_type_base(ttype, &ntype, CMP_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, NODE_OPTIONS);
00197     node_type_socket_templates(&ntype, cmp_node_curve_rgb_in, cmp_node_curve_rgb_out);
00198     node_type_size(&ntype, 200, 140, 320);
00199     node_type_init(&ntype, node_composit_init_curve_rgb);
00200     node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
00201     node_type_exec(&ntype, node_composit_exec_curve_rgb);
00202 
00203     nodeRegisterType(ttype, &ntype);
00204 }