Blender  V2.93
COM_TextureOperation.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #include "COM_TextureOperation.h"
20 #include "COM_WorkScheduler.h"
21 
22 #include "BKE_image.h"
23 #include "BKE_node.h"
24 
25 #include "BLI_listbase.h"
26 #include "BLI_threads.h"
27 
28 namespace blender::compositor {
29 
31 {
32  this->addInputSocket(DataType::Vector); // offset
33  this->addInputSocket(DataType::Vector); // size
34  this->m_texture = nullptr;
35  this->m_inputSize = nullptr;
36  this->m_inputOffset = nullptr;
37  this->m_rd = nullptr;
38  this->m_pool = nullptr;
39  this->m_sceneColorManage = false;
40  flags.complex = true;
41 }
43 {
45 }
47 {
49 }
50 
52 {
53  this->m_inputOffset = getInputSocketReader(0);
54  this->m_inputSize = getInputSocketReader(1);
55  this->m_pool = BKE_image_pool_new();
56  if (this->m_texture != nullptr && this->m_texture->nodetree != nullptr &&
57  this->m_texture->use_nodes) {
58  ntreeTexBeginExecTree(this->m_texture->nodetree);
59  }
61 }
63 {
64  this->m_inputSize = nullptr;
65  this->m_inputOffset = nullptr;
66  BKE_image_pool_free(this->m_pool);
67  this->m_pool = nullptr;
68  if (this->m_texture != nullptr && this->m_texture->use_nodes &&
69  this->m_texture->nodetree != nullptr && this->m_texture->nodetree->execdata != nullptr) {
70  ntreeTexEndExecTree(this->m_texture->nodetree->execdata);
71  }
73 }
74 
75 void TextureBaseOperation::determineResolution(unsigned int resolution[2],
76  unsigned int preferredResolution[2])
77 {
78  if (preferredResolution[0] == 0 || preferredResolution[1] == 0) {
79  int width = this->m_rd->xsch * this->m_rd->size / 100;
80  int height = this->m_rd->ysch * this->m_rd->size / 100;
81  resolution[0] = width;
82  resolution[1] = height;
83  }
84  else {
85  resolution[0] = preferredResolution[0];
86  resolution[1] = preferredResolution[1];
87  }
88 }
89 
91  float x,
92  float y,
93  PixelSampler sampler)
94 {
95  float color[4];
97  output[0] = color[3];
98 }
99 
101  float x,
102  float y,
103  PixelSampler sampler)
104 {
105  TexResult texres = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, nullptr};
106  float textureSize[4];
107  float textureOffset[4];
108  float vec[3];
109  int retval;
110  const float cx = this->getWidth() / 2;
111  const float cy = this->getHeight() / 2;
112  float u = (x - cx) / this->getWidth() * 2;
113  float v = (y - cy) / this->getHeight() * 2;
114 
115  /* When no interpolation/filtering happens in multitex() force nearest interpolation.
116  * We do it here because (a) we can't easily say multitex() that we want nearest
117  * interpolation and (b) in such configuration multitex() simply floor's the value
118  * which often produces artifacts.
119  */
120  if (m_texture != nullptr && (m_texture->imaflag & TEX_INTERPOL) == 0) {
121  u += 0.5f / cx;
122  v += 0.5f / cy;
123  }
124 
125  this->m_inputSize->readSampled(textureSize, x, y, sampler);
126  this->m_inputOffset->readSampled(textureOffset, x, y, sampler);
127 
128  vec[0] = textureSize[0] * (u + textureOffset[0]);
129  vec[1] = textureSize[1] * (v + textureOffset[1]);
130  vec[2] = textureSize[2] * textureOffset[2];
131 
132  const int thread_id = WorkScheduler::current_thread_id();
133  retval = multitex_ext(this->m_texture,
134  vec,
135  nullptr,
136  nullptr,
137  0,
138  &texres,
139  thread_id,
140  m_pool,
141  m_sceneColorManage,
142  false);
143 
144  if (texres.talpha) {
145  output[3] = texres.ta;
146  }
147  else {
148  output[3] = texres.tin;
149  }
150 
151  if ((retval & TEX_RGB)) {
152  output[0] = texres.tr;
153  output[1] = texres.tg;
154  output[2] = texres.tb;
155  }
156  else {
157  output[0] = output[1] = output[2] = output[3];
158  }
159 }
160 
161 } // namespace blender::compositor
struct ImagePool * BKE_image_pool_new(void)
Definition: image.c:5173
void BKE_image_pool_free(struct ImagePool *pool)
Definition: image.c:5181
void ntreeTexEndExecTree(struct bNodeTreeExec *exec)
struct bNodeTreeExec * ntreeTexBeginExecTree(struct bNodeTree *ntree)
#define TEX_RGB
#define TEX_INTERPOL
_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 GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_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
ATTR_WARN_UNUSED_RESULT const BMVert * v
#define output
void readSampled(float result[4], float x, float y, PixelSampler sampler)
void addInputSocket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
void addOutputSocket(DataType datatype)
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) override
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
@ Vector
Vector data type.
int talpha
Definition: RE_texture.h:85
float tb
Definition: RE_texture.h:84
float tin
Definition: RE_texture.h:84
float ta
Definition: RE_texture.h:84
float tr
Definition: RE_texture.h:84
float tg
Definition: RE_texture.h:84
short imaflag
char use_nodes
struct bNodeTree * nodetree
struct bNodeTreeExec * execdata
int multitex_ext(Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, TexResult *texres, const short thread, struct ImagePool *pool, bool scene_color_manage, const bool skip_load_image)