Blender V2.61 - r43446

node_composite_viewer.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 /* **************** VIEWER ******************** */
00037 static bNodeSocketTemplate cmp_node_viewer_in[]= {
00038     {   SOCK_RGBA, 1, "Image",      0.0f, 0.0f, 0.0f, 1.0f},
00039     {   SOCK_FLOAT, 1, "Alpha",     1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE},
00040     {   SOCK_FLOAT, 1, "Z",         1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE},
00041     {   -1, 0, ""   }
00042 };
00043 
00044 
00045 static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
00046 {
00047     /* image assigned to output */
00048     /* stack order input sockets: col, alpha, z */
00049     
00050     if(node->id && (node->flag & NODE_DO_OUTPUT)) { /* only one works on out */
00051         RenderData *rd= data;
00052         Image *ima= (Image *)node->id;
00053         ImBuf *ibuf;
00054         CompBuf *cbuf, *tbuf;
00055         int rectx, recty;
00056         void *lock;
00057         
00058         BKE_image_user_calc_frame(node->storage, rd->cfra, 0);
00059 
00060         /* always returns for viewer image, but we check nevertheless */
00061         ibuf= BKE_image_acquire_ibuf(ima, node->storage, &lock);
00062         if(ibuf==NULL) {
00063             printf("node_composit_exec_viewer error\n");
00064             BKE_image_release_ibuf(ima, lock);
00065             return;
00066         }
00067         
00068         /* free all in ibuf */
00069         imb_freerectImBuf(ibuf);
00070         imb_freerectfloatImBuf(ibuf);
00071         IMB_freezbuffloatImBuf(ibuf);
00072         
00073         /* get size */
00074         tbuf= in[0]->data?in[0]->data:(in[1]->data?in[1]->data:in[2]->data);
00075         if(tbuf==NULL) {
00076             rectx= 320; recty= 256;
00077         }
00078         else {
00079             rectx= tbuf->x;
00080             recty= tbuf->y;
00081         }
00082         
00083         /* make ibuf, and connect to ima */
00084         ibuf->x= rectx;
00085         ibuf->y= recty;
00086         imb_addrectfloatImBuf(ibuf);
00087         
00088         ima->ok= IMA_OK_LOADED;
00089 
00090         /* now we combine the input with ibuf */
00091         cbuf= alloc_compbuf(rectx, recty, CB_RGBA, 0);  /* no alloc*/
00092         cbuf->rect= ibuf->rect_float;
00093         
00094         /* when no alpha, we can simply copy */
00095         if(in[1]->data==NULL) {
00096             composit1_pixel_processor(node, cbuf, in[0]->data, in[0]->vec, do_copy_rgba, CB_RGBA);
00097         }
00098         else
00099             composit2_pixel_processor(node, cbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_copy_a_rgba, CB_RGBA, CB_VAL);
00100         
00101         /* zbuf option */
00102         if(in[2]->data) {
00103             CompBuf *zbuf= alloc_compbuf(rectx, recty, CB_VAL, 1);
00104             ibuf->zbuf_float= zbuf->rect;
00105             ibuf->mall |= IB_zbuffloat;
00106             
00107             composit1_pixel_processor(node, zbuf, in[2]->data, in[2]->vec, do_copy_value, CB_VAL);
00108             
00109             /* free compbuf, but not the rect */
00110             zbuf->malloc= 0;
00111             free_compbuf(zbuf);
00112         }
00113 
00114         BKE_image_release_ibuf(ima, lock);
00115 
00116         generate_preview(data, node, cbuf);
00117         free_compbuf(cbuf);
00118 
00119     }
00120     else if(in[0]->data) {
00121         generate_preview(data, node, in[0]->data);
00122     }
00123 }
00124 
00125 static void node_composit_init_viewer(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
00126 {
00127     ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user");
00128     node->storage= iuser;
00129     iuser->sfra= 1;
00130     iuser->fie_ima= 2;
00131     iuser->ok= 1;
00132 }
00133 
00134 void register_node_type_cmp_viewer(bNodeTreeType *ttype)
00135 {
00136     static bNodeType ntype;
00137 
00138     node_type_base(ttype, &ntype, CMP_NODE_VIEWER, "Viewer", NODE_CLASS_OUTPUT, NODE_PREVIEW);
00139     node_type_socket_templates(&ntype, cmp_node_viewer_in, NULL);
00140     node_type_size(&ntype, 80, 60, 200);
00141     node_type_init(&ntype, node_composit_init_viewer);
00142     node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage);
00143     node_type_exec(&ntype, node_composit_exec_viewer);
00144     /* Do not allow muting this node. */
00145     node_type_mute(&ntype, NULL, NULL);
00146 
00147     nodeRegisterType(ttype, &ntype);
00148 }