4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2006 Blender Foundation.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): Robin Allen
27 * ***** END GPL LICENSE BLOCK *****
30 #include "../TEX_util.h"
32 static bNodeSocketType outputs[]= {
33 { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
37 static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread))
41 Image *ima= (Image *)node->id;
42 ImageUser *iuser= (ImageUser *)node->storage;
45 ImBuf *ibuf = BKE_image_get_ibuf(ima, iuser);
57 px = (int)( (x-xoff) * xsize );
58 py = (int)( (y-yoff) * ysize );
60 if( (!xsize) || (!ysize) ) return;
61 if( !ibuf->rect_float ) IMB_float_from_rect(ibuf);
63 while( px < 0 ) px += ibuf->x;
64 while( py < 0 ) py += ibuf->y;
65 while( px >= ibuf->x ) px -= ibuf->x;
66 while( py >= ibuf->y ) py -= ibuf->y;
68 result = ibuf->rect_float + py*ibuf->x*4 + px*4;
69 QUATCOPY( out, result );
74 static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
76 tex_output(node, in, out[0], &colorfn, data);
79 static void init(bNode* node)
81 ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user");
88 bNodeType tex_node_image= {
89 /* *next,*prev */ NULL, NULL,
90 /* type code */ TEX_NODE_IMAGE,
92 /* width+range */ 120, 80, 300,
93 /* class+opts */ NODE_CLASS_INPUT, NODE_PREVIEW|NODE_OPTIONS,
94 /* input sock */ NULL,
95 /* output sock */ outputs,
96 /* storage */ "ImageUser",
100 /* freestoragefunc */ node_free_standard_storage,
101 /* copystoragefunc */ node_copy_standard_storage,