[Bf-blender-cvs] [1662bf8ebf5] compositor-full-frame: Compositor: Initial support for canvas compositing

Manuel Castilla noreply at git.blender.org
Fri Aug 27 00:50:35 CEST 2021


Commit: 1662bf8ebf5aacf577e091dbbbb3b6a0fd53ee56
Author: Manuel Castilla
Date:   Thu Aug 26 18:54:51 2021 +0200
Branches: compositor-full-frame
https://developer.blender.org/rB1662bf8ebf5aacf577e091dbbbb3b6a0fd53ee56

Compositor: Initial support for canvas compositing

===================================================================

M	source/blender/compositor/intern/COM_Converter.cc
M	source/blender/compositor/intern/COM_FullFrameExecutionModel.cc
M	source/blender/compositor/intern/COM_FullFrameExecutionModel.h
M	source/blender/compositor/intern/COM_MemoryBuffer.cc
M	source/blender/compositor/intern/COM_MemoryBuffer.h
M	source/blender/compositor/intern/COM_NodeOperation.cc
M	source/blender/compositor/intern/COM_NodeOperation.h
M	source/blender/compositor/intern/COM_NodeOperationBuilder.cc
M	source/blender/compositor/intern/COM_SharedOperationBuffers.cc
M	source/blender/compositor/intern/COM_SharedOperationBuffers.h
M	source/blender/compositor/nodes/COM_BoxMaskNode.cc
M	source/blender/compositor/nodes/COM_EllipseMaskNode.cc
M	source/blender/compositor/nodes/COM_ScaleNode.cc
M	source/blender/compositor/nodes/COM_TranslateNode.cc
M	source/blender/compositor/operations/COM_BokehBlurOperation.cc
M	source/blender/compositor/operations/COM_CalculateMeanOperation.cc
M	source/blender/compositor/operations/COM_CropOperation.cc
M	source/blender/compositor/operations/COM_MapUVOperation.cc
M	source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cc
M	source/blender/compositor/operations/COM_PreviewOperation.cc
M	source/blender/compositor/operations/COM_RotateOperation.cc
M	source/blender/compositor/operations/COM_RotateOperation.h
M	source/blender/compositor/operations/COM_ScaleOperation.cc
M	source/blender/compositor/operations/COM_ScaleOperation.h
M	source/blender/compositor/operations/COM_TonemapOperation.cc
M	source/blender/compositor/operations/COM_TransformOperation.cc
M	source/blender/compositor/operations/COM_TranslateOperation.cc
M	source/blender/compositor/operations/COM_TranslateOperation.h
M	source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc

===================================================================

diff --git a/source/blender/compositor/intern/COM_Converter.cc b/source/blender/compositor/intern/COM_Converter.cc
index 2958e494b55..9a1b894c2c4 100644
--- a/source/blender/compositor/intern/COM_Converter.cc
+++ b/source/blender/compositor/intern/COM_Converter.cc
@@ -463,7 +463,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();
@@ -473,13 +475,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;
@@ -514,63 +515,68 @@ 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);
-    }
+  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;
-    }
-    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);
+    unsigned int resolution[2] = {fromOperation->getWidth(), fromOperation->getHeight()};
+    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);
+  }
 
-    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;
+  }
+  const float addX = doCenter ? (toWidth - fromWidth) / 2.0f : 0.0f;
+  const float addY = doCenter ? (toHeight - fromHeight) / 2.0f : 0.0f;
+  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 66d34e58a3d..1d429a5e229 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(

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list