Blender V2.61 - r43446

node_composite_sepcombRGBA.c

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