Blender V5.3
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
10#include "BLI_threads.hh"
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
19namespace blender {
20
22 {SOCK_RGBA, N_("Image")},
23 {-1, ""},
24};
25
26static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack ** /*in*/, short /*thread*/)
27{
28 float x = p->co[0];
29 float y = p->co[1];
30 Image *ima = id_cast<Image *>(node->id);
31 ImageUser *iuser = static_cast<ImageUser *>(node->storage);
32
33 if (ima) {
34 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, nullptr);
35 if (ibuf) {
36 float xsize, ysize;
37 float xoff, yoff;
38 int px, py;
39
40 const float *result;
41
42 xsize = ibuf->x / 2;
43 ysize = ibuf->y / 2;
44 xoff = yoff = -1;
45
46 px = int((x - xoff) * xsize);
47 py = int((y - yoff) * ysize);
48
49 if ((!xsize) || (!ysize)) {
50 return;
51 }
52
53 if (!ibuf->float_data()) {
55 if (!ibuf->float_data()) {
57 }
59 }
60
61 while (px < 0) {
62 px += ibuf->x;
63 }
64 while (py < 0) {
65 py += ibuf->y;
66 }
67 while (px >= ibuf->x) {
68 px -= ibuf->x;
69 }
70 while (py >= ibuf->y) {
71 py -= ibuf->y;
72 }
73
74 result = ibuf->float_data() + py * ibuf->x * 4 + px * 4;
76
77 BKE_image_release_ibuf(ima, ibuf, nullptr);
78 }
79 }
80}
81
82static void exec(void *data,
83 int /*thread*/,
84 bNode *node,
85 bNodeExecData *execdata,
86 bNodeStack **in,
88{
89 tex_output(node, execdata, in, out[0], &colorfn, static_cast<TexCallData *>(data));
90}
91
92static void init(bNodeTree * /*ntree*/, bNode *node)
93{
94 ImageUser *iuser = MEM_new<ImageUser>("node image user");
95 node->storage = iuser;
96 iuser->sfra = 1;
97 iuser->flag |= IMA_ANIM_ALWAYS;
98}
99
101{
102 static bke::bNodeType ntype;
103
104 tex_node_type_base(&ntype, "TextureNodeImage"_ustr, TEX_NODE_IMAGE);
105 ntype.ui_name = "Image";
106 ntype.enum_name_legacy = "IMAGE";
107 ntype.nclass = NODE_CLASS_INPUT;
109 ntype.initfunc = init;
112 ntype.exec_fn = exec;
114 ntype.flag |= NODE_PREVIEW;
115
117}
118
119} // namespace blender
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define TEX_NODE_IMAGE
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:6134
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:6166
BMesh Iterators.
static void exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void colorfn(float *out, TexParams *p, bNode *, bNodeStack **in, short thread)
void register_node_type_tex_image()
void IMB_float_from_byte(ImBuf *ibuf)
BMesh const char void * data
void tex_output(bNode *node, bNodeExecData *, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
void tex_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
static bke::bNodeSocketTemplate outputs[]
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
MINLINE void copy_v4_v4(float r[4], const float a[4])
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
void BLI_thread_unlock(int type)
Definition threads.cc:336
void node_image_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
Definition node_util.cc:146
void BLI_thread_lock(int type)
Definition threads.cc:331
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
const float * float_data() const
eImageUser_Flag flag
Compact definition of a node socket.
Definition BKE_node.hh:102
Defines a node type.
Definition BKE_node.hh:265
NodeExecFunction exec_fn
Definition BKE_node.hh:371
void(*) labelfunc(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:301
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
#define N_(msgid)