Blender  V2.93
COM_KeyingBlurOperation.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 2012, Blender Foundation.
17  */
18 
20 
21 #include "MEM_guardedalloc.h"
22 
23 #include "BLI_listbase.h"
24 #include "BLI_math.h"
25 
26 namespace blender::compositor {
27 
29 {
32 
33  this->m_size = 0;
34  this->m_axis = BLUR_AXIS_X;
35 
36  this->flags.complex = true;
37 }
38 
40 {
42 
43  return buffer;
44 }
45 
46 void KeyingBlurOperation::executePixel(float output[4], int x, int y, void *data)
47 {
48  MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
49  const int bufferWidth = inputBuffer->getWidth();
50  float *buffer = inputBuffer->getBuffer();
51  int count = 0;
52  float average = 0.0f;
53 
54  if (this->m_axis == 0) {
55  const int start = MAX2(0, x - this->m_size + 1), end = MIN2(bufferWidth, x + this->m_size);
56  for (int cx = start; cx < end; cx++) {
57  int bufferIndex = (y * bufferWidth + cx);
58  average += buffer[bufferIndex];
59  count++;
60  }
61  }
62  else {
63  const int start = MAX2(0, y - this->m_size + 1),
64  end = MIN2(inputBuffer->getHeight(), y + this->m_size);
65  for (int cy = start; cy < end; cy++) {
66  int bufferIndex = (cy * bufferWidth + x);
67  average += buffer[bufferIndex];
68  count++;
69  }
70  }
71 
72  average /= (float)count;
73 
74  output[0] = average;
75 }
76 
78  ReadBufferOperation *readOperation,
79  rcti *output)
80 {
81  rcti newInput;
82 
83  if (this->m_axis == BLUR_AXIS_X) {
84  newInput.xmin = input->xmin - this->m_size;
85  newInput.ymin = input->ymin;
86  newInput.xmax = input->xmax + this->m_size;
87  newInput.ymax = input->ymax;
88  }
89  else {
90  newInput.xmin = input->xmin;
91  newInput.ymin = input->ymin - this->m_size;
92  newInput.xmax = input->xmax;
93  newInput.ymax = input->ymax + this->m_size;
94  }
95 
96  return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
97 }
98 
99 } // namespace blender::compositor
typedef float(TangentPoint)[2]
#define MAX2(a, b)
#define MIN2(a, b)
_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
Read Guarded memory(de)allocation.
#define output
void executePixel(float output[4], int x, int y, void *data) override
calculate a single pixel
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) override
a MemoryBuffer contains access to the data of a chunk
const int getHeight() const
get the height of this MemoryBuffer
const int getWidth() const
get the width of this MemoryBuffer
float * getBuffer()
get the data of this MemoryBuffer
virtual void * initializeTileData(rcti *)
void addInputSocket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
NodeOperation * getInputOperation(unsigned int inputSocketindex)
void addOutputSocket(DataType datatype)
virtual bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
int count
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
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
ccl_device_inline float average(const float2 &a)