diff options
Diffstat (limited to 'source/blender/compositor/operations/COM_EllipseMaskOperation.cc')
-rw-r--r-- | source/blender/compositor/operations/COM_EllipseMaskOperation.cc | 126 |
1 files changed, 61 insertions, 65 deletions
diff --git a/source/blender/compositor/operations/COM_EllipseMaskOperation.cc b/source/blender/compositor/operations/COM_EllipseMaskOperation.cc index bf6eee6d3f9..a051e06d15e 100644 --- a/source/blender/compositor/operations/COM_EllipseMaskOperation.cc +++ b/source/blender/compositor/operations/COM_EllipseMaskOperation.cc @@ -17,84 +17,80 @@ */ #include "COM_EllipseMaskOperation.h" -#include "BLI_math.h" -#include "DNA_node_types.h" - -#include <functional> namespace blender::compositor { EllipseMaskOperation::EllipseMaskOperation() { - this->addInputSocket(DataType::Value); - this->addInputSocket(DataType::Value); - this->addOutputSocket(DataType::Value); - this->m_inputMask = nullptr; - this->m_inputValue = nullptr; - this->m_cosine = 0.0f; - this->m_sine = 0.0f; + this->add_input_socket(DataType::Value); + this->add_input_socket(DataType::Value); + this->add_output_socket(DataType::Value); + input_mask_ = nullptr; + input_value_ = nullptr; + cosine_ = 0.0f; + sine_ = 0.0f; } -void EllipseMaskOperation::initExecution() +void EllipseMaskOperation::init_execution() { - this->m_inputMask = this->getInputSocketReader(0); - this->m_inputValue = this->getInputSocketReader(1); - const double rad = (double)this->m_data->rotation; - this->m_cosine = cos(rad); - this->m_sine = sin(rad); - this->m_aspectRatio = ((float)this->getWidth()) / this->getHeight(); + input_mask_ = this->get_input_socket_reader(0); + input_value_ = this->get_input_socket_reader(1); + const double rad = (double)data_->rotation; + cosine_ = cos(rad); + sine_ = sin(rad); + aspect_ratio_ = ((float)this->get_width()) / this->get_height(); } -void EllipseMaskOperation::executePixelSampled(float output[4], - float x, - float y, - PixelSampler sampler) +void EllipseMaskOperation::execute_pixel_sampled(float output[4], + float x, + float y, + PixelSampler sampler) { - float inputMask[4]; - float inputValue[4]; + float input_mask[4]; + float input_value[4]; - float rx = x / this->getWidth(); - float ry = y / this->getHeight(); + float rx = x / MAX2(this->get_width() - 1.0f, FLT_EPSILON); + float ry = y / MAX2(this->get_height() - 1.0f, FLT_EPSILON); - const float dy = (ry - this->m_data->y) / this->m_aspectRatio; - const float dx = rx - this->m_data->x; - rx = this->m_data->x + (this->m_cosine * dx + this->m_sine * dy); - ry = this->m_data->y + (-this->m_sine * dx + this->m_cosine * dy); + const float dy = (ry - data_->y) / aspect_ratio_; + const float dx = rx - data_->x; + rx = data_->x + (cosine_ * dx + sine_ * dy); + ry = data_->y + (-sine_ * dx + cosine_ * dy); - this->m_inputMask->readSampled(inputMask, x, y, sampler); - this->m_inputValue->readSampled(inputValue, x, y, sampler); + input_mask_->read_sampled(input_mask, x, y, sampler); + input_value_->read_sampled(input_value, x, y, sampler); - const float halfHeight = (this->m_data->height) / 2.0f; - const float halfWidth = this->m_data->width / 2.0f; - float sx = rx - this->m_data->x; + const float half_height = (data_->height) / 2.0f; + const float half_width = data_->width / 2.0f; + float sx = rx - data_->x; sx *= sx; - const float tx = halfWidth * halfWidth; - float sy = ry - this->m_data->y; + const float tx = half_width * half_width; + float sy = ry - data_->y; sy *= sy; - const float ty = halfHeight * halfHeight; + const float ty = half_height * half_height; - bool inside = ((sx / tx) + (sy / ty)) < 1.0f; + bool inside = ((sx / tx) + (sy / ty)) <= (1.0f + FLT_EPSILON); - switch (this->m_maskType) { + switch (mask_type_) { case CMP_NODE_MASKTYPE_ADD: if (inside) { - output[0] = MAX2(inputMask[0], inputValue[0]); + output[0] = MAX2(input_mask[0], input_value[0]); } else { - output[0] = inputMask[0]; + output[0] = input_mask[0]; } break; case CMP_NODE_MASKTYPE_SUBTRACT: if (inside) { - output[0] = inputMask[0] - inputValue[0]; + output[0] = input_mask[0] - input_value[0]; CLAMP(output[0], 0, 1); } else { - output[0] = inputMask[0]; + output[0] = input_mask[0]; } break; case CMP_NODE_MASKTYPE_MULTIPLY: if (inside) { - output[0] = inputMask[0] * inputValue[0]; + output[0] = input_mask[0] * input_value[0]; } else { output[0] = 0; @@ -102,15 +98,15 @@ void EllipseMaskOperation::executePixelSampled(float output[4], break; case CMP_NODE_MASKTYPE_NOT: if (inside) { - if (inputMask[0] > 0.0f) { + if (input_mask[0] > 0.0f) { output[0] = 0; } else { - output[0] = inputValue[0]; + output[0] = input_value[0]; } } else { - output[0] = inputMask[0]; + output[0] = input_mask[0]; } break; } @@ -121,7 +117,7 @@ void EllipseMaskOperation::update_memory_buffer_partial(MemoryBuffer *output, Span<MemoryBuffer *> inputs) { MaskFunc mask_func; - switch (m_maskType) { + switch (mask_type_) { case CMP_NODE_MASKTYPE_ADD: mask_func = [](const bool is_inside, const float *mask, const float *value) { return is_inside ? MAX2(mask[0], value[0]) : mask[0]; @@ -156,28 +152,28 @@ void EllipseMaskOperation::apply_mask(MemoryBuffer *output, { const MemoryBuffer *input_mask = inputs[0]; const MemoryBuffer *input_value = inputs[1]; - const float op_w = this->getWidth(); - const float op_h = this->getHeight(); - const float half_w = this->m_data->width / 2.0f; - const float half_h = this->m_data->height / 2.0f; + const float op_last_x = MAX2(this->get_width() - 1.0f, FLT_EPSILON); + const float op_last_y = MAX2(this->get_height() - 1.0f, FLT_EPSILON); + const float half_w = data_->width / 2.0f; + const float half_h = data_->height / 2.0f; const float tx = half_w * half_w; const float ty = half_h * half_h; for (int y = area.ymin; y < area.ymax; y++) { - const float op_ry = y / op_h; - const float dy = (op_ry - this->m_data->y) / m_aspectRatio; + const float op_ry = y / op_last_y; + const float dy = (op_ry - data_->y) / aspect_ratio_; float *out = output->get_elem(area.xmin, y); const float *mask = input_mask->get_elem(area.xmin, y); const float *value = input_value->get_elem(area.xmin, y); for (int x = area.xmin; x < area.xmax; x++) { - const float op_rx = x / op_w; - const float dx = op_rx - this->m_data->x; - const float rx = this->m_data->x + (m_cosine * dx + m_sine * dy); - const float ry = this->m_data->y + (-m_sine * dx + m_cosine * dy); - float sx = rx - this->m_data->x; + const float op_rx = x / op_last_x; + const float dx = op_rx - data_->x; + const float rx = data_->x + (cosine_ * dx + sine_ * dy); + const float ry = data_->y + (-sine_ * dx + cosine_ * dy); + float sx = rx - data_->x; sx *= sx; - float sy = ry - this->m_data->y; + float sy = ry - data_->y; sy *= sy; - const bool inside = ((sx / tx) + (sy / ty)) < 1.0f; + const bool inside = ((sx / tx) + (sy / ty)) <= (1.0f + FLT_EPSILON); out[0] = mask_func(inside, mask, value); mask += input_mask->elem_stride; @@ -187,10 +183,10 @@ void EllipseMaskOperation::apply_mask(MemoryBuffer *output, } } -void EllipseMaskOperation::deinitExecution() +void EllipseMaskOperation::deinit_execution() { - this->m_inputMask = nullptr; - this->m_inputValue = nullptr; + input_mask_ = nullptr; + input_value_ = nullptr; } } // namespace blender::compositor |