Blender V2.61 - r43446

node_composite_vecBlur.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 /* **************** VECTOR BLUR ******************** */
00037 static bNodeSocketTemplate cmp_node_vecblur_in[]= {
00038     {   SOCK_RGBA, 1, "Image",          1.0f, 1.0f, 1.0f, 1.0f},
00039     {   SOCK_FLOAT, 1, "Z",         0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE},
00040     {   SOCK_VECTOR, 1, "Speed",            0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_VELOCITY},
00041     {   -1, 0, ""   }
00042 };
00043 static bNodeSocketTemplate cmp_node_vecblur_out[]= {
00044     {   SOCK_RGBA, 0, "Image"},
00045     {   -1, 0, ""   }
00046 };
00047 
00048 
00049 
00050 static void node_composit_exec_vecblur(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
00051 {
00052     NodeBlurData *nbd= node->storage;
00053     CompBuf *new, *img= in[0]->data, *vecbuf= in[2]->data, *zbuf= in[1]->data;
00054     
00055     if(img==NULL || vecbuf==NULL || zbuf==NULL || out[0]->hasoutput==0)
00056         return;
00057     if(vecbuf->x!=img->x || vecbuf->y!=img->y) {
00058         printf("ERROR: cannot do different sized vecbuf yet\n");
00059         return;
00060     }
00061     if(vecbuf->type!=CB_VEC4) {
00062         printf("ERROR: input should be vecbuf\n");
00063         return;
00064     }
00065     if(zbuf->type!=CB_VAL) {
00066         printf("ERROR: input should be zbuf\n");
00067         return;
00068     }
00069     if(zbuf->x!=img->x || zbuf->y!=img->y) {
00070         printf("ERROR: cannot do different sized zbuf yet\n");
00071         return;
00072     }
00073     
00074     /* allow the input image to be of another type */
00075     img= typecheck_compbuf(in[0]->data, CB_RGBA);
00076 
00077     new= dupalloc_compbuf(img);
00078     
00079     /* call special zbuffer version */
00080     RE_zbuf_accumulate_vecblur(nbd, img->x, img->y, new->rect, img->rect, vecbuf->rect, zbuf->rect);
00081     
00082     out[0]->data= new;
00083     
00084     if(img!=in[0]->data)
00085         free_compbuf(img);
00086 }
00087 
00088 static void node_composit_init_vecblur(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
00089 {
00090     NodeBlurData *nbd= MEM_callocN(sizeof(NodeBlurData), "node blur data");
00091     node->storage= nbd;
00092     nbd->samples= 32;
00093     nbd->fac= 1.0f;
00094 }
00095 
00096 /* custom1: itterations, custom2: maxspeed (0 = nolimit) */
00097 void register_node_type_cmp_vecblur(bNodeTreeType *ttype)
00098 {
00099     static bNodeType ntype;
00100 
00101     node_type_base(ttype, &ntype, CMP_NODE_VECBLUR, "Vector Blur", NODE_CLASS_OP_FILTER, NODE_OPTIONS);
00102     node_type_socket_templates(&ntype, cmp_node_vecblur_in, cmp_node_vecblur_out);
00103     node_type_size(&ntype, 120, 80, 200);
00104     node_type_init(&ntype, node_composit_init_vecblur);
00105     node_type_storage(&ntype, "NodeBlurData", node_free_standard_storage, node_copy_standard_storage);
00106     node_type_exec(&ntype, node_composit_exec_vecblur);
00107 
00108     nodeRegisterType(ttype, &ntype);
00109 }