Blender V2.61 - r43446

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