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 YUVA ******************** */ 00037 static bNodeSocketTemplate cmp_node_sepyuva_in[]= { 00038 { SOCK_RGBA, 1, "Image", 1.0f, 1.0f, 1.0f, 1.0f}, 00039 { -1, 0, "" } 00040 }; 00041 static bNodeSocketTemplate cmp_node_sepyuva_out[]= { 00042 { SOCK_FLOAT, 0, "Y"}, 00043 { SOCK_FLOAT, 0, "U"}, 00044 { SOCK_FLOAT, 0, "V"}, 00045 { SOCK_FLOAT, 0, "A"}, 00046 { -1, 0, "" } 00047 }; 00048 00049 static void do_sepyuva(bNode *UNUSED(node), float *out, float *in) 00050 { 00051 float y, u, v; 00052 00053 rgb_to_yuv(in[0], in[1], in[2], &y, &u, &v); 00054 00055 out[0]= y; 00056 out[1]= u; 00057 out[2]= v; 00058 out[3]= in[3]; 00059 } 00060 00061 static void node_composit_exec_sepyuva(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 y, u, v; 00069 00070 rgb_to_yuv(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &u, &v); 00071 00072 out[0]->vec[0] = y; 00073 out[1]->vec[0] = u; 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 /* make copy of buffer so input image 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 YUV representation */ 00083 composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepyuva, 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_sepyuva(bNodeTreeType *ttype) 00103 { 00104 static bNodeType ntype; 00105 00106 node_type_base(ttype, &ntype, CMP_NODE_SEPYUVA, "Separate YUVA", NODE_CLASS_CONVERTOR, 0); 00107 node_type_socket_templates(&ntype, cmp_node_sepyuva_in, cmp_node_sepyuva_out); 00108 node_type_size(&ntype, 80, 40, 140); 00109 node_type_exec(&ntype, node_composit_exec_sepyuva); 00110 00111 nodeRegisterType(ttype, &ntype); 00112 } 00113 00114 00115 00116 /* **************** COMBINE YUVA ******************** */ 00117 static bNodeSocketTemplate cmp_node_combyuva_in[]= { 00118 { SOCK_FLOAT, 1, "Y", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, 00119 { SOCK_FLOAT, 1, "U", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, 00120 { SOCK_FLOAT, 1, "V", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, 00121 { SOCK_FLOAT, 1, "A", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, 00122 { -1, 0, "" } 00123 }; 00124 static bNodeSocketTemplate cmp_node_combyuva_out[]= { 00125 { SOCK_RGBA, 0, "Image"}, 00126 { -1, 0, "" } 00127 }; 00128 00129 static void do_comb_yuva(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4) 00130 { 00131 float r,g,b; 00132 yuv_to_rgb(in1[0], in2[0], in3[0], &r, &g, &b); 00133 00134 out[0] = r; 00135 out[1] = g; 00136 out[2] = b; 00137 out[3] = in4[0]; 00138 } 00139 00140 static void node_composit_exec_combyuva(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00141 { 00142 /* stack order out: 1 rgba channels */ 00143 /* stack order in: 4 value channels */ 00144 00145 /* input no image? then only color operation */ 00146 if((in[0]->data==NULL) && (in[1]->data==NULL) && (in[2]->data==NULL) && (in[3]->data==NULL)) { 00147 out[0]->vec[0] = in[0]->vec[0]; 00148 out[0]->vec[1] = in[1]->vec[0]; 00149 out[0]->vec[2] = in[2]->vec[0]; 00150 out[0]->vec[3] = in[3]->vec[0]; 00151 } 00152 else { 00153 /* make output size of first available input image */ 00154 CompBuf *cbuf; 00155 CompBuf *stackbuf; 00156 00157 /* allocate a CompBuf the size of the first available input */ 00158 if (in[0]->data) cbuf = in[0]->data; 00159 else if (in[1]->data) cbuf = in[1]->data; 00160 else if (in[2]->data) cbuf = in[2]->data; 00161 else cbuf = in[3]->data; 00162 00163 stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ 00164 00165 composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, 00166 in[2]->data, in[2]->vec, in[3]->data, in[3]->vec, 00167 do_comb_yuva, CB_VAL, CB_VAL, CB_VAL, CB_VAL); 00168 00169 out[0]->data= stackbuf; 00170 } 00171 } 00172 00173 void register_node_type_cmp_combyuva(bNodeTreeType *ttype) 00174 { 00175 static bNodeType ntype; 00176 00177 node_type_base(ttype, &ntype, CMP_NODE_COMBYUVA, "Combine YUVA", NODE_CLASS_CONVERTOR, NODE_OPTIONS); 00178 node_type_socket_templates(&ntype, cmp_node_combyuva_in, cmp_node_combyuva_out); 00179 node_type_size(&ntype, 80, 40, 140); 00180 node_type_exec(&ntype, node_composit_exec_combyuva); 00181 00182 nodeRegisterType(ttype, &ntype); 00183 }