|
Blender
V2.59
|
00001 /* 00002 * $Id: CMP_lummaMatte.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 00038 /* ******************* Luma Matte Node ********************************* */ 00039 static bNodeSocketType cmp_node_luma_matte_in[]={ 00040 {SOCK_RGBA,1,"Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, 00041 {-1,0,""} 00042 }; 00043 00044 static bNodeSocketType cmp_node_luma_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_luma_matte(bNode *node, float *out, float *in) 00051 { 00052 NodeChroma *c=(NodeChroma *)node->storage; 00053 float alpha; 00054 00055 alpha=0.0; 00056 00057 /* test range*/ 00058 if(in[0]>c->t1) { 00059 alpha=1.0; 00060 } 00061 else if(in[0]<c->t2){ 00062 alpha=0.0; 00063 } 00064 else {/*blend */ 00065 alpha=(in[0]-c->t2)/(c->t1-c->t2); 00066 } 00067 00068 /* don't make something that was more transparent less transparent */ 00069 if (alpha<in[3]) { 00070 out[3]=alpha; 00071 } 00072 else { 00073 out[3]=in[3]; 00074 } 00075 00076 } 00077 00078 static void node_composit_exec_luma_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) 00079 { 00080 CompBuf *cbuf; 00081 CompBuf *outbuf; 00082 00083 if(in[0]->hasinput==0) return; 00084 if(in[0]->data==NULL) return; 00085 if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return; 00086 00087 cbuf=typecheck_compbuf(in[0]->data, CB_RGBA); 00088 00089 outbuf=dupalloc_compbuf(cbuf); 00090 00091 composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_yuva, CB_RGBA); 00092 composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_luma_matte, CB_RGBA); 00093 composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_yuva_to_rgba, CB_RGBA); 00094 00095 generate_preview(data, node, outbuf); 00096 out[0]->data=outbuf; 00097 if (out[1]->hasoutput) 00098 out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A); 00099 if(cbuf!=in[0]->data) 00100 free_compbuf(cbuf); 00101 } 00102 00103 static void node_composit_init_luma_matte(bNode *node) 00104 { 00105 NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma"); 00106 node->storage=c; 00107 c->t1= 1.0f; 00108 c->t2= 0.0f; 00109 } 00110 00111 void register_node_type_cmp_luma_matte(ListBase *lb) 00112 { 00113 static bNodeType ntype; 00114 00115 node_type_base(&ntype, CMP_NODE_LUMA_MATTE, "Luminance Key", NODE_CLASS_MATTE, NODE_PREVIEW|NODE_OPTIONS, 00116 cmp_node_luma_matte_in, cmp_node_luma_matte_out); 00117 node_type_size(&ntype, 200, 80, 250); 00118 node_type_init(&ntype, node_composit_init_luma_matte); 00119 node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); 00120 node_type_exec(&ntype, node_composit_exec_luma_matte); 00121 00122 nodeRegisterType(lb, &ntype); 00123 } 00124 00125