Blender  V3.3
node_texture_image.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2006 Blender Foundation. All rights reserved. */
3 
8 #include "NOD_texture.h"
9 #include "node_texture_util.h"
10 
12  {SOCK_RGBA, N_("Image")},
13  {-1, ""},
14 };
15 
16 static void colorfn(
17  float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread))
18 {
19  float x = p->co[0];
20  float y = p->co[1];
21  Image *ima = (Image *)node->id;
22  ImageUser *iuser = (ImageUser *)node->storage;
23 
24  if (ima) {
25  ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
26  if (ibuf) {
27  float xsize, ysize;
28  float xoff, yoff;
29  int px, py;
30 
31  const float *result;
32 
33  xsize = ibuf->x / 2;
34  ysize = ibuf->y / 2;
35  xoff = yoff = -1;
36 
37  px = (int)((x - xoff) * xsize);
38  py = (int)((y - yoff) * ysize);
39 
40  if ((!xsize) || (!ysize)) {
41  return;
42  }
43 
44  if (!ibuf->rect_float) {
46  if (!ibuf->rect_float) {
47  IMB_float_from_rect(ibuf);
48  }
50  }
51 
52  while (px < 0) {
53  px += ibuf->x;
54  }
55  while (py < 0) {
56  py += ibuf->y;
57  }
58  while (px >= ibuf->x) {
59  px -= ibuf->x;
60  }
61  while (py >= ibuf->y) {
62  py -= ibuf->y;
63  }
64 
65  result = ibuf->rect_float + py * ibuf->x * 4 + px * 4;
67 
68  BKE_image_release_ibuf(ima, ibuf, NULL);
69  }
70  }
71 }
72 
73 static void exec(void *data,
74  int UNUSED(thread),
75  bNode *node,
76  bNodeExecData *execdata,
77  bNodeStack **in,
78  bNodeStack **out)
79 {
80  tex_output(node, execdata, in, out[0], &colorfn, data);
81 }
82 
83 static void init(bNodeTree *UNUSED(ntree), bNode *node)
84 {
85  ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "node image user");
86  node->storage = iuser;
87  iuser->sfra = 1;
88  iuser->flag |= IMA_ANIM_ALWAYS;
89 }
90 
92 {
93  static bNodeType ntype;
94 
97  node_type_init(&ntype, init);
99  node_type_exec(&ntype, NULL, NULL, exec);
100  ntype.labelfunc = node_image_label;
101  ntype.flag |= NODE_PREVIEW;
102 
103  nodeRegisterType(&ntype);
104 }
void BKE_image_release_ibuf(struct Image *ima, struct ImBuf *ibuf, void *lock)
struct ImBuf * BKE_image_acquire_ibuf(struct Image *ima, struct ImageUser *iuser, void **r_lock)
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4358
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
#define TEX_NODE_IMAGE
Definition: BKE_node.h:1355
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4426
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction init_exec_fn, NodeFreeExecFunction free_exec_fn, NodeExecFunction exec_fn)
Definition: node.cc:4455
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
MINLINE void copy_v4_v4(float r[4], const float a[4])
void BLI_thread_unlock(int type)
Definition: threads.cc:361
@ LOCK_IMAGE
Definition: BLI_threads.h:66
void BLI_thread_lock(int type)
Definition: threads.cc:356
#define UNUSED(x)
#define IMA_ANIM_ALWAYS
#define NODE_PREVIEW
@ SOCK_RGBA
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
void IMB_float_from_rect(struct ImBuf *ibuf)
Definition: divers.c:805
Definition: thread.h:34
OperationNode * node
bNodeTree * ntree
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static bNodeSocketTemplate outputs[]
void register_node_type_tex_image(void)
static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread))
static void init(bNodeTree *UNUSED(ntree), bNode *node)
void tex_node_type_base(struct 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_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:55
void node_free_standard_storage(bNode *node)
Definition: node_util.c:43
void node_image_label(const bNodeTree *UNUSED(ntree), const bNode *node, char *label, int maxlen)
Definition: node_util.c:189
float * rect_float
const float * co
Compact definition of a node socket.
Definition: BKE_node.h:84
Defines a node type.
Definition: BKE_node.h:226
short flag
Definition: BKE_node.h:236
void(* labelfunc)(const struct bNodeTree *ntree, const struct bNode *node, char *label, int maxlen)
Definition: BKE_node.h:256
#define N_(msgid)