Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Castilla <manzanillawork@gmail.com>2021-09-28 20:33:06 +0300
committerManuel Castilla <manzanillawork@gmail.com>2021-09-28 23:00:17 +0300
commitf84fb12f5d72433780a96c3cc4381399f153cf1a (patch)
tree62ca25765b3b5ccc2bc8ca35449ddd8f3999071a /source/blender/compositor/intern
parent76377f0176b9561a7fc8f46b4ed704c631ddd90d (diff)
Compositor: Add support for canvas compositing
This commit adds functionality for operations that require pixel translation or resizing on "Full Frame" mode, allowing to adjust their canvas. It fixes most cropping issues in translate, scale, rotate and transform nodes by adjusting their canvas to the result, instead of the input canvas. Operations output buffer is still always on (0,0) position for easier image algorithm implementation, even when the canvas is not. Current limitations (will be addressed on bcon2): - Displayed translation in Viewer node is limited to 6000px. - When scaling up the canvas size is limited to the scene resolution size x 1.5 . From that point it crops. If none of these limitations are hit, the Viewer node displays the full input with any translation. Differential Revision: https://developer.blender.org/D12466
Diffstat (limited to 'source/blender/compositor/intern')
-rw-r--r--source/blender/compositor/intern/COM_CompositorContext.cc6
-rw-r--r--source/blender/compositor/intern/COM_CompositorContext.h2
-rw-r--r--source/blender/compositor/intern/COM_Converter.cc118
-rw-r--r--source/blender/compositor/intern/COM_FullFrameExecutionModel.cc64
-rw-r--r--source/blender/compositor/intern/COM_FullFrameExecutionModel.h6
-rw-r--r--source/blender/compositor/intern/COM_MemoryBuffer.cc2
-rw-r--r--source/blender/compositor/intern/COM_MemoryBuffer.h58
-rw-r--r--source/blender/compositor/intern/COM_NodeOperation.cc40
-rw-r--r--source/blender/compositor/intern/COM_NodeOperation.h32
-rw-r--r--source/blender/compositor/intern/COM_NodeOperationBuilder.cc17
-rw-r--r--source/blender/compositor/intern/COM_SharedOperationBuffers.cc12
-rw-r--r--source/blender/compositor/intern/COM_SharedOperationBuffers.h2
12 files changed, 248 insertions, 111 deletions
diff --git a/source/blender/compositor/intern/COM_CompositorContext.cc b/source/blender/compositor/intern/COM_CompositorContext.cc
index a93820b66dc..f5f490b0bf6 100644
--- a/source/blender/compositor/intern/COM_CompositorContext.cc
+++ b/source/blender/compositor/intern/COM_CompositorContext.cc
@@ -43,6 +43,12 @@ int CompositorContext::getFramenumber() const
return m_rd->cfra;
}
+Size2f CompositorContext::get_render_size() const
+{
+ return {getRenderData()->xsch * getRenderPercentageAsFactor(),
+ getRenderData()->ysch * getRenderPercentageAsFactor()};
+}
+
eExecutionModel CompositorContext::get_execution_model() const
{
if (U.experimental.use_full_frame_compositor) {
diff --git a/source/blender/compositor/intern/COM_CompositorContext.h b/source/blender/compositor/intern/COM_CompositorContext.h
index c6e83f93777..ae298c5a65a 100644
--- a/source/blender/compositor/intern/COM_CompositorContext.h
+++ b/source/blender/compositor/intern/COM_CompositorContext.h
@@ -288,6 +288,8 @@ class CompositorContext {
return m_rd->size * 0.01f;
}
+ Size2f get_render_size() const;
+
/**
* Get active execution model.
*/
diff --git a/source/blender/compositor/intern/COM_Converter.cc b/source/blender/compositor/intern/COM_Converter.cc
index bd05a8e4ef0..ee77beb8a82 100644
--- a/source/blender/compositor/intern/COM_Converter.cc
+++ b/source/blender/compositor/intern/COM_Converter.cc
@@ -467,7 +467,9 @@ void COM_convert_canvas(NodeOperationBuilder &builder,
/* Data type conversions are executed before resolutions to ensure convert operations have
* resolution. This method have to ensure same datatypes are linked for new operations. */
BLI_assert(fromSocket->getDataType() == toSocket->getDataType());
+
ResizeMode mode = toSocket->getResizeMode();
+ BLI_assert(mode != ResizeMode::None);
NodeOperation *toOperation = &toSocket->getOperation();
const float toWidth = toOperation->getWidth();
@@ -477,13 +479,12 @@ void COM_convert_canvas(NodeOperationBuilder &builder,
const float fromHeight = fromOperation->getHeight();
bool doCenter = false;
bool doScale = false;
- float addX = (toWidth - fromWidth) / 2.0f;
- float addY = (toHeight - fromHeight) / 2.0f;
float scaleX = 0;
float scaleY = 0;
switch (mode) {
case ResizeMode::None:
+ case ResizeMode::Align:
break;
case ResizeMode::Center:
doCenter = true;
@@ -518,63 +519,74 @@ void COM_convert_canvas(NodeOperationBuilder &builder,
break;
}
- if (doCenter) {
- NodeOperation *first = nullptr;
- ScaleOperation *scaleOperation = nullptr;
- if (doScale) {
- scaleOperation = new ScaleRelativeOperation(fromSocket->getDataType());
- scaleOperation->getInputSocket(1)->setResizeMode(ResizeMode::None);
- scaleOperation->getInputSocket(2)->setResizeMode(ResizeMode::None);
- first = scaleOperation;
- SetValueOperation *sxop = new SetValueOperation();
- sxop->setValue(scaleX);
- builder.addLink(sxop->getOutputSocket(), scaleOperation->getInputSocket(1));
- SetValueOperation *syop = new SetValueOperation();
- syop->setValue(scaleY);
- builder.addLink(syop->getOutputSocket(), scaleOperation->getInputSocket(2));
- builder.addOperation(sxop);
- builder.addOperation(syop);
-
- const rcti &scale_canvas = fromOperation->get_canvas();
- scaleOperation->set_canvas(scale_canvas);
- sxop->set_canvas(scale_canvas);
- syop->set_canvas(scale_canvas);
- builder.addOperation(scaleOperation);
- }
+ float addX = doCenter ? (toWidth - fromWidth) / 2.0f : 0.0f;
+ float addY = doCenter ? (toHeight - fromHeight) / 2.0f : 0.0f;
+ NodeOperation *first = nullptr;
+ ScaleOperation *scaleOperation = nullptr;
+ if (doScale) {
+ scaleOperation = new ScaleRelativeOperation(fromSocket->getDataType());
+ scaleOperation->getInputSocket(1)->setResizeMode(ResizeMode::None);
+ scaleOperation->getInputSocket(2)->setResizeMode(ResizeMode::None);
+ first = scaleOperation;
+ SetValueOperation *sxop = new SetValueOperation();
+ sxop->setValue(scaleX);
+ builder.addLink(sxop->getOutputSocket(), scaleOperation->getInputSocket(1));
+ SetValueOperation *syop = new SetValueOperation();
+ syop->setValue(scaleY);
+ builder.addLink(syop->getOutputSocket(), scaleOperation->getInputSocket(2));
+ builder.addOperation(sxop);
+ builder.addOperation(syop);
- TranslateOperation *translateOperation = new TranslateOperation(toSocket->getDataType());
- translateOperation->getInputSocket(1)->setResizeMode(ResizeMode::None);
- translateOperation->getInputSocket(2)->setResizeMode(ResizeMode::None);
- if (!first) {
- first = translateOperation;
+ rcti scale_canvas = fromOperation->get_canvas();
+ if (builder.context().get_execution_model() == eExecutionModel::FullFrame) {
+ ScaleOperation::scale_area(scale_canvas, scaleX, scaleY);
+ scale_canvas.xmax = scale_canvas.xmin + toOperation->getWidth();
+ scale_canvas.ymax = scale_canvas.ymin + toOperation->getHeight();
+ addX = 0;
+ addY = 0;
}
- SetValueOperation *xop = new SetValueOperation();
- xop->setValue(addX);
- builder.addLink(xop->getOutputSocket(), translateOperation->getInputSocket(1));
- SetValueOperation *yop = new SetValueOperation();
- yop->setValue(addY);
- builder.addLink(yop->getOutputSocket(), translateOperation->getInputSocket(2));
- builder.addOperation(xop);
- builder.addOperation(yop);
+ scaleOperation->set_canvas(scale_canvas);
+ sxop->set_canvas(scale_canvas);
+ syop->set_canvas(scale_canvas);
+ builder.addOperation(scaleOperation);
+ }
- const rcti &translate_canvas = toOperation->get_canvas();
- translateOperation->set_canvas(translate_canvas);
- xop->set_canvas(translate_canvas);
- yop->set_canvas(translate_canvas);
- builder.addOperation(translateOperation);
+ TranslateOperation *translateOperation = new TranslateOperation(toSocket->getDataType());
+ translateOperation->getInputSocket(1)->setResizeMode(ResizeMode::None);
+ translateOperation->getInputSocket(2)->setResizeMode(ResizeMode::None);
+ if (!first) {
+ first = translateOperation;
+ }
+ SetValueOperation *xop = new SetValueOperation();
+ xop->setValue(addX);
+ builder.addLink(xop->getOutputSocket(), translateOperation->getInputSocket(1));
+ SetValueOperation *yop = new SetValueOperation();
+ yop->setValue(addY);
+ builder.addLink(yop->getOutputSocket(), translateOperation->getInputSocket(2));
+ builder.addOperation(xop);
+ builder.addOperation(yop);
- if (doScale) {
- translateOperation->getInputSocket(0)->setResizeMode(ResizeMode::None);
- builder.addLink(scaleOperation->getOutputSocket(), translateOperation->getInputSocket(0));
- }
+ rcti translate_canvas = toOperation->get_canvas();
+ if (mode == ResizeMode::Align) {
+ translate_canvas.xmax = translate_canvas.xmin + fromWidth;
+ translate_canvas.ymax = translate_canvas.ymin + fromHeight;
+ }
+ translateOperation->set_canvas(translate_canvas);
+ xop->set_canvas(translate_canvas);
+ yop->set_canvas(translate_canvas);
+ builder.addOperation(translateOperation);
- /* remove previous link and replace */
- builder.removeInputLink(toSocket);
- first->getInputSocket(0)->setResizeMode(ResizeMode::None);
- toSocket->setResizeMode(ResizeMode::None);
- builder.addLink(fromSocket, first->getInputSocket(0));
- builder.addLink(translateOperation->getOutputSocket(), toSocket);
+ if (doScale) {
+ translateOperation->getInputSocket(0)->setResizeMode(ResizeMode::None);
+ builder.addLink(scaleOperation->getOutputSocket(), translateOperation->getInputSocket(0));
}
+
+ /* remove previous link and replace */
+ builder.removeInputLink(toSocket);
+ first->getInputSocket(0)->setResizeMode(ResizeMode::None);
+ toSocket->setResizeMode(ResizeMode::None);
+ builder.addLink(fromSocket, first->getInputSocket(0));
+ builder.addLink(translateOperation->getOutputSocket(), toSocket);
}
} // namespace blender::compositor
diff --git a/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc b/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc
index 957bbe24e5f..c44a168390b 100644
--- a/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc
+++ b/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc
@@ -74,34 +74,61 @@ void FullFrameExecutionModel::determine_areas_to_render_and_reads()
}
}
-Vector<MemoryBuffer *> FullFrameExecutionModel::get_input_buffers(NodeOperation *op)
+/**
+ * Returns input buffers with an offset relative to given output coordinates. Returned memory
+ * buffers must be deleted.
+ */
+Vector<MemoryBuffer *> FullFrameExecutionModel::get_input_buffers(NodeOperation *op,
+ const int output_x,
+ const int output_y)
{
const int num_inputs = op->getNumberOfInputSockets();
Vector<MemoryBuffer *> inputs_buffers(num_inputs);
for (int i = 0; i < num_inputs; i++) {
- NodeOperation *input_op = op->get_input_operation(i);
- inputs_buffers[i] = active_buffers_.get_rendered_buffer(input_op);
+ NodeOperation *input = op->get_input_operation(i);
+ const int offset_x = (input->get_canvas().xmin - op->get_canvas().xmin) + output_x;
+ const int offset_y = (input->get_canvas().ymin - op->get_canvas().ymin) + output_y;
+ MemoryBuffer *buf = active_buffers_.get_rendered_buffer(input);
+
+ rcti rect = buf->get_rect();
+ BLI_rcti_translate(&rect, offset_x, offset_y);
+ inputs_buffers[i] = new MemoryBuffer(
+ buf->getBuffer(), buf->get_num_channels(), rect, buf->is_a_single_elem());
}
return inputs_buffers;
}
-MemoryBuffer *FullFrameExecutionModel::create_operation_buffer(NodeOperation *op)
+MemoryBuffer *FullFrameExecutionModel::create_operation_buffer(NodeOperation *op,
+ const int output_x,
+ const int output_y)
{
+ rcti rect;
+ BLI_rcti_init(&rect, output_x, output_x + op->getWidth(), output_y, output_y + op->getHeight());
+
const DataType data_type = op->getOutputSocket(0)->getDataType();
const bool is_a_single_elem = op->get_flags().is_constant_operation;
- return new MemoryBuffer(data_type, op->get_canvas(), is_a_single_elem);
+ return new MemoryBuffer(data_type, rect, is_a_single_elem);
}
void FullFrameExecutionModel::render_operation(NodeOperation *op)
{
- Vector<MemoryBuffer *> input_bufs = get_input_buffers(op);
+ /* Output has no offset for easier image algorithms implementation on operations. */
+ constexpr int output_x = 0;
+ constexpr int output_y = 0;
const bool has_outputs = op->getNumberOfOutputSockets() > 0;
- MemoryBuffer *op_buf = has_outputs ? create_operation_buffer(op) : nullptr;
+ MemoryBuffer *op_buf = has_outputs ? create_operation_buffer(op, output_x, output_y) : nullptr;
if (op->getWidth() > 0 && op->getHeight() > 0) {
- Span<rcti> areas = active_buffers_.get_areas_to_render(op);
+ Vector<MemoryBuffer *> input_bufs = get_input_buffers(op, output_x, output_y);
+ const int op_offset_x = output_x - op->get_canvas().xmin;
+ const int op_offset_y = output_y - op->get_canvas().ymin;
+ Span<rcti> areas = active_buffers_.get_areas_to_render(op, op_offset_x, op_offset_y);
op->render(op_buf, areas, input_bufs);
DebugInfo::operation_rendered(op, op_buf);
+
+ for (MemoryBuffer *buf : input_bufs) {
+ delete buf;
+ }
}
/* Even if operation has no resolution set the empty buffer. It will be clipped with a
* TranslateOperation from convert resolutions if linked to an operation with resolution. */
@@ -187,7 +214,8 @@ void FullFrameExecutionModel::determine_areas_to_render(NodeOperation *output_op
std::pair<NodeOperation *, rcti> pair = stack.pop_last();
NodeOperation *operation = pair.first;
const rcti &render_area = pair.second;
- if (active_buffers_.is_area_registered(operation, render_area)) {
+ if (BLI_rcti_is_empty(&render_area) ||
+ active_buffers_.is_area_registered(operation, render_area)) {
continue;
}
@@ -239,9 +267,8 @@ void FullFrameExecutionModel::get_output_render_area(NodeOperation *output_op, r
BLI_assert(output_op->isOutputOperation(context_.isRendering()));
/* By default return operation bounds (no border). */
- const int op_width = output_op->getWidth();
- const int op_height = output_op->getHeight();
- BLI_rcti_init(&r_area, 0, op_width, 0, op_height);
+ rcti canvas = output_op->get_canvas();
+ r_area = canvas;
const bool has_viewer_border = border_.use_viewer_border &&
(output_op->get_flags().is_viewer_operation ||
@@ -251,12 +278,13 @@ void FullFrameExecutionModel::get_output_render_area(NodeOperation *output_op, r
/* Get border with normalized coordinates. */
const rctf *norm_border = has_viewer_border ? border_.viewer_border : border_.render_border;
- /* Return de-normalized border. */
- BLI_rcti_init(&r_area,
- norm_border->xmin * op_width,
- norm_border->xmax * op_width,
- norm_border->ymin * op_height,
- norm_border->ymax * op_height);
+ /* Return de-normalized border within canvas. */
+ const int w = output_op->getWidth();
+ const int h = output_op->getHeight();
+ r_area.xmin = canvas.xmin + norm_border->xmin * w;
+ r_area.xmax = canvas.xmin + norm_border->xmax * w;
+ r_area.ymin = canvas.ymin + norm_border->ymin * h;
+ r_area.ymax = canvas.ymin + norm_border->ymax * h;
}
}
diff --git a/source/blender/compositor/intern/COM_FullFrameExecutionModel.h b/source/blender/compositor/intern/COM_FullFrameExecutionModel.h
index f75d4f1afdc..66dfb8f052c 100644
--- a/source/blender/compositor/intern/COM_FullFrameExecutionModel.h
+++ b/source/blender/compositor/intern/COM_FullFrameExecutionModel.h
@@ -61,8 +61,10 @@ class FullFrameExecutionModel : public ExecutionModel {
void determine_areas_to_render_and_reads();
void render_operations();
void render_output_dependencies(NodeOperation *output_op);
- Vector<MemoryBuffer *> get_input_buffers(NodeOperation *op);
- MemoryBuffer *create_operation_buffer(NodeOperation *op);
+ Vector<MemoryBuffer *> get_input_buffers(NodeOperation *op,
+ const int output_x,
+ const int output_y);
+ MemoryBuffer *create_operation_buffer(NodeOperation *op, const int output_x, const int output_y);
void render_operation(NodeOperation *op);
void operation_finished(NodeOperation *operation);
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cc b/source/blender/compositor/intern/COM_MemoryBuffer.cc
index 5327be50b53..f57f0f055bf 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.cc
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.cc
@@ -122,6 +122,8 @@ void MemoryBuffer::set_strides()
this->elem_stride = m_num_channels;
this->row_stride = getWidth() * m_num_channels;
}
+ to_positive_x_stride_ = m_rect.xmin < 0 ? -m_rect.xmin + 1 : (m_rect.xmin == 0 ? 1 : 0);
+ to_positive_y_stride_ = m_rect.ymin < 0 ? -m_rect.ymin + 1 : (m_rect.ymin == 0 ? 1 : 0);
}
void MemoryBuffer::clear()
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h
index f730d53acec..4d6c5790987 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.h
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.h
@@ -114,6 +114,12 @@ class MemoryBuffer {
*/
bool owns_data_;
+ /** Stride to make any x coordinate within buffer positive (non-zero). */
+ int to_positive_x_stride_;
+
+ /** Stride to make any y coordinate within buffer positive (non-zero). */
+ int to_positive_y_stride_;
+
public:
/**
* \brief construct new temporarily MemoryBuffer for an area
@@ -166,9 +172,9 @@ class MemoryBuffer {
/**
* Get offset needed to jump from buffer start to given coordinates.
*/
- int get_coords_offset(int x, int y) const
+ intptr_t get_coords_offset(int x, int y) const
{
- return (y - m_rect.ymin) * row_stride + (x - m_rect.xmin) * elem_stride;
+ return ((intptr_t)y - m_rect.ymin) * row_stride + ((intptr_t)x - m_rect.xmin) * elem_stride;
}
/**
@@ -176,7 +182,7 @@ class MemoryBuffer {
*/
float *get_elem(int x, int y)
{
- BLI_assert(x >= m_rect.xmin && x < m_rect.xmax && y >= m_rect.ymin && y < m_rect.ymax);
+ BLI_assert(has_coords(x, y));
return m_buffer + get_coords_offset(x, y);
}
@@ -185,7 +191,7 @@ class MemoryBuffer {
*/
const float *get_elem(int x, int y) const
{
- BLI_assert(x >= m_rect.xmin && x < m_rect.xmax && y >= m_rect.ymin && y < m_rect.ymax);
+ BLI_assert(has_coords(x, y));
return m_buffer + get_coords_offset(x, y);
}
@@ -196,7 +202,7 @@ class MemoryBuffer {
void read_elem_checked(int x, int y, float *out) const
{
- if (x < m_rect.xmin || x >= m_rect.xmax || y < m_rect.ymin || y >= m_rect.ymax) {
+ if (!has_coords(x, y)) {
clear_elem(out);
}
else {
@@ -206,12 +212,7 @@ class MemoryBuffer {
void read_elem_checked(float x, float y, float *out) const
{
- if (x < m_rect.xmin || x >= m_rect.xmax || y < m_rect.ymin || y >= m_rect.ymax) {
- clear_elem(out);
- }
- else {
- read_elem(x, y, out);
- }
+ read_elem_checked(floor_x(x), floor_y(y), out);
}
void read_elem_bilinear(float x, float y, float *out) const
@@ -286,8 +287,7 @@ class MemoryBuffer {
*/
float &get_value(int x, int y, int channel)
{
- BLI_assert(x >= m_rect.xmin && x < m_rect.xmax && y >= m_rect.ymin && y < m_rect.ymax &&
- channel >= 0 && channel < m_num_channels);
+ BLI_assert(has_coords(x, y) && channel >= 0 && channel < m_num_channels);
return m_buffer[get_coords_offset(x, y) + channel];
}
@@ -296,8 +296,7 @@ class MemoryBuffer {
*/
const float &get_value(int x, int y, int channel) const
{
- BLI_assert(x >= m_rect.xmin && x < m_rect.xmax && y >= m_rect.ymin && y < m_rect.ymax &&
- channel >= 0 && channel < m_num_channels);
+ BLI_assert(has_coords(x, y) && channel >= 0 && channel < m_num_channels);
return m_buffer[get_coords_offset(x, y) + channel];
}
@@ -306,7 +305,7 @@ class MemoryBuffer {
*/
const float *get_row_end(int y) const
{
- BLI_assert(y >= 0 && y < getHeight());
+ BLI_assert(has_y(y));
return m_buffer + (is_a_single_elem() ? m_num_channels : get_coords_offset(getWidth(), y));
}
@@ -681,6 +680,33 @@ class MemoryBuffer {
return y - m_rect.ymin;
}
+ template<typename T> bool has_coords(T x, T y) const
+ {
+ return has_x(x) && has_y(y);
+ }
+
+ template<typename T> bool has_x(T x) const
+ {
+ return x >= m_rect.xmin && x < m_rect.xmax;
+ }
+
+ template<typename T> bool has_y(T y) const
+ {
+ return y >= m_rect.ymin && y < m_rect.ymax;
+ }
+
+ /* Fast floor functions. The caller should check result is within buffer bounds. It ceils in near
+ * cases and when given coordinate is negative and less than buffer rect `min - 1`. */
+ int floor_x(float x) const
+ {
+ return (int)(x + to_positive_x_stride_) - to_positive_x_stride_;
+ }
+
+ int floor_y(float y) const
+ {
+ return (int)(y + to_positive_y_stride_) - to_positive_y_stride_;
+ }
+
void copy_single_elem_from(const MemoryBuffer *src,
int channel_offset,
int elem_size,
diff --git a/source/blender/compositor/intern/COM_NodeOperation.cc b/source/blender/compositor/intern/COM_NodeOperation.cc
index ff232efdb08..a6a395261f2 100644
--- a/source/blender/compositor/intern/COM_NodeOperation.cc
+++ b/source/blender/compositor/intern/COM_NodeOperation.cc
@@ -40,6 +40,24 @@ NodeOperation::NodeOperation()
this->m_btree = nullptr;
}
+/** Get constant value when operation is constant, otherwise return default_value. */
+float NodeOperation::get_constant_value_default(float default_value)
+{
+ BLI_assert(m_outputs.size() > 0 && getOutputSocket()->getDataType() == DataType::Value);
+ return *get_constant_elem_default(&default_value);
+}
+
+/** Get constant elem when operation is constant, otherwise return default_elem. */
+const float *NodeOperation::get_constant_elem_default(const float *default_elem)
+{
+ BLI_assert(m_outputs.size() > 0);
+ if (get_flags().is_constant_operation) {
+ return static_cast<ConstantOperation *>(this)->get_constant_elem();
+ }
+
+ return default_elem;
+}
+
/**
* Generate a hash that identifies the operation result in the current execution.
* Requires `hash_output_params` to be implemented, otherwise `std::nullopt` is returned.
@@ -186,6 +204,28 @@ void NodeOperation::deinitExecution()
{
/* pass */
}
+
+void NodeOperation::set_canvas(const rcti &canvas_area)
+{
+ canvas_ = canvas_area;
+ flags.is_canvas_set = true;
+}
+
+const rcti &NodeOperation::get_canvas() const
+{
+ return canvas_;
+}
+
+/**
+ * Mainly used for re-determining canvas of constant operations in cases where preferred canvas
+ * depends on the constant element.
+ */
+void NodeOperation::unset_canvas()
+{
+ BLI_assert(m_inputs.size() == 0);
+ flags.is_canvas_set = false;
+}
+
SocketReader *NodeOperation::getInputSocketReader(unsigned int inputSocketIndex)
{
return this->getInputSocket(inputSocketIndex)->getReader();
diff --git a/source/blender/compositor/intern/COM_NodeOperation.h b/source/blender/compositor/intern/COM_NodeOperation.h
index 9f113b60345..f507665bee3 100644
--- a/source/blender/compositor/intern/COM_NodeOperation.h
+++ b/source/blender/compositor/intern/COM_NodeOperation.h
@@ -62,9 +62,13 @@ enum class ResizeMode {
/** \brief Center the input image to the center of the working area of the node, no resizing
* occurs */
Center = NS_CR_CENTER,
- /** \brief The bottom left of the input image is the bottom left of the working area of the node,
- * no resizing occurs */
+ /** No resizing or translation. */
None = NS_CR_NONE,
+ /**
+ * Input image is translated so that its bottom left matches the bottom left of the working area
+ * of the node, no resizing occurs.
+ */
+ Align = 100,
/** \brief Fit the width of the input image to the width of the working area of the node */
FitWidth = NS_CR_FIT_WIDTH,
/** \brief Fit the height of the input image to the height of the working area of the node */
@@ -381,6 +385,9 @@ class NodeOperation {
return m_id;
}
+ float get_constant_value_default(float default_value);
+ const float *get_constant_elem_default(const float *default_elem);
+
const NodeOperationFlags get_flags() const
{
return flags;
@@ -507,18 +514,9 @@ class NodeOperation {
}
virtual void deinitExecution();
- void set_canvas(const rcti &canvas_area)
- {
- if (!this->flags.is_canvas_set) {
- canvas_ = canvas_area;
- flags.is_canvas_set = true;
- }
- }
-
- const rcti &get_canvas() const
- {
- return canvas_;
- }
+ void set_canvas(const rcti &canvas_area);
+ const rcti &get_canvas() const;
+ void unset_canvas();
/**
* \brief is this operation the active viewer output
@@ -575,12 +573,12 @@ class NodeOperation {
unsigned int getWidth() const
{
- return BLI_rcti_size_x(&canvas_);
+ return BLI_rcti_size_x(&get_canvas());
}
unsigned int getHeight() const
{
- return BLI_rcti_size_y(&canvas_);
+ return BLI_rcti_size_y(&get_canvas());
}
inline void readSampled(float result[4], float x, float y, PixelSampler sampler)
@@ -677,6 +675,7 @@ class NodeOperation {
void addInputSocket(DataType datatype, ResizeMode resize_mode = ResizeMode::Center);
void addOutputSocket(DataType datatype);
+ /* TODO(manzanilla): to be removed with tiled implementation. */
void setWidth(unsigned int width)
{
canvas_.xmax = canvas_.xmin + width;
@@ -687,6 +686,7 @@ class NodeOperation {
canvas_.ymax = canvas_.ymin + height;
this->flags.is_canvas_set = true;
}
+
SocketReader *getInputSocketReader(unsigned int inputSocketindex);
NodeOperation *getInputOperation(unsigned int inputSocketindex);
diff --git a/source/blender/compositor/intern/COM_NodeOperationBuilder.cc b/source/blender/compositor/intern/COM_NodeOperationBuilder.cc
index 3791d05602d..acb7f61f6dd 100644
--- a/source/blender/compositor/intern/COM_NodeOperationBuilder.cc
+++ b/source/blender/compositor/intern/COM_NodeOperationBuilder.cc
@@ -33,6 +33,7 @@
#include "COM_SetValueOperation.h"
#include "COM_SetVectorOperation.h"
#include "COM_SocketProxyOperation.h"
+#include "COM_TranslateOperation.h"
#include "COM_ViewerOperation.h"
#include "COM_WriteBufferOperation.h"
@@ -448,9 +449,19 @@ void NodeOperationBuilder::determine_canvases()
Vector<Link> convert_links;
for (const Link &link : m_links) {
if (link.to()->getResizeMode() != ResizeMode::None) {
- NodeOperation &from_op = link.from()->getOperation();
- NodeOperation &to_op = link.to()->getOperation();
- if (from_op.getWidth() != to_op.getWidth() || from_op.getHeight() != to_op.getHeight()) {
+ const rcti &from_canvas = link.from()->getOperation().get_canvas();
+ const rcti &to_canvas = link.to()->getOperation().get_canvas();
+
+ bool needs_conversion;
+ if (link.to()->getResizeMode() == ResizeMode::Align) {
+ needs_conversion = from_canvas.xmin != to_canvas.xmin ||
+ from_canvas.ymin != to_canvas.ymin;
+ }
+ else {
+ needs_conversion = !BLI_rcti_compare(&from_canvas, &to_canvas);
+ }
+
+ if (needs_conversion) {
convert_links.append(link);
}
}
diff --git a/source/blender/compositor/intern/COM_SharedOperationBuffers.cc b/source/blender/compositor/intern/COM_SharedOperationBuffers.cc
index 7e0486b0f54..55153bd4f0a 100644
--- a/source/blender/compositor/intern/COM_SharedOperationBuffers.cc
+++ b/source/blender/compositor/intern/COM_SharedOperationBuffers.cc
@@ -76,9 +76,17 @@ void SharedOperationBuffers::register_read(NodeOperation *read_op)
/**
* Get registered areas given operation needs to render.
*/
-blender::Span<rcti> SharedOperationBuffers::get_areas_to_render(NodeOperation *op)
+Vector<rcti> SharedOperationBuffers::get_areas_to_render(NodeOperation *op,
+ const int offset_x,
+ const int offset_y)
{
- return get_buffer_data(op).render_areas.as_span();
+ Span<rcti> render_areas = get_buffer_data(op).render_areas.as_span();
+ Vector<rcti> dst_areas;
+ for (rcti dst : render_areas) {
+ BLI_rcti_translate(&dst, offset_x, offset_y);
+ dst_areas.append(std::move(dst));
+ }
+ return dst_areas;
}
/**
diff --git a/source/blender/compositor/intern/COM_SharedOperationBuffers.h b/source/blender/compositor/intern/COM_SharedOperationBuffers.h
index f7763cd8ae4..4461ba75cbe 100644
--- a/source/blender/compositor/intern/COM_SharedOperationBuffers.h
+++ b/source/blender/compositor/intern/COM_SharedOperationBuffers.h
@@ -53,7 +53,7 @@ class SharedOperationBuffers {
bool has_registered_reads(NodeOperation *op);
void register_read(NodeOperation *read_op);
- blender::Span<rcti> get_areas_to_render(NodeOperation *op);
+ Vector<rcti> get_areas_to_render(NodeOperation *op, int offset_x, int offset_y);
bool is_operation_rendered(NodeOperation *op);
void set_rendered_buffer(NodeOperation *op, std::unique_ptr<MemoryBuffer> buffer);
MemoryBuffer *get_rendered_buffer(NodeOperation *op);