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