Blender V2.61 - r43446

node_composite_lummaMatte.c

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