Blender V2.61 - r43446
|
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 00036 /* **************** VALTORGB ******************** */ 00037 static bNodeSocketTemplate cmp_node_valtorgb_in[]= { 00038 { SOCK_FLOAT, 1, "Fac", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, 00039 { -1, 0, "" } 00040 }; 00041 static bNodeSocketTemplate cmp_node_valtorgb_out[]= { 00042 { SOCK_RGBA, 0, "Image"}, 00043 { SOCK_FLOAT, 0, "Alpha"}, 00044 { -1, 0, "" } 00045 }; 00046 00047 static void do_colorband_composit(bNode *node, float *out, float *in) 00048 { 00049 do_colorband(node->storage, in[0], out); 00050 } 00051 00052 static void node_composit_exec_valtorgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00053 { 00054 /* stack order in: fac */ 00055 /* stack order out: col, alpha */ 00056 00057 if(out[0]->hasoutput==0 && out[1]->hasoutput==0) 00058 return; 00059 00060 if(node->storage) { 00061 /* input no image? then only color operation */ 00062 if(in[0]->data==NULL) { 00063 do_colorband(node->storage, in[0]->vec[0], out[0]->vec); 00064 } 00065 else { 00066 /* make output size of input image */ 00067 CompBuf *cbuf= in[0]->data; 00068 CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ 00069 00070 composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_colorband_composit, CB_VAL); 00071 00072 out[0]->data= stackbuf; 00073 00074 if(out[1]->hasoutput) 00075 out[1]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A); 00076 00077 } 00078 } 00079 } 00080 00081 static void node_composit_init_valtorgb(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) 00082 { 00083 node->storage= add_colorband(1); 00084 } 00085 00086 void register_node_type_cmp_valtorgb(bNodeTreeType *ttype) 00087 { 00088 static bNodeType ntype; 00089 00090 node_type_base(ttype, &ntype, CMP_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, NODE_OPTIONS); 00091 node_type_socket_templates(&ntype, cmp_node_valtorgb_in, cmp_node_valtorgb_out); 00092 node_type_size(&ntype, 240, 200, 300); 00093 node_type_init(&ntype, node_composit_init_valtorgb); 00094 node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); 00095 node_type_exec(&ntype, node_composit_exec_valtorgb); 00096 00097 nodeRegisterType(ttype, &ntype); 00098 } 00099 00100 00101 00102 /* **************** RGBTOBW ******************** */ 00103 static bNodeSocketTemplate cmp_node_rgbtobw_in[]= { 00104 { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, 00105 { -1, 0, "" } 00106 }; 00107 static bNodeSocketTemplate cmp_node_rgbtobw_out[]= { 00108 { SOCK_FLOAT, 0, "Val", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, 00109 { -1, 0, "" } 00110 }; 00111 00112 static void do_rgbtobw(bNode *UNUSED(node), float *out, float *in) 00113 { 00114 out[0]= in[0]*0.35f + in[1]*0.45f + in[2]*0.2f; 00115 } 00116 00117 static void node_composit_exec_rgbtobw(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00118 { 00119 /* stack order out: bw */ 00120 /* stack order in: col */ 00121 00122 if(out[0]->hasoutput==0) 00123 return; 00124 00125 /* input no image? then only color operation */ 00126 if(in[0]->data==NULL) { 00127 do_rgbtobw(node, out[0]->vec, in[0]->vec); 00128 } 00129 else { 00130 /* make output size of input image */ 00131 CompBuf *cbuf= in[0]->data; 00132 CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */ 00133 00134 composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_rgbtobw, CB_RGBA); 00135 00136 out[0]->data= stackbuf; 00137 } 00138 } 00139 00140 void register_node_type_cmp_rgbtobw(bNodeTreeType *ttype) 00141 { 00142 static bNodeType ntype; 00143 00144 node_type_base(ttype, &ntype, CMP_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0); 00145 node_type_socket_templates(&ntype, cmp_node_rgbtobw_in, cmp_node_rgbtobw_out); 00146 node_type_size(&ntype, 80, 40, 120); 00147 node_type_exec(&ntype, node_composit_exec_rgbtobw); 00148 00149 nodeRegisterType(ttype, &ntype); 00150 }