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