Blender  V2.93
COM_BoxMaskNode.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #include "COM_BoxMaskNode.h"
20 #include "COM_BoxMaskOperation.h"
21 #include "COM_ExecutionSystem.h"
22 
23 #include "COM_ScaleOperation.h"
24 #include "COM_SetValueOperation.h"
25 
26 namespace blender::compositor {
27 
28 BoxMaskNode::BoxMaskNode(bNode *editorNode) : Node(editorNode)
29 {
30  /* pass */
31 }
32 
34  const CompositorContext &context) const
35 {
36  NodeInput *inputSocket = this->getInputSocket(0);
37  NodeOutput *outputSocket = this->getOutputSocket(0);
38 
39  BoxMaskOperation *operation;
40  operation = new BoxMaskOperation();
41  operation->setData((NodeBoxMask *)this->getbNode()->storage);
42  operation->setMaskType(this->getbNode()->custom1);
43  converter.addOperation(operation);
44 
45  if (inputSocket->isLinked()) {
46  converter.mapInputSocket(inputSocket, operation->getInputSocket(0));
47  converter.mapOutputSocket(outputSocket, operation->getOutputSocket());
48  }
49  else {
50  /* Value operation to produce original transparent image */
51  SetValueOperation *valueOperation = new SetValueOperation();
52  valueOperation->setValue(0.0f);
53  converter.addOperation(valueOperation);
54 
55  /* Scale that image up to render resolution */
56  const RenderData *rd = context.getRenderData();
57  const float render_size_factor = context.getRenderPercentageAsFactor();
58  ScaleFixedSizeOperation *scaleOperation = new ScaleFixedSizeOperation();
59 
60  scaleOperation->setIsAspect(false);
61  scaleOperation->setIsCrop(false);
62  scaleOperation->setOffset(0.0f, 0.0f);
63  scaleOperation->setNewWidth(rd->xsch * render_size_factor);
64  scaleOperation->setNewHeight(rd->ysch * render_size_factor);
65  scaleOperation->getInputSocket(0)->setResizeMode(ResizeMode::None);
66  converter.addOperation(scaleOperation);
67 
68  converter.addLink(valueOperation->getOutputSocket(0), scaleOperation->getInputSocket(0));
69  converter.addLink(scaleOperation->getOutputSocket(0), operation->getInputSocket(0));
70  converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0));
71  }
72 
73  converter.mapInputSocket(getInputSocket(1), operation->getInputSocket(1));
74 }
75 
76 } // namespace blender::compositor
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
Overall context of the compositor.
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addOperation(NodeOperation *operation)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void addLink(NodeOperationOutput *from, NodeOperationInput *to)
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:210
void setResizeMode(ResizeMode resizeMode)
NodeOperationInput * getInputSocket(unsigned int index)
NodeOperationOutput * getOutputSocket(unsigned int index=0)
NodeOutput are sockets that can send data/input.
Definition: COM_Node.h:258
NodeOutput * getOutputSocket(const unsigned int index=0) const
Definition: COM_Node.cc:108
bNode * getbNode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:82
NodeInput * getInputSocket(const unsigned int index) const
Definition: COM_Node.cc:113
@ None
The bottom left of the input image is the bottom left of the working area of the node,...