Blender V4.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
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;
70 copy_v4_v4(out, result);
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,
82 bNodeStack **out)
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_cnew<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, TEX_NODE_IMAGE, "Image", NODE_CLASS_INPUT);
100 blender::bke::node_type_socket_templates(&ntype, nullptr, outputs);
101 ntype.initfunc = init;
104 ntype.exec_fn = exec;
106 ntype.flag |= NODE_PREVIEW;
107
109}
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:404
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:67
@ IMA_ANIM_ALWAYS
@ NODE_PREVIEW
@ SOCK_RGBA
void IMB_float_from_rect(ImBuf *ibuf)
Definition divers.cc:802
void init()
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:4570
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
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_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void tex_output(bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
void node_image_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
Definition node_util.cc:193
ImBufFloatBuffer float_buffer
const float * co
Compact definition of a node socket.
Definition BKE_node.hh:103
Defines a node type.
Definition BKE_node.hh:218
NodeExecFunction exec_fn
Definition BKE_node.hh:316
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:249
#define N_(msgid)