diff options
Diffstat (limited to 'source/blender/compositor/operations/COM_TranslateOperation.cc')
-rw-r--r-- | source/blender/compositor/operations/COM_TranslateOperation.cc | 65 |
1 files changed, 62 insertions, 3 deletions
diff --git a/source/blender/compositor/operations/COM_TranslateOperation.cc b/source/blender/compositor/operations/COM_TranslateOperation.cc index 49135f25320..a3db086e974 100644 --- a/source/blender/compositor/operations/COM_TranslateOperation.cc +++ b/source/blender/compositor/operations/COM_TranslateOperation.cc @@ -20,12 +20,15 @@ namespace blender::compositor { -TranslateOperation::TranslateOperation() +TranslateOperation::TranslateOperation() : TranslateOperation(DataType::Color) { - this->addInputSocket(DataType::Color); +} +TranslateOperation::TranslateOperation(DataType data_type) +{ + this->addInputSocket(data_type); this->addInputSocket(DataType::Value); this->addInputSocket(DataType::Value); - this->addOutputSocket(DataType::Color); + this->addOutputSocket(data_type); this->setResolutionInputSocketIndex(0); this->m_inputOperation = nullptr; this->m_inputXOperation = nullptr; @@ -33,6 +36,8 @@ TranslateOperation::TranslateOperation() this->m_isDeltaSet = false; this->m_factorX = 1.0f; this->m_factorY = 1.0f; + this->x_extend_mode_ = MemoryBufferExtend::Clip; + this->y_extend_mode_ = MemoryBufferExtend::Clip; } void TranslateOperation::initExecution() { @@ -83,4 +88,58 @@ void TranslateOperation::setFactorXY(float factorX, float factorY) m_factorY = factorY; } +void TranslateOperation::set_wrapping(int wrapping_type) +{ + switch (wrapping_type) { + case CMP_NODE_WRAP_X: + x_extend_mode_ = MemoryBufferExtend::Repeat; + break; + case CMP_NODE_WRAP_Y: + y_extend_mode_ = MemoryBufferExtend::Repeat; + break; + case CMP_NODE_WRAP_XY: + x_extend_mode_ = MemoryBufferExtend::Repeat; + y_extend_mode_ = MemoryBufferExtend::Repeat; + break; + default: + break; + } +} + +void TranslateOperation::get_area_of_interest(const int input_idx, + const rcti &output_area, + rcti &r_input_area) +{ + if (input_idx == 0) { + ensureDelta(); + r_input_area = output_area; + if (x_extend_mode_ == MemoryBufferExtend::Clip) { + const int delta_x = this->getDeltaX(); + BLI_rcti_translate(&r_input_area, -delta_x, 0); + } + if (y_extend_mode_ == MemoryBufferExtend::Clip) { + const int delta_y = this->getDeltaY(); + BLI_rcti_translate(&r_input_area, 0, -delta_y); + } + } +} + +void TranslateOperation::update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> inputs) +{ + MemoryBuffer *input = inputs[0]; + const int delta_x = this->getDeltaX(); + const int delta_y = this->getDeltaY(); + for (int y = area.ymin; y < area.ymax; y++) { + float *out = output->get_elem(area.xmin, y); + for (int x = area.xmin; x < area.xmax; x++) { + const int input_x = x - delta_x; + const int input_y = y - delta_y; + input->read(out, input_x, input_y, x_extend_mode_, y_extend_mode_); + out += output->elem_stride; + } + } +} + } // namespace blender::compositor |