From 2ef6d2a9f5a4c92995b69bd9fdb135cad9e456e0 Mon Sep 17 00:00:00 2001 From: Habib Gahbiche Date: Fri, 8 Dec 2023 16:03:01 +0100 Subject: [PATCH 1/3] Full frame Compositor: Unify relative translate behavior with GPU compositor "Relative" in translation means relative to input size and not render size, as described in the user manual. --- .../compositor/nodes/COM_TranslateNode.cc | 9 +----- .../operations/COM_TranslateOperation.cc | 9 +----- .../operations/COM_TranslateOperation.h | 30 +++++++++++++++---- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/source/blender/compositor/nodes/COM_TranslateNode.cc b/source/blender/compositor/nodes/COM_TranslateNode.cc index 44e26438a60..2b89a80c10f 100644 --- a/source/blender/compositor/nodes/COM_TranslateNode.cc +++ b/source/blender/compositor/nodes/COM_TranslateNode.cc @@ -30,14 +30,7 @@ void TranslateNode::convert_to_operations(NodeConverter &converter, new TranslateOperation() : new TranslateCanvasOperation(); operation->set_wrapping(data->wrap_axis); - if (data->relative) { - const RenderData *rd = context.get_render_data(); - const float render_size_factor = context.get_render_percentage_as_factor(); - float fx = rd->xsch * render_size_factor; - float fy = rd->ysch * render_size_factor; - - operation->setFactorXY(fx, fy); - } + operation->setIsRelative(data->relative); converter.add_operation(operation); converter.map_input_socket(input_xsocket, operation->get_input_socket(1)); diff --git a/source/blender/compositor/operations/COM_TranslateOperation.cc b/source/blender/compositor/operations/COM_TranslateOperation.cc index cadeae23e70..02231d2dada 100644 --- a/source/blender/compositor/operations/COM_TranslateOperation.cc +++ b/source/blender/compositor/operations/COM_TranslateOperation.cc @@ -18,8 +18,7 @@ TranslateOperation::TranslateOperation(DataType data_type, ResizeMode resize_mod input_xoperation_ = nullptr; input_yoperation_ = nullptr; is_delta_set_ = false; - factor_x_ = 1.0f; - factor_y_ = 1.0f; + is_relative_ = false; this->x_extend_mode_ = MemoryBufferExtend::Clip; this->y_extend_mode_ = MemoryBufferExtend::Clip; @@ -69,12 +68,6 @@ bool TranslateOperation::determine_depending_area_of_interest(rcti *input, return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); } -void TranslateOperation::setFactorXY(float factorX, float factorY) -{ - factor_x_ = factorX; - factor_y_ = factorY; -} - void TranslateOperation::set_wrapping(int wrapping_type) { switch (wrapping_type) { diff --git a/source/blender/compositor/operations/COM_TranslateOperation.h b/source/blender/compositor/operations/COM_TranslateOperation.h index d0bf724f331..c045b8725f2 100644 --- a/source/blender/compositor/operations/COM_TranslateOperation.h +++ b/source/blender/compositor/operations/COM_TranslateOperation.h @@ -22,8 +22,7 @@ class TranslateOperation : public MultiThreadedOperation { float delta_x_; float delta_y_; bool is_delta_set_; - float factor_x_; - float factor_y_; + bool is_relative_; protected: MemoryBufferExtend x_extend_mode_; @@ -42,11 +41,20 @@ class TranslateOperation : public MultiThreadedOperation { float getDeltaX() { - return delta_x_ * factor_x_; + return delta_x_; } float getDeltaY() { - return delta_y_ * factor_y_; + return delta_y_; + } + + void setIsRelative(const bool is_relative) + { + is_relative_ = is_relative; + } + bool getIsRelative() + { + return is_relative_; } inline void ensure_delta() @@ -58,17 +66,27 @@ class TranslateOperation : public MultiThreadedOperation { delta_x_ = temp_delta[0]; input_yoperation_->read_sampled(temp_delta, 0, 0, PixelSampler::Nearest); delta_y_ = temp_delta[0]; + if(getIsRelative()) { + const int input_width = BLI_rcti_size_x(&input_operation_->get_canvas()); + const int input_height = BLI_rcti_size_y(&input_operation_->get_canvas()); + delta_x_ *= input_width; + delta_y_ *= input_height; + } } else { delta_x_ = get_input_operation(X_INPUT_INDEX)->get_constant_value_default(0.0f); delta_y_ = get_input_operation(Y_INPUT_INDEX)->get_constant_value_default(0.0f); + if(getIsRelative()) { + const int input_width = BLI_rcti_size_x(&get_input_operation(IMAGE_INPUT_INDEX)->get_canvas()); + const int input_height = BLI_rcti_size_y(&get_input_operation(IMAGE_INPUT_INDEX)->get_canvas()); + delta_x_ *= input_width; + delta_y_ *= input_height; + } } is_delta_set_ = true; } } - - void setFactorXY(float factorX, float factorY); void set_wrapping(int wrapping_type); void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; -- 2.30.2 From dd5dfad300d0401e078edda2720215ae9d5da43a Mon Sep 17 00:00:00 2001 From: Habib Gahbiche Date: Tue, 12 Dec 2023 10:57:49 +0100 Subject: [PATCH 2/3] Cleanup: use snake_case for method naming --- source/blender/compositor/nodes/COM_TranslateNode.cc | 2 +- .../compositor/operations/COM_TranslateOperation.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/blender/compositor/nodes/COM_TranslateNode.cc b/source/blender/compositor/nodes/COM_TranslateNode.cc index 2b89a80c10f..8ba403d62b5 100644 --- a/source/blender/compositor/nodes/COM_TranslateNode.cc +++ b/source/blender/compositor/nodes/COM_TranslateNode.cc @@ -30,7 +30,7 @@ void TranslateNode::convert_to_operations(NodeConverter &converter, new TranslateOperation() : new TranslateCanvasOperation(); operation->set_wrapping(data->wrap_axis); - operation->setIsRelative(data->relative); + operation->set_is_relative(data->relative); converter.add_operation(operation); converter.map_input_socket(input_xsocket, operation->get_input_socket(1)); diff --git a/source/blender/compositor/operations/COM_TranslateOperation.h b/source/blender/compositor/operations/COM_TranslateOperation.h index c045b8725f2..757070a35b0 100644 --- a/source/blender/compositor/operations/COM_TranslateOperation.h +++ b/source/blender/compositor/operations/COM_TranslateOperation.h @@ -48,11 +48,11 @@ class TranslateOperation : public MultiThreadedOperation { return delta_y_; } - void setIsRelative(const bool is_relative) + void set_is_relative(const bool is_relative) { is_relative_ = is_relative; } - bool getIsRelative() + bool get_is_relative() { return is_relative_; } @@ -66,7 +66,7 @@ class TranslateOperation : public MultiThreadedOperation { delta_x_ = temp_delta[0]; input_yoperation_->read_sampled(temp_delta, 0, 0, PixelSampler::Nearest); delta_y_ = temp_delta[0]; - if(getIsRelative()) { + if(get_is_relative()) { const int input_width = BLI_rcti_size_x(&input_operation_->get_canvas()); const int input_height = BLI_rcti_size_y(&input_operation_->get_canvas()); delta_x_ *= input_width; @@ -76,7 +76,7 @@ class TranslateOperation : public MultiThreadedOperation { else { delta_x_ = get_input_operation(X_INPUT_INDEX)->get_constant_value_default(0.0f); delta_y_ = get_input_operation(Y_INPUT_INDEX)->get_constant_value_default(0.0f); - if(getIsRelative()) { + if(get_is_relative()) { const int input_width = BLI_rcti_size_x(&get_input_operation(IMAGE_INPUT_INDEX)->get_canvas()); const int input_height = BLI_rcti_size_y(&get_input_operation(IMAGE_INPUT_INDEX)->get_canvas()); delta_x_ *= input_width; -- 2.30.2 From efd77b3c8f1c1cfb9f2e31c16735b8e1459818f4 Mon Sep 17 00:00:00 2001 From: Habib Gahbiche Date: Tue, 12 Dec 2023 11:53:21 +0100 Subject: [PATCH 3/3] Cleanup: use snake_case for get_delta_x --- .../operations/COM_TranslateOperation.cc | 24 +++++++++---------- .../operations/COM_TranslateOperation.h | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/source/blender/compositor/operations/COM_TranslateOperation.cc b/source/blender/compositor/operations/COM_TranslateOperation.cc index 02231d2dada..242e098004b 100644 --- a/source/blender/compositor/operations/COM_TranslateOperation.cc +++ b/source/blender/compositor/operations/COM_TranslateOperation.cc @@ -46,8 +46,8 @@ void TranslateOperation::execute_pixel_sampled(float output[4], { ensure_delta(); - float original_xpos = x - this->getDeltaX(); - float original_ypos = y - this->getDeltaY(); + float original_xpos = x - this->get_delta_x(); + float original_ypos = y - this->get_delta_y(); input_operation_->read_sampled(output, original_xpos, original_ypos, PixelSampler::Bilinear); } @@ -60,10 +60,10 @@ bool TranslateOperation::determine_depending_area_of_interest(rcti *input, ensure_delta(); - new_input.xmin = input->xmin - this->getDeltaX(); - new_input.xmax = input->xmax - this->getDeltaX(); - new_input.ymin = input->ymin - this->getDeltaY(); - new_input.ymax = input->ymax - this->getDeltaY(); + new_input.xmin = input->xmin - this->get_delta_x(); + new_input.xmax = input->xmax - this->get_delta_x(); + new_input.ymin = input->ymin - this->get_delta_y(); + new_input.ymax = input->ymax - this->get_delta_y(); return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); } @@ -94,11 +94,11 @@ void TranslateOperation::get_area_of_interest(const int input_idx, ensure_delta(); r_input_area = output_area; if (x_extend_mode_ == MemoryBufferExtend::Clip) { - const int delta_x = this->getDeltaX(); + const int delta_x = this->get_delta_x(); BLI_rcti_translate(&r_input_area, -delta_x, 0); } if (y_extend_mode_ == MemoryBufferExtend::Clip) { - const int delta_y = this->getDeltaY(); + const int delta_y = this->get_delta_y(); BLI_rcti_translate(&r_input_area, 0, -delta_y); } } @@ -112,8 +112,8 @@ void TranslateOperation::update_memory_buffer_partial(MemoryBuffer *output, Span inputs) { MemoryBuffer *input = inputs[0]; - const int delta_x = this->getDeltaX(); - const int delta_y = this->getDeltaY(); + const int delta_x = this->get_delta_x(); + const int delta_y = this->get_delta_y(); 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++) { @@ -142,8 +142,8 @@ void TranslateCanvasOperation::determine_canvas(const rcti &preferred_area, rcti y_socket->determine_canvas(r_area, unused); ensure_delta(); - const float delta_x = x_extend_mode_ == MemoryBufferExtend::Clip ? getDeltaX() : 0.0f; - const float delta_y = y_extend_mode_ == MemoryBufferExtend::Clip ? getDeltaY() : 0.0f; + const float delta_x = x_extend_mode_ == MemoryBufferExtend::Clip ? get_delta_x() : 0.0f; + const float delta_y = y_extend_mode_ == MemoryBufferExtend::Clip ? get_delta_y() : 0.0f; BLI_rcti_translate(&r_area, delta_x, delta_y); } } diff --git a/source/blender/compositor/operations/COM_TranslateOperation.h b/source/blender/compositor/operations/COM_TranslateOperation.h index 757070a35b0..263e922b306 100644 --- a/source/blender/compositor/operations/COM_TranslateOperation.h +++ b/source/blender/compositor/operations/COM_TranslateOperation.h @@ -39,11 +39,11 @@ class TranslateOperation : public MultiThreadedOperation { void init_execution() override; void deinit_execution() override; - float getDeltaX() + float get_delta_x() { return delta_x_; } - float getDeltaY() + float get_delta_y() { return delta_y_; } -- 2.30.2