Blender V2.61 - r43446

node_composite_splitViewer.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 /* **************** SPLIT VIEWER ******************** */
00036 static bNodeSocketTemplate cmp_node_splitviewer_in[]= {
00037     {   SOCK_RGBA, 1, "Image",      0.0f, 0.0f, 0.0f, 1.0f},
00038     {   SOCK_RGBA, 1, "Image",      0.0f, 0.0f, 0.0f, 1.0f},
00039     {   -1, 0, ""   }
00040 };
00041 
00042 static void do_copy_split_rgba(bNode *UNUSED(node), float *out, float *in1, float *in2, float *fac)
00043 {
00044     if(*fac==0.0f) {
00045         copy_v4_v4(out, in1);
00046     }
00047     else {
00048         copy_v4_v4(out, in2);
00049     }
00050 }
00051 
00052 static void node_composit_exec_splitviewer(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
00053 {
00054     /* image assigned to output */
00055     /* stack order input sockets: image image */
00056     
00057     if(in[0]->data==NULL || in[1]->data==NULL)
00058         return;
00059     
00060     if(node->id && (node->flag & NODE_DO_OUTPUT)) { /* only one works on out */
00061         Image *ima= (Image *)node->id;
00062         RenderData *rd= data;
00063         ImBuf *ibuf;
00064         CompBuf *cbuf, *buf1, *buf2, *mask;
00065         int x, y;
00066         float offset;
00067         void *lock;
00068         
00069         buf1= typecheck_compbuf(in[0]->data, CB_RGBA);
00070         buf2= typecheck_compbuf(in[1]->data, CB_RGBA);
00071         
00072         BKE_image_user_calc_frame(node->storage, rd->cfra, 0);
00073         
00074         /* always returns for viewer image, but we check nevertheless */
00075         ibuf= BKE_image_acquire_ibuf(ima, node->storage, &lock);
00076         if(ibuf==NULL) {
00077             printf("node_composit_exec_viewer error\n");
00078             BKE_image_release_ibuf(ima, lock);
00079             return;
00080         }
00081         
00082         /* free all in ibuf */
00083         imb_freerectImBuf(ibuf);
00084         imb_freerectfloatImBuf(ibuf);
00085         IMB_freezbuffloatImBuf(ibuf);
00086         
00087         /* make ibuf, and connect to ima */
00088         ibuf->x= buf1->x;
00089         ibuf->y= buf1->y;
00090         imb_addrectfloatImBuf(ibuf);
00091         
00092         ima->ok= IMA_OK_LOADED;
00093 
00094         /* output buf */
00095         cbuf= alloc_compbuf(buf1->x, buf1->y, CB_RGBA, 0);  /* no alloc*/
00096         cbuf->rect= ibuf->rect_float;
00097         
00098         /* mask buf */
00099         mask= alloc_compbuf(buf1->x, buf1->y, CB_VAL, 1);
00100         
00101         
00102         /* Check which offset mode is selected and limit offset if needed */
00103         if(node->custom2 == 0) {
00104             offset = buf1->x / 100.0f * node->custom1;
00105             CLAMP(offset, 0, buf1->x);
00106         }
00107         else {
00108             offset = buf1->y / 100.0f * node->custom1;
00109             CLAMP(offset, 0, buf1->y);
00110         }
00111         
00112         if(node->custom2 == 0) {
00113             for(y=0; y<buf1->y; y++) {
00114                 float *fac= mask->rect + y*buf1->x;
00115                 for(x=offset; x>0; x--, fac++)
00116                     *fac= 1.0f;
00117             }
00118         }
00119         else {
00120             for(y=0; y<offset; y++) {
00121                 float *fac= mask->rect + y*buf1->x;
00122                 for(x=buf1->x; x>0; x--, fac++)
00123                     *fac= 1.0f;
00124             }
00125         }
00126         
00127         composit3_pixel_processor(node, cbuf, buf1, in[0]->vec, buf2, in[1]->vec, mask, NULL, do_copy_split_rgba, CB_RGBA, CB_RGBA, CB_VAL);
00128         
00129         BKE_image_release_ibuf(ima, lock);
00130         
00131         generate_preview(data, node, cbuf);
00132         free_compbuf(cbuf);
00133         free_compbuf(mask);
00134         
00135         if(in[0]->data != buf1) 
00136             free_compbuf(buf1);
00137         if(in[1]->data != buf2) 
00138             free_compbuf(buf2);
00139     }
00140 }
00141 
00142 static void node_composit_init_splitviewer(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
00143 {
00144     ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user");
00145     node->storage= iuser;
00146     iuser->sfra= 1;
00147     iuser->fie_ima= 2;
00148     iuser->ok= 1;
00149     node->custom1= 50;  /* default 50% split */
00150 }
00151 
00152 void register_node_type_cmp_splitviewer(bNodeTreeType *ttype)
00153 {
00154     static bNodeType ntype;
00155 
00156     node_type_base(ttype, &ntype, CMP_NODE_SPLITVIEWER, "SplitViewer", NODE_CLASS_OUTPUT, NODE_PREVIEW|NODE_OPTIONS);
00157     node_type_socket_templates(&ntype, cmp_node_splitviewer_in, NULL);
00158     node_type_size(&ntype, 140, 100, 320);
00159     node_type_init(&ntype, node_composit_init_splitviewer);
00160     node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage);
00161     node_type_exec(&ntype, node_composit_exec_splitviewer);
00162     /* Do not allow muting this node. */
00163     node_type_mute(&ntype, NULL, NULL);
00164 
00165     nodeRegisterType(ttype, &ntype);
00166 }