|
Blender
V2.59
|
00001 /* 00002 * $Id: CMP_diffMatte.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): Bob Holcomb 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00035 #include "../CMP_util.h" 00036 00037 /* ******************* channel Difference Matte ********************************* */ 00038 static bNodeSocketType cmp_node_diff_matte_in[]={ 00039 {SOCK_RGBA,1,"Image 1", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, 00040 {SOCK_RGBA,1,"Image 2", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, 00041 {-1,0,""} 00042 }; 00043 00044 static bNodeSocketType cmp_node_diff_matte_out[]={ 00045 {SOCK_RGBA,0,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, 00046 {SOCK_VALUE,0,"Matte",0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, 00047 {-1,0,""} 00048 }; 00049 00050 static void do_diff_matte(bNode *node, float *outColor, float *inColor1, float *inColor2) 00051 { 00052 NodeChroma *c= (NodeChroma *)node->storage; 00053 float tolerence=c->t1; 00054 float falloff=c->t2; 00055 float difference; 00056 float alpha; 00057 00058 difference= fabs(inColor2[0]-inColor1[0])+ 00059 fabs(inColor2[1]-inColor1[1])+ 00060 fabs(inColor2[2]-inColor1[2]); 00061 00062 /*average together the distances*/ 00063 difference=difference/3.0; 00064 00065 VECCOPY(outColor, inColor1); 00066 00067 /*make 100% transparent*/ 00068 if(difference < tolerence) { 00069 outColor[3]=0.0; 00070 } 00071 /*in the falloff region, make partially transparent */ 00072 else if(difference < falloff+tolerence) { 00073 difference=difference-tolerence; 00074 alpha=difference/falloff; 00075 /*only change if more transparent than before */ 00076 if(alpha < inColor1[3]) { 00077 outColor[3]=alpha; 00078 } 00079 else { /* leave as before */ 00080 outColor[3]=inColor1[3]; 00081 } 00082 } 00083 else { 00084 /*foreground object*/ 00085 outColor[3]= inColor1[3]; 00086 } 00087 } 00088 00089 static void node_composit_exec_diff_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) 00090 { 00091 CompBuf *outbuf=0; 00092 CompBuf *imbuf1=0; 00093 CompBuf *imbuf2=0; 00094 NodeChroma *c; 00095 00096 /*is anything connected?*/ 00097 if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return; 00098 00099 /*must have an image imput*/ 00100 if(in[0]->data==NULL) return; 00101 00102 00103 imbuf1=typecheck_compbuf(in[0]->data, CB_RGBA); 00104 00105 /* if there's an image, use that, if not use the color */ 00106 if(in[1]->data) { 00107 imbuf2=typecheck_compbuf(in[1]->data, CB_RGBA); 00108 } 00109 00110 c=node->storage; 00111 outbuf=dupalloc_compbuf(imbuf1); 00112 00113 /* note, processor gets a keyvals array passed on as buffer constant */ 00114 composit2_pixel_processor(node, outbuf, imbuf1, in[0]->vec, imbuf2, in[1]->vec, do_diff_matte, CB_RGBA, CB_RGBA); 00115 00116 out[0]->data=outbuf; 00117 if(out[1]->hasoutput) 00118 out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A); 00119 generate_preview(data, node, outbuf); 00120 00121 if(imbuf1!=in[0]->data) 00122 free_compbuf(imbuf1); 00123 00124 if(imbuf2!=in[1]->data) 00125 free_compbuf(imbuf2); 00126 } 00127 00128 static void node_composit_init_diff_matte(bNode *node) 00129 { 00130 NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma"); 00131 node->storage= c; 00132 c->t1= 0.1f; 00133 c->t2= 0.1f; 00134 } 00135 00136 void register_node_type_cmp_diff_matte(ListBase *lb) 00137 { 00138 static bNodeType ntype; 00139 00140 node_type_base(&ntype, CMP_NODE_DIFF_MATTE, "Difference Key", NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS, 00141 cmp_node_diff_matte_in, cmp_node_diff_matte_out); 00142 node_type_size(&ntype, 200, 80, 250); 00143 node_type_init(&ntype, node_composit_init_diff_matte); 00144 node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); 00145 node_type_exec(&ntype, node_composit_exec_diff_matte); 00146 00147 nodeRegisterType(lb, &ntype); 00148 } 00149 00150 00151