|
Blender
V2.59
|
00001 /* 00002 * $Id: CMP_mapValue.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): none yet. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00035 #include "../CMP_util.h" 00036 00037 /* **************** MAP VALUE ******************** */ 00038 static bNodeSocketType cmp_node_map_value_in[]= { 00039 { SOCK_VALUE, 1, "Value", 1.0f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, 00040 { -1, 0, "" } 00041 }; 00042 static bNodeSocketType cmp_node_map_value_out[]= { 00043 { SOCK_VALUE, 0, "Value", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, 00044 { -1, 0, "" } 00045 }; 00046 00047 static void do_map_value(bNode *node, float *out, float *src) 00048 { 00049 TexMapping *texmap= node->storage; 00050 00051 out[0]= (src[0] + texmap->loc[0])*texmap->size[0]; 00052 if(texmap->flag & TEXMAP_CLIP_MIN) 00053 if(out[0]<texmap->min[0]) 00054 out[0]= texmap->min[0]; 00055 if(texmap->flag & TEXMAP_CLIP_MAX) 00056 if(out[0]>texmap->max[0]) 00057 out[0]= texmap->max[0]; 00058 } 00059 00060 static void node_composit_exec_map_value(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00061 { 00062 /* stack order in: valbuf */ 00063 /* stack order out: valbuf */ 00064 if(out[0]->hasoutput==0) return; 00065 00066 /* input no image? then only value operation */ 00067 if(in[0]->data==NULL) { 00068 do_map_value(node, out[0]->vec, in[0]->vec); 00069 } 00070 else { 00071 /* make output size of input image */ 00072 CompBuf *cbuf= in[0]->data; 00073 CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */ 00074 00075 composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_map_value, CB_VAL); 00076 00077 out[0]->data= stackbuf; 00078 } 00079 } 00080 00081 00082 static void node_composit_init_map_value(bNode* node) 00083 { 00084 node->storage= add_mapping(); 00085 } 00086 00087 void register_node_type_cmp_map_value(ListBase *lb) 00088 { 00089 static bNodeType ntype; 00090 00091 node_type_base(&ntype, CMP_NODE_MAP_VALUE, "Map Value", NODE_CLASS_OP_VECTOR, NODE_OPTIONS, 00092 cmp_node_map_value_in, cmp_node_map_value_out); 00093 node_type_size(&ntype, 100, 60, 150); 00094 node_type_init(&ntype, node_composit_init_map_value); 00095 node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage); 00096 node_type_exec(&ntype, node_composit_exec_map_value); 00097 00098 nodeRegisterType(lb, &ntype); 00099 } 00100 00101 00102 00103