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