Blender  V2.59
CMP_idMask.c
Go to the documentation of this file.
00001 /*
00002  * $Id: CMP_idMask.c 35237 2011-02-27 20:13:22Z jesterking $
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): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00035 #include "../CMP_util.h"
00036 
00037 
00038 /* **************** ID Mask  ******************** */
00039 
00040 static bNodeSocketType cmp_node_idmask_in[]= {
00041         {       SOCK_VALUE, 1, "ID value",                      0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
00042         {       -1, 0, ""       }
00043 };
00044 static bNodeSocketType cmp_node_idmask_out[]= {
00045         {       SOCK_VALUE, 0, "Alpha",                 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00046         {       -1, 0, ""       }
00047 };
00048 
00049 /* stackbuf should be zeroed */
00050 static void do_idmask(CompBuf *stackbuf, CompBuf *cbuf, float idnr)
00051 {
00052         float *rect;
00053         int x;
00054         char *abuf= MEM_mapallocN(cbuf->x*cbuf->y, "anti ali buf");
00055         
00056         rect= cbuf->rect;
00057         for(x= cbuf->x*cbuf->y - 1; x>=0; x--)
00058                 if(rect[x]==idnr)
00059                         abuf[x]= 255;
00060         
00061         antialias_tagbuf(cbuf->x, cbuf->y, abuf);
00062         
00063         rect= stackbuf->rect;
00064         for(x= cbuf->x*cbuf->y - 1; x>=0; x--)
00065                 if(abuf[x]>1)
00066                         rect[x]= (1.0f/255.0f)*(float)abuf[x];
00067         
00068         MEM_freeN(abuf);
00069 }
00070 
00071 /* full sample version */
00072 static void do_idmask_fsa(CompBuf *stackbuf, CompBuf *cbuf, float idnr)
00073 {
00074         float *rect, *rs;
00075         int x;
00076         
00077         rect= cbuf->rect;
00078         rs= stackbuf->rect;
00079         for(x= cbuf->x*cbuf->y - 1; x>=0; x--)
00080                 if(rect[x]==idnr)
00081                         rs[x]= 1.0f;
00082         
00083 }
00084 
00085 
00086 static void node_composit_exec_idmask(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
00087 {
00088         RenderData *rd= data;
00089         
00090         if(out[0]->hasoutput==0)
00091                 return;
00092         
00093         if(in[0]->data) {
00094                 CompBuf *cbuf= in[0]->data;
00095                 CompBuf *stackbuf;
00096                 
00097                 if(cbuf->type!=CB_VAL)
00098                         return;
00099                 
00100                 stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */;
00101                 
00102                 if(rd->scemode & R_FULL_SAMPLE)
00103                         do_idmask_fsa(stackbuf, cbuf, (float)node->custom1);
00104                 else
00105                         do_idmask(stackbuf, cbuf, (float)node->custom1);
00106                 
00107                 out[0]->data= stackbuf;
00108         }
00109 }
00110 
00111 
00112 void register_node_type_cmp_idmask(ListBase *lb)
00113 {
00114         static bNodeType ntype;
00115 
00116         node_type_base(&ntype, CMP_NODE_ID_MASK, "ID Mask", NODE_CLASS_CONVERTOR, NODE_OPTIONS,
00117                 cmp_node_idmask_in, cmp_node_idmask_out);
00118         node_type_size(&ntype, 140, 100, 320);
00119         node_type_exec(&ntype, node_composit_exec_idmask);
00120 
00121         nodeRegisterType(lb, &ntype);
00122 }
00123 
00124 
00125