Blender  V2.93
COM_EllipseMaskOperation.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 
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 
46  float x,
47  float y,
48  PixelSampler sampler)
49 {
50  float inputMask[4];
51  float inputValue[4];
52 
53  float rx = x / this->getWidth();
54  float ry = y / this->getHeight();
55 
56  const float dy = (ry - this->m_data->y) / this->m_aspectRatio;
57  const float dx = rx - this->m_data->x;
58  rx = this->m_data->x + (this->m_cosine * dx + this->m_sine * dy);
59  ry = this->m_data->y + (-this->m_sine * dx + this->m_cosine * dy);
60 
61  this->m_inputMask->readSampled(inputMask, x, y, sampler);
62  this->m_inputValue->readSampled(inputValue, x, y, sampler);
63 
64  const float halfHeight = (this->m_data->height) / 2.0f;
65  const float halfWidth = this->m_data->width / 2.0f;
66  float sx = rx - this->m_data->x;
67  sx *= sx;
68  const float tx = halfWidth * halfWidth;
69  float sy = ry - this->m_data->y;
70  sy *= sy;
71  const float ty = halfHeight * halfHeight;
72 
73  bool inside = ((sx / tx) + (sy / ty)) < 1.0f;
74 
75  switch (this->m_maskType) {
77  if (inside) {
78  output[0] = MAX2(inputMask[0], inputValue[0]);
79  }
80  else {
81  output[0] = inputMask[0];
82  }
83  break;
85  if (inside) {
86  output[0] = inputMask[0] - inputValue[0];
87  CLAMP(output[0], 0, 1);
88  }
89  else {
90  output[0] = inputMask[0];
91  }
92  break;
94  if (inside) {
95  output[0] = inputMask[0] * inputValue[0];
96  }
97  else {
98  output[0] = 0;
99  }
100  break;
102  if (inside) {
103  if (inputMask[0] > 0.0f) {
104  output[0] = 0;
105  }
106  else {
107  output[0] = inputValue[0];
108  }
109  }
110  else {
111  output[0] = inputMask[0];
112  }
113  break;
114  }
115 }
116 
118 {
119  this->m_inputMask = nullptr;
120  this->m_inputValue = nullptr;
121 }
122 
123 } // 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