|
Blender
V2.59
|
00001 /* 00002 * $Id: TEX_image.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): Robin Allen 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00035 #include "../TEX_util.h" 00036 #include "TEX_node.h" 00037 00038 static bNodeSocketType outputs[]= { 00039 { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, 00040 { -1, 0, "" } 00041 }; 00042 00043 static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread)) 00044 { 00045 float x = p->co[0]; 00046 float y = p->co[1]; 00047 Image *ima= (Image *)node->id; 00048 ImageUser *iuser= (ImageUser *)node->storage; 00049 00050 if( ima ) { 00051 ImBuf *ibuf = BKE_image_get_ibuf(ima, iuser); 00052 if( ibuf ) { 00053 float xsize, ysize; 00054 float xoff, yoff; 00055 int px, py; 00056 00057 float *result; 00058 00059 xsize = ibuf->x / 2; 00060 ysize = ibuf->y / 2; 00061 xoff = yoff = -1; 00062 00063 px = (int)( (x-xoff) * xsize ); 00064 py = (int)( (y-yoff) * ysize ); 00065 00066 if( (!xsize) || (!ysize) ) return; 00067 00068 if( !ibuf->rect_float ) { 00069 BLI_lock_thread(LOCK_IMAGE); 00070 if( !ibuf->rect_float ) 00071 IMB_float_from_rect(ibuf); 00072 BLI_unlock_thread(LOCK_IMAGE); 00073 } 00074 00075 while( px < 0 ) px += ibuf->x; 00076 while( py < 0 ) py += ibuf->y; 00077 while( px >= ibuf->x ) px -= ibuf->x; 00078 while( py >= ibuf->y ) py -= ibuf->y; 00079 00080 result = ibuf->rect_float + py*ibuf->x*4 + px*4; 00081 QUATCOPY( out, result ); 00082 } 00083 } 00084 } 00085 00086 static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) 00087 { 00088 tex_output(node, in, out[0], &colorfn, data); 00089 } 00090 00091 static void init(bNode* node) 00092 { 00093 ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user"); 00094 node->storage= iuser; 00095 iuser->sfra= 1; 00096 iuser->fie_ima= 2; 00097 iuser->ok= 1; 00098 } 00099 00100 void register_node_type_tex_image(ListBase *lb) 00101 { 00102 static bNodeType ntype; 00103 00104 node_type_base(&ntype, TEX_NODE_IMAGE, "Image", NODE_CLASS_INPUT, NODE_PREVIEW|NODE_OPTIONS, 00105 NULL, outputs); 00106 node_type_size(&ntype, 120, 80, 300); 00107 node_type_init(&ntype, init); 00108 node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage); 00109 node_type_exec(&ntype, exec); 00110 00111 nodeRegisterType(lb, &ntype); 00112 }