Blender  V2.93
COM_BoxMaskOperation.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_BoxMaskOperation.h"
20 #include "BLI_math.h"
21 #include "DNA_node_types.h"
22 
23 namespace blender::compositor {
24 
26 {
30  this->m_inputMask = nullptr;
31  this->m_inputValue = nullptr;
32  this->m_cosine = 0.0f;
33  this->m_sine = 0.0f;
34 }
36 {
37  this->m_inputMask = this->getInputSocketReader(0);
38  this->m_inputValue = this->getInputSocketReader(1);
39  const double rad = (double)this->m_data->rotation;
40  this->m_cosine = cos(rad);
41  this->m_sine = sin(rad);
42  this->m_aspectRatio = ((float)this->getWidth()) / this->getHeight();
43 }
44 
45 void BoxMaskOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
46 {
47  float inputMask[4];
48  float inputValue[4];
49 
50  float rx = x / this->getWidth();
51  float ry = y / this->getHeight();
52 
53  const float dy = (ry - this->m_data->y) / this->m_aspectRatio;
54  const float dx = rx - this->m_data->x;
55  rx = this->m_data->x + (this->m_cosine * dx + this->m_sine * dy);
56  ry = this->m_data->y + (-this->m_sine * dx + this->m_cosine * dy);
57 
58  this->m_inputMask->readSampled(inputMask, x, y, sampler);
59  this->m_inputValue->readSampled(inputValue, x, y, sampler);
60 
61  float halfHeight = this->m_data->height / 2.0f;
62  float halfWidth = this->m_data->width / 2.0f;
63  bool inside = (rx > this->m_data->x - halfWidth && rx < this->m_data->x + halfWidth &&
64  ry > this->m_data->y - halfHeight && ry < this->m_data->y + halfHeight);
65 
66  switch (this->m_maskType) {
68  if (inside) {
69  output[0] = MAX2(inputMask[0], inputValue[0]);
70  }
71  else {
72  output[0] = inputMask[0];
73  }
74  break;
76  if (inside) {
77  output[0] = inputMask[0] - inputValue[0];
78  CLAMP(output[0], 0, 1);
79  }
80  else {
81  output[0] = inputMask[0];
82  }
83  break;
85  if (inside) {
86  output[0] = inputMask[0] * inputValue[0];
87  }
88  else {
89  output[0] = 0;
90  }
91  break;
93  if (inside) {
94  if (inputMask[0] > 0.0f) {
95  output[0] = 0;
96  }
97  else {
98  output[0] = inputValue[0];
99  }
100  }
101  else {
102  output[0] = inputMask[0];
103  }
104  break;
105  }
106 }
107 
109 {
110  this->m_inputMask = nullptr;
111  this->m_inputValue = nullptr;
112 }
113 
114 } // namespace blender::compositor
typedef float(TangentPoint)[2]
#define MAX2(a, b)
typedef double(DMatrix)[4][4]
@ CMP_NODE_MASKTYPE_NOT
@ CMP_NODE_MASKTYPE_SUBTRACT
@ CMP_NODE_MASKTYPE_MULTIPLY
@ CMP_NODE_MASKTYPE_ADD
_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
Group RGB to Bright Vector Camera CLAMP
#define output
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
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)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:319
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:311