Blender V2.61 - r43446

node_composite_mixrgb.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 
00032 #include "node_composite_util.h"
00033 
00034 /* **************** MIX RGB ******************** */
00035 static bNodeSocketTemplate cmp_node_mix_rgb_in[]= {
00036     {   SOCK_FLOAT, 1, "Fac",           1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 5.0f, PROP_FACTOR},
00037     {   SOCK_RGBA, 1, "Image",          1.0f, 1.0f, 1.0f, 1.0f},
00038     {   SOCK_RGBA, 1, "Image",          1.0f, 1.0f, 1.0f, 1.0f},
00039     {   -1, 0, ""   }
00040 };
00041 static bNodeSocketTemplate cmp_node_mix_rgb_out[]= {
00042     {   SOCK_RGBA, 0, "Image"},
00043     {   -1, 0, ""   }
00044 };
00045 
00046 static void do_mix_rgb(bNode *node, float *out, float *in1, float *in2, float *fac)
00047 {
00048     float col[3];
00049     
00050     copy_v3_v3(col, in1);
00051     if(node->custom2)
00052         ramp_blend(node->custom1, col, in2[3]*fac[0], in2);
00053     else
00054         ramp_blend(node->custom1, col, fac[0], in2);
00055     copy_v3_v3(out, col);
00056     out[3]= in1[3];
00057 }
00058 
00059 static void node_composit_exec_mix_rgb(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
00060 {
00061     /* stack order in: fac, Image, Image */
00062     /* stack order out: Image */
00063     float *fac= in[0]->vec;
00064     
00065     if(out[0]->hasoutput==0) return;
00066     
00067     /* input no image? then only color operation */
00068     if(in[1]->data==NULL && in[2]->data==NULL) {
00069         do_mix_rgb(node, out[0]->vec, in[1]->vec, in[2]->vec, fac);
00070     }
00071     else {
00072         /* make output size of first available input image */
00073         CompBuf *cbuf= in[1]->data?in[1]->data:in[2]->data;
00074         CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
00075         
00076         composit3_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, in[0]->data, fac, do_mix_rgb, CB_RGBA, CB_RGBA, CB_VAL);
00077         
00078         out[0]->data= stackbuf;
00079         
00080         generate_preview(data, node, out[0]->data);
00081     }
00082 }
00083 
00084 /* custom1 = mix type */
00085 void register_node_type_cmp_mix_rgb(bNodeTreeType *ttype)
00086 {
00087     static bNodeType ntype;
00088 
00089     node_type_base(ttype, &ntype, CMP_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, NODE_PREVIEW|NODE_OPTIONS);
00090     node_type_socket_templates(&ntype, cmp_node_mix_rgb_in, cmp_node_mix_rgb_out);
00091     node_type_size(&ntype, 110, 60, 120);
00092     node_type_label(&ntype, node_blend_label);
00093     node_type_exec(&ntype, node_composit_exec_mix_rgb);
00094 
00095     nodeRegisterType(ttype, &ntype);
00096 }