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