Blender V2.61 - r43446

node_composite_idMask.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): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #include "node_composite_util.h"
00034 
00035 
00036 /* **************** ID Mask  ******************** */
00037 
00038 static bNodeSocketTemplate cmp_node_idmask_in[]= {
00039     {   SOCK_FLOAT, 1, "ID value",          1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
00040     {   -1, 0, ""   }
00041 };
00042 static bNodeSocketTemplate cmp_node_idmask_out[]= {
00043     {   SOCK_FLOAT, 0, "Alpha"},
00044     {   -1, 0, ""   }
00045 };
00046 
00047 /* stackbuf should be zeroed */
00048 static void do_idmask(CompBuf *stackbuf, CompBuf *cbuf, float idnr)
00049 {
00050     float *rect;
00051     int x;
00052     char *abuf= MEM_mapallocN(cbuf->x*cbuf->y, "anti ali buf");
00053     
00054     rect= cbuf->rect;
00055     for(x= cbuf->x*cbuf->y - 1; x>=0; x--)
00056         if(rect[x]==idnr)
00057             abuf[x]= 255;
00058     
00059     antialias_tagbuf(cbuf->x, cbuf->y, abuf);
00060     
00061     rect= stackbuf->rect;
00062     for(x= cbuf->x*cbuf->y - 1; x>=0; x--)
00063         if(abuf[x]>1)
00064             rect[x]= (1.0f/255.0f)*(float)abuf[x];
00065     
00066     MEM_freeN(abuf);
00067 }
00068 
00069 /* full sample version */
00070 static void do_idmask_fsa(CompBuf *stackbuf, CompBuf *cbuf, float idnr)
00071 {
00072     float *rect, *rs;
00073     int x;
00074     
00075     rect= cbuf->rect;
00076     rs= stackbuf->rect;
00077     for(x= cbuf->x*cbuf->y - 1; x>=0; x--)
00078         if(rect[x]==idnr)
00079             rs[x]= 1.0f;
00080     
00081 }
00082 
00083 
00084 static void node_composit_exec_idmask(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
00085 {
00086     RenderData *rd= data;
00087     
00088     if(out[0]->hasoutput==0)
00089         return;
00090     
00091     if(in[0]->data) {
00092         CompBuf *cbuf= in[0]->data;
00093         CompBuf *stackbuf;
00094         
00095         if(cbuf->type!=CB_VAL)
00096             return;
00097         
00098         stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */;
00099         
00100         if((rd->scemode & R_FULL_SAMPLE) || node->custom2 == 0)
00101             do_idmask_fsa(stackbuf, cbuf, (float)node->custom1);
00102         else
00103             do_idmask(stackbuf, cbuf, (float)node->custom1);
00104         
00105         out[0]->data= stackbuf;
00106     }
00107 }
00108 
00109 
00110 void register_node_type_cmp_idmask(bNodeTreeType *ttype)
00111 {
00112     static bNodeType ntype;
00113 
00114     node_type_base(ttype, &ntype, CMP_NODE_ID_MASK, "ID Mask", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
00115     node_type_socket_templates(&ntype, cmp_node_idmask_in, cmp_node_idmask_out);
00116     node_type_size(&ntype, 140, 100, 320);
00117     node_type_exec(&ntype, node_composit_exec_idmask);
00118 
00119     nodeRegisterType(ttype, &ntype);
00120 }