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