Blender V4.5
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 "BKE_image.hh"
10#include "BLI_math_vector.h"
11#include "BLI_threads.h"
12#include "IMB_imbuf.hh"
13#include "node_texture_util.hh"
14#include "node_util.hh"
15
17 {SOCK_RGBA, N_("Image")},
18 {-1, ""},
19};
20
21static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack ** /*in*/, short /*thread*/)
22{
23 float x = p->co[0];
24 float y = p->co[1];
25 Image *ima = (Image *)node->id;
26 ImageUser *iuser = (ImageUser *)node->storage;
27
28 if (ima) {
29 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, nullptr);
30 if (ibuf) {
31 float xsize, ysize;
32 float xoff, yoff;
33 int px, py;
34
35 const float *result;
36
37 xsize = ibuf->x / 2;
38 ysize = ibuf->y / 2;
39 xoff = yoff = -1;
40
41 px = int((x - xoff) * xsize);
42 py = int((y - yoff) * ysize);
43
44 if ((!xsize) || (!ysize)) {
45 return;
46 }
47
48 if (!ibuf->float_buffer.data) {
50 if (!ibuf->float_buffer.data) {
52 }
54 }
55
56 while (px < 0) {
57 px += ibuf->x;
58 }
59 while (py < 0) {
60 py += ibuf->y;
61 }
62 while (px >= ibuf->x) {
63 px -= ibuf->x;
64 }
65 while (py >= ibuf->y) {
66 py -= ibuf->y;
67 }
68
69 result = ibuf->float_buffer.data + py * ibuf->x * 4 + px * 4;
71
72 BKE_image_release_ibuf(ima, ibuf, nullptr);
73 }
74 }
75}
76
77static void exec(void *data,
78 int /*thread*/,
79 bNode *node,
80 bNodeExecData *execdata,
81 bNodeStack **in,
83{
84 tex_output(node, execdata, in, out[0], &colorfn, static_cast<TexCallData *>(data));
85}
86
87static void init(bNodeTree * /*ntree*/, bNode *node)
88{
89 ImageUser *iuser = MEM_callocN<ImageUser>("node image user");
90 node->storage = iuser;
91 iuser->sfra = 1;
92 iuser->flag |= IMA_ANIM_ALWAYS;
93}
94
96{
97 static blender::bke::bNodeType ntype;
98
99 tex_node_type_base(&ntype, "TextureNodeImage", TEX_NODE_IMAGE);
100 ntype.ui_name = "Image";
101 ntype.enum_name_legacy = "IMAGE";
102 ntype.nclass = NODE_CLASS_INPUT;
104 ntype.initfunc = init;
107 ntype.exec_fn = exec;
109 ntype.flag |= NODE_PREVIEW;
110
112}
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:433
#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:2748
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:5541
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:5603
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:98
Defines a node type.
Definition BKE_node.hh:226
NodeExecFunction exec_fn
Definition BKE_node.hh:328
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:277
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:258
const char * enum_name_legacy
Definition BKE_node.hh:235
#define N_(msgid)