Blender  V3.3
COM_BoxMaskOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
4 #include "COM_BoxMaskOperation.h"
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  float half_height = data_->height / 2.0f + FLT_EPSILON;
48  float half_width = data_->width / 2.0f + FLT_EPSILON;
49  bool inside = (rx >= data_->x - half_width && rx <= data_->x + half_width &&
50  ry >= data_->y - half_height && ry <= data_->y + half_height);
51 
52  switch (mask_type_) {
54  if (inside) {
55  output[0] = MAX2(input_mask[0], input_value[0]);
56  }
57  else {
58  output[0] = input_mask[0];
59  }
60  break;
62  if (inside) {
63  output[0] = input_mask[0] - input_value[0];
64  CLAMP(output[0], 0, 1);
65  }
66  else {
67  output[0] = input_mask[0];
68  }
69  break;
71  if (inside) {
72  output[0] = input_mask[0] * input_value[0];
73  }
74  else {
75  output[0] = 0;
76  }
77  break;
79  if (inside) {
80  if (input_mask[0] > 0.0f) {
81  output[0] = 0;
82  }
83  else {
84  output[0] = input_value[0];
85  }
86  }
87  else {
88  output[0] = input_mask[0];
89  }
90  break;
91  }
92 }
93 
95  const rcti &area,
97 {
98  MaskFunc mask_func;
99  switch (mask_type_) {
101  mask_func = [](const bool is_inside, const float *mask, const float *value) {
102  return is_inside ? MAX2(mask[0], value[0]) : mask[0];
103  };
104  break;
106  mask_func = [](const bool is_inside, const float *mask, const float *value) {
107  return is_inside ? CLAMPIS(mask[0] - value[0], 0, 1) : mask[0];
108  };
109  break;
111  mask_func = [](const bool is_inside, const float *mask, const float *value) {
112  return is_inside ? mask[0] * value[0] : 0;
113  };
114  break;
116  mask_func = [](const bool is_inside, const float *mask, const float *value) {
117  if (is_inside) {
118  return mask[0] > 0.0f ? 0.0f : value[0];
119  }
120  return mask[0];
121  };
122  break;
123  }
124  apply_mask(output, area, inputs, mask_func);
125 }
126 
127 void BoxMaskOperation::apply_mask(MemoryBuffer *output,
128  const rcti &area,
130  MaskFunc mask_func)
131 {
132  const float op_last_x = MAX2(this->get_width() - 1.0f, FLT_EPSILON);
133  const float op_last_y = MAX2(this->get_height() - 1.0f, FLT_EPSILON);
134  const float half_w = data_->width / 2.0f + FLT_EPSILON;
135  const float half_h = data_->height / 2.0f + FLT_EPSILON;
136  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
137  const float op_ry = it.y / op_last_y;
138  const float dy = (op_ry - data_->y) / aspect_ratio_;
139  const float op_rx = it.x / op_last_x;
140  const float dx = op_rx - data_->x;
141  const float rx = data_->x + (cosine_ * dx + sine_ * dy);
142  const float ry = data_->y + (-sine_ * dx + cosine_ * dy);
143 
144  const bool inside = (rx >= data_->x - half_w && rx <= data_->x + half_w &&
145  ry >= data_->y - half_h && ry <= data_->y + half_h);
146  const float *mask = it.in(0);
147  const float *value = it.in(1);
148  *it.out = mask_func(inside, mask, value);
149  }
150 }
151 
153 {
154  input_mask_ = nullptr;
155  input_value_ = nullptr;
156 }
157 
158 } // 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_global KernelShaderEvalInput ccl_global float * output
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])
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
static bNodeSocketTemplate inputs[]