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/COM_Converter.cc
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/COM_Converter.cc')
-rw-r--r--source/blender/compositor/intern/COM_Converter.cc118
1 files changed, 65 insertions, 53 deletions
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