Blender  V3.3
COM_EllipseMaskOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
5 
6 namespace blender::compositor {
7 
9 {
13  input_mask_ = nullptr;
14  input_value_ = nullptr;
15  cosine_ = 0.0f;
16  sine_ = 0.0f;
17 }
19 {
20  input_mask_ = this->get_input_socket_reader(0);
21  input_value_ = this->get_input_socket_reader(1);
22  const double rad = (double)data_->rotation;
23  cosine_ = cos(rad);
24  sine_ = sin(rad);
25  aspect_ratio_ = ((float)this->get_width()) / this->get_height();
26 }
27 
29  float x,
30  float y,
32 {
33  float input_mask[4];
34  float input_value[4];
35 
36  float rx = x / MAX2(this->get_width() - 1.0f, FLT_EPSILON);
37  float ry = y / MAX2(this->get_height() - 1.0f, FLT_EPSILON);
38 
39  const float dy = (ry - data_->y) / aspect_ratio_;
40  const float dx = rx - data_->x;
41  rx = data_->x + (cosine_ * dx + sine_ * dy);
42  ry = data_->y + (-sine_ * dx + cosine_ * dy);
43 
44  input_mask_->read_sampled(input_mask, x, y, sampler);
45  input_value_->read_sampled(input_value, x, y, sampler);
46 
47  const float half_height = (data_->height) / 2.0f;
48  const float half_width = data_->width / 2.0f;
49  float sx = rx - data_->x;
50  sx *= sx;
51  const float tx = half_width * half_width;
52  float sy = ry - data_->y;
53  sy *= sy;
54  const float ty = half_height * half_height;
55 
56  bool inside = ((sx / tx) + (sy / ty)) <= (1.0f + FLT_EPSILON);
57 
58  switch (mask_type_) {
60  if (inside) {
61  output[0] = MAX2(input_mask[0], input_value[0]);
62  }
63  else {
64  output[0] = input_mask[0];
65  }
66  break;
68  if (inside) {
69  output[0] = input_mask[0] - input_value[0];
70  CLAMP(output[0], 0, 1);
71  }
72  else {
73  output[0] = input_mask[0];
74  }
75  break;
77  if (inside) {
78  output[0] = input_mask[0] * input_value[0];
79  }
80  else {
81  output[0] = 0;
82  }
83  break;
85  if (inside) {
86  if (input_mask[0] > 0.0f) {
87  output[0] = 0;
88  }
89  else {
90  output[0] = input_value[0];
91  }
92  }
93  else {
94  output[0] = input_mask[0];
95  }
96  break;
97  }
98 }
99 
101  const rcti &area,
103 {
104  MaskFunc mask_func;
105  switch (mask_type_) {
107  mask_func = [](const bool is_inside, const float *mask, const float *value) {
108  return is_inside ? MAX2(mask[0], value[0]) : mask[0];
109  };
110  break;
112  mask_func = [](const bool is_inside, const float *mask, const float *value) {
113  return is_inside ? CLAMPIS(mask[0] - value[0], 0, 1) : mask[0];
114  };
115  break;
117  mask_func = [](const bool is_inside, const float *mask, const float *value) {
118  return is_inside ? mask[0] * value[0] : 0;
119  };
120  break;
122  mask_func = [](const bool is_inside, const float *mask, const float *value) {
123  if (is_inside) {
124  return mask[0] > 0.0f ? 0.0f : value[0];
125  }
126  return mask[0];
127  };
128  break;
129  }
130  apply_mask(output, area, inputs, mask_func);
131 }
132 
133 void EllipseMaskOperation::apply_mask(MemoryBuffer *output,
134  const rcti &area,
136  MaskFunc mask_func)
137 {
138  const MemoryBuffer *input_mask = inputs[0];
139  const MemoryBuffer *input_value = inputs[1];
140  const float op_last_x = MAX2(this->get_width() - 1.0f, FLT_EPSILON);
141  const float op_last_y = MAX2(this->get_height() - 1.0f, FLT_EPSILON);
142  const float half_w = data_->width / 2.0f;
143  const float half_h = data_->height / 2.0f;
144  const float tx = half_w * half_w;
145  const float ty = half_h * half_h;
146  for (int y = area.ymin; y < area.ymax; y++) {
147  const float op_ry = y / op_last_y;
148  const float dy = (op_ry - data_->y) / aspect_ratio_;
149  float *out = output->get_elem(area.xmin, y);
150  const float *mask = input_mask->get_elem(area.xmin, y);
151  const float *value = input_value->get_elem(area.xmin, y);
152  for (int x = area.xmin; x < area.xmax; x++) {
153  const float op_rx = x / op_last_x;
154  const float dx = op_rx - data_->x;
155  const float rx = data_->x + (cosine_ * dx + sine_ * dy);
156  const float ry = data_->y + (-sine_ * dx + cosine_ * dy);
157  float sx = rx - data_->x;
158  sx *= sx;
159  float sy = ry - data_->y;
160  sy *= sy;
161  const bool inside = ((sx / tx) + (sy / ty)) <= (1.0f + FLT_EPSILON);
162  out[0] = mask_func(inside, mask, value);
163 
164  mask += input_mask->elem_stride;
165  value += input_value->elem_stride;
166  out += output->elem_stride;
167  }
168  }
169 }
170 
172 {
173  input_mask_ = nullptr;
174  input_value_ = nullptr;
175 }
176 
177 } // namespace blender::compositor
typedef float(TangentPoint)[2]
#define CLAMPIS(a, b, c)
#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 Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
a MemoryBuffer contains access to the data of a chunk
void add_output_socket(DataType datatype)
SocketReader * get_input_socket_reader(unsigned int index)
void read_sampled(float result[4], float x, float y, PixelSampler sampler)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
static bool is_inside(int x, int y, int cols, int rows)
Definition: filesel.c:706
ccl_gpu_kernel_postfix ccl_global float int int sy
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_gpu_kernel_postfix ccl_global float int sx
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
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
static void area(int d1, int d2, int e1, int e2, float weights[2])
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static bNodeSocketTemplate inputs[]