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 /* **************** SEPARATE HSVA ******************** */ 00037 static bNodeSocketTemplate cmp_node_sephsva_in[]= { 00038 { SOCK_RGBA, 1, "Image", 1.0f, 1.0f, 1.0f, 1.0f}, 00039 { -1, 0, "" } 00040 }; 00041 static bNodeSocketTemplate cmp_node_sephsva_out[]= { 00042 { SOCK_FLOAT, 0, "H"}, 00043 { SOCK_FLOAT, 0, "S"}, 00044 { SOCK_FLOAT, 0, "V"}, 00045 { SOCK_FLOAT, 0, "A"}, 00046 { -1, 0, "" } 00047 }; 00048 00049 static void do_sephsva(bNode *UNUSED(node), float *out, float *in) 00050 { 00051 float h, s, v; 00052 00053 rgb_to_hsv(in[0], in[1], in[2], &h, &s, &v); 00054 00055 out[0]= h; 00056 out[1]= s; 00057 out[2]= v; 00058 out[3]= in[3]; 00059 } 00060 00061 static void node_composit_exec_sephsva(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00062 { 00063 /* stack order out: bw channels */ 00064 /* stack order in: col */ 00065 00066 /* input no image? then only color operation */ 00067 if(in[0]->data==NULL) { 00068 float h, s, v; 00069 00070 rgb_to_hsv(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &h, &s, &v); 00071 00072 out[0]->vec[0] = h; 00073 out[1]->vec[0] = s; 00074 out[2]->vec[0] = v; 00075 out[3]->vec[0] = in[0]->vec[3]; 00076 } 00077 else if ((out[0]->hasoutput) || (out[1]->hasoutput) || (out[2]->hasoutput) || (out[3]->hasoutput)) { 00078 /* create new buffer so input buffer doesn't get corrupted */ 00079 CompBuf *cbuf= dupalloc_compbuf(in[0]->data); 00080 CompBuf *cbuf2= typecheck_compbuf(cbuf, CB_RGBA); 00081 00082 /* convert the RGB stackbuf to an HSV representation */ 00083 composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sephsva, CB_RGBA); 00084 00085 /* separate each of those channels */ 00086 if(out[0]->hasoutput) 00087 out[0]->data= valbuf_from_rgbabuf(cbuf2, CHAN_R); 00088 if(out[1]->hasoutput) 00089 out[1]->data= valbuf_from_rgbabuf(cbuf2, CHAN_G); 00090 if(out[2]->hasoutput) 00091 out[2]->data= valbuf_from_rgbabuf(cbuf2, CHAN_B); 00092 if(out[3]->hasoutput) 00093 out[3]->data= valbuf_from_rgbabuf(cbuf2, CHAN_A); 00094 00095 /*not used anymore */ 00096 if(cbuf2!=cbuf) 00097 free_compbuf(cbuf2); 00098 free_compbuf(cbuf); 00099 } 00100 } 00101 00102 void register_node_type_cmp_sephsva(bNodeTreeType *ttype) 00103 { 00104 static bNodeType ntype; 00105 00106 node_type_base(ttype, &ntype, CMP_NODE_SEPHSVA, "Separate HSVA", NODE_CLASS_CONVERTOR, 0); 00107 node_type_socket_templates(&ntype, cmp_node_sephsva_in, cmp_node_sephsva_out); 00108 node_type_size(&ntype, 80, 40, 140); 00109 node_type_exec(&ntype, node_composit_exec_sephsva); 00110 00111 nodeRegisterType(ttype, &ntype); 00112 } 00113 00114 00115 /* **************** COMBINE HSVA ******************** */ 00116 static bNodeSocketTemplate cmp_node_combhsva_in[]= { 00117 { SOCK_FLOAT, 1, "H", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, 00118 { SOCK_FLOAT, 1, "S", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, 00119 { SOCK_FLOAT, 1, "V", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, 00120 { SOCK_FLOAT, 1, "A", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, 00121 { -1, 0, "" } 00122 }; 00123 static bNodeSocketTemplate cmp_node_combhsva_out[]= { 00124 { SOCK_RGBA, 0, "Image"}, 00125 { -1, 0, "" } 00126 }; 00127 00128 static void do_comb_hsva(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4) 00129 { 00130 float r,g,b; 00131 hsv_to_rgb(in1[0], in2[0], in3[0], &r, &g, &b); 00132 00133 out[0] = r; 00134 out[1] = g; 00135 out[2] = b; 00136 out[3] = in4[0]; 00137 } 00138 00139 static void node_composit_exec_combhsva(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00140 { 00141 /* stack order out: 1 rgba channels */ 00142 /* stack order in: 4 value channels */ 00143 00144 /* input no image? then only color operation */ 00145 if((in[0]->data==NULL) && (in[1]->data==NULL) && (in[2]->data==NULL) && (in[3]->data==NULL)) { 00146 out[0]->vec[0] = in[0]->vec[0]; 00147 out[0]->vec[1] = in[1]->vec[0]; 00148 out[0]->vec[2] = in[2]->vec[0]; 00149 out[0]->vec[3] = in[3]->vec[0]; 00150 } 00151 else { 00152 /* make output size of first available input image */ 00153 CompBuf *cbuf; 00154 CompBuf *stackbuf; 00155 00156 /* allocate a CompBuf the size of the first available input */ 00157 if (in[0]->data) cbuf = in[0]->data; 00158 else if (in[1]->data) cbuf = in[1]->data; 00159 else if (in[2]->data) cbuf = in[2]->data; 00160 else cbuf = in[3]->data; 00161 00162 stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ 00163 00164 composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, 00165 in[2]->data, in[2]->vec, in[3]->data, in[3]->vec, 00166 do_comb_hsva, CB_VAL, CB_VAL, CB_VAL, CB_VAL); 00167 00168 out[0]->data= stackbuf; 00169 } 00170 } 00171 00172 void register_node_type_cmp_combhsva(bNodeTreeType *ttype) 00173 { 00174 static bNodeType ntype; 00175 00176 node_type_base(ttype, &ntype, CMP_NODE_COMBHSVA, "Combine HSVA", NODE_CLASS_CONVERTOR, NODE_OPTIONS); 00177 node_type_socket_templates(&ntype, cmp_node_combhsva_in, cmp_node_combhsva_out); 00178 node_type_size(&ntype, 80, 40, 140); 00179 node_type_exec(&ntype, node_composit_exec_combhsva); 00180 00181 nodeRegisterType(ttype, &ntype); 00182 }