Blender  V2.59
CMP_mixrgb.c
Go to the documentation of this file.
00001 /*
00002  * $Id: CMP_mixrgb.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 
00034 #include "../CMP_util.h"
00035 
00036 /* **************** MIX RGB ******************** */
00037 static bNodeSocketType cmp_node_mix_rgb_in[]= {
00038         {       SOCK_VALUE, 1, "Fac",                   0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 5.0f},
00039         {       SOCK_RGBA, 1, "Image",                  0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
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_mix_rgb_out[]= {
00044         {       SOCK_RGBA, 0, "Image",                  0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00045         {       -1, 0, ""       }
00046 };
00047 
00048 static void do_mix_rgb(bNode *node, float *out, float *in1, float *in2, float *fac)
00049 {
00050         float col[3];
00051         
00052         VECCOPY(col, in1);
00053         if(node->custom2)
00054                 ramp_blend(node->custom1, col, col+1, col+2, in2[3]*fac[0], in2);
00055         else
00056                 ramp_blend(node->custom1, col, col+1, col+2, fac[0], in2);
00057         VECCOPY(out, col);
00058         out[3]= in1[3];
00059 }
00060 
00061 static void node_composit_exec_mix_rgb(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
00062 {
00063         /* stack order in: fac, Image, Image */
00064         /* stack order out: Image */
00065         float *fac= in[0]->vec;
00066         
00067         if(out[0]->hasoutput==0) return;
00068         
00069         /* input no image? then only color operation */
00070         if(in[1]->data==NULL && in[2]->data==NULL) {
00071                 do_mix_rgb(node, out[0]->vec, in[1]->vec, in[2]->vec, fac);
00072         }
00073         else {
00074                 /* make output size of first available input image */
00075                 CompBuf *cbuf= in[1]->data?in[1]->data:in[2]->data;
00076                 CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
00077                 
00078                 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);
00079                 
00080                 out[0]->data= stackbuf;
00081                 
00082                 generate_preview(data, node, out[0]->data);
00083         }
00084 }
00085 
00086 /* custom1 = mix type */
00087 void register_node_type_cmp_mix_rgb(ListBase *lb)
00088 {
00089         static bNodeType ntype;
00090 
00091         node_type_base(&ntype, CMP_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, NODE_PREVIEW|NODE_OPTIONS,
00092                 cmp_node_mix_rgb_in, cmp_node_mix_rgb_out);
00093         node_type_size(&ntype, 110, 60, 120);
00094         node_type_label(&ntype, node_blend_label);
00095         node_type_exec(&ntype, node_composit_exec_mix_rgb);
00096 
00097         nodeRegisterType(lb, &ntype);
00098 }
00099