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