Blender V5.0
node_texture_image.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_math_vector.h"
10#include "BLI_threads.h"
11
12#include "IMB_imbuf.hh"
13
14#include "BKE_image.hh"
15
16#include "node_texture_util.hh"
17#include "node_util.hh"
18
20 {SOCK_RGBA, N_("Image")},
21 {-1, ""},
22};
23
24static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack ** /*in*/, short /*thread*/)
25{
26 float x = p->co[0];
27 float y = p->co[1];
28 Image *ima = (Image *)node->id;
29 ImageUser *iuser = (ImageUser *)node->storage;
30
31 if (ima) {
32 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, nullptr);
33 if (ibuf) {
34 float xsize, ysize;
35 float xoff, yoff;
36 int px, py;
37
38 const float *result;
39
40 xsize = ibuf->x / 2;
41 ysize = ibuf->y / 2;
42 xoff = yoff = -1;
43
44 px = int((x - xoff) * xsize);
45 py = int((y - yoff) * ysize);
46
47 if ((!xsize) || (!ysize)) {
48 return;
49 }
50
51 if (!ibuf->float_buffer.data) {
53 if (!ibuf->float_buffer.data) {
55 }
57 }
58
59 while (px < 0) {
60 px += ibuf->x;
61 }
62 while (py < 0) {
63 py += ibuf->y;
64 }
65 while (px >= ibuf->x) {
66 px -= ibuf->x;
67 }
68 while (py >= ibuf->y) {
69 py -= ibuf->y;
70 }
71
72 result = ibuf->float_buffer.data + py * ibuf->x * 4 + px * 4;
74
75 BKE_image_release_ibuf(ima, ibuf, nullptr);
76 }
77 }
78}
79
80static void exec(void *data,
81 int /*thread*/,
82 bNode *node,
83 bNodeExecData *execdata,
84 bNodeStack **in,
86{
87 tex_output(node, execdata, in, out[0], &colorfn, static_cast<TexCallData *>(data));
88}
89
90static void init(bNodeTree * /*ntree*/, bNode *node)
91{
92 ImageUser *iuser = MEM_callocN<ImageUser>("node image user");
93 node->storage = iuser;
94 iuser->sfra = 1;
95 iuser->flag |= IMA_ANIM_ALWAYS;
96}
97
99{
100 static blender::bke::bNodeType ntype;
101
102 tex_node_type_base(&ntype, "TextureNodeImage", TEX_NODE_IMAGE);
103 ntype.ui_name = "Image";
104 ntype.enum_name_legacy = "IMAGE";
105 ntype.nclass = NODE_CLASS_INPUT;
107 ntype.initfunc = init;
110 ntype.exec_fn = exec;
112 ntype.flag |= NODE_PREVIEW;
113
115}
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define TEX_NODE_IMAGE
MINLINE void copy_v4_v4(float r[4], const float a[4])
void BLI_thread_unlock(int type)
Definition threads.cc:333
void BLI_thread_lock(int type)
Definition threads.cc:328
@ LOCK_IMAGE
Definition BLI_threads.h:63
@ IMA_ANIM_ALWAYS
@ NODE_PREVIEW
@ SOCK_RGBA
void IMB_float_from_byte(ImBuf *ibuf)
BMesh const char void * data
void init()
#define in
#define out
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:5352
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:5414
static blender::bke::bNodeSocketTemplate outputs[]
static void colorfn(float *out, TexParams *p, bNode *, bNodeStack **in, short thread)
static void exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void init(bNodeTree *, bNode *node)
void register_node_type_tex_image()
static void exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **, short)
void tex_output(bNode *node, bNodeExecData *, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
void tex_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
void node_image_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
Definition node_util.cc:189
ImBufFloatBuffer float_buffer
const float * co
struct ID * id
void * storage
Compact definition of a node socket.
Definition BKE_node.hh:99
Defines a node type.
Definition BKE_node.hh:238
NodeExecFunction exec_fn
Definition BKE_node.hh:340
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:270
const char * enum_name_legacy
Definition BKE_node.hh:247
#define N_(msgid)