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