Blender  V2.59
CMP_sepcombRGBA.c
Go to the documentation of this file.
00001 /*
00002  * $Id: CMP_sepcombRGBA.c 35237 2011-02-27 20:13:22Z jesterking $
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 /* **************** SEPARATE RGBA ******************** */
00038 static bNodeSocketType cmp_node_seprgba_in[]= {
00039         {       SOCK_RGBA, 1, "Image",                  0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
00040         {       -1, 0, ""       }
00041 };
00042 static bNodeSocketType cmp_node_seprgba_out[]= {
00043         {       SOCK_VALUE, 0, "R",                     0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00044         {       SOCK_VALUE, 0, "G",                     0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00045         {       SOCK_VALUE, 0, "B",                     0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00046         {       SOCK_VALUE, 0, "A",                     0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00047         {       -1, 0, ""       }
00048 };
00049 
00050 static void node_composit_exec_seprgba(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **in, bNodeStack **out)
00051 {
00052         /* stack order out: bw channels */
00053         /* stack order in: col */
00054         
00055         /* input no image? then only color operation */
00056         if(in[0]->data==NULL) {
00057                 out[0]->vec[0] = in[0]->vec[0];
00058                 out[1]->vec[0] = in[0]->vec[1];
00059                 out[2]->vec[0] = in[0]->vec[2];
00060                 out[3]->vec[0] = in[0]->vec[3];
00061         }
00062         else {
00063                 /* make sure we get right rgba buffer */
00064                 CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
00065 
00066                 /* don't do any pixel processing, just copy the stack directly (faster, I presume) */
00067                 if(out[0]->hasoutput)
00068                         out[0]->data= valbuf_from_rgbabuf(cbuf, CHAN_R);
00069                 if(out[1]->hasoutput)
00070                         out[1]->data= valbuf_from_rgbabuf(cbuf, CHAN_G);
00071                 if(out[2]->hasoutput)
00072                         out[2]->data= valbuf_from_rgbabuf(cbuf, CHAN_B);
00073                 if(out[3]->hasoutput)
00074                         out[3]->data= valbuf_from_rgbabuf(cbuf, CHAN_A);
00075                 
00076                 if(cbuf!=in[0]->data) 
00077                         free_compbuf(cbuf);
00078 
00079         }
00080 }
00081 
00082 void register_node_type_cmp_seprgba(ListBase *lb)
00083 {
00084         static bNodeType ntype;
00085 
00086         node_type_base(&ntype, CMP_NODE_SEPRGBA, "Separate RGBA", NODE_CLASS_CONVERTOR, 0,
00087                 cmp_node_seprgba_in, cmp_node_seprgba_out);
00088         node_type_size(&ntype, 80, 40, 140);
00089         node_type_exec(&ntype, node_composit_exec_seprgba);
00090 
00091         nodeRegisterType(lb, &ntype);
00092 }
00093 
00094 
00095 
00096 /* **************** COMBINE RGBA ******************** */
00097 static bNodeSocketType cmp_node_combrgba_in[]= {
00098         {       SOCK_VALUE, 1, "R",                     0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00099         {       SOCK_VALUE, 1, "G",                     0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00100         {       SOCK_VALUE, 1, "B",                     0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00101         {       SOCK_VALUE, 1, "A",                     1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00102         {       -1, 0, ""       }
00103 };
00104 static bNodeSocketType cmp_node_combrgba_out[]= {
00105         {       SOCK_RGBA, 0, "Image",                  0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
00106         {       -1, 0, ""       }
00107 };
00108 
00109 static void do_combrgba(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4)
00110 {
00111         out[0] = in1[0];
00112         out[1] = in2[0];
00113         out[2] = in3[0];
00114         out[3] = in4[0];
00115 }
00116 
00117 static void node_composit_exec_combrgba(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
00118 {
00119         /* stack order out: 1 rgba channels */
00120         /* stack order in: 4 value channels */
00121         
00122         /* input no image? then only color operation */
00123         if((in[0]->data==NULL) && (in[1]->data==NULL) && (in[2]->data==NULL) && (in[3]->data==NULL)) {
00124                 out[0]->vec[0] = in[0]->vec[0];
00125                 out[0]->vec[1] = in[1]->vec[0];
00126                 out[0]->vec[2] = in[2]->vec[0];
00127                 out[0]->vec[3] = in[3]->vec[0];
00128         }
00129         else {
00130                 /* make output size of first available input image */
00131                 CompBuf *cbuf;
00132                 CompBuf *stackbuf;
00133 
00134                 /* allocate a CompBuf the size of the first available input */
00135                 if (in[0]->data) cbuf = in[0]->data;
00136                 else if (in[1]->data) cbuf = in[1]->data;
00137                 else if (in[2]->data) cbuf = in[2]->data;
00138                 else cbuf = in[3]->data;
00139                 
00140                 stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
00141                 
00142                 composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, 
00143                                                                   in[2]->data, in[2]->vec, in[3]->data, in[3]->vec, 
00144                                                                   do_combrgba, CB_VAL, CB_VAL, CB_VAL, CB_VAL);
00145                 
00146                 out[0]->data= stackbuf;
00147         }       
00148 }
00149 
00150 void register_node_type_cmp_combrgba(ListBase *lb)
00151 {
00152         static bNodeType ntype;
00153 
00154         node_type_base(&ntype, CMP_NODE_COMBRGBA, "Combine RGBA", NODE_CLASS_CONVERTOR, NODE_OPTIONS,
00155                 cmp_node_combrgba_in, cmp_node_combrgba_out);
00156         node_type_size(&ntype, 80, 40, 140);
00157         node_type_exec(&ntype, node_composit_exec_combrgba);
00158 
00159         nodeRegisterType(lb, &ntype);
00160 }
00161 
00162