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 00032 #include "node_composite_util.h" 00033 00034 /* **************** INVERT ******************** */ 00035 static bNodeSocketTemplate cmp_node_invert_in[]= { 00036 { SOCK_FLOAT, 1, "Fac", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, 00037 { SOCK_RGBA, 1, "Color", 1.0f, 1.0f, 1.0f, 1.0f}, 00038 { -1, 0, "" } 00039 }; 00040 00041 static bNodeSocketTemplate cmp_node_invert_out[]= { 00042 { SOCK_RGBA, 0, "Color"}, 00043 { -1, 0, "" } 00044 }; 00045 00046 static void do_invert(bNode *node, float *out, float *in) 00047 { 00048 if(node->custom1 & CMP_CHAN_RGB) { 00049 out[0] = 1.0f - in[0]; 00050 out[1] = 1.0f - in[1]; 00051 out[2] = 1.0f - in[2]; 00052 } else 00053 copy_v3_v3(out, in); 00054 00055 if(node->custom1 & CMP_CHAN_A) 00056 out[3] = 1.0f - in[3]; 00057 else 00058 out[3] = in[3]; 00059 } 00060 00061 static void do_invert_fac(bNode *node, float *out, float *in, float *fac) 00062 { 00063 float col[4], facm; 00064 00065 do_invert(node, col, in); 00066 00067 /* blend inverted result against original input with fac */ 00068 facm = 1.0f - fac[0]; 00069 00070 if(node->custom1 & CMP_CHAN_RGB) { 00071 col[0] = fac[0]*col[0] + (facm*in[0]); 00072 col[1] = fac[0]*col[1] + (facm*in[1]); 00073 col[2] = fac[0]*col[2] + (facm*in[2]); 00074 } 00075 if(node->custom1 & CMP_CHAN_A) 00076 col[3] = fac[0]*col[3] + (facm*in[3]); 00077 00078 copy_v4_v4(out, col); 00079 } 00080 00081 static void node_composit_exec_invert(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00082 { 00083 /* stack order in: fac, Image, Image */ 00084 /* stack order out: Image */ 00085 float *fac= in[0]->vec; 00086 00087 if(out[0]->hasoutput==0) return; 00088 00089 /* input no image? then only color operation */ 00090 if(in[1]->data==NULL && in[0]->data==NULL) { 00091 do_invert_fac(node, out[0]->vec, in[1]->vec, fac); 00092 } 00093 else { 00094 /* make output size of first available input image, or then size of fac */ 00095 CompBuf *cbuf= in[1]->data?in[1]->data:in[0]->data; 00096 00097 /* if neither RGB or A toggled on, pass through */ 00098 if (node->custom1 != 0) { 00099 CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ 00100 00101 if (fac[0] < 1.0f || in[0]->data!=NULL) 00102 composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, fac, do_invert_fac, CB_RGBA, CB_VAL); 00103 else 00104 composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_invert, CB_RGBA); 00105 out[0]->data= stackbuf; 00106 return; 00107 00108 } else { 00109 out[0]->data = pass_on_compbuf(cbuf); 00110 return; 00111 } 00112 } 00113 } 00114 00115 static void node_composit_init_invert(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) 00116 { 00117 node->custom1 |= CMP_CHAN_RGB; 00118 } 00119 00120 /* custom1 = mix type */ 00121 void register_node_type_cmp_invert(bNodeTreeType *ttype) 00122 { 00123 static bNodeType ntype; 00124 00125 node_type_base(ttype, &ntype, CMP_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, NODE_OPTIONS); 00126 node_type_socket_templates(&ntype, cmp_node_invert_in, cmp_node_invert_out); 00127 node_type_size(&ntype, 120, 120, 140); 00128 node_type_init(&ntype, node_composit_init_invert); 00129 node_type_exec(&ntype, node_composit_exec_invert); 00130 00131 nodeRegisterType(ttype, &ntype); 00132 }