Blender  V2.93
COM_ReadBufferOperation.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 
21 #include "COM_defines.h"
22 
23 namespace blender::compositor {
24 
26 {
27  this->addOutputSocket(datatype);
28  this->m_single_value = false;
29  this->m_offset = 0;
30  this->m_buffer = nullptr;
32 }
33 
35 {
36  return m_buffer;
37 }
38 
39 void ReadBufferOperation::determineResolution(unsigned int resolution[2],
40  unsigned int preferredResolution[2])
41 {
42  if (this->m_memoryProxy != nullptr) {
43  WriteBufferOperation *operation = this->m_memoryProxy->getWriteBufferOperation();
44  operation->determineResolution(resolution, preferredResolution);
45  operation->setResolution(resolution);
46 
48  if (this->m_memoryProxy->getExecutor()) {
49  this->m_memoryProxy->getExecutor()->setResolution(resolution);
50  }
51 
52  m_single_value = operation->isSingleValue();
53  }
54 }
56  float x,
57  float y,
58  PixelSampler sampler)
59 {
60  if (m_single_value) {
61  /* write buffer has a single value stored at (0,0) */
62  m_buffer->read(output, 0, 0);
63  }
64  else {
65  switch (sampler) {
67  m_buffer->read(output, x, y);
68  break;
70  default:
71  m_buffer->readBilinear(output, x, y);
72  break;
74  m_buffer->readBilinear(output, x, y);
75  break;
76  }
77  }
78 }
79 
81  float x,
82  float y,
83  PixelSampler sampler,
84  MemoryBufferExtend extend_x,
85  MemoryBufferExtend extend_y)
86 {
87  if (m_single_value) {
88  /* write buffer has a single value stored at (0,0) */
89  m_buffer->read(output, 0, 0);
90  }
91  else if (sampler == PixelSampler::Nearest) {
92  m_buffer->read(output, x, y, extend_x, extend_y);
93  }
94  else {
95  m_buffer->readBilinear(output, x, y, extend_x, extend_y);
96  }
97 }
98 
100  float output[4], float x, float y, float dx[2], float dy[2])
101 {
102  if (m_single_value) {
103  /* write buffer has a single value stored at (0,0) */
104  m_buffer->read(output, 0, 0);
105  }
106  else {
107  const float uv[2] = {x, y};
108  const float deriv[2][2] = {{dx[0], dx[1]}, {dy[0], dy[1]}};
109  m_buffer->readEWA(output, uv, deriv);
110  }
111 }
112 
114  ReadBufferOperation *readOperation,
115  rcti *output)
116 {
117  if (this == readOperation) {
118  BLI_rcti_init(output, input->xmin, input->xmax, input->ymin, input->ymax);
119  return true;
120  }
121  return false;
122 }
123 
125 {
126  if (this->m_memoryProxy != nullptr) {
127  WriteBufferOperation *operation = this->m_memoryProxy->getWriteBufferOperation();
128  this->setWidth(operation->getWidth());
129  this->setHeight(operation->getHeight());
130  }
131 }
132 
134 {
135  this->m_buffer = this->getMemoryProxy()->getBuffer();
136 }
137 
138 } // namespace blender::compositor
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition: rct.c:446
_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
#define output
void setResolution(unsigned int resolution[2])
set the resolution of this executiongroup
void read(float *result, int x, int y, MemoryBufferExtend extend_x=MemoryBufferExtend::Clip, MemoryBufferExtend extend_y=MemoryBufferExtend::Clip)
void readEWA(float *result, const float uv[2], const float derivatives[2][2])
void readBilinear(float *result, float x, float y, MemoryBufferExtend extend_x=MemoryBufferExtend::Clip, MemoryBufferExtend extend_y=MemoryBufferExtend::Clip)
ExecutionGroup * getExecutor() const
get the ExecutionGroup that can be scheduled to calculate a certain chunk.
MemoryBuffer * getBuffer()
get the allocated memory
WriteBufferOperation * getWriteBufferOperation() const
get the WriteBufferOperation that is responsible for writing to this MemoryProxy
void addOutputSocket(DataType datatype)
void setWidth(unsigned int width)
void setHeight(unsigned int height)
void setResolution(unsigned int resolution[2])
set the resolution
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) override
determine the resolution of this node
void executePixelExtend(float output[4], float x, float y, PixelSampler sampler, MemoryBufferExtend extend_x, MemoryBufferExtend extend_y)
void executePixelFiltered(float output[4], float x, float y, float dx[2], float dy[2]) override
calculate a single pixel using an EWA filter
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) override
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) override
determine the resolution of this node
DataType
possible data types for sockets
Definition: COM_defines.h:27
int ymin
Definition: DNA_vec_types.h:80
int ymax
Definition: DNA_vec_types.h:80
int xmin
Definition: DNA_vec_types.h:79
int xmax
Definition: DNA_vec_types.h:79