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 /* ******************* Color Key ********************************************************** */ 00036 static bNodeSocketTemplate cmp_node_color_in[]={ 00037 {SOCK_RGBA,1,"Image", 1.0f, 1.0f, 1.0f, 1.0f}, 00038 {SOCK_RGBA,1,"Key Color", 1.0f, 1.0f, 1.0f, 1.0f}, 00039 {-1,0,""} 00040 }; 00041 00042 static bNodeSocketTemplate cmp_node_color_out[]={ 00043 {SOCK_RGBA,0,"Image"}, 00044 {SOCK_FLOAT,0,"Matte"}, 00045 {-1,0,""} 00046 }; 00047 00048 static void do_color_key(bNode *node, float *out, float *in) 00049 { 00050 float h_wrap; 00051 NodeChroma *c; 00052 c=node->storage; 00053 00054 00055 copy_v3_v3(out, in); 00056 00057 if( 00058 /* do hue last because it needs to wrap, and does some more checks */ 00059 00060 /* sat */ (fabsf(in[1]-c->key[1]) < c->t2) && 00061 /* val */ (fabsf(in[2]-c->key[2]) < c->t3) && 00062 00063 /* multiply by 2 because it wraps on both sides of the hue, 00064 * otherwise 0.5 would key all hue's */ 00065 00066 /* hue */ ((h_wrap= 2.0f * fabsf(in[0]-c->key[0])) < c->t1 || (2.0f - h_wrap) < c->t1) 00067 ) { 00068 out[3]=0.0; /*make transparent*/ 00069 } 00070 00071 else { /*pixel is outside key color */ 00072 out[3]=in[3]; /* make pixel just as transparent as it was before */ 00073 } 00074 } 00075 00076 static void node_composit_exec_color_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) 00077 { 00078 CompBuf *cbuf; 00079 CompBuf *colorbuf; 00080 NodeChroma *c; 00081 00082 if(in[0]->hasinput==0) return; 00083 if(in[0]->data==NULL) return; 00084 if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return; 00085 00086 cbuf= typecheck_compbuf(in[0]->data, CB_RGBA); 00087 00088 colorbuf= dupalloc_compbuf(cbuf); 00089 00090 c=node->storage; 00091 00092 /*convert rgbbuf to hsv*/ 00093 composit1_pixel_processor(node, colorbuf, cbuf, in[0]->vec, do_rgba_to_hsva, CB_RGBA); 00094 00095 /*convert key to hsv*/ 00096 do_rgba_to_hsva(node, c->key, in[1]->vec); 00097 00098 00099 /*per pixel color key*/ 00100 composit1_pixel_processor(node, colorbuf, colorbuf, in[0]->vec, do_color_key, CB_RGBA); 00101 00102 /*convert back*/ 00103 composit1_pixel_processor(node, colorbuf, colorbuf, in[0]->vec, do_hsva_to_rgba, CB_RGBA); 00104 00105 out[0]->data= colorbuf; 00106 if(out[1]->hasoutput) 00107 out[1]->data= valbuf_from_rgbabuf(colorbuf, CHAN_A); 00108 00109 generate_preview(data, node, colorbuf); 00110 00111 if(cbuf!=in[0]->data) 00112 free_compbuf(cbuf); 00113 } 00114 00115 static void node_composit_init_color_matte(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) 00116 { 00117 NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node color"); 00118 node->storage= c; 00119 c->t1= 0.01f; 00120 c->t2= 0.1f; 00121 c->t3= 0.1f; 00122 c->fsize= 0.0f; 00123 c->fstrength= 1.0f; 00124 } 00125 00126 void register_node_type_cmp_color_matte(bNodeTreeType *ttype) 00127 { 00128 static bNodeType ntype; 00129 00130 node_type_base(ttype, &ntype, CMP_NODE_COLOR_MATTE, "Color Key", NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS); 00131 node_type_socket_templates(&ntype, cmp_node_color_in, cmp_node_color_out); 00132 node_type_size(&ntype, 200, 80, 300); 00133 node_type_init(&ntype, node_composit_init_color_matte); 00134 node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); 00135 node_type_exec(&ntype, node_composit_exec_color_matte); 00136 00137 nodeRegisterType(ttype, &ntype); 00138 }